-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
66 lines (60 loc) · 2.44 KB
/
Game.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
/*
* Game.cpp
*
* Created on: 2017-12-21
* Author: David (GitHub: DPigeon)
*/
#include "Board.h"
#include "Pawn.h"
#include "Player.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
//Variables
int i = 0;
string name, name2, fromCoords, toCoords;
char start, pawn;
cout<<"Player 1 enter your name please:"<<endl;
cin>>name;
Player P1(name);
cout<<"Player 2 enter your name please:"<<endl;
cin>>name2;
Player P2(name2);
cout<<"Welcome to DPigeon's chess Game, "<<name<<" and "<<name2<<" ! Press S to start a game."<<endl;
cin>>start;
if(start == 's' || start == 'S'){
Board B1("Chess Game");
Board Bcheck("");
Pawn P("Chess Pawns"); //to show the pawns
B1.Display();
cout<<"Its "<<P1.getName()<<"'s turn ! Type the pawn's character and its coordinate. Example P B1"<<endl;
cout<<"Then, type the coordinate that you want to move it to. Example: C1"<<endl;
cout<<P.pawns.nickname<<" are pawns, "<<P.rook.nickname<<" are towers, "<<P.knight.nickname<<" are Knights, "<<P.bishop.nickname<<" are Bishops, "<<P.queen.nickname<<" are Queens and "<<P.king.nickname<<" are Kings."<<endl;
cout<<P1.getName()<<" has the capital character pawns and "<<P2.getName()<<" has the lower character pawns at the bottom."<<endl;
do{
Bcheck = B1; //putting the board checking as same as original board
if(i%2 == 0){ //p1 plays first every even numbers
P1.setTurn(true);
P2.setTurn(false);
cout<<"It is "<<P1.getName()<<"'s turn !"<<endl;
} else {
P2.setTurn(false);
P2.setTurn(true);
cout<<"It is "<<P2.getName()<<"'s turn !"<<endl;
}
cin>>pawn>>fromCoords>>toCoords; //reads the pawn, its coords and the moving to coords
if( ( (pawn == P.pawns.nickname || pawn == P.rook.nickname || pawn == P.bishop.nickname || pawn == P.knight.nickname || pawn == P.queen.nickname || pawn == P.king.nickname) && P1.isTurn() ) || ( (pawn == P.pawns.nickname2 || pawn == P.rook.nickname2 || pawn == P.bishop.nickname2 || pawn == P.knight.nickname2 || pawn == P.queen.nickname2 || pawn == P.king.nickname2) && P2.isTurn() ) ) //checking if they play with the right pawns
B1.findPawnMove(pawn, fromCoords, toCoords); //changes board
else
cout<<"Please play with your right pawns !"<<endl;
if(B1 != Bcheck) //if the board is not the same as previous one, change turn
i++;
}while(!B1.checkMate()); //keep going until check mate
}
else {
cout<<"Terminating the game..."<<endl;
exit(1);
}
return 0;
}