Ditutup

tic tac toe

tic tac toe game in c++ programming

//L1F11BSCS0260//USAMA AMJAD//SECTION=F//UNIVERSITY OF CENTERAL PUNJAB//PROJECT GAME TIC TAC TOE.........

#include <iostream.h>

#include <conio.h>

char square[10] = {'o','1','2','3','4','5','6','7','8','9'};//INITIALIZATION AND DECLARATION OF CHARATER ARRAY

int checkwin();//DECLARATION OF INT VARIABLE

void board();

int main()

{

int player = 1,i,choice;

char mark;

do

{

board();

player=(player%2)?1:2;

cout << "Player " << player << ", enter a number: ";

cin >> choice;

mark=(player == 1) ? 'T' : 'F';

if (choice == 1 && square[1] == '1')

square[1] = mark;

else if (choice == 2 && square[2] == '2')

square[2] = mark;

else if (choice == 3 && square[3] == '3')

square[3] = mark;

else if (choice == 4 && square[4] == '4')

square[4] = mark;

else if (choice == 5 && square[5] == '5')

square[5] = mark;

else if (choice == 6 && square[6] == '6')

square[6] = mark;

else if (choice == 7 && square[7] == '7')

square[7] = mark;

else if (choice == 8 && square[8] == '8')

square[8] = mark;

else if (choice == 9 && square[9] == '9')

square[9] = mark;

else

{

cout<<"Invalid move ";

player--;

getch();

}

i=checkwin();

player++;

}while(i==-1);

board();

if(i==1)

cout<<"==>\aPlayer "<<--player<<" win ";

else

cout<<"==>\aGame draw";

getch();

return 0;

}

/*********************************************

FUNCTION TO RETURN GAME STATUS

1 FOR GAME IS OVER WITH RESULT

-1 FOR GAME IS IN PROGRESS

O GAME IS OVER AND NO RESULT

**********************************************/

int checkwin()

{

if (square[1] == square[2] && square[2] == square[3])

return 1;

else if (square[4] == square[5] && square[5] == square[6])

return 1;

else if (square[7] == square[8] && square[8] == square[9])

return 1;

else if (square[1] == square[4] && square[4] == square[7])

return 1;

else if (square[2] == square[5] && square[5] == square[8])

return 1;

else if (square[3] == square[6] && square[6] == square[9])

return 1;

else if (square[1] == square[5] && square[5] == square[9])

return 1;

else if (square[3] == square[5] && square[5] == square[7])

return 1;

else if (square[1] != '1' && square[2] != '2' && square[3] != '3' && square[4] != '4' && square[5] != '5' && square[6] != '6' && square[7] != '7' && square[8] != '8' && square[9] != '9')

return 0;

else

return -1;

}

/*******************************************************************

FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK

********************************************************************/

void board()

{

cout << "\n\n\tTic Tac Toe\n\n";

cout << "Player 1 (T) - Player 2 (F)" << endl << endl;

cout << endl;

cout << " | | " << endl;

cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl;

cout << "_____|_____|_____" << endl;

cout << " | | " << endl;

cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl;

cout << "_____|_____|_____" << endl;

cout << " | | " << endl;

cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl;

cout << " | | " << endl << endl;

}

Kemahiran: .NET, Pengaturcaraan C, Pengaturcaraan C#, Pengaturcaraan C++, Visual Basic

Lihat lebih lanjut: programming tic tac toe, tic tac toe programming, project tic tac toe, visual basic game programming, variable programming, variable in programming, programming variable, programming board game, programming array, if else c programming, game in c++ programming, else if c programming, do while c programming, c programming if else, c programming char, char in c programming, char c programming, basic game programming, array programming, array in c programming, progress programming, h game, VOID, usama, tic-tac

Tentang Majikan:
( 0 ulasan ) Pakistan

ID Projek: #1591851

21 freelancers are bidding on average $274 for this job

hegazy

whats your problem man..

$250 USD dalam sehari
(9 Ulasan)
5.2
kevinxiaozi

Dear sir, I am strong in C++ programming especially in algorithm implementation. I have implemented Tic-Tac-Toe in C++ and I can do it high quality. I can show you my past code. Wait for your response Thank you Lagi

$250 USD dalam 0 hari
(19 Ulasan)
5.1
csharpdotnettech

sir i am an expert .Net, C# programmer(among Top 10% programmers at Odesk with 91% percentile) can view my profile [url removed, login to view]~~26186839692c4731 i have 100% completion rate with 5/5 rating(can vi Lagi

$250 USD dalam 2 hari
(12 Ulasan)
4.7
minhtridn2001

Hi! I can do it! Please accept my bid and I will finish it within 1 day

$250 USD dalam sehari
(17 Ulasan)
4.4
aleexaibi

salaam....!! I am confident to do this job .. :)

$250 USD dalam 0 hari
(13 Ulasan)
3.5
JohnBHarris

I am not quite sure what you require; are you looking for a fault in the code you have presented ? Or do you want the computer to be able to play against a person - ie. the computer is one of the player ? I would be Lagi

$250 USD dalam 5 hari
(2 Ulasan)
2.4
iDKr

*** SOLVED *** please check the message

$250 USD dalam sehari
(2 Ulasan)
2.0
ravinow

what's your problems?

$250 USD dalam 0 hari
(1 Ulasan)
1.8
azaryan

I have good experience in cpp and making project for others.

$250 USD dalam 2 hari
(0 Ulasan)
0.0
Sayeduzzaman

Assalamu Alaikum :) Please check the PM immediately... the code's waiting ... ;)

$251 USD dalam 0 hari
(0 Ulasan)
0.0
Shelly28

Can you please elaborate litle more that what exactly have to do in this.

$250 USD dalam sehari
(0 Ulasan)
0.0
webbydesignz

Hi Will fix it in 2 hours. Thanks

$250 USD dalam sehari
(0 Ulasan)
0.0
StuartWebber

I have many years of experience with c/c++.

$250 USD dalam sehari
(0 Ulasan)
0.0
imn001

Hi,I would like to do the job.

$250 USD dalam sehari
(0 Ulasan)
0.0
scrptexpert

Hi, I have been working in C++ since last 5 years, I can finish this thing in one hour.

$250 USD dalam sehari
(0 Ulasan)
0.0
truongminhsong

dear. I can do it completely.

$250 USD dalam sehari
(0 Ulasan)
0.0
MohanParamane

Hi, We are Pune (India) based company working since 1996. We will complete your work in time. We provide online support for software and customer satisfaction is our goal. See the private message box. Regards

$250 USD dalam 4 hari
(0 Ulasan)
0.0
saad090129

i am doing CS from FAST and i can make your game easily.

$250 USD dalam sehari
(0 Ulasan)
0.0
invisiblesteps

i love tic tac toe......

$250 USD dalam 5 hari
(0 Ulasan)
0.0
programmer2

Hello, all day long I create games, quality guaranted.

$250 USD dalam 5 hari
(0 Ulasan)
0.0