1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
if (i == 1)
{
Left = false;
}
else
{}
if (i == 2)
{
Middle = false;
}
else
{}
if (i == 3)
{
Right = false;
}
else
{}
//Scenario where player moves left//
if (Left)
{}
else
{
GameLogic MoveLeft;
MoveLeft.PlayerMoveLeft();
}
//Scenario where player moves middle//
if (Middle)
{}
else
{
GameLogic MoveMiddle;
MoveMiddle.PlayerMoveMiddle();
}
//Scenario where player moves right//
if (Right)
{}
else
{
GameLogic MoveRight;
MoveRight.PlayerMoveRight();
}
|
|
This is bizarrely formatted. Is that intentional?
Your logic, formatted, looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
if (i == 1)
{
Left = false;
}
else
{
// Nothing
}
if (i == 2)
{
Middle = false;
}
else
{
// Nothing
}
if (i == 3)
{
Right = false;
}
else
{
}
//Scenario where player moves left//
if (Left)
{
// Nothing
}
else
{
GameLogic MoveLeft;
MoveLeft.PlayerMoveLeft();
}
//Scenario where player moves middle//
if (Middle)
{
// Nothing
}
else
{
GameLogic MoveMiddle;
MoveMiddle.PlayerMoveMiddle();
}
//Scenario where player moves right//
if (Right)
{
// Nothing
}
else
{
GameLogic MoveRight;
MoveRight.PlayerMoveRight();
}
|
Are all of those blank if bodies intentional?
Some tips in no particular order:
- Don't just draw a hard-coded board. Separate your logic to draw the board, and plug in what is in each position, perhaps based on something like:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
enum class Piece {
Empty,
Rook1,
King1,
Rook2,
King2
};
// ...
Piece board[3][3] = {
{ Rook1, King1, Rook1 },
{ Rook2, Empty, Empty },
{ Empty, King2, Rook2 }
};
|
- Don't seed your RNG more than once, you'll just get the same numbers if the logic loops more than once a second.
- You define a class-scope variable called "i", which is a bad name to begin with, but then also make local i variables in your functions. Avoid using "i" as a variable except as simple for-loop counters.
- You never use any functionality from <Windows.h>, so don't include it. Doing so limits the ability of your code to compile on other platforms.