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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include "../../../Libraries/HXPA5v1_0_GameEngine.h"
int main()
{
Engine.HideConsole();
WINDOW win;
win.Initialize(400,300,"Lights Out", (Engine.GetScreenWidth()/2)-200,(Engine.GetScreenHeight()/2)-150);
win.Clear(Colors.Black);
GRID grid;
IMAGE img;
bool Cells[25];
grid.Initialize(32,32,5,5);
img.Create(32*5,32*5);
img.DefineCells();
//Build grid image
for (int i=0; i<grid.GetCellCount(); ++i)
{
Cells[i] = false;
}
//Set default starting game
Cells[12] = true;
bool gameRunning = true;
bool redraw = true;
while (gameRunning)
{
if (redraw == true)
{
//Color grid cells appropriately
img.Focus();
img.Clear(Colors.LightGray);
for (int i=0; i<grid.GetCellCount(); ++i)
{
img.Rect(i).Draw(Colors.Black);
if (Cells[i] == true) { img.Rect(i).Draw(Colors.Yellow,true); }
else { img.Rect(i).Draw(Colors.Black,false); }
}
//Return focus to the window and draw the grid image
win.Focus();
img.Draw(img.Rect(),Point(200-(img.GetWidth()/2),150-(img.GetHeight()/2)));
win.Refresh();
redraw = false;
}
//Prepare to receive user input
win.DoEvents();
int input = win.GetInput();
switch (input)
{
case WINDOW_CLOSE:
gameRunning = false;
break;
case MOUSE_DOWN_LEFT:
int aCell = grid.GetCell(Point(win.Mouse.Pt.X - (200-(img.GetWidth()/2)), win.Mouse.Pt.Y - (150-(img.GetHeight()/2))));
if (aCell == -1) break; //Invalid or out of bounds cell
Cells[aCell] = !Cells[aCell];
for (int j=NORTH; j<4; j++)
{
int neighbor = grid.GetNeighbor(aCell,static_cast<DIRECTION>(j));
if (neighbor != -1) Cells[neighbor] = !Cells[neighbor];
}
redraw = true;
break;
}
}
win.Destroy();
return 0;
}
|