-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
131 lines (115 loc) · 5.52 KB
/
Copy pathindex.html
File metadata and controls
131 lines (115 loc) · 5.52 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
129
130
131
<!DOCTYPE html>
<html>
<head>
<title>WSD2017 Tetris</title>
<style>
body { font-family: Helvetica, sans-serif; }
#tetris { margin: 1em auto; padding: 1em; border: 4px solid black; border-radius: 10px; background-color: #F8F8F8; }
#canvas { display: inline-block; vertical-align: top; background: url(cloud_texture.jpg); box-shadow: 10px 10px 10px #999; border: 2px solid #333; }
#menu { display: inline-block; vertical-align: top; position: relative; }
#menu p { margin: 0.5em 0; text-align: center; }
#menu p a { text-decoration: none; color: black; }
#upcoming { display: block; margin: 0 auto; background-color: #E0E0E0; }
#score { color: red; font-weight: bold; vertical-align: middle; }
#rows { color: blue; font-weight: bold; vertical-align: middle; }
@media screen and (min-width: 0px) and (min-height: 0px) { #tetris { font-size: 0.75em; width: 250px; } #menu { width: 100px; height: 200px; } #upcoming { width: 50px; height: 50px; } #canvas { width: 100px; height: 200px; } } /* 10px chunks */
@media screen and (min-width: 400px) and (min-height: 400px) { #tetris { font-size: 1.00em; width: 350px; } #menu { width: 150px; height: 300px; } #upcoming { width: 75px; height: 75px; } #canvas { width: 150px; height: 300px; } } /* 15px chunks */
@media screen and (min-width: 500px) and (min-height: 500px) { #tetris { font-size: 1.25em; width: 450px; } #menu { width: 200px; height: 400px; } #upcoming { width: 100px; height: 100px; } #canvas { width: 200px; height: 400px; } } /* 20px chunks */
@media screen and (min-width: 600px) and (min-height: 600px) { #tetris { font-size: 1.50em; width: 550px; } #menu { width: 250px; height: 500px; } #upcoming { width: 125px; height: 125px; } #canvas { width: 250px; height: 500px; } } /* 25px chunks */
@media screen and (min-width: 700px) and (min-height: 700px) { #tetris { font-size: 1.75em; width: 650px; } #menu { width: 300px; height: 600px; } #upcoming { width: 150px; height: 150px; } #canvas { width: 300px; height: 600px; } } /* 30px chunks */
@media screen and (min-width: 800px) and (min-height: 800px) { #tetris { font-size: 2.00em; width: 750px; } #menu { width: 350px; height: 700px; } #upcoming { width: 175px; height: 175px; } #canvas { width: 350px; height: 700px; } } /* 35px chunks */
@media screen and (min-width: 900px) and (min-height: 900px) { #tetris { font-size: 2.25em; width: 850px; } #menu { width: 400px; height: 800px; } #upcoming { width: 200px; height: 200px; } #canvas { width: 400px; height: 800px; } } /* 40px chunks */
.div {
margin: auto;
width: 50%;
border: 3px solid green;
padding: 10px;
text-align:center
}
</style>
<script>
/* global $, alert */
document.ready(function () {
"use strict"
var message = {
messageType: "SETTING",
options: {
"width": 400, //Integer
"height": 500 //Integer
}
};
parent.postMessage(message,'*');
// These variable track the state of this "game"
var playerItems = [];
var points = 0;
// Simulates "game over" when a score would be sent
$("#submit_score").click(function () {
var msg = {
"messageType": "SCORE",
"score": parseFloat($("#score").text())
};
window.parent.postMessage(msg, "*");
console.log(msg);
});
// Sends this game's state to the service.
// The format of the game state is decided
// by the game
$("#save").click(function () {
var msg = {
"messageType": "SAVE",
"gameState": {
"playerItems": playerItems,
"score": parseFloat($("#score").text())
}
};
window.parent.postMessage(msg, "*");
});
// Sends a request to the service for a
// state to be sent, if there is one.
$("#load").click(function () {
var msg = {
"messageType": "LOAD_REQUEST"
};
window.parent.postMessage(msg, "*");
});
// Listen incoming messages, if the messageType
// is LOAD then the game state will be loaded.
// Note that no checking is done, whether the
// gameState in the incoming message contains
// correct information.
//
// Also handles any errors that the service
// wants to send (displays them as an alert).
window.addEventListener("message", function (evt) {
if (evt.data.messageType === "LOAD") {
playerItems = evt.data.gameState.playerItems;
points = evt.data.gameState.score;
$("#score").text(points);
updateItems();
} else if (evt.data.messageType === "ERROR") {
alert(evt.data.text);
}
});
});
</script>
</head>
<body>
<div id="tetris">
<div id="menu">
<p id="start"><a href="javascript:play();">Press Space to Play.</a></p>
<p><canvas id="upcoming"></canvas></p>
<p>score <span id="score">00000</span></p>
<p>rows <span id="rows">0</span></p>
</div>
<canvas id="canvas">
Sorry, this game cannot be played because your browser does not support the <canvas> element
</canvas>
</div>
<script src="game.js"></script>
<div class="div">
<button id="submit_score" onclick="submit_score() ">Submit score</button><br>
<button id="save" onclick="save_game()">Save</button>
<button id="load" onclick="load_game()">Load</button>
</div>
</body>
</html>