Skip to content

Commit

Permalink
Improve game design
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgoll committed Jan 5, 2023
1 parent 202b046 commit 57ea79f
Show file tree
Hide file tree
Showing 6 changed files with 404 additions and 318 deletions.
108 changes: 78 additions & 30 deletions vanilla-refactor/css/index.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@500;600&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600&display=swap");

:root {
--dark-gray: #1a2a32;
--gray: #2e4756;
--turquoise: #3cc4bf;
--yellow: #f2b147;
--light-gray: #d3d3d3;
}

* {
Expand Down Expand Up @@ -54,7 +55,8 @@ button:hover {
}
}

/* Shared */
/* Shared utility classes */

.hidden {
display: none !important;
}
Expand All @@ -72,54 +74,100 @@ button:hover {
rgba(0, 0, 0, 0.3) 0px 7px 13px -3px, rgba(0, 0, 0, 0.2) 0px -3px 0px inset;
}

.border {
border: 1px solid rgba(211, 211, 211, 0.4) !important;
}

/* Game controls (symbols, current turn indicator, wipe score btn) */

.control-1,
.control-2,
.control-3 {
.turn {
align-self: center;
grid-column-start: 1;
grid-column-end: 3;
display: flex;
justify-content: center;
align-items: center;
gap: 5px;
gap: 20px;
}

.control-1 {
font-size: 30px;
@keyframes turn-icon-animation {
0% {
transform: scale(1);
}
25% {
transform: scale(1.4);
}
100% {
transform: scale(1);
}
}

.control-2 {
font-size: 12px;
font-weight: 600;
display: flex;
justify-content: space-around;
border-radius: 10px;
background-color: var(--gray);
white-space: nowrap;
.turn i {
font-size: 1.8rem;
margin-left: 10px;
animation: 0.6s ease-in-out turn-icon-animation;
}

.control-2 p:nth-child(2) {
font-size: 10px;
font-weight: 400;
color: rgba(255, 255, 255, 0.3);
@keyframes turn-text-animation {
0% {
opacity: 0;
transform: translateX(-20px);
}
100% {
opacity: 100%;
transform: translateX(0);
}
}

control-2 i {
font-size: 16px;
.turn p {
font-size: 14px;
animation: 0.6s ease-in-out turn-text-animation;
}

.control-3 {
border-radius: 10px;
color: white;
.menu {
position: relative;
}

.menu .items {
position: absolute;
z-index: 10;
top: 60px;
right: 0;
background-color: #203139;
border-radius: 2px;
padding: 10px;
}

.menu .items button {
background-color: transparent;
padding: 8px;
color: white;
}

.menu .items button:hover {
text-decoration: underline;
cursor: pointer;
}

.control-3:hover {
opacity: 90%;
.menu-btn {
width: 100%;
height: 100%;
display: flex;
justify-content: space-around;
align-items: center;
border-radius: 10px;
color: white;
background-color: rgba(211, 211, 211, 0.05);
border: 1px solid transparent;
}

.menu-btn:focus,
.menu-btn:hover {
background-color: rgba(211, 211, 211, 0.07);
}

/* Game board buttons */
.option {

.square {
height: 100%;
width: 100%;
background-color: var(--gray);
Expand All @@ -130,7 +178,7 @@ control-2 i {
font-size: 3rem;
}

.option:hover {
.square:hover {
cursor: pointer;
opacity: 90%;
}
Expand Down
72 changes: 39 additions & 33 deletions vanilla-refactor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,48 @@
<title>Vanilla Refactor</title>
</head>
<body>
<main class="grid">
<div class="control-1">
<i class="fa-solid fa-x turquoise"></i>
<i class="fa-solid fa-o yellow"></i>
</div>
<div class="control-2 shadow">
<div>
<p class="turquoise">Player 1</p>
<p>You're up!</p>
<main>
<div class="grid" data-id="grid">
<div class="turn" data-id="turn">
<i class="fa-solid fa-x turquoise"></i>
<p>Player 1, you're up!</p>
</div>
<i class="fa-solid fa-x turquoise circle-icon"></i>
</div>
<button class="control-3">Reset</button>

<!-- <i class="fa-solid fa-o yellow"></i> -->
<div id="1" class="option shadow"></div>
<div id="2" class="option shadow"></div>
<div id="3" class="option shadow"></div>
<div id="4" class="option shadow"></div>
<div id="5" class="option shadow"></div>
<div id="6" class="option shadow"></div>
<div id="7" class="option shadow"></div>
<div id="8" class="option shadow"></div>
<div id="9" class="option shadow"></div>
<div class="menu">
<button class="menu-btn" data-id="menu-button">
Actions
<i class="fa-solid fa-chevron-down"></i>
</button>

<div class="score shadow" style="background-color: var(--turquoise)">
<p>Player 1</p>
<span data-id="player1-stats">5W 2L</span>
</div>
<div class="score shadow" style="background-color: lightgrey">
<p>Ties</p>
<span data-id="ties">0</span>
</div>
<div class="score shadow" style="background-color: var(--yellow)">
<p>Player 2</p>
<span data-id="player2-stats">5W 2L</span>
<div class="items border hidden" data-id="menu-popover">
<button data-id="reset-btn">Reset</button>
<button data-id="new-round-btn">New Round</button>
</div>
</div>

<!-- <i class="fa-solid fa-o yellow"></i> -->
<div id="1" class="square shadow"></div>
<div id="2" class="square shadow"></div>
<div id="3" class="square shadow"></div>
<div id="4" class="square shadow"></div>
<div id="5" class="square shadow"></div>
<div id="6" class="square shadow"></div>
<div id="7" class="square shadow"></div>
<div id="8" class="square shadow"></div>
<div id="9" class="square shadow"></div>

<div class="score shadow" style="background-color: var(--turquoise)">
<p>Player 1</p>
<span data-id="player1-stats">5W 2L</span>
</div>
<div class="score shadow" style="background-color: var(--light-gray)">
<p>Ties</p>
<span data-id="ties">0</span>
</div>
<div class="score shadow" style="background-color: var(--yellow)">
<p>Player 2</p>
<span data-id="player2-stats">5W 2L</span>
</div>
</div>
</main>

Expand Down
65 changes: 60 additions & 5 deletions vanilla-refactor/js/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,64 @@
import Controller from "./controller.js";
import Store from "./store.js";
import View from "./view.js";

const store = new Store("game-state-key");
const view = new View();
const controller = new Controller(store, view);
const config = {
/**
* A possible improvement to the game would be to allow for 3+ players
* and a UI to show a leaderboard. This would require a refactor since
* our logic assumes there are only 2 possible players.
*/
player1: {
id: 1,
name: "Player 1",
iconClass: "fa-x",
colorClass: "turquoise",
},
player2: {
id: 2,
name: "Player 2",
iconClass: "fa-o",
colorClass: "yellow",
},
};

controller.init();
// MV* pattern
function init() {
// "Model"
const store = new Store("game-state-key");

// "View"
const view = new View();

/**
* "Controller" logic (event listeners + handlers)
*/
view.bindPlayerMoveEvent((squareId) => {
store.playerMove(squareId);
});

view.bindGameResetEvent(() => {
view.closeAll();
store.reset();
});

view.bindNewRoundEvent(() => {
view.closeAll();
store.newRound();
});

/**
* -----------------------------------------------------------------------
* IMPORTANT: This is where we listen for state changes. When the state
* changes, we re-render the entire application.
* -----------------------------------------------------------------------
*/
store.addEventListener("statechange", (event) => {
view.render(event.target); // event.target is the Store class instance
});

// Loads existing state from local storage
store.init(config);
}

// On window load, initialize app
window.addEventListener("load", () => init());
70 changes: 0 additions & 70 deletions vanilla-refactor/js/controller.js

This file was deleted.

Loading

0 comments on commit 57ea79f

Please sign in to comment.