Skip to content

Commit

Permalink
winner highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTip0 committed Aug 7, 2021
1 parent 792a4fc commit 48b3d03
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if (require('electron-squirrel-startup')) { // eslint-disable-line global-requir
const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 235,
height: 315,
width: 245,
height: 370,
});

// and load the index.html of the app.
Expand Down
12 changes: 7 additions & 5 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@1,700&display=swap');
body {
display: flex;
flex: content;
flex-direction: column;
flex-wrap: wrap;
align-items: center;
Expand All @@ -11,8 +10,8 @@ body {
display: grid;
grid: initial;
grid-auto-flow: row;
grid-template-rows: 50px 50px 50px;
grid-template-columns: 50px 50px 50px;
grid-template-rows: auto;
justify-items: center;
column-gap: 10px;
row-gap: 10px;
Expand Down Expand Up @@ -42,19 +41,22 @@ h1 {
color: crimson;
}
.restart {
grid-column-start: 2;
grid-row-start: 2;
grid-row-start: 4;
grid-column: 1 / span 3;
background: none;
border-width: 1px;
border-radius: 10px;
border-color: black;
box-shadow: 2px 2px 0px 0px rgba(0, 0, 0, 0.4);
width: 150px;
height: 50px;
width: 100%;
font-size: large;
font-family: "Roboto", sans-serif;
}
.restart:active {
box-shadow: none;
color: #000;
}
.winner {
background-color: rgb(109, 255, 145);
}
22 changes: 12 additions & 10 deletions src/tris.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var xTurn = true
var turno = 0
var finito = false
var scritta = ""
var winner = []
creaTavolo()

function gioco(numero) {
Expand All @@ -23,16 +24,15 @@ function gioco(numero) {

function creaTavolo() {
board.innerHTML = ""
if (!finito) {
for (let i = 0; i < 9; i++) {
let a = document.createElement("button")
a.addEventListener("click", ()=> gioco(i))
a.innerText = tavolo[i]
a.setAttribute("class", `button ${a.innerText == 'X' ? 'X': 'O'}`)
board.appendChild(a)
text.innerText = `Turn: ${xTurn ? "X" : "O"}`
}
} else {
for (let i = 0; i < 9; i++) {
let a = document.createElement("button")
a.addEventListener("click", ()=> gioco(i))
a.innerText = tavolo[i]
a.setAttribute("class", `button${a.innerText == 'X' ? ' X': a.innerText == 'O' ? ' O' : ''}${winner.includes(i) ? ' winner': ''}`)
board.appendChild(a)
text.innerText = `Turn: ${xTurn ? "X" : "O"}`
}
if (finito) {
text.innerText = scritta
var b = document.createElement("button")
b.innerText = "Restart"
Expand All @@ -59,6 +59,7 @@ function checkWin(){
if (act != "" && act == tavolo[value[1]] && act == tavolo[value[2]]) {
scritta = `The winner is ${act}`
finito = true
winner = value
}
});
}
Expand All @@ -68,5 +69,6 @@ function restart() {
turno = 0
finito = false
scritta = ""
winner = []
creaTavolo()
}

0 comments on commit 48b3d03

Please sign in to comment.