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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include <iostream>
#include <ctype.h>
void fillBoard(int board[3][3]);
void printBoard(int board[3][3]);
void evaluate(int board[3][3], int sums[8]);
void translate(int board[3][3], int choice);
void step1(int board[3][3], int sums[], bool &turn);
void step2(int board[3][3], int sums[], bool &turn);
void step3(int board[3][3], bool &turn);
void step4(int board[3][3], int sums[], bool &turn);
void step5(int board[3][3], int sums[], bool &turn);
void trollWin (int board[3][3]);
void mywait(float seconds);
bool checkLose (int board[3][3], int sums[]);
char converter(int);
int main(){
int nums[3][3] = {}, sums[8] = {}, choice, turnCount=0;
bool win;
char first;
start:
turnCount=0;
win=false;
fillBoard(nums);
std::cout << "Do you want to go (f)irst or (s)econd or (q)uit? (You are X's): ";
std::cin >> first;
first=tolower(first);
std::cout << "\n";
if (first=='q') {
goto end;
}
if (first=='s') {
nums[1][1]=5;
}
if (first=='t') {
trollWin(nums);
}
while (win==false) {
bool turn=false;
printBoard(nums);
std::cout << "\nWhich space would you like to go in?: ";
std::cin >> choice;
turnCount++;
translate(nums, choice);
if (turnCount==4 && first=='s') {
std::cout << "\n\n\n";
printBoard(nums);
std::cout << "You tied! Better luck next time!\n\n\n\n";
goto start;
return 0;
}
if (turnCount==5) {
std::cout << "\n\n\n";
printBoard(nums);
std::cout << "You tied! Better luck next time!\n\n\n\n";
goto start;
return 0;
}
translate(nums, choice);
evaluate(nums, sums);
step1(nums, sums, turn);
if(turn==false)
step2(nums, sums, turn);
if(turn==false)
step3(nums, turn);
if(turn==false)
step4(nums, sums, turn);
if(turn==false)
step5(nums, sums, turn);
win=checkLose (nums, sums);
}
turnCount=0;
goto start;
end:
if (first=='q') {
std::cout << "Thanks for playing!";
}
if (first!='q')
std::cout << "I WON";
return 0;
}
|