[code]
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<string>
using namespace std;
int Random(int low, int high){
return rand() % (high-low)+low;
}
/*
Hello there, here is the a code of a game called "Tic-Tac-Toe checkers, a game made by "Animo" that is a combination of tic-tac-toe
and checkers; where you place yours 3 token and the start moving the around (the game area its the onme used on tic-tac-toe, and
i was trying to emulate it but got stuck at the second part, where you start moving the tokens in order to win, and can't figure out
what is wrong.
Now for the actual code:
I used like 5 do-while loops, if loops, switch and other stuff, so it may seem a little messy but i'll comment it as much as is necessary,
*/
int main(){
srand(time(NULL)); //this is for the random
int lol=Random(1,5); //This is not being used
int op=0; //Its takes the spot that the Player1 enters
int to=0; //Here is the same as the one up but for Player 2
int E1=0; //It takes the "z" that the player wants to move (Later ill say "ficha" it just the same as the "z" you see here
int Sh=0; //This takes the place where the player1 wants his "z" to be moved on the part "2" of the game.
char* P1= "z"; //The token of player 1
char* P2= "x"; //Token of player 2
int N_of_P1=0; //In this game the players can only use 3 tokens so I made a do-while loop with those 2 variants to stop it, this one for player 1
int N_of_P2=0; //the same but this one for player 2
int ifplayer_wins=1; //Not mind this, is just being used to end the part 1 loop
bool Winner=false; //Not mind this, is just being used to end the part 2 loop, but is not ended so it does nothing
char* Blanks[9]; //An array for the spaces on the board
for(int x=0; x<9; x++){ //A for loop to assign the space to the blanks =" "
Blanks[x]=" ";
}
cout<<"1___2___3"<<endl; //It display the game board and show the numbers of the spots
cout<<"| / | ) |"<<endl;
cout<<"4---5---6"<<endl; // by the way the ")" used on the board are supposed to be "\" but those didn't show up.
cout<<"| ) | / |"<<endl;
cout<<"7---8---9"<<'\n'<<endl; //if you enter a letter it will crash
cout<<"Do not enter a letter or something different from a number, it will cause the program so crash and to your pc to explode"<<'\n'<<endl;
do{ //This is the first part loop and it holds another 2 do-while loops that lets the player 1 and 2 play.
do{ //PLayer 1
cout<<"PLayer 1 with ""z"", what spot do you wanna play?"<<'\n'<<endl;
cin>>op;
switch(op){
case 1:
if(Blanks[0]==" "){ //On those cases first it checks if the space (according to the array above and the board),
Blanks[0]="z"; //is free and, if it is, set to "z" (the token for P1) ITs the same for the rest
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 2:
if(Blanks[1]==" "){
Blanks[1]="z";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 3:
if(Blanks[2]==" "){
Blanks[2]="z";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 4:
if(Blanks[3]==" "){
Blanks[3]="z";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 5:
if(Blanks[4]==" "){
Blanks[4]="z";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 6:
if(Blanks[5]==" "){
Blanks[5]="z";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 7:
if(Blanks[6]==" "){
Blanks[6]="z";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 8:
if(Blanks[7]==" "){
Blanks[7]="z";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 9:
if(Blanks[8]==" "){
Blanks[8]="z";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
default:
cout<<"Sorry that spot is not legal, try again"<<'\n'<<endl;
continue;
}
cout<<Blanks[0]<<"___"<<Blanks[1]<<"___"<<Blanks[2]<<endl; //it display the board but now using the array
cout<<"| / | ) |"<<endl;
cout<<Blanks[3]<<"---"<<Blanks[4]<<"---"<<Blanks[5]<<endl;
cout<<"| ) | / |"<<endl;
cout<<Blanks[6]<<"---"<<Blanks[7]<<"---"<<Blanks[8]<<endl;
N_of_P1++; //This one adds 1 to N_of_P1 so when it gets to 3 it will stop
break;
}
while(N_of_P1!=3); //PLayer 1 ends
do{ //PLayer 2
cout<<"Player 2 with ""x"", what spot do you wanna play?"<<'\n'<<endl;
cin>>to;
switch(to){
case 1:
if(Blanks[0]==" "){
Blanks[0]="x";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 2:
if(Blanks[1]==" "){
Blanks[1]="x";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 3:
if(Blanks[2]==" "){
Blanks[2]="x";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 4:
if(Blanks[3]==" "){
Blanks[3]="x";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 5:
if(Blanks[4]==" "){
Blanks[4]="x";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 6:
if(Blanks[5]==" "){
Blanks[5]="x";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 7:
if(Blanks[6]==" "){
Blanks[6]="x";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 8:
if(Blanks[7]==" "){
Blanks[7]="x";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
case 9:
if(Blanks[8]==" "){
Blanks[8]="x";
}
else{
cout<<"Sorry this spot is already being used, choose another one"<<'\n'<<endl;
continue;
}
break;
default:
cout<<"Sorry that spot is not legal, try again"<<'\n'<<endl;
continue;
}
cout<<Blanks[0]<<"___"<<Blanks[1]<<"___"<<Blanks[2]<<endl;
cout<<"| / | ) |"<<endl;
cout<<Blanks[3]<<"---"<<Blanks[4]<<"---"<<Blanks[5]<<endl;
cout<<"| ) | / |"<<endl;
cout<<Blanks[6]<<"---"<<Blanks[7]<<"---"<<Blanks[8]<<endl;
N_of_P2++;
break;
}
while(N_of_P2!=3); //PLayer 2 ends
if(N_of_P1 && N_of_P2 == 3){ //Ignore this, it just make this do loop to end;
ifplayer_wins=2;
}
}
while(ifplayer_wins!=2); //Ends Part 1 loop
//Now, here's where the problem is.
do{ //Aqui es donde movemos las fichas //Here start the part 2
cout<<"Now that all of those shits are at the desk, lets start the real game"<<'\n'<<endl;
cout<<Blanks[0]<<"___"<<Blanks[1]<<"___"<<Blanks[2]<<endl;
cout<<"| / | ) |"<<endl;
cout<<Blanks[3]<<"---"<<Blanks[4]<<"---"<<Blanks[5]<<endl;
cout<<"| ) | / |"<<endl;
cout<<Blanks[6]<<"---"<<Blanks[7]<<"---"<<Blanks[8]<<endl;
do{
cout<<"Player 1, your turn. Enter the number of the ficha that you wanna move"<<'\n'<<endl;
cin>>E1;
cout<<"Now enter the spot where you wanna move it"<<'\n'<<endl;
cin>>Sh;
if(E1==1 && Sh==2 ||4){ //The E1 its the taken the player wanna move and Sh is the spot where he want to get that token to;
if(Sh==2 && Blanks[1]==" "){
Blanks[1]="z";
Blanks[0]=" ";
}
if(Sh==4&& Blanks[3]==" "){
Blanks[3]="z";
Blanks[0]=" ";
}
}
if(E1==2 && Sh==1 ||3||4||6||5){
if(Sh==1 && Blanks[0]==" "){
Blanks[0]="z";
Blanks[1]=" ";
}
if(Sh==3&& Blanks[2]==" "){
Blanks[2]="z";
Blanks[1]=" ";
}
if(Sh==4&& Blanks[3]==" "){
Blanks[3]="z";
Blanks[1]=" ";
}
if(Sh==5&& Blanks[4]==" "){
Blanks[4]="z";
Blanks[1]=" ";
}
if(Sh==6&& Blanks[5]==" "){
Blanks[5]="z";
Blanks[1]=" ";
}
}
if(E1==3 && Sh==2||6){
if(Sh==2 && Blanks[1]==" "){
Blanks[1]="z";
Blanks[2]=" ";
}
if(Sh==6 && Blanks[5]==" "){
Blanks[5]="z";
Blanks[2]=" ";
}
}
if(E1==4 && Sh==1||2||5||8||7){
if(Sh==1 && Blanks[0]==" "){
Blanks[0]="z";
Blanks[3]=" ";
}
if(Sh==2&& Blanks[1]==" "){
Blanks[1]="z";
Blanks[3]=" ";
}
if(Sh==5&& Blanks[4]==" "){
Blanks[4]="z";
Blanks[3]=" ";
}
if(Sh==7&& Blanks[6]==" "){
Blanks[6]="z";
Blanks[3]=" ";
}
if(Sh==8&& Blanks[7]==" "){
Blanks[7]="z";
Blanks[3]=" ";
}
}
if(E1==5 && Sh==2||4||6||8){
if(Sh==2 && Blanks[1]==" "){
Blanks[1]="z";
Blanks[4]=" ";
}
if(Sh==4&& Blanks[3]==" "){
Blanks[3]="z";
Blanks[4]=" ";
}
if(Sh==6&& Blanks[5]==" "){
Blanks[5]="z";
Blanks[4]=" ";
}
if(Sh==8&& Blanks[7]==" "){
Blanks[7]="z";
Blanks[4]=" ";
}
}
if(E1==6 && Sh==3||2||5||8||9){
if(Sh==2 && Blanks[1]==" "){
Blanks[1]="z";
Blanks[5]=" ";
}
if(Sh==3&& Blanks[2]==" "){
Blanks[2]="z";
Blanks[5]=" ";
}
if(Sh==5&& Blanks[4]==" "){
Blanks[4]="z";
Blanks[5]=" ";
}
if(Sh==8&& Blanks[7]==" "){
Blanks[7]="z";
Blanks[5]=" ";
}
if(Sh==9&& Blanks[8]==" "){
Blanks[8]="z";
Blanks[5]=" ";
}
}
if(E1==7 && Sh==4||8){
if(Sh==4 && Blanks[3]==" "){
Blanks[3]="z";
Blanks[6]=" ";
}
if(Sh==8 && Blanks[7]==" "){
Blanks[7]="z";
Blanks[6]=" ";
}
}
if(E1==8 && Sh==4||5||6||7||9){
if(Sh==4 && Blanks[3]==" "){
Blanks[3]="z";
Blanks[7]=" ";
}
if(Sh==5&& Blanks[4]==" "){
Blanks[4]="z";
Blanks[7]=" ";
}
if(Sh==6&& Blanks[5]==" "){
Blanks[5]="z";
Blanks[7]=" ";
}
if(Sh==7&& Blanks[6]==" "){
Blanks[6]="z";
Blanks[7]=" ";
}
if(Sh==9&& Blanks[8]==" "){
Blanks[8]="z";
Blanks[7]=" ";
}
}
if(E1==9 && Sh==6||8){
if(Sh==6 && Blanks[5]==" "){
Blanks[5]="z";
Blanks[8]=" ";
}
if(Sh==8 && Blanks[7]==" "){
Blanks[7]="z";
Blanks[8]=" ";
}
}
else{
cout<<"Sorry this spot is not legal"<<'\n'<<endl;
continue;
}
cout<<Blanks[0]<<"___"<<Blanks[1]<<"___"<<Blanks[2]<<endl;
cout<<"| / | ) |"<<endl;
cout<<Blanks[3]<<"---"<<Blanks[4]<<"---"<<Blanks[5]<<endl;
cout<<"| ) | / |"<<endl;
cout<<Blanks[6]<<"---"<<Blanks[7]<<"---"<<Blanks[8]<<endl;
}
while(true);
}
while(Winner==true); //Ends the part 2 loop
} //Ends main function
//dhgd
[/code]