Driving Behavioral Change for Information Management through Data-Driven Gree...
Include
1. #include <allegro.h>
BITMAP *xSprite;
BITMAP *oSprite;
int board[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0}; //This will be used to keep
//track of the Xs and Os
int curSquare = 0; //This will keep track of the current square
//the selector is on
int turn = 1; //This will keep track of whose turn it is
//1 Will be for X and 2 for O
int x = 0; //X and Y position of selector
int y = 0;
int tempX = 0; //holds temporary values used to clear selector
int tempY = 0;
void setupBoard(){ //This function will draw in the grid
acquire_screen();
line( screen, 200, 0, 200, 480, makecol( 255, 255, 255));
line( screen, 400, 0, 400, 480, makecol( 255, 255, 255));
line( screen, 0, 150, 680, 150, makecol( 255, 255, 255));
line( screen, 0, 300, 680, 300, makecol( 255, 255, 255));
rect( screen, x+1, y+1, x + 199, y + 149, makecol( 255, 255, 0));
release_screen();
}
void updateBoard(){ //draws in selector
rect( screen, tempX+1, tempY+1, tempX + 199, tempY + 149, makecol( 0, 0,
0));
rect( screen, x+1, y+1, x + 199, y + 149, makecol( 255, 255, 0));
rest(100);
}
void announceWinner(){ //Announces the winner
if( turn == 1){
textout_ex( screen, font, "X Wins!!!!", 300, 240,
makecol( 255, 0, 0), makecol(0, 0, 0));
} else {
textout_ex( screen, font, "O Wins!!!!", 300, 240, makecol(
255, 0, 0), makecol(0, 0, 0));
}
}
void checkWin(){ //checks for a winner