C++11

No description

fork
loading
Files
  • main.cpp
  • board.h
  • checkPiece.h
  • declarations.h
  • detYval.h
  • pieces.h
main.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
#include <iostream>
#include <cstdio> // getchar() and toupper()

#include "board.h"
#include "pieces.h"
#include "declarations.h"
#include "checkPiece.h"
#include "detYval.h"

int main(){
  createPieces();
  printBoard();
  while (GAMEOVER == false){
    std::cout << " enter the row, column and type of the piece you want to move(e.g. \"G1P\" means \"G1,\" Pawn): ";
    row = getchar();
    col = getchar();
    typ = getchar();
    getchar(); // catches newline (\n or \0) char
    row = toupper(row);
    int newRow = detYval(row);
    typ = toupper(typ);
    if (typ == 'K'){
      if (checkPieceK(col - 1, newRow) == failureCondK){
        std::cout << "There is no " << typ << " at that place!\n";
      }
      else if (checkPieceK(col - 1, newRow) == whiteKing){
        std::cout << "Enter the row and column of the place you want to move " << typ << " to(e.g. \"C1\"): ";
        row = getchar();
        col = getchar();
        getchar();
        newRow = detYval(row);
        board[whiteKing.getMY()][whiteKing.getMX()] = ' ';
        whiteKing.changeMXY(col - 1, newRow);
        board[whiteKing.getMY()][whiteKing.getMX()] = 'K';
      }
      else if (checkPieceK(col - 1, newRow) == blackKing){
        std::cout << "Enter the row and column of the place you want to move " << typ << " to(e.g. \"C1\"): ";
        row = getchar();
        col = getchar();
        getchar();
        newRow = detYval(row);
        board[blackKing.getMY()][blackKing.getMX()] = ' ';
        blackKing.changeMXY(col - 1, newRow);
        board[blackKing.getMY()][blackKing.getMX()] = 'K';
      }
    }

    GAMEOVER = true;
  }
}