Пример #1
0
	bool Pieces::getIllegal()
	{
		Display screen;
		screen.menu();
		if(illegal)
			cout<< "You cannot move the piece like that, please move it again correctly ";
		Sleep(1800);
		screen.cls();
		return illegal;
	}
Пример #2
0
	void Play::action()
	{
		stdOut = GetStdHandle(STD_OUTPUT_HANDLE); // to able to manipulate colors
		SetConsoleTextAttribute(stdOut, BACKGROUND_BLUE | BACKGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
		iR = 0;
		tempIC = 0;
		
		do
		{
			whoseMove.displayWhoseTurn();
			
			cout << ", select the piece you would like to move: "; // input the piece that you want to move
			cin >> tempIC >> iR;
			screen.cls();

			actionValidator();
			count++;
		}while(count < 5);//while game is not StaleMate or CheckMate or Retire
	}
Пример #3
0
	void Play::actionValidator()
	{
		 fC = 0; // edited
		 iC = 0; // edited
		 fR = 0; // added tempIC variables
		 tempFC = 0;
		 error = false;
		 //illegal = false;
		//-----------
		Pieces unit;
		//-----------
		//error = unit.illegal;

		//edited
		if(tempIC == 'a')
			iC = 1;
		if(tempIC == 'b')
			iC = 2;
		if(tempIC == 'c')
			iC = 3;
		if(tempIC == 'd')
			iC = 4;
		if(tempIC == 'e')
			iC = 5;
		if(tempIC == 'f')
			iC = 6;
		if(tempIC == 'g')
			iC = 7;
		if(tempIC == 'h')
			iC = 8;

		//if client has selected an empty square, prompt an error and retry
		if(cCB[iC][iR] == EMPTY)
		{
			cout << "It's an empty square, please select a correct position\n\n";
			error = true; //will activate RETRY process located at the end of actionValidator function
		}

		if(!error)
		{
			
			screen.menu();
			cout << "Select the destination                      : "; // input the tempIC where you want to put the selected piece
			cin >> tempFC >> fR;
			screen.cls();

			if(tempFC == 'a')
				fC = 1;
			if(tempFC == 'b')
				fC = 2;
			if(tempFC == 'c')
				fC = 3;
			if(tempFC == 'd')
				fC = 4;
			if(tempFC == 'e')
				fC = 5;
			if(tempFC == 'f')
				fC = 6;
			if(tempFC == 'g')
				fC = 7;
			if(tempFC == 'h')
				fC = 8;

			
			pieceValue = cCB[iC][iR];
			
			whoseMove.checkTurn(pieceValue, iC, iR, fC, fR);
			illegal = whoseMove.getIllegal();

//			if(whoseMove.whiteTurn)
			//unit.king(iC, iR, fC, fR);//validates the unit movement before moving it
			
			//ILLEGAL CHOICES
			//==============================
			//if the client has chosen empty square
			if(error)
			{
				action();//retry for client
			}
			//if the client movement fails to comply with rules
			//illegal = unit.illegalMove();
			if(illegal)
			{
				action();//retry for client
			}
			//==============================

			// Search Engine, moves the pieces (simpler
			int tempNum;
			for(int r = 1; r <= 8; r++)
			{
				for(int c = 1; c <=8; c++)
				{
					if(c == iC && r == iR)
					{
						tempNum = cCB[iC][iR];
						cCB[c][r] = EMPTY;
						cCB[fC][fR] = tempNum;
						//continue;
					}	
				}
			}
			showChessBoard();
		}