Skip to content

Commit 207f7fb

Browse files
author
christianwheeler09
committed
Remove the canMove3 function
1 parent 4b1ba00 commit 207f7fb

File tree

8 files changed

+22
-42
lines changed

8 files changed

+22
-42
lines changed

classes/Pawn.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ export class Pawn extends ChessPiece {
7676
*/
7777
canMove(target, occSet) {
7878
if (super.canMove(target, occSet)) { //ask the parent class
79-
const CM2 = this.canMove2(target, occSet);//ask the pawn's specific rules for movement
80-
return this.canMove3(CM2);//publish the results
79+
return this.canMove2(target, occSet);//ask the pawn's specific rules for movement
8180
}
8281
//else super says no, you cannot move there
8382
return false;
@@ -95,7 +94,7 @@ export class Pawn extends ChessPiece {
9594
return true;//attack successful
9695
}
9796
//else not an attack move
98-
this.message = 'Error: for a pawn to move to an occupied square, it must be a forward diagonal move of distance 1.'
97+
this.setFeedback('Error: for a pawn to move to an occupied square, it must be a forward diagonal move of distance 1.');
9998
return false;
10099
}
101100
//else target square is empty
@@ -110,11 +109,11 @@ export class Pawn extends ChessPiece {
110109
return this.validatePath(path, occSet);//validate the path
111110
}
112111
//else not first move
113-
this.message = 'Error: a pawn may move 2 spaces forward, but only on its first move.';
112+
this.setFeedback('Error: a pawn may move 2 spaces forward, but only on its first move.');
114113
return false;
115114
}
116115
//else it is not allowed
117-
this.message = 'Error: for a pawn to move to an empty square, it must be a forward vertical move of distance 1 or 2.'
116+
this.setFeedback('Error: for a pawn to move to an empty square, it must be a forward vertical move of distance 1 or 2.');
118117
return false;
119118
}
120119
}

classes/bishop.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export class Bishop extends ChessPiece {
2121
*/
2222
canMove(target, occSet) {
2323
if (super.canMove(target, occSet)) { //ask the parent class
24-
const CM2 = this.canMove2(target);//ask the bishop's specific rules for movement
25-
return this.canMove3(CM2);//publish the results
24+
return this.canMove2(target, occSet);//ask the bishop's specific rules for movement
2625
}
2726
//else super says no, you cannot move there
2827
return false;
@@ -36,7 +35,7 @@ export class Bishop extends ChessPiece {
3635
canMove2(target, occSet) {
3736
const ordinalDir = SQUARE.isPathOrdinal(this.location, target);
3837
if (ordinalDir <= 0) { //if the direction is NOT ordinal
39-
this.message = 'The bishop must move in an ordinal direction: Northeast, Southeast, Southwest, or Northwest';
38+
this.setFeedback('The bishop must move in an ordinal direction: Northeast, Southeast, Southwest, or Northwest');
4039
return false;
4140
}
4241
//else path is ordinal

classes/chess_piece.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export class ChessPiece {
99
constructor(pieceID, location) {
1010
this.pieceID = pieceID;
1111
this.location = location;
12-
this.message = '';
1312
}
1413

1514
//getters
@@ -60,6 +59,7 @@ export class ChessPiece {
6059

6160
//for giving the user feedback on whether their move was successful
6261
setFeedback(text) {
62+
console.log(text);
6363
document.querySelector('#feedback').textContent = text;
6464
}
6565

@@ -118,20 +118,6 @@ export class ChessPiece {
118118
return true;
119119
}
120120

121-
/**
122-
*
123-
* @param {boolean} CM2 the result of calling the canMove2() function
124-
* @returns
125-
*/
126-
canMove3(CM2) {
127-
if (CM2) { //ask the result of canMove2
128-
return true; //we can move there
129-
}
130-
//else we cannot move there
131-
this.setFeedback(this.message); //tell the user the bad news
132-
return false;
133-
}
134-
135121
/**
136122
*
137123
* @param {string[]} path the path of squares that we want to travel on

classes/king.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export class King extends ChessPiece {
2121
*/
2222
canMove(target, occSet) {
2323
if (super.canMove(target, occSet)) { //ask the parent class
24-
const CM2 = this.canMove2(target);//ask the knight's specific rules for movement
25-
return this.canMove3(CM2);//publish the results
24+
return this.canMove2(target);//ask the knight's specific rules for movement
2625
}
2726
//else super says no, you cannot move there
2827
return false;
@@ -46,7 +45,7 @@ export class King extends ChessPiece {
4645
return true; //diagonal move, distance 1
4746
}
4847
//else dyAbs > 1
49-
this.message = 'You cannot move the king that far.';
48+
this.setFeedback('You cannot move the king that far.');
5049
return false; //not allowed
5150
}
5251
//else dxAbs !== 1
@@ -55,11 +54,11 @@ export class King extends ChessPiece {
5554
return true; //vertical move, distance 1
5655
}
5756
//else dyAbs !== 1, which means dyAbs > 1
58-
this.message = 'You cannot move the king that far.';
57+
this.setFeedback('You cannot move the king that far.');
5958
return false; //not allowed
6059
}
6160
//else dxAbs > 1
62-
this.message = 'You cannot move the king that far.';
61+
this.setFeedback('You cannot move the king that far.');
6362
return false; //not allowed
6463
}
6564
}

classes/knight.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ export class Knight extends ChessPiece {
4141
if(dyAbs === 2){
4242
return true;
4343
}
44-
this.message = 'For knight, if |DeltaX| === 1, then |DeltaY| must equal 2.';
44+
this.setFeedback('For knight, if |DeltaX| === 1, then |DeltaY| must equal 2.');
4545
return false;
4646
}
4747
if(dxAbs === 2){
4848
if(dyAbs === 1){
4949
return true;
5050
}
51-
this.message = 'For knight, if |DeltaX| === 2, then |DeltaY| must equal 1.';
51+
this.setFeedback('For knight, if |DeltaX| === 2, then |DeltaY| must equal 1.');
5252
return false;
5353
}
54-
this.message = 'A knight must move in an "L"-shaped pattern';
54+
this.setFeedback('A knight must move in an "L"-shaped pattern.');
5555
return false;
5656
}
5757
}

classes/queen.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export class Queen extends ChessPiece {
2121
*/
2222
canMove(target, occSet) {
2323
if (super.canMove(target, occSet)) { //ask the parent class
24-
const CM2 = this.canMove2(target, occSet);//ask the queen's specific rules for movement
25-
return this.canMove3(CM2);//publish the results
24+
return this.canMove2(target, occSet);//ask the queen's specific rules for movement
25+
//return this.canMove3(CM2);//publish the results
2626
}
2727
//else super says no, you cannot move there
2828
return false;
@@ -46,7 +46,7 @@ export class Queen extends ChessPiece {
4646
return this.validatePath(path, occupiedSquares);//validate the path
4747
}
4848
//else it is not allowed
49-
this.message = `You cannot move the queen to ${target}`;
49+
this.setFeedback(`You cannot move the queen to ${target}`);
5050
return false;
5151
}
5252
}

classes/rook.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export class Rook extends ChessPiece {
2121
*/
2222
canMove(target, occSet) {
2323
if (super.canMove(target, occSet)) { //ask the parent class
24-
const CM2 = this.canMove2(target, occSet);//ask the rook's specific rules for movement
25-
return this.canMove3(CM2);//publish the results
24+
return this.canMove2(target, occSet);//ask the rook's specific rules for movement
2625
}
2726
//else super says no, you cannot move there
2827
return false;
@@ -38,7 +37,7 @@ export class Rook extends ChessPiece {
3837
canMove2(target, occSet) {
3938
const cardinalDir = SQUARE.isPathCardinal(this.location, target);
4039
if (cardinalDir <= 0) { //if the direction is NOT cardinal
41-
this.message = 'The rook must move in a cardinal direction: North, East, South, or West';
40+
this.setFeedback('The rook must move in a cardinal direction: North, East, South, or West');
4241
return false;
4342
}
4443
//else path is cardinal

game_master.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class GameMaster {
2222
#whoseTurn = 'Light';
2323
#occupiedSquares = new Set();
2424

25+
//constructor
2526
constructor() {
2627
//make references for all the square IDs and put them in a set
2728
//A1 A2 A3... B1 B2 B3...
@@ -256,19 +257,16 @@ export class GameMaster {
256257

257258
//get the team
258259
const TEAM = document.querySelector('#spnPromoPawn').innerText[0];
259-
console.log(TEAM);
260-
261260
//get the type
262261
const TYPE = document.querySelector('#selPromo').value;
263-
console.log(TYPE);
264-
265262
// get the location
266263
const LOCATION = document.querySelector('#spnPromoLoc').innerText;
267-
264+
//find a number ID
268265
let numId = 2;//start out with some number ID
269266
while(this.#chessPieces.has(`${TEAM}${TYPE}${numId}`)) { //if this particular ID is taken
270267
numId++; //try a different number part of the ID
271268
}
269+
//create the piece ID from these three separate parts
272270
const pieceID = `${TEAM}${TYPE}${numId}`;
273271

274272
switch (TYPE) {

0 commit comments

Comments
 (0)