-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
159 lines (136 loc) · 6.03 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
<!DOCTYPE html>
<html>
<head>
<title>Catan Map Generator</title>
<!-- Meta tags -->
<meta name="robots" content="index, follow, archive">
<meta name="description" content="Create randomized 'Settlers of Catan' maps and choose where the best opening placements are. Share with others, and challenge them to do better!">
<meta charset="utf-8" />
<meta http-equiv="Cache-control" content="public">
<!-- Semantic Markup -->
<meta property="og:title" content="Catan Map Generator">
<meta property="og:type" content="website">
<meta property="og:image" content="https://alexbeals.com/projects/catan/assets/preview_new.jpg">
<meta property="og:url" content="https://alexbeals.com/projects/catan">
<meta property="og:description" content="Create randomized 'Settlers of Catan' maps and choose where the best opening placements are. Share with others, and challenge them to do better!">
<meta name="twitter:card" content="summary">
<meta name="twitter:creator" content="@alex_beals">
<!-- Favicons -->
<link rel="apple-touch-icon" sizes="180x180" href="./assets/favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="./assets/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="./assets/favicon/favicon-16x16.png">
<link rel="manifest" href="./assets/favicon/manifest.json">
<link rel="mask-icon" href="./assets/favicon/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="./assets/favicon/favicon.ico">
<meta name="msapplication-config" content="./assets/favicon/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
<link rel="stylesheet" type="text/css" href="catan.css">
<script src="js/helper.js"></script>
<script src="js/main.js"></script>
<script>
window.onload = function() {
var search = window.location.search;
var game;
var type = 'spiral';
if (search.startsWith("?")) {
search = search.slice(1).split("&");
var searchQuery = {};
for (var i = 0; i < search.length; i++) {
var parts = search[i].split("=");
if (parts.length == 2) {
searchQuery[parts[0]] = parts[1];
}
}
if (searchQuery['game']) {
game = decode(searchQuery['game']);
}
if (searchQuery['moves']) {
game.locs = decodeMoves(searchQuery['moves']);
}
if (searchQuery['gameType']) {
type = searchQuery['gameType'];
}
}
if (!game) {
if (type == 'random') {
game = newRandomGame();
} else if (type == 'pseudorandom') {
game = newPseudoRandomGame();
} else {
game = newSpiralGame();
}
}
var gameCode = encode(game);
displayGame(game);
document.querySelector('#gameid').href = '?game=' + gameCode;
document.querySelector('#moveid').href = '?game=' + gameCode + '&moves=' + encodeMoves(game);
var moveColors = ['Red', 'Blue', 'Yellow', 'White', 'White', 'Yellow', 'Blue', 'Red', 'No one'];
var index = game.locs.length;
// Set up clickable spots
var spots = document.querySelectorAll('.chunk span');
document.querySelector('#placement').innerHTML = moveColors[index] + ' is placing.';
if (index == moveColors.length - 1) {
for (var i = 0; i < spots.length; i++) {
spots[i].classList.remove('open');
}
}
// Undo button
document.querySelector('#undo').addEventListener('click', function(event) {
if (game.locs.length > 0) {
// Pop off a move
var removed = game.locs.pop();
// Update the move URL
document.querySelector('#moveid').href = '?game=' + gameCode + '&moves=' + encodeMoves(game);
// Update the index
index -= 1;
document.querySelector('#placement').innerHTML = moveColors[index] + ' is placing.';
// Update the spot
var spot = document.querySelector('.chunk span[data-num="' + removed + '"]');
spot.className = '';
// Make sure open spots are marked as open
for (var i = 0; i < spots.length; i++) {
if (spots[i].className == '') {
spots[i].classList.add('open');
}
}
}
});
for (var i = 0; i < spots.length; i++) {
spots[i].addEventListener('click', function(event) {
if (index < moveColors.length - 1) {
if (this.classList.contains('open')) {
// Set it to whatever spot it is now
this.classList.remove('open');
this.classList.add(moveColors[index].toLowerCase());
if (index < 4) {
this.classList.add('first');
}
// Add it to the list
game.locs.push(parseInt(this.dataset.num));
document.querySelector('#moveid').href = '?game=' + gameCode + '&moves=' + encodeMoves(game);
// Increment who you're playing for
index += 1;
document.querySelector('#placement').innerHTML = moveColors[index] + ' is placing.';
}
if (index == moveColors.length - 1) {
for (var i = 0; i < spots.length; i++) {
spots[i].classList.remove('open');
}
}
}
});
}
};
</script>
<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-70745807-1', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
</body>
</html>