-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessErrHandler.cpp
More file actions
91 lines (87 loc) · 2.57 KB
/
Copy pathChessErrHandler.cpp
File metadata and controls
91 lines (87 loc) · 2.57 KB
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
// Bryan Liu (chl312), Dept. of Computing, Imperial College London
// ChessErrHandler.cpp - Implementation of ChessErrHandler
#include "pch.h"
#include "ChessErrHandler.hpp"
ChessErrHandler::ChessErrHandler() {
}
/* ChessErrHandler.printErr():
Print the error message w.r.t. given error number
*/
void ChessErrHandler::printErr(int errNo, Piece* piece, wstring sourceFileRank, wstring destFileRank)
{
UNREFERENCED_PARAMETER(piece);
UNREFERENCED_PARAMETER(sourceFileRank);
UNREFERENCED_PARAMETER(destFileRank);
switch (errNo) {
case DEST_EQ_SOURCE: {
//cout << "Skipping your move? You cannot move from "
// << sourceFileRank << " to " << sourceFileRank << "!" << endl;
break;
}
case SOURCE_OUTOF_BOUND: {
//cout << "You cannot move pieces which are not on the board!" << endl;
break;
}
case DEST_OUTOF_BOUND: {
//cout << "You cannot move the piece away from the board!" << endl;
break;
}
case INVALID_FILE_RANK: {
//cout << "Stop submitting rubbish! You can't progress in such way!"
// << endl;
break;
}
case MOVED_EMPTY_PIECE: {
//cout << "Playing Air Chess? There is nothing to move"
// << " at " << sourceFileRank << "!" << endl;
break;
}
case NOT_OWNER_TURN: {
//cout << "It is not " << piece->playerToString()
// << " turn to move! Be patient!" << endl;
break;
}
/* The following five cases have common heading, thus the implementation
of nested case statement to prevent duplicate code
*/
case ILLEGAL_MOVE_PATTERN:
case OBSTRUCTION_EN_ROUTE:
case FRIENDLY_AT_DEST:
case PAWN_ILLEGAL_CAPTURE_PATTERN:
case ALLOW_KING_IN_CHECK: {
//cout << "Illegal move for " << piece->toString()
// << " at " << sourceFileRank << ": ";
switch (errNo) {
case ILLEGAL_MOVE_PATTERN: {
//cout << "Have you even read the rules?" << endl;
break;
}
case OBSTRUCTION_EN_ROUTE: {
//cout << "Way to " << destFileRank << " is blocked dude." << endl;
break;
}
case FRIENDLY_AT_DEST: {
//cout << "You cannot force your friendlies at "
// << destFileRank << " out of their way!" << endl;
break;
}
case PAWN_ILLEGAL_CAPTURE_PATTERN: {
//cout << "Head-on collision is not allowed!" << endl;
break;
}
case ALLOW_KING_IN_CHECK: {
//cout << "Now go back and keep your King (or yourself) safe!" << endl;
break;
}
}
break;
}
case GAME_HAS_ENDED: {
//cout << "The game has ended! What are you still doing here?" << endl;
break;
}
default: {
//cout << "An unexpected error has occured. Please try again." << endl;
}
}
}