Skip to content

Commit

Permalink
Add custom modal to board container
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill-the-dev committed Apr 13, 2022
1 parent f898a26 commit a7b774f
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 23 deletions.
6 changes: 3 additions & 3 deletions dist/main.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ <h1 class="title">Onitama</h1>
</div>
<!--grid layout for overall page, fr -->
<div id="board-container">
<div class="modal__win">
<div class="win-color"></div>
<div class="win-type"></div>
<div class="btn-restart">Play Again</div>
</div>
<div id="board">
<div class="square inactive" id="[4,0]"></div>
<div class="square inactive" id="[4,1]"></div>
Expand Down
6 changes: 0 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,10 @@ document.addEventListener("DOMContentLoaded", () => {
let modalView = document.querySelector(".modal__fill");
document.querySelector(".modal__fill").innerHTML = modalFill;

// const sanitizer = new Sanitizer();

// Modal How To on
addGlobalEventListener("click", "#how-to-play", e => {
e.preventDefault();
console.log("on");
// modalView.setHTML("Hellooooooo");
// modalView.innerHTML = modalFill;
// document.querySelector(".modal__fill").innerHTML = modalFill;
// document.querySelector(".modal__fill").innerHTML = modalFill;
modalHowTo.classList.add("modal__fill-active");
});

Expand Down
24 changes: 14 additions & 10 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), 1700);
setTimeout(() => square.removeChild(child), 800);
}

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


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

checkWinStone() {
let masterRed = document.querySelector(".red-master-piece");
let masterBlue = document.querySelector(".blue-master-piece");
!masterBlue ? ["Red", "Stone"] : false
!masterRed ? ["Blue", "Stone"] : false
}

// win condition shrine
Expand All @@ -87,17 +90,18 @@ export default class Board {
console.log(masterBlue);
console.log(masterRed);
if (masterRed.parentElement.id === "[0,2]") {
return this.gameWin("red", "stream");
return ["Red", "Stream"];
} else if (masterBlue.parentElement.id === "[4,2]") {
return this.gameWin("blue", "stream");
return ["Blue", "Stream"];
} else {
return console.log("nobody wins yet");
console.log("nobody wins yet");
return false
}
}
gameWin(colorStr, typeStr) {
// probably want to end game in game instead...
return console.log(`${colorStr} wins by ${typeStr}!`)
}
// gameWin(colorStr, typeStr) {
// console.log(`${colorStr} wins by ${typeStr}!`)
// return [true, colorStr, typeStr]
// }

removePiece(pos) {
return (this.grid[pos[0]][pos[1]] = null);
Expand Down
44 changes: 41 additions & 3 deletions src/scripts/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default class Game {
constructor() {
this.activeGame = false;
this.gameWin = false;
this.gameWinType = '';
this.gameWinColor = '';
this.targetPos = null; // checkHighlight
this.targetCard = null;
this.targetMoves = null;
Expand Down Expand Up @@ -217,6 +219,15 @@ export default class Game {
let piece = that.board.getPiece(posEnd); // Piece
// debugger
that.board.viewRemovePiece(posStart); // remove old pos

// WIN CHECK
debugger;
setTimeout(() => {
if (that.checkWin()) {
that.modalWin()
}
}, 1000);

// TURN SWAP
setTimeout(() => {
that.viewSwapTurn();
Expand Down Expand Up @@ -247,6 +258,36 @@ export default class Game {
that.deck.viewDealSwap(newDeckCard, deckCardEl);
}

checkWin() {
// returns [colorStr, typeStr] || false
if (that.board.checkWinStone() !== false ){
let winResults = that.board.checkWinStone()
this.activeGame = false
this.gameWin = true
this.gameWinType = winResults[1]
this.gameWinColor = winResults[0]
return true
}
if (that.board.checkWinStream() !== false) {
let winResults = that.board.checkWinStream()
this.activeGame = false
this.gameWin = true;
this.gameWinType = winResults[1];
this.gameWinColor = winResults[0];
return true
}
return false
}

modalWin() {
let modalWin = document.querySelector(".modal__win");
let winColor = `${this.gameWinColor} Wins!`
let winType = `Way of ${this.gameWinType}`
document.querySelector(".win-color").innerHTML = winColor;
document.querySelector(".win-type").innerHTML = winType;
modalWin.style.display = 'flex';
}

// checkWinStream() {
// debugger;
// let that = this
Expand Down Expand Up @@ -278,9 +319,6 @@ export default class Game {
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")
Expand Down
3 changes: 2 additions & 1 deletion src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ header {
align-self: center;
grid-column: 2 ;
grid-row: 3 ;
place-items: center;}
place-items: center;
}

#board {
display: grid;
Expand Down
25 changes: 25 additions & 0 deletions src/styles/modal_win.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.win-modal{
display: none;
flex-direction: column;
align-items: center;
justify-content: space-around;
}

// Board Styling:
// justify-self: center;
// align-self: center;
// grid-column: 2;
// grid-row: 3;
// place-items: center;

.win-color{

}

.win-type{

}

.btn-restart {

}

0 comments on commit a7b774f

Please sign in to comment.