-
Notifications
You must be signed in to change notification settings - Fork 0
/
TicTacToe-Replay.cpp
120 lines (107 loc) · 2.72 KB
/
TicTacToe-Replay.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
int main(int argc, char** argv) {
char game_move;
bool game_input=false, exit_save=false, replay=true;
int game_number, current_position=1, number_of_moves=1;
string savestring, game, bracket_check, winner_check;
//game input
{
while(game_input==false)
{
system("CLS");
if(1==0)
{
A:
system("CLS");
cout<<"Game doesn't exitst in game folder. Try again.'\n";
}
cout<<"Input game number: ";
cin>> game_number;
savestring=".//saves//save" + to_string(game_number) + ".txt";
ifstream ulaz(savestring);
exit_save=ulaz.is_open();
exit_save=(exit_save and exit_save==ulaz.good());
if(exit_save==true)
{
system("CLS");
cout<<"Good input!\nYou move trough game with left and right arrow on keyboard.\nFor game replay press ENTER.";
while(getch()!=13){}
system("CLS");
game_input=true;
} else goto A;
}
ifstream ulaz(savestring);
getline(ulaz, game);
ulaz.close();
}
//Game control
{
while(replay==true)
{
//print
{
system("CLS");
cout<<endl<<" "<<game[current_position+0]<<"|"<<game[current_position+2]<<"|"<<game[current_position+4]<<endl;
cout<<" "<<"-+-+-\n";
cout<<" "<<game[current_position+6]<<"|"<<game[current_position+8]<<"|"<<game[current_position+10]<<endl;
cout<<" "<<"-+-+-\n";
cout<<" "<<game[current_position+12]<<"|"<<game[current_position+14]<<"|"<<game[current_position+16]<<endl;
bracket_check=game[current_position+20];
if(bracket_check!="[")
{
cout<<"\nMove "<<number_of_moves;
}
else
{
cout<<"\nLast move and ";
winner_check=game[current_position+21];
if(winner_check=="=") cout<<"game ended with a draw.";
if(winner_check=="O" or winner_check=="X") cout<<"\""<<game[current_position+21]<<"\" won!";
cout<<"\nPress left arrow to go back or press ENTER for program ending.";
}
}
//moving
{
while(1==1)
{
getch();
game_move=getch();
bracket_check=game[current_position+20];
if(bracket_check!="["){
if(game_move==75)
{
if((current_position-21)>=0){
current_position-=21;
number_of_moves--;
break;
}
}
else if (game_move==77)
{
current_position+=21;
number_of_moves++;
break;
}
}
else if(game_move==75)
{
current_position-=21;
number_of_moves--;
break;
}
else if(game_move==13)
{
goto E;
}
}
}
}
}
E:
return 0;
}