-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAltLoading.html
More file actions
128 lines (124 loc) · 4.89 KB
/
AltLoading.html
File metadata and controls
128 lines (124 loc) · 4.89 KB
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
<!DOCTYPE html>
<html>
<head>
<title>NAXJO Battleship ... Loading</title>
<style>
body, html {
font-size: 24px;
font-family: monospace;
background-color: darkgrey;
}
header {
background-color: dodgerblue;
text-align: center;
display: table-cell;
vertical-align: middle;
}
button {
font-size: 20px;
font-family: monospace;
background-color: lightsteelblue;
}
</style>
<script>
function startGame() {
var playerLimit = 15;
var ships = new Array(playerLimit);
var taken = new Array(100);
var count = 0;
for (i = 0; i < playerLimit; i++) {
for (k = 0; k < 2; k++) {
var findPair = true;
while (findPair == true) {
var message = "";
var startOver = false;
var x = Math.floor(Math.random() * 9);
var y = Math.floor(Math.random() * 9);
x = x + 1;
y = y + 1;
if (inArray(x,y,taken,count)) {
message = message + "Pair (" + x + "," + y + ") is taken. Going again...\n";
startOver = true;
}
else {
message = message + "Pair (" + x + "," + y + ") is new.\n";
}
var Sa = [x,y,0,i]; // To feed into session, etc.: contains coordinates, status, and player id
var pick = Math.floor(Math.random() * 2);
if (pick == 1) { // Horizontal
y = y + 1;
if (inArray(x,y,taken,count)) {
message = message + "Pair (" + x + "," + y + ") is taken. Going again...\n";
y = y - 2;
if (inArray(x,y,taken,count) || y == 0) {
message = message + "Pair (" + x + "," + y + ") is taken. Going again...\n";
y = y + 1;
x = x + 1;
if (inArray(x,y,taken,count)) {
message = message + "Pair (" + x + "," + y + ") is taken. Going again...\n";
x = x - 2;
if (inArray(x,y,taken,count) || x == 0) {
message = message + "Pair (" + x + "," + y + ") is taken. Starting over...\n";
startOver = true;
}
}
}
}
}
else { // Vertical
x = x + 1;
if (inArray(x,y,taken,count)) {
message = message + "Pair (" + x + "," + y + ") is taken. Going again...\n";
x = x - 2;
if (inArray(x,y,taken,count) || x == 0) {
message = message + "Pair (" + x + "," + y + ") is taken. Going again...\n";
x = x + 1;
y = y + 1;
if (inArray(x,y,taken,count)) {
message = message + "Pair (" + x + "," + y + ") is taken. Going again...\n";
y = y - 2;
if (inArray(x,y,taken,count) || y == 0) {
message = message + "Pair (" + x + "," + y + ") is taken. Starting over...\n";
startOver = true;
}
}
}
}
}
var Sb = [x,y,0,i];
if (startOver == false) {
findPair = false;
taken[count] = [Sa[0],Sa[1]];
taken[count+1] = [Sb[0],Sb[1]];
count += 2;
message = message + "(" + x + "," + y + ") should work.\n";
alert(message);
}
}
}
}
}
function inArray(x,y,array,count) {
for (var i=0; i < count; i++) {
if (array[i][0]===x && array[i][1]===y) {
return true;
}
}
return false;
}
</script>
</head>
<body>
<center>
<H1>NAXJO Battleship</H1>
<p>Waiting for More Players to Join...</p>
<text id = "roomnum"></text>
<BR></BR>
<form>
<BR></BR>
<button type = "button" onclick = "startGame()">Launch Game</button>
<BR></BR>
</form>
</center>
</body>
</html>