Tic-Tac-Toe - Game Using C Programming Language


“Tic-Tac-Toe” is a simple game made by using computer programming language (C Language). Consisting of simple code and easy concept too, you can download this code by Clicking Here. The graphics used in this game is pretty simple and you can learn in no time.

 

How to download source code?

  • Click here for source code.
  • New window will open where there is a source code of this project. You can download that code.
  • Remember to run this code runs only in Turbo C++ compiler.

 

Demo of the game

Check out the following video for the demo of this project.


For more projects, source code and tutorial, SUBSCRBE to my YouTube channel.
 

 

Development platform

Computer programming language (C programming language) has been used to develop this project.

 

Compiler

Turbo C has been used as compiler. The compiler version for Turbo C that is used is 3.7.8.9 which is also the latest one.

 

Header files used

The header files used in this project are as follows :

  1. Conio
  2. Graphics
  3. Stdio

 

Library functions

The following library functions has been used

  1. Under conio header file :
    1. Clrscr
    2. Getch
  2. Under dos header file
    1. Delay
  3. Under graphics header file
    1. Arc
    2. Closegraph
    3. Floodfill
    4. Initgraph
    5. Line
    6. Outtextxy
    7. Setcolor
    8. Settextstyle
    9. Rectangle

 

Concepts used

Topics/ concepts of this language that you need to know for making this type of game :

  1. Array
  2. Function
    1. Function returning no value with no parameter
    2. Function returning value with parameter
  3. Looping statements
  4. For loop
  5. Do while loop
  6. Graphics


User-defined function

The following user-defined functions have been used:

  1. Newgame()
  2. Compare(int , int)

 

Logic Description

newgame()

This function, first of all, creates three arrays of sizes (two five and one nine), two arrays for storing the choices of first player and second player respectively and another for choices of both players combinedly. Initially set all three arrays with any number other than 1 to 9.

A loop is initiated that loops for ten times. This loop is also controlled by compare() function. This loop is terminated if values returned by compare function is other than 0. For odd loop count, it's turn for first player and for even count it's turn for second player.

After a determination of whose turn, the next step is to check if the choice given by players is valid. Validation of choice is done according to the number i.e. is choice number lies in between 1 to 9.

After a validation of choice, check if the new choice is already taken by any of the player. For this check the third array. And after validation, save choice in respective arrays. Then, call compare function which returns values among 0, 1 and 2.

After the loop has been executed for 10 times or the value returned by compare function is other than 0, the main loop is terminated. Then the final step is to determine which player is winner. If latest value returned by compare function is 0, game is draw, player 1 wins if returned value is 1 and player 2 wins if 2.


compare(int, int)

This function takes 2 arrays as parameter which are the arrays that stores the choices made by each players. This function simply returns the integer value which is either 0, 1 or 2. For that, it firstly checks the choices made by the first player and then choices made by second player.


For a returning value of 1 or 2, the choices made by the players must be of the form 1-2-3, 4-5-6, 7-8-9, 1-4-7, 2-5-8, 3-6-9, 1-5-9, 3-5-7. Remember that the order of three number can be jumbled which means it can be 1-2-3, 1-3-2, 2-1-3, 2-3-1, 3-1-2, or 3-2-1. If these numbers do not appear in two arrays, value returned by this function is 0.


No comments:

Post a Comment

Article Ad1