-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGamePlay_setup_Values.html
182 lines (162 loc) · 5.77 KB
/
GamePlay_setup_Values.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>🏴‍☠️ Complete Javascripts Course</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" />
<style>
.btn {
background-color: red;
text-align: center;
border-radius: 10px;
font-size: 1em;
padding: 15px;
color: white;
}
.btn:hover {
background-color: crimson;
}
.gameTile {
display: inline-block;
padding: 3px;
}
.flipImage {
max-width: 150px;
}
</style>
</head>
<body>
<br />
<br />
<center>
<!-- <input type="text" id="item"> -->
<br />
<div id="wrapper">📃 🏪 👾</div>
<br />
<div id="output">Complete JavaScript Course </div>
<div id="wrapper">
<div id="start" class="btn">Start</div>
<div id="score"></div>
<div id="message"></div>
<div id="gameboard"></div>
</div>
<!-- <input type="button" class="btn btn-outline-warning" onClick="lookUp()" value="Find Text"> -->
<br /><br />
</center>
<script>
var playLockout = false;
var gamePlay = false;
var tileImages = [],
tileArray = [],
tfo = [];
var cardFlipped = -1;
var timer;
var sb = document.getElementById('start');
var message = document.getElementById('message');
var score = document.getElementById('score');
var gameBoard = document.getElementById('gameboard');
sb.addEventListener('click', startGame);
function startGame() {
// hide start button
sb.style.display = 'none';
message.innerHTML = "Its working" + gamePlay;
if (!gamePlay) {
gamePlay = true;
buildArray();
tileArray = tileImages.concat(tileImages);
shuffleArray(tileArray);
buildBoard();
}
}
function buildBoard() {
var html = "";
var x = 0;
tileArray.forEach(function (ele) {
x++;
html += '<div class="gameTile">';
html += '<img id="cardz' + x +
'" src="http://via.placeholder.com/250/000000/ffffff?text=click" onclick="pickCard(' + (x -
1) + ',this)" class="flipImage"></div>';
});
gameBoard.innerHTML = html;
}
function pickCard(i, t) {
console.log(event.target);
// not in array of flipped over
// not locked out
if (!playLockout && !isinArray(t.id, tfo)) {
if (cardFlipped >= 0) {
cardFlip(i, t);
playLockout = true;
if (checkSrc(tfo[tfo.length - 1]) == checkSrc(tfo[tfo.length - 2])) {
message.innerHTML = "Match Found";
cardFlipped = -1;
playLockout = false;
// Conclude the game
if (tfo.length == tileArray.length) {
gameover();
}
} else {
message.innerHTML = "No Match";
timer = setInterval(hideCard, 1000);
}
//check to see if its a match
} else {
cardFlipped = i;
cardFlip(i, t);
}
} else {
message.innerHTML = "Locked Out";
}
}
function gameover() {
message.innerHTML = "GAME OVER";
sb.style.display = "block";
gamePlay = false;
tfo = [];
tileImages = [];
gameBoard.innerHTML = "";
}
function isinArray(v, array) {
return array.indexOf(v) > -1;
}
function hideCard() {
for (var x = 0; x < 2; x++) {
var vid = tfo.pop();
document.getElementById(vid).src = 'http://via.placeholder.com/250/000000/ffffff?text=click';
}
clearInterval(timer);
cardFlipped = -1;
playLockout = false;
message.innerHTML = "Select Again";
}
function checkSrc(a) {
return document.getElementById(a).src;
}
function cardFlip(i, t) {
t.src = "http://via.placeholder.com/250/ffffff/000000?text=" + tileArray[i];
tfo.push(t.id);
}
function buildArray() {
for (var x = 1; x < 7; x++) {
tileImages.push(x + '.jpg');
}
}
function shuffleArray(array) {
for (var x = array.length - 1; x > 0; x--) {
var holder = Math.floor(Math.random() * (x + 1));
var itemValue = array[x];
array[x] = array[holder];
array[holder] = itemValue;
}
return array;
}
</script>
<script src="https://code.jquery.com/jquery-3.5.0.js"
integrity="sha256-r/AaFHrszJtwpe+tHyNi/XCfMxYpbsRg2Uqn0x3s2zc=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"></script>
</body>
</html>