Blogspot Dev C++

Here we will learn how to develop a tic tac toy multi player game in 小++ programming language with source code

Dev C++ Blogspot

Blogspot Dev C++

Itu merupakan perbedaan Borland C dan Dev-C yang mungkin saya ketahui / yang pernah saya alami dan perbedaan itu tidak keseluruhan yang saya ketahui. Sekian Untuk postingan kali ini semoga apa yang telah disampaikan dapat bermanfaat untuk kalian semua. Blog for the new and improved 2011-2015 fork of Bloodshed Dev-C. The official site of the Bloodshed Dev-C update, which is fully portable, and optionally ships with a 64bit compiler. The official site of the Bloodshed Dev-C update, which is fully portable, and optionally ships with a 64bit compiler. A free, portable, fast and simple C/C IDE. Best Way to Get Help Unfortunately, this project hasn't indicated the best way to get help.

Introduction
Let's assume you are a beginner in c++ programming language and looking for a detail guide with source code for tic tac toy game. This post will definitely help you to guide the complete process of development with explanation of code.

Game is developed in C++ code blocks IDE. It has the defined board size of 5X5 with two modes

1. Player vs Player. 2. Player vs Computer

C++ Concept used in this code are
  • Two dimensional Arrays (2D arrays)
  • Nested for loop

Code Explanation
In this game, there are total 5 global variables and 11 functions. Every function defines separate different action in the game so it will be helpful to maintain the code.

Variables
#define BoardSize 5
char Player1Move = 'X';
char Player2Move = 'O';
int p1 = 1;
int p2 = 2;

Functions
void menu();
void printBoard();
void input(int);
void player1();
void player2();
void p2p();
bool check();
bool defend(int, int, int);
bool attack();
void computerMoves(int);
void p2c();

2D Arrays
char board[BoardSize][BoardSize];int b[BoardSize][BoardSize] = { 0 }
How code works?
'board' and 'b' are two arrays board contains X(for player 1) and O(for player 2) on board. and b(used only in player Vs Computer game) contains 1(for player 1) and 2(for player 2) which helps to build logic for computer moves.

Global variables description
  1. BoardSize define the tic tac toe game board size(5) basically it is the size of array we use for board.
  2. player1Move” defines the symbol for player 1 which is 'X'
  3. player2Move” defines the symbol for player 2 which is 'O'
  4. p1 contains value for player 1, it will be 1 or 2
  5. p2 contain value for player 2, it will be 1 or 2
  6. p1 and p2 are the variables which help to build the logic for player to computer module. player will select as a 1st or 2nd turn


Functions description

Dev C++ Free Download


menu
simple menu function shows and manage three options
  1. player vs player
  2. player vs computer
  3. exit

according to the user choice call related function.

printBoard
print the 5-by-5 board on console.

input(int)
takes input from user in both cases player to player(form both players) and in player to computer(only form player).
Asks the user to enter row number and column number eg. 1 and 1 mean first cell of the board

player1
calls in the case of player to player for player 1 move simply clear the screen first and then print the marker sign of player and then call above described input function.

Blogspot De Secundaria

C++
player2
calls in the case of player to player for player 2 move simply clear the screen first and then print the marker sign of player and then call above described input function.

p2p

Dev C++ Programs


calls player1 and player 2 function one by one and calls check function after the every turn of the player e.g check function call when player1 place his/her marker on the board.

check
checks the status of game after every placement of the new marker this function will return true when all marks of same type are in any row, column or diagonally, otherwise this function will return false.

defend
this function is for computer Vs player move and called for computer move in this function computer will check the first all rows, columns and diagonals.

If the computer is having a possible winning move. Take the step and wins and also Checks if the player (opponent) have a possible winning move, takes a step as to block the player.

attack
(Attacking move) Take a step such that it have winning possibilities in future moves. place the marker in such row or column which contain computer's marker more.

computerMove
calls first defend function, check any possibility to win in this move, then check any possibility for the wining to player.

Dev C++ Pdf

If find any possibility in either case place the marker at that place for winning or block the user but if not find then return false and if defend function return false then call the attack function.

if any cell is empty which help the computer to win n future place marker at that point but if not found then place any cell empty in the board.

p2c
first asks the user to play as 1st or 2nd, according to the user choice call the first turn for computer or player after every turn call the check function to determine the winning of any player, and when board filled, draw the game and return to main menu.

C++ Source Code

Blogspot De Novelas Romanticas



Check more examples here C++ Simple Examples

Download Dev C

Read More...