Skip to content

Commit

Permalink
Add functioning win condition, stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill-the-dev committed Apr 12, 2022
1 parent f9c3dac commit f898a26
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 18 deletions.
4 changes: 2 additions & 2 deletions dist/main.js

Large diffs are not rendered by default.

28 changes: 20 additions & 8 deletions src/scripts/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class Board {
let posStr = JSON.stringify(pos);
let square = document.getElementById(posStr);
let child = square.firstChild;
setTimeout(() => square.removeChild(child), 2000);
setTimeout(() => square.removeChild(child), 1700);
}

placePiece(pos, piece) {
Expand All @@ -74,18 +74,30 @@ export default class Board {


// win condition capture
winStone(endPos, piece) {

checkWinStone(endPos, piece) {
}

// win condition shrine
winStream(endPos, piece) {
if (piece.type === "master" && piece.color === "blue" && pos === this.redShrine) {
this.winStream === "blue";
} else if (piece.type === "master" && piece.color === "red" && pos === this.blueShrine) {
this.winStream === "red";
checkWinStream() {
debugger;
let that = this;
let masterRed = document.querySelector(".red-master-piece");
let masterBlue = document.querySelector(".blue-master-piece");
console.log(masterBlue);
console.log(masterRed);
if (masterRed.parentElement.id === "[0,2]") {
return this.gameWin("red", "stream");
} else if (masterBlue.parentElement.id === "[4,2]") {
return this.gameWin("blue", "stream");
} else {
return console.log("nobody wins yet");
}
}
gameWin(colorStr, typeStr) {
// probably want to end game in game instead...
return console.log(`${colorStr} wins by ${typeStr}!`)
}

removePiece(pos) {
return (this.grid[pos[0]][pos[1]] = null);
Expand Down
45 changes: 37 additions & 8 deletions src/scripts/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Player from "./player";
export default class Game {
constructor() {
this.activeGame = false;
this.gameWin = false;
this.targetPos = null; // checkHighlight
this.targetCard = null;
this.targetMoves = null;
Expand Down Expand Up @@ -246,23 +247,49 @@ export default class Game {
that.deck.viewDealSwap(newDeckCard, deckCardEl);
}

// checkWinStream() {
// debugger;
// let that = this
// let masterRed = document.querySelector(".red-master-piece");
// let masterBlue = document.querySelector(".blue-master-piece");
// console.log(masterBlue)
// console.log(masterRed)
// if (masterRed.parentElement.id === "[0,2]") {
// return this.gameWin("red", "stream")
// } else if (masterBlue.parentElement.id === "[4,2]") {
// return this.gameWin("blue", "stream")
// }
// }

// checkWinStone() {

// }

// gameWin(colorStr, typeStr) {
// console.log(`${colorStr} wins by ${typeStr}!`)
// }

viewSwapTurn() {
let that = this;
// debugger
let playedCard = document.querySelector(".active-card");
let deckCard = document.querySelector("#back3");
let body = document.querySelector(".body");
let turnRedCircle = document.querySelector(".turn-red-circle")
let turnBlueCircle = document.querySelector(".turn-blue-circle")
let turnRedCircle = document.querySelector(".turn-red-circle");
let turnBlueCircle = document.querySelector(".turn-blue-circle");

debugger
// that.board.checkWinStone();
that.board.checkWinStream();

if (that.currentPlayerIdx === 0) {
// body.classList.remove("turn-blue")
body.classList.replace("turn-blue", "turn-red");
turnBlueCircle.style.visibility = 'hidden';
turnRedCircle.style.visibility = 'visible';

} else {
body.classList.replace("turn-red", "turn-blue")
body.classList.replace("turn-red", "turn-blue");
turnRedCircle.style.visibility = 'hidden';
turnBlueCircle.style.visibility = 'visible';

Expand All @@ -285,6 +312,8 @@ export default class Game {
}
});



// hide used cards
setTimeout(() => {
// flip used
Expand All @@ -300,13 +329,13 @@ export default class Game {
that.viewRemoveCardHighlight().then(
// swap turn @ board
that.swapTurn()
)
);
}, 600)
)
);
}, 600)
)
);
}, 600)
)
);
}, 1000);
}

Expand Down

0 comments on commit f898a26

Please sign in to comment.