gpt4 book ai didi

java - Android 等距棋盘

转载 作者:行者123 更新时间:2023-12-01 18:45:22 25 4
gpt4 key购买 nike

使用此代码,我用单个棋盘 bmpWhitebmpBlack 绘制了一个等距棋盘

for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if (white == true) {
color[i][j] = 0;
white = false;
}
else {
color[i][j] = 1;
white = true;
}
}
}
}
<小时/>
public void onDraw(Canvas canvas)
{
if (gameViewWidth == 0)
{
gameViewWidth = theGameView.getWidth();
gameViewHeight = theGameView.getHeight();
}
for (int xx=0; xx < 7; xx++)
{
for (int yy=0; yy < 7; yy++)
{
int x_start=(yy * 23);
int y_start=(gameViewHeight / 2) + (yy * 12);
int xx1=x_start + (xx * 23);
int yy1=y_start - (xx * 12);
if (color[xx][yy] == 0)
{
canvas.drawBitmap(bmpWhite, xx1, yy1, null);
}
else if (color [xx][yy] == 1)
{
canvas.drawBitmap(bmpBlack, xx1, yy1, null);
}
}
}

输出应该是一个具有交替颜色的棋盘(8x8)。但输出是这样的:

enter image description here

正如您所看到的,底部和顶部的最后两行颜色相同。我做错了什么?

最佳答案

你写的是:

for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if (white == true) {
color[i][j] = 0;
white = false;
}
else {
color[i][j] = 1;
white = true;
}
}
}

但看起来你有一个 8*8 的板。所以你必须写:

for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (white) {
color[i][j] = 0;
white = false;
}
else {
color[i][j] = 1;
white = true;
}
}
}

以及代码的第二部分

关于java - Android 等距棋盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17977195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com