-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
211 lines (179 loc) · 6.05 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
<!DOCTYPE html>
<html>
<head>
<title>Survival Wolf</title>
<!-- 3rd Party -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<!-- Ours -->
<script src="map.js"></script>
<script src="game.js"></script>
<script src="animals-base.js"></script>
<script src="animals-wolves.js"></script>
<style>
body{background-color:#1C2536;}
</style>
</head>
<body>
<a href="https://github.com/cncplyr/survival-wolf"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png"></a>
<br><br>
<div class="container">
<div class="row">
<div class="col-sm-8 col-md-8">
<canvas id="grid" width="800" height="800"></canvas>
</div>
<div class="col-sm-4 col-md-4">
<div class="panel panel-default">
<div class="panel-body">
<button type="button" class="btn btn-default btn-block" onclick="newGame();">New Game</button>
<button type="button" class="btn btn-default btn-block" id="run" onclick="toggleRun();">Run</button>
<br>
<span>Progress:</span><br>
<div class="progress">
<div id="info-progressbar" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%;">0%</div>
</div>
<br>
<ul class="nav nav-pills nav-stacked">
<li class="active"><a href="#"><span id="count-stone" class="badge pull-right">100</span>Stone</a></li>
<li class="active"><a href="#"><span id="count-lion" class="badge pull-right">100</span>Lion</a></li>
<li class="active"><a href="#"><span id="count-bear" class="badge pull-right">100</span>Bear</a></li>
</ul>
<br>
<h3>Rules</h3>
<P>Starts with 100 of each animal.</p>
<P>Each turn animals may move once.</p>
<p>When animals meet, they fight to the death.</p>
<p>Games last 500 turns.</p>
<p>The winner is the animal with the most remaining at the end.</p>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var canvas;
var game;
var running = false;
/* Button actions */
function newGame(){
game.newGame();
// Populate the game with the basic animals
game.populate(animalsBase, 100);
// TODO: Populate the game with wolves
//game.populate(animalsWolves);
// Update the map and info
infoNewGame();
if (running) { infoUpdateGame(); }
draw();
}
function run(){
if (running && !game.isFinished()) {
game.next();
draw();
} else if (game.isFinished()){
infoEndGame();
}
}
function toggleRun(){
if (game.isFinished()){
running = false;
// Reset so we can start a new game
newGame();
} else {
running = running ? false : true;
infoUpdateGame();
}
}
/* Map display */
function draw() {
canvas.width = canvas.width; // clears the canvas
var ctx = canvas.getContext("2d");
size = game.blockSize;
// draw all the circles
// TODO: Fix the drawing bug here
for(var x = 0; x < game.mapSize; x++){
for(var y = 0; y < game.mapSize; y++){
if(game.map[x][y] != null) {
// Set the colour for that animal
switch(game.map[x][y].name()){
case "l" :
// Lions are yellow
ctx.fillStyle = "rgb(255,247,115)";
break;
case "b" :
// Bears are orange
ctx.fillStyle = "rgb(255,174,115)";
break;
case "s" :
// Stones are green
ctx.fillStyle = "rgb(93,207,195)";
break;
case "w" :
// Wolves are purple
ctx.fillStyle = "rgb(160,105,214)";
break;
}
// Draw a circle where the animal is
ctx.moveTo(x*size+(size/2),y*size);
ctx.beginPath();
ctx.arc(x*size, y*size, size/2, 0, 2*Math.PI);
ctx.closePath();
ctx.fill();
}
}
}
// Update the info panel
infoUpdateGame();
}
/* Info display */
function infoNewGame() {
// Progress bar
$('#info-progressbar').removeClass('progress-bar-success');
// ToggleRun button
$('#run').text('Start!').removeClass('btn-danger').addClass('btn-success');
}
function infoUpdateGame() {
// Progress bar
var progress = game.getProgress();
$('#info-progressbar').attr('aria-valuenow', progress).attr('style', 'width:' + progress + '%;').text(progress + '%');
// Animal counts
$('#count-stone').text(animalsBaseCount['s']);
$('#count-lion').text(animalsBaseCount['l']);
$('#count-bear').text(animalsBaseCount['b']);
// ToggleRun button
if (running) {
$('#run').text('Pause').removeClass('btn-success').addClass('btn-danger');
} else {
if (game.currentTurn == 0) {
$('#run').text('Start!').removeClass('btn-danger').addClass('btn-success');
} else {
$('#run').text('Continue').removeClass('btn-danger').addClass('btn-success');
}
}
}
function infoEndGame(){
// Progress bar
$('#info-progressbar').addClass('progress-bar-success');
// ToggleRun button
$('#run').text('Game Finished!').removeClass('btn-succes').addClass('btn-danger');
}
function init(blockSize, mapSize) {
canvas = document.getElementById('grid');
game = new SurvivalGame(blockSize, mapSize);
newGame();
setInterval('run()', 50);
}
init(5, 150);
</script>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-58040822-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>