//variables
bool GetSelectedSquare = 0;
bool UpdateBoard = 0;
bool isXTurn = true;
uint8_t chosenSquare = GetSelectedSquare; //some function that gets player's input
UpdateBoard (chosenSquare), isXTurn ? 'X' : 'O'; //check if is X's turn, if not use O
isXTurn = !isXTurn;
我遇到UpdateBoard
行的问题,检查其X的转弯是否给出了标题中的错误。
答案 0 :(得分:0)
是100%C ++在视觉工作室中使用它但是我想要做的是一个井字游戏,鼠标点击将在X和O之间交替。我可以发布我的整个代码但是那里有#s很多if语句因为这是我们老师希望我们现在写的方式。
#include <GameDev2D.h>
//Function prototypes
void Init();
void Shutdown();
void Update(double delta);
void Draw();
int MouseClicked(float x, float y);
//variables
int state[9] = {};
int Click[9] = {};
bool GetSelectedSquare = 0;
bool UpdateBoard = 0;
bool isXTurn = true;
//Entry point to the application
int WINAPI WinMain(HINSTANCE aCurrentInstance, HINSTANCE aPreviousInstance, LPSTR aCommandLine, int aCommandShow)
{
//Run GameDev2D, pass in the Init, Shutdown, Update and Draw methods
GameDev2D::Run(Init, Shutdown, Update, Draw);
return 0;
}
void Init()
{
GameDev2D::RegisterLeftMouseButtonPressedCallback(MouseClicked);
GameDev2D::LoadTexture("x");
GameDev2D::LoadTexture("o");
}
void Shutdown()
{
GameDev2D::UnloadTexture("x");
GameDev2D::UnloadTexture("o");
}
void Update(double aDelta)
{
}
void Draw()
{
//Guide lines
GameDev2D::DrawRectangle(256.0f, 0.0f, 10.0f, 768.0f, 0.0f, GameDev2D::Color::BlackColor(), true);
GameDev2D::DrawRectangle(512.0f, 0.0f, 10.0f, 768.0f, 0.0f, GameDev2D::Color::BlackColor(), true);
GameDev2D::DrawRectangle(0.0f, 256.0f, 768.0f, 10.0f, 0.0f, GameDev2D::Color::BlackColor(), true);
GameDev2D::DrawRectangle(0.0f, 512.0f, 768.0f, 10.0f, 0.0f, GameDev2D::Color::BlackColor(), true);
//Drawing in diffrent boxes
if (state[0] == 1)
{
GameDev2D::DrawTexture("x", 0.0f, 0.0f, 0.0f); // row 1 / 1
}
if (state[0] == 2)
{
GameDev2D::DrawTexture("o", 0.0f, 0.0f, 0.0f);
}
if (state[1] == 1)
{
GameDev2D::DrawTexture("x", 256.0f, 0.0f, 0.0f); // row 1 / 2
}
if (state[1] == 2)
{
GameDev2D::DrawTexture("o", 256.0f, 0.0f, 0.0f);
}
if (state[2] == 1)
{
GameDev2D::DrawTexture("x", 512.0f, 0.0f, 0.0f); // row 1 / 3
}
if (state[2] == 2)
{
GameDev2D::DrawTexture("o", 512.0f, 0.0f, 0.0f);
}
if (state[3] == 1)
{
GameDev2D::DrawTexture("x", 0.0f, 256.0f, 0.0f); // row 2 / 1
}
if (state[3] == 2)
{
GameDev2D::DrawTexture("o", 0.0f, 256.0f, 0.0f);
}
if (state[4] == 1)
{
GameDev2D::DrawTexture("x", 256.0f, 256.0f, 0.0f); // row 2 / 2
}
if (state[4] == 2)
{
GameDev2D::DrawTexture("o", 256.0f, 256.0f, 0.0f);
}
if (state[5] == 1)
{
GameDev2D::DrawTexture("x", 512.0f, 256.0f, 0.0f); // row 2 / 3
}
if (state[5] == 2)
{
GameDev2D::DrawTexture("o", 512.0f, 256.0f, 0.0f);
}
if (state[6] == 1)
{
GameDev2D::DrawTexture("x", 0.0f, 512.0f, 0.0f); // row 3 / 1
}
if (state[6] == 2)
{
GameDev2D::DrawTexture("o", 0.0f, 512.0f, 0.0f);
}
if (state[7] == 1)
{
GameDev2D::DrawTexture("x", 256.0f, 512.0f, 0.0f); // row 3 / 2
}
if (state[7] == 2)
{
GameDev2D::DrawTexture("o", 256.0f, 512.0f, 0.0f);
}
if (state[8] == 1)
{
GameDev2D::DrawTexture("x", 512.0f, 512.0f, 0.0f); // row 3 / 3
}
if (state[8] == 2)
{
GameDev2D::DrawTexture("o", 512.0f, 512.0f, 0.0f);
}
}
int MouseClicked(float x, float y)
{
uint8_t chosenSquare = GetSelectedSquare; //some function that gets player's input
UpdateBoard (chosenSquare), isXTurn ? 'X' : 'O'; //check if is X's turn, if not use O
isXTurn = !isXTurn; //alternate turns
{
if (x > 0 && x < 256 && y > 0 && y < 256)
{
state[0] = 1 || 2;
}
if (x > 256 && x < 512 && y > 0 && y < 256)
{
if (state[1] == 0)
{
state[1] = 1 || 2;
}
}
if (x > 512 && x < 768 && y > 0 && y < 256)
{
if (state[2] == 0)
{
state[2] = 1 || 2;
}
}
if (x > 0 && x < 256 && y > 256 && y < 512)
{
if (state[3] == 0)
{
state[3] = 1 || 2;
}
}
if (x > 256 && x < 512 && y > 256 && y < 512)
{
if (state[4] == 0)
{
state[4] = 1 || 2;
}
}
if (x > 512 && x < 768 && y > 256 && y < 512)
{
if (state[5] == 0)
{
state[5] = 1 || 2;
}
}
if (x > 0 && x < 256 && y > 512 && y < 768)
{
if (state[6] == 0)
{
state[6] = 1 || 2;
}
}
if (x > 256 && x < 512 && y > 512 && y < 768)
{
if (state[7] == 0)
{
state[7] = 1 || 2;
}
}
if (x > 512 && x < 768 && y > 512 && y < 768)
{
if (state[8] == 0)
{
state[8] = 1 || 2;
}
}
}
return 0;
}