-
Notifications
You must be signed in to change notification settings - Fork 0
/
toe.cpp
98 lines (87 loc) · 4.05 KB
/
toe.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//------------------------------------------------------------------
// File name: toe.cpp
// Assign ID: TICTACTOE
// Due Date: 01/17/13 at 11pm
//
// Purpose: Simulate a basic tic tac toe game
//
// Author: jelize Jonathan Elize
//
// -----------------------------------------------------------------
#include "toeFunctions.h"
int main()
{
//------------------------------------------------------------------------
// Declare and Initialize variables
//------------------------------------------------------------------------
int row, //row user chooses to place mark
column, //column user chooses to place mark
numMoves = 0; //number of moves user will make
bool endGame = false; // flag to know whether to end game
char mark, //mark user chooses
gStatus = 'n', //character that marks status of game
position[3][3] = {{' ', ' ', ' '}, //layout of board pieces
{' ', ' ', ' '},
{' ', ' ',' '}};
//-|----------------------------------------------------------------------
//-| Print the copyright notice declaring authorship.
//-|----------------------------------------------------------------------
cout << endl << "(c) 2017, jelize Jonathan Elize" << endl << endl;
//-|------------------------------------------------------------------------
//-| Intro
//-|------------------------------------------------------------------------
cout << "Moves: 0" << endl << endl;
statusDisplay(gStatus);
displayBoard(position);
//-|----------------------------------------------------------------------
//-| 1. Loop game until winner is found
//-|----------------------------------------------------------------------
while(!endGame)
{
//-|------------------------------------------------------------------
//-| 2. Status of game is now progress
//-|------------------------------------------------------------------
gStatus = 'p';
//-|------------------------------------------------------------------
//-| 3. Prompt for numMoves
//-|------------------------------------------------------------------
cout << "Moves: ";
cin >> numMoves;
//-|------------------------------------------------------------------
//-| 4. For loop to mark board and check for winner
//-|------------------------------------------------------------------
for(int i = 0; i < numMoves; i++)
{
//-|---------------------------------------------------------------
//-| 5. Input for mark, row, and column
//-|---------------------------------------------------------------
cin >> mark >> row >> column;
//-|---------------------------------------------------------------
//-| 6. Use function markBoard to mark board
//-|---------------------------------------------------------------
markBoard(position, row, column, mark);
//-|---------------------------------------------------------------
//-| 7. Use "check" functions to search for winner
//-|---------------------------------------------------------------
if(rowCheck(position, gStatus))
endGame = true;
else if(columnCheck(position, gStatus))
endGame = true;
else if(crossCheck(position, gStatus))
endGame = true;
//-|---------------------------------------------------------------
//-| 8. Determine status of game through statusDisplay function
//-|---------------------------------------------------------------
statusDisplay(gStatus);
//-|---------------------------------------------------------------
//-| 9. Use function displayBoard
//-|---------------------------------------------------------------
displayBoard(position);
}//for
}//while
//-|----------------------------------------------------------------------
//-| Print the copyright notice declaring authorship.
//-|----------------------------------------------------------------------
cout << endl << "(c) 2017, jelize Jonathan Elize" << endl << endl;
return 0;
}