-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
218 lines (201 loc) · 8.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html>
<head>
<title>The Game of War</title>
<link
rel="icon"
type="image/x-icon"
href="https://cdn-icons-png.flaticon.com/512/2162/2162846.png"
alt="flaticon"
width="30"
height="24"
/>
<meta charset="UTF-8" />
<link
rel="stylesheet"
href="node_modules/bootstrap/dist/css/bootstrap.css"
/>
<link rel="stylesheet" href="css/game.css" />
<script>
let suit = Array.from(Array(13)).map((element, index) => index + 1);
let deck = suit.concat(suit, suit, suit);
let shuffle = [...deck].sort(() => Math.random() - 0.5);
let handOne = shuffle.slice(0, 26);
let handTwo = shuffle.slice(26, 52);
function getDeck() {
document.getElementById("deck").innerHTML = deck;
console.log("Deck of cards: ", deck);
console.log("Shuffled deck... ", shuffle);
console.log("Hand one: ", handOne);
console.log("Hand two: ", handTwo);
}
let war = (handOne, handTwo) => {
let playerOneScore = 0;
let playerTwoScore = 0;
let intro = "War never changes...";
console.log("War never changes...");
document.getElementById("intro").innerHTML = intro;
const main = document.querySelector("main");
const scores = document.querySelector("scores");
let htmlString = "";
let htmlScore = "";
handOne.forEach((card, index) => {
const cardTwo = handTwo[index];
if (card === cardTwo) {
let response = "Tie, no points scored.";
htmlString += `<p class="response response-tie">${response}<p>`;
console.log("Tie, no points scored.");
} else if (card === 1) {
let response = `Player One Played: ${card}. Player Two Played: ${cardTwo}. Aces wins this round. Point to Player One.`;
htmlString += `<p class="response response-ace">${response}<p>`;
console.log(
`Player One Played: ${card}. Player Two Played: ${cardTwo}. Aces wins this round. Point to Player One.`
);
playerOneScore++;
} else if (cardTwo === 1) {
let response = `Player One Played: ${card}. Player Two Played: ${cardTwo}. Aces wins this round. Point to Player Two.`;
htmlString += `<p class="response response-ace">${response}<p>`;
console.log(
`Player One Played: ${card}. Player Two Played: ${cardTwo}. Aces wins this round. Point to Player Two.`
);
playerTwoScore++;
} else if (card > cardTwo && (card && cardTwo) != 1) {
let response = `Player One Played: ${card}. Player Two Played: ${cardTwo}. Player One Wins this round.`;
htmlString += `<p class="response response-playerOne">${response}<p>`;
console.log(
`Player One Played: ${card}. Player Two Played: ${cardTwo}. Player One Wins this round.`
);
playerOneScore++;
} else if (cardTwo > card && (card && cardTwo) != 1) {
let response = `Player One Played: ${card}. Player Two Played: ${cardTwo}. Player Two Wins this round.`;
htmlString += `<p class="response response-playerTwo">${response}<p>`;
console.log(
`Player One Played: ${card}. Player Two Played: ${cardTwo}. Player Two Wins this round.`
);
playerTwoScore++;
}
main.innerHTML = htmlString;
});
let pOneFinalScore = playerOneScore;
document.getElementById("pOneFinalScore").innerHTML = pOneFinalScore;
let pTwoFinalScore = playerTwoScore;
document.getElementById("pTwoFinalScore").innerHTML = pTwoFinalScore;
console.log("Final Scores: ", playerOneScore, playerTwoScore);
if (playerOneScore > playerTwoScore) {
console.log("Player One has won the war... but at what cost.");
let scoreSettled = "Player One has won the war... but at what cost.";
htmlScore += `<p class="alert alert-danger mx-2 border border-dark" role="alert">${scoreSettled}</p>`;
} else if (playerOneScore < playerTwoScore) {
console.log("Player Two has won the war... but at what cost.");
let scoreSettled = "Player Two has won the war... but at what cost.";
htmlScore += `<p class="alert alert-danger mx-2 border border-dark" role="alert">${scoreSettled}</p>`;
} else {
console.log("No one wins in war...");
let scoreSettled = "No one wins in war...";
htmlScore += `<p class="alert alert-danger mx-2 border border-dark" role="alert">${scoreSettled}</p>`;
}
scores.innerHTML = htmlScore;
};
</script>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-aFq/bzH65dt+w6FI2ooMVUpc+21e0SRygnTpmBvdBgSdnuTN7QbdgL+OapgHtvPp"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-qKXV1j0HvMUeCBQ+QVp7JcfGl760yU08IQ+GpUo5hlbpg51QRiuqHAJz8+BrxE/N"
crossorigin="anonymous"
></script>
</head>
<body>
<nav class="navbar navbar-expand-lg bg-dark" data-bs-theme="dark">
<div class="container-fluid">
<a class="navbar-brand" href="index.html"
><img
src="https://cdn-icons-png.flaticon.com/512/2162/2162846.png"
alt="flaticon"
width="30"
height="24"
class="d-inline-block align-text-top"
/></a>
<!-- Card Icon: https://www.flaticon.com/free-icon/poker-cards_2162846?term=card&page=1&position=64&origin=search&related_id=2162846 -->
<button
class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarNav"
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.html"
>Week9</a
>
</li>
<li class="nav-item">
<a class="nav-link" href="Pages/Contact/contact.html">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Pages/Game/game.html">Week10</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<h1 class="col-sm-12 m-2 border border-dark d-flex justify-content-center">The Game of War Simulation</h1>
<p class="col-sm-12 m-2 border-bottom border-dark d-flex justify-content-center">Let's play War!</p>
</div>
<div class="row d-flex justify-content-center my-2">
<div class="col-md-4 d-flex justify-content-center">
<button class="btn btn-warning m-2" onclick="war(handOne, handTwo)" style="background-color: aquamarine;">
Run Game
</button>
</div>
<div class="col-md-4 d-flex justify-content-center">
<button class="btn btn-danger m-2" onclick="window.location.reload()">
New Game
</button>
</div>
</div>
<div class="row d-flex justify-content-center">
<col>
<p id="intro" class="m-2 alert alert-danger" role="alert"></p>
<main class="bg-dark p-2 border border-dark"></main>
<div class="d-flex justify-content-center p-2 mt-2">
<table class="table">
<thead class="border border-dark">
<tr>
<th class="border border-dark">Players</th>
<th class="border border-dark">Player Score</th>
</tr>
</thead>
<tbody class="border border-dark">
<tr class="border border-dark">
<th>Player One</th>
<td id="pOneFinalScore" class="border border-dark"></td>
</tr>
<tr class="border border-dark">
<th>Player Two</th>
<td id="pTwoFinalScore" class="border border-dark"></td>
</tr>
</tbody>
</table>
</div>
<scores></scores>
</col>
</div>
</div>
</body>
</html>
<!-- https://www.youtube.com/watch?v=zIh16K8BN7k
Kootkot: I was looking for a way to display each iteration of the game in browser.
^their tutorial on doing just that was incredibly helpful. -->