-
Notifications
You must be signed in to change notification settings - Fork 0
/
match.html
192 lines (176 loc) · 5.08 KB
/
match.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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>Truchet</title>
</head>
<style>
table, th, td {
padding: 0px;
text-align: center;
border: 0px solid black;
border-collapse: collapse;
}
table {
border: 1px solid black;
}
svg {
display: block;
margin: auto ;
border: 0px solid black;
}
.buttonDiv {
display: inline-block;
padding: 2px;
border: 2px;
}
.centered {
text-align: center;
}
</style>
<script src="js/bldrs.js"></script> <!-- required for callback registration-->
<script src="js/evnts.js"></script> <!-- required for callback registration-->
<script src="js/truchet.js"></script>
<script>
//initialize target
var tilesToMatch;
var count = 0;
var remainingDistance = 0;
var initialDistance = 0;
var puzzleType = "easy";
function reset() {
truchet.tileStyle = truchet.tileTraditional;
truchet.rule = truchet.ruleRotate;
switch(puzzleType) {
case "easy":
truchet.start(120,2);
tilesToMatch = new Tiles(120,2,true);
break;
case "tricky":
truchet.start(60,4);
tilesToMatch = new Tiles(60,4,true);
break;
case "trickier":
truchet.start(40,6);
tilesToMatch = new Tiles(40,6,true);
break;
}
tilesToMatch.init();
for (var i=0; i<100; i++){
tilesToMatch.randomizeTile();
tilesToMatch.randomizeTile();
}
tilesToMatch.applyAll();
truchet.rule = truchet.ruleNone;
initialDistance = truchet.tiles.distance(tilesToMatch);
count = 0;
remainingDistance = 0;
$('#distanceLabel').html("<h4>Match the tiles to the pattern below in " + initialDistance + " moves.</h4>");
$('#tileBoard').html(truchet.tiles.htmlTable());
$('#tilesToMatch').html(tilesToMatch.htmlTable());
evnts.fireEvent("refresh");
}
$(document).ready(function(){
evnts.addCallback("refresh", function() {
var d = truchet.tiles.distance(tilesToMatch);
var message = "";
if (d === 0) {
truchet.tiles.static = true;
var delta = count - initialDistance;
message = "Success!";
if (delta >0) {
message += " You used " + delta + " moves more than needed.";
}
}
$('#counterLabel').html("<h4> You have made " + count + " moves. " + message + "</h4>");
count++;
});
reset();
});
function setButtons() {
$(".btn-primary").addClass("btn-secondary");
$(".btn-primary").removeClass("btn-primary");
$("#" + puzzleType).addClass("btn-primary");
$("#" + puzzleType).removeClass("btn-secondary");
$("#btnCurrentPage").addClass("btn-primary");
}
$(document).ready(function(){
$('.puzzleTypeBtn').on("click", function(event){
puzzleType = event.currentTarget.id;
setButtons();
reset();
});
});
</script>
<body>
<nav class="navbar navbar-default" style="margin-bottom:0px">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="..">
<img src="imgs/github_badge1.png" style="max-width:100%;max-height:100%" >
</a>
<p class="navbar-text navbar-right">
<a href=".." class="navbar-link">dmackinnon1.github.io</a>
</p>
</div>
</div>
</nav>
<div class="container-fluid">
<div class='row'>
<div class='col-sm-1'></div>
<div class='col-sm-10'>
<div class="page-header">
<h1>Truchet tiles
<div class="btn-group btn-group-md " role="group">
<a class="btn btn-primary" id="btnCurrentPage" href="./match.html">Puzzles</a>
<a class="btn btn-default" href=".">Explorer</a>
<a class="btn btn-default" href="./gen.html">Generator</a>
</div>
</h1>
</div>
<div class="media">
<a class="media-left media-middle" href="#">
<img class="media-object" src="imgs/truchet.png" alt="Truchet" width="150" height="150">
</a>
<div class="media-body">
<h4 class="media-heading">Truchet Puzzles</h4>
The tiles on the first square below (left or top) can be rotated by clicking on them. Your goal is to make the pattern on the first square match the pattern on the second square, using the smallest possible number of moves. Get a new puzzle or change the difficulty level by clicking on one of the three
buttons below.
</div>
</div>
<br>
<hr><br>
<div class="centered">
<div class="btn-group btn-group-lg " role="group">
<button type="button" id="easy" class="puzzleTypeBtn btn btn-primary">easy</button>
<button type="button" id="tricky" class="puzzleTypeBtn btn btn-secondary">tricky</button>
<button type="button" id="trickier" class="puzzleTypeBtn btn btn-secondary">trickier</button>
</div>
</div>
<br>
<div id="distanceLabel" class="centered"></div>
<div id="counterLabel" class="centered"></div>
<hr>
</div>
<div class='col-sm-1'></div>
</div>
<div class='row'>
<div class='col-sm-3'></div>
<div class='col-sm-3'>
<div id="tileBoard"/></div>
<hr>
</div>
<!--<div class='col-sm-2'></div>-->
<div class='col-sm-3'>
<div id="tilesToMatch"/></div>
<hr>
</div>
<div class='col-sm-3'></div>
</div>
</div>
</body>
</html>