Graphics With C: Explore The Unexplored
Graphics With C: Explore The Unexplored
The game will be a simple 2 player game. All the inputs will
be taken from keyboard by arrow keys & space.
The Code :
Explaination :
Global Variables :
Definations :
mx & my are defined to getmaxx()
(https://graphicswithc.wordpress.com/all-about-built-in-
graphics-functions/) & getmaxy()
(https://graphicswithc.wordpress.com/all-about-built-in-
graphics-functions/).
I will not reveal the use of d, s and f. Try playing with these
three attributes to see what they actually affect in program.
(Note that these three attributes are only used for displaying
grid).
Details of program :
After initializing the graphics mode & setting the text style
the control enters the game loop.
To abort the game at any time, pressing the ‘E’ key will do the
work!
Functions :
(https://graphicswithc.wordpress.com/2016/07/08/simple-tic-
tac-toe-with-c-graphics/screenshot-4/)
(https://graphicswithc.wordpress.com/2016/07/08/simple-tic-
tac-toe-with-c-graphics/screenshot-3/)
(https://graphicswithc.wordpress.com/2016/07/08/simple-tic-
tac-toe-with-c-graphics/screenshot-2/)
checkWin() : The function checks if any of the two players
has won the game or not. It returns 1 if any of the two
players win else returns 0. Note that the function recieves 3
integers sx, sy & player number. We simply check the win by
using two if statements, one check for all six horizontal &
vertical rows & columns while second if statement checks for
diagonals. Note that if true, the end() function is called which
prints the result & closes the graphmode.
Programs