tictactoe

tictactoe - /* * tictactoe.cpp * * * Created by Billups,...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /* * tictactoe.cpp * * * Created by Billups, Tanisha on 4/15/08. * Copyright 2008 __MyCompanyName__. All rights reserved. * */ #include <iostream> #include <iomanip> using namespace std; // Function Prototypes char TheBoard[3][3]; void SetBoard(); void DisplayBoard(); void Winner(); void Cat(); void Repeat(); int SetBoard(int, char); char PlayerOne[30]; char PlayerTwo[30]; char option; char yes; char no; int pos1 = 0; int pos2 = 0; int X = 0; int O = 0; char r; char c; int catwinnings = 0; int playercount = 1; // The Main Function int main(){ option = yes; cout << "Player 1: Please enter your name: "; cin >> PlayerOne; cout << endl; cout << "Player 2: Please enter your name: "; cin >> PlayerTwo; cout << endl; cout << PlayerOne << " your mark is X. " << endl; cout << PlayerTwo << " your mark is O. " << endl; SetBoard(); DisplayBoard(); cout << endl; while(option == yes){ Repeat(); } return 0; } // Function Definitions void SetBoard(){ TheBoard[0][0] = '1'; TheBoard[0][1] = '2'; TheBoard[0][2] = '3'; TheBoard[1][0] = '4'; TheBoard[1][1] = '5'; TheBoard[1][2] = '6'; TheBoard[2][0] = '7'; TheBoard[2][1] = '8'; TheBoard[2][2] = '9'; } int SetBoard(int position, char mark){ switch(position){ case 1: if(TheBoard[0][0] == '1'){ return 0; } else{ return 1; } break; case 2: if(TheBoard[0][1] = '2'){ return 0; } else{ return 2; } break; case 3: if(TheBoard[0][2] = '3'){ return 0; } else{ return 3; } break; case 4: if(TheBoard[1][0] = '4'){ return 0; } else{ return 4; } break; case 5: if(TheBoard[1][1] = '5'){ return 0; } else{ return 5; } break; case 6: if(TheBoard[1][2] = '6'){ return 0; } else{ return 6; } break; case 7: if(TheBoard[2][0] = '7'){ return 0; } else{ return 7; } break; case 8: if(TheBoard[2][1] = '8'){ return 0; } else{ return 8; } break; case 9: if(TheBoard[2][2] = '9'){ return 0; } else{ return 9; } break; } } void DisplayBoard(){ cout << endl; cout << TheBoard[0][0] << "|" << TheBoard[0][1] << "|" << TheBoard[0][2] << endl; cout << "-+-+-" << endl; cout << TheBoard[1][0] << "|" << TheBoard[1][1] << "|" << TheBoard[1][2] << endl; cout << "-+-+-" << endl; cout << TheBoard[2][0] << "|" << TheBoard[2][1] << "|" << TheBoard[2][2] << endl; } void Winner(){ char option1 = 'y'; int row, column, width = 9; if ((TheBoard[0][0] == 'X' && TheBoard[0][1] == 'X' && TheBoard[0][2] == 'X')|| (TheBoard[1][0] == 'X' && TheBoard[1][1] == 'X' && TheBoard[1][2] == 'X')|| (TheBoard[2][0] == 'X' && TheBoard[2][1] == 'X' && TheBoard[2][2] == 'X')|| (TheBoard[0][0] == 'X' && TheBoard[1][0] == 'X' && TheBoard[2][0] == 'X')|| (TheBoard[0][1] == 'X' && TheBoard[1][1] == 'X' && TheBoard[2][1] == 'X')|| (TheBoard[0][2] == 'X' && TheBoard[1][2] == 'X' && TheBoard[2][2] == 'X')||...
View Full Document

This document was uploaded on 05/01/2011.

Page1 / 10

tictactoe - /* * tictactoe.cpp * * * Created by Billups,...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online