Skip to content

Commit 07dad62

Browse files
committed
Added new game: Simon Says
1 parent 6bb7df6 commit 07dad62

11 files changed

Lines changed: 387 additions & 0 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

Games/SimonSays.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
"""Simon Says
2+
Exercises
3+
4+
1. Speed up tile flash rate.
5+
2. Add more tiles.
6+
7+
"""
8+
9+
from random import choice
10+
from time import sleep
11+
from turtle import *
12+
from freegames import floor, square, vector
13+
14+
pattern = []
15+
guesses = []
16+
tiles = {
17+
vector(0, 0): ('red', 'dark red'),
18+
vector(0, -200): ('blue', 'dark blue'),
19+
vector(-200, 0): ('green', 'dark green'),
20+
vector(-200, -200): ('yellow', 'khaki'),
21+
}
22+
23+
def grid():
24+
"Draw grid of tiles."
25+
square(0, 0, 200, 'dark red')
26+
square(0, -200, 200, 'dark blue')
27+
square(-200, 0, 200, 'dark green')
28+
square(-200, -200, 200, 'khaki')
29+
update()
30+
31+
def flash(tile):
32+
"Flash tile in grid."
33+
glow, dark = tiles[tile]
34+
square(tile.x, tile.y, 200, glow)
35+
update()
36+
sleep(0.5)
37+
square(tile.x, tile.y, 200, dark)
38+
update()
39+
sleep(0.5)
40+
41+
def grow():
42+
"Grow pattern and flash tiles."
43+
tile = choice(list(tiles))
44+
pattern.append(tile)
45+
46+
for tile in pattern:
47+
flash(tile)
48+
49+
print('Pattern length:', len(pattern))
50+
guesses.clear()
51+
52+
def tap(x, y):
53+
"Respond to screen tap."
54+
onscreenclick(None)
55+
x = floor(x, 200)
56+
y = floor(y, 200)
57+
tile = vector(x, y)
58+
index = len(guesses)
59+
60+
if tile != pattern[index]:
61+
exit()
62+
63+
guesses.append(tile)
64+
flash(tile)
65+
66+
if len(guesses) == len(pattern):
67+
grow()
68+
69+
onscreenclick(tap)
70+
71+
def start(x, y):
72+
"Start game."
73+
grow()
74+
onscreenclick(tap)
75+
76+
setup(420, 420, 370, 0)
77+
hideturtle()
78+
tracer(False)
79+
grid()
80+
onscreenclick(start)
81+
done()

assets/.DS_Store

6 KB
Binary file not shown.

assets/images/.DS_Store

6 KB
Binary file not shown.

assets/images/simon-says.png

152 KB
Loading

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ <h1 class="display-4">Gaming With Python</h1>
236236
</div>
237237
</div>
238238

239+
<div class="card-deck">
240+
<div class="card">
241+
<a href="python/Simon-Says.html" rel="noopener noreferrer"><img src="assets\images\simon-says.png" class="card-image"></a>
242+
<div class="card-body">
243+
<a href="python/Simon-Says.html" rel="noopener noreferrer"><h5 class="card-title">Simon Says</h5></a>
244+
</div>
245+
</div>
246+
<div class="card">
247+
<a href="#" rel="noopener noreferrer"><img src="https://via.placeholder.com/350" class="card-image"></a>
248+
<div class="card-body">
249+
<a href="#" rel="noopener noreferrer"><h5 class="card-title">Coming Soon!</h5></a>
250+
</div>
251+
</div>
252+
</div>
239253
<!-- <div class="card-deck">
240254
<div class="card">
241255
<a href="python/temp.html" rel="noopener noreferrer"><img src="assets\images\caterpillar.png" class="card-image"></a>

python/.DS_Store

8 KB
Binary file not shown.

python/Simon-Says.html

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7+
8+
<meta property="og:title" content="PyBox - Python Games">
9+
<meta property="og:type" content="website">
10+
<meta property="og:description" content="Python Games to increase your skill and experience in Python">
11+
<!-- <meta property="og:image" content="">
12+
<meta property="og:url" content=""> -->
13+
14+
<meta name="twitter:title" content="PyBox - Python Games">
15+
<meta name="twitter:site" content="@hhhrrrttt222111">
16+
<meta name="twitter:creator" content="@hhhrrrttt222111">
17+
<meta name="twitter:description" content="Python Games to increase your skill and experience in Python">
18+
19+
20+
<link rel = "icon" href ="..\assets\icons\logo-png.png" type = "image/x-icon">
21+
22+
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"
23+
integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
24+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
25+
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
26+
<link rel="stylesheet" href="games.css">
27+
<title>PyBox - Simon Says </title>
28+
</head>
29+
<body>
30+
31+
<nav class="navbar static-top">
32+
<div class="container">
33+
<a class="navbar-brand" href="../index.html"><img src="..\assets\icons\logo-png.png" class="nav-logo" alt="PyBox"></a>
34+
<button onclick="goBack()" class="btn btn-dark">Go Back</button>
35+
</div>
36+
37+
</nav>
38+
39+
40+
<div class="container">
41+
<div class="row">
42+
<div class="col-sm-4">
43+
<h1 class="game-title">Simon Says</h1>
44+
<p class="game-desc">Simon Says (or Simple Simon Says) is a children's game for three or more players. One player takes the role of "Simon" and issues instructions (usually physical actions such as "jump in the air" or "stick out your tongue") to the other players, which should be followed only when prefaced with the phrase "Simon says". Players are eliminated from the game by either following instructions that are not immediately preceded by the phrase, or by failing to follow an instruction which does include the phrase "Simon says".
45+
</p>
46+
<ul class="nav nav-pills flex-column">
47+
<li class="nav-item">
48+
<a class="fa fa-2x fa-github" href="https://github.com/hhhrrrttt222111/PyBox/blob/master/Games/Tic-Tac-Toe.py" target="_blank" rel="noopener noreferrer"></a>
49+
<a href="https://github.com/hhhrrrttt222111/PyBox/stargazers" target="_blank" rel="noopener noreferrer" class="git-star"><img alt="GitHub stars" src="https://img.shields.io/github/stars/hhhrrrttt222111/PyBox?style=social"></a>
50+
</li>
51+
</ul>
52+
<hr class="d-sm-none">
53+
</div>
54+
55+
56+
<div class="col-sm-8">
57+
58+
59+
<div class="download">
60+
<h4 class="dwnld">Download</h4>
61+
<a class="btn" href="Text/SimonSays.txt" download><i class="fa fa-2x fa-file"></i></a>
62+
<a class="btn" href="../Games/SimonSays.py" download><img src="../assets/icons/python-icon.png" alt="python-icon" class="python-icon"></i></a>
63+
</div>
64+
65+
66+
67+
<!-- CODE -->
68+
<pre class="code">
69+
70+
<span class="comment"># import modules</span>
71+
<span class="in-built">from</span> random <span class="in-built">import</span> choice
72+
<span class="in-built">from</span> time <span class="in-built">import</span> sleep
73+
<span class="in-built">from</span> turtle <span class="in-built">import</span> *
74+
<span class="in-built">from</span> freegames <span class="in-built">import</span> floor, square, vector
75+
pattern = <span class="function">[]</span>
76+
guesses = <span class="function">[]</span>
77+
<span class="comment"># Create main window</span>
78+
titles = <span class="function">{</span>
79+
vector(0, 0):<span class="function">('red', 'dark red'),</span>
80+
vector(0, -200):<span class="function">('blue', 'dark blue'),</span>
81+
vector(-200, 0):<span class="function">('green', 'dark green'),</span>
82+
vector(-200, -200):<span class="function">('yellow', 'khaki'),</span>
83+
}
84+
85+
86+
def grid():<span class="function"></span>
87+
"Draw grid of tiles."<span class="function"></span>
88+
square(0, 0, 200, 'dark red')<span class="function"></span>
89+
square(0, -200, 200, 'dark blue')<span class="function"></span>
90+
square(-200, 0, 200, 'dark green')<span class="function"></span>
91+
square(-200, -200, 200, 'khaki')<span class="function"></span>
92+
update()
93+
94+
def flash(tile):<span class="function"></span>
95+
"Flash tile in grid."<span class="function"></span>
96+
glow, dark = tiles[tile]<span class="function"></span>
97+
square(tile.x, tile.y, 200, glow)<span class="function"></span>
98+
update()<span class="function"></span>
99+
sleep(0.5)<span class="function"></span>
100+
square(tile.x, tile.y, 200, dark)<span class="function"></span>
101+
update()<span class="function"></span>
102+
sleep(0.5)<span class="function"></span>
103+
104+
def grow():<span class="function"></span>
105+
"Grow pattern and flash tiles."<span class="function"></span>
106+
tile = choice(list(tiles))<span class="function"></span>
107+
pattern.append(tile)<span class="function"></span>
108+
<br><span class="function"></span>
109+
for tile in pattern:<span class="function"></span>
110+
flash(tile)<span class="function"></span>
111+
<br>
112+
print('Pattern length:', len(pattern))<span class="function"></span>
113+
guesses.clear()
114+
115+
def tap(x, y):<span class="function"></span>
116+
"Respond to screen tap."<span class="function"></span>
117+
onscreenclick(None)<span class="function"></span>
118+
x = floor(x, 200)<span class="function"></span>
119+
y = floor(y, 200)<span class="function"></span>
120+
tile = vector(x, y)<span class="function"></span>
121+
index = len(guesses)<span class="function"></span>
122+
<br>
123+
if tile != pattern[index]:
124+
exit()
125+
guesses.append(tile)
126+
flash(tile)
127+
if len(guesses) == len(pattern):
128+
grow()
129+
onscreenclick(tap)
130+
131+
def start(x, y):
132+
"Start game."
133+
grow()
134+
onscreenclick(tap)
135+
136+
setup(420, 420, 370, 0)
137+
hideturtle()
138+
tracer(False)
139+
grid()
140+
onscreenclick(start)
141+
done()
142+
</pre>
143+
144+
<!-- CODE -->
145+
<br>
146+
<div class="images">
147+
<div id="carouselExampleFade" class="carousel slide carousel-fade" data-ride="carousel">
148+
<ol class="carousel-indicators">
149+
<li data-target="#carouselExampleCaptions" data-slide-to="0" class="active"></li>
150+
<li data-target="#carouselExampleCaptions" data-slide-to="1"></li>
151+
152+
</ol>
153+
<div class="carousel-inner">
154+
<div class="carousel-item active">
155+
<img src="img/simon-says1.PNG" class="d-block w-100" alt="...">
156+
</div>
157+
<div class="carousel-item">
158+
<img src="img/simon-says2.PNG" class="d-block w-100" alt="...">
159+
</div>
160+
</div>
161+
<a class="carousel-control-prev" href="#carouselExampleFade" role="button" data-slide="prev">
162+
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
163+
<span class="sr-only">Previous</span>
164+
</a>
165+
<a class="carousel-control-next" href="#carouselExampleFade" role="button" data-slide="next">
166+
<span class="carousel-control-next-icon" aria-hidden="true"></span>
167+
<span class="sr-only">Next</span>
168+
</a>
169+
</div>
170+
</div>
171+
172+
173+
174+
175+
<div class="buyme">
176+
177+
<a href="https://ko-fi.com/hhhrrrttt222111" target="_blank" rel="noopener noreferrer"><span class="buy">Buy Me A Coffee</span><img src="../assets/icons/kofi.png" alt="ko-fi" class="coffee"></a>
178+
</div>
179+
180+
</div>
181+
182+
</div>
183+
184+
</div>
185+
186+
187+
188+
<div class="footer">
189+
<p class="footer-heart">
190+
Made with <g-emoji class="g-emoji" alias="heart" fallback-src="https://raw.githubusercontent.com/hhhrrrttt222111/etudia/master/assets/necro.png?token=AKLVDPY75U5YNHZ7PRA4Y4K6TRB2I">
191+
<img class="emoji" alt="heart" height="20" width="20" src="https://raw.githubusercontent.com/hhhrrrttt222111/etudia/master/assets/necro.png?token=AKLVDPY75U5YNHZ7PRA4Y4K6TRB2I">
192+
</g-emoji> by <a href="http://hhhrrrttt222111.me/" target="_blank">HRT</a>
193+
</p>
194+
</div>
195+
196+
197+
198+
199+
<script>
200+
function goBack() {
201+
window.history.back();
202+
}
203+
</script>
204+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
205+
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
206+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
207+
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
208+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
209+
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
210+
</body>
211+
</html>

python/Text/SimonSays.txt

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
"""Simon Says
2+
Exercises
3+
4+
1. Speed up tile flash rate.
5+
2. Add more tiles.
6+
7+
"""
8+
9+
from random import choice
10+
from time import sleep
11+
from turtle import *
12+
from freegames import floor, square, vector
13+
14+
pattern = []
15+
guesses = []
16+
tiles = {
17+
vector(0, 0): ('red', 'dark red'),
18+
vector(0, -200): ('blue', 'dark blue'),
19+
vector(-200, 0): ('green', 'dark green'),
20+
vector(-200, -200): ('yellow', 'khaki'),
21+
}
22+
23+
def grid():
24+
"Draw grid of tiles."
25+
square(0, 0, 200, 'dark red')
26+
square(0, -200, 200, 'dark blue')
27+
square(-200, 0, 200, 'dark green')
28+
square(-200, -200, 200, 'khaki')
29+
update()
30+
31+
def flash(tile):
32+
"Flash tile in grid."
33+
glow, dark = tiles[tile]
34+
square(tile.x, tile.y, 200, glow)
35+
update()
36+
sleep(0.5)
37+
square(tile.x, tile.y, 200, dark)
38+
update()
39+
sleep(0.5)
40+
41+
def grow():
42+
"Grow pattern and flash tiles."
43+
tile = choice(list(tiles))
44+
pattern.append(tile)
45+
46+
for tile in pattern:
47+
flash(tile)
48+
49+
print('Pattern length:', len(pattern))
50+
guesses.clear()
51+
52+
def tap(x, y):
53+
"Respond to screen tap."
54+
onscreenclick(None)
55+
x = floor(x, 200)
56+
y = floor(y, 200)
57+
tile = vector(x, y)
58+
index = len(guesses)
59+
60+
if tile != pattern[index]:
61+
exit()
62+
63+
guesses.append(tile)
64+
flash(tile)
65+
66+
if len(guesses) == len(pattern):
67+
grow()
68+
69+
onscreenclick(tap)
70+
71+
def start(x, y):
72+
"Start game."
73+
grow()
74+
onscreenclick(tap)
75+
76+
setup(420, 420, 370, 0)
77+
hideturtle()
78+
tracer(False)
79+
grid()
80+
onscreenclick(start)
81+
done()

python/img/simon-says1.png

254 KB
Loading

0 commit comments

Comments
 (0)