Skip to content

Commit 4230928

Browse files
committed
Update Python-Projects
1 parent 9d6c85e commit 4230928

File tree

8 files changed

+35
-34
lines changed

8 files changed

+35
-34
lines changed

Asteroids.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def fire(self):
159159

160160
while True:
161161
pen.goto(-350, 250)
162-
pen.write(f"{player.score}", False, font=("Courier New", 18, "normal"))
162+
pen.write(f"{player.score}", False, font=("commodore 64 pixelized", 18, "normal"))
163163

164164
pen.clear()
165165

Missile Command/Missile-Command.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def tick(self):
294294
game.score += (city_bonus + silo_bonus + missile_bonus)
295295

296296
print("Level {} Complete".format(game.level))
297-
print("City Bonus: {} Silo Bonus: {} Missile Bonus: {}".format(city_bonus, silo_bonus, missile_bonus))
297+
print(f"City Bonus: {city_bonus} Silo Bonus: {silo_bonus} Missile Bonus: {missile_bonus}")
298298
game.level += 1
299299

300300
# Reset enemy missiles
@@ -327,4 +327,4 @@ def tick(self):
327327
player_missiles[i].clear()
328328

329329
# Update status label
330-
status_label.update("Missile Command \nLevel: {} \nScore: {} \nCities: {} \nSilos: {} \nPlayer Missiles: {} \nEnemy Missiles: {}".format(game.level, game.score, len(cities), len(silos), len(player_missiles), len(enemy_missiles)))
330+
status_label.update(f"Missile Command \nLevel: {game.level} \nScore: {game.score} \nCities: {len(cities)} \nSilos: {len(silos)} \nPlayer Missiles: {len(player_missiles)} \nEnemy Missiles: {len(enemy_missiles)}")
-570 Bytes
Binary file not shown.

Missile Command/spgl.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(
7171
screen_width = 800,
7272
screen_height = 600,
7373
background_color = "black",
74-
title = "Simple Game Library by Jonathan",
74+
title = "Simple Game Library",
7575
splash_time = 3):
7676

7777
# Setup using Turtle module methods
@@ -171,7 +171,7 @@ def tick(self):
171171
self.update_screen()
172172

173173
def click(self, x, y):
174-
print ("The window was clicked at ({},{})".format(x, y))
174+
print (f"The window was clicked at ({x},{y})")
175175

176176
def show_splash(self, seconds):
177177
# Show splash screen
@@ -192,7 +192,7 @@ def show_splash(self, seconds):
192192
turtle.bgpic("")
193193

194194
except:
195-
Game.logs.append("Warning: {} missing from disk.".format(self.SPLASHFILE))
195+
Game.logs.append(f"Warning: {self.SPLASHFILE} missing from disk.")
196196

197197
# Change state to running
198198
self.state = "running"
@@ -208,7 +208,7 @@ def save_data(self, key, value):
208208
data = pickle.load(open(self.DATAFILE, "rb"))
209209
except:
210210
data = {}
211-
Game.logs.append("Warning: Creating new {} file on disk.".format(self.DATAFILE))
211+
Game.logs.append(f"Warning: Creating new {self.DATAFILE} file on disk.")
212212

213213
data[key] = value
214214

@@ -221,7 +221,7 @@ def load_data(self, key):
221221
data = pickle.load(open(self.DATAFILE, "rb"))
222222
except:
223223
data = {}
224-
Game.logs.append("Warning: {} missing from disk.".format(self.DATAFILE))
224+
Game.logs.append(f"Warning: {self.DATAFILE} missing from disk.")
225225

226226
if key in data:
227227
return data[key]
@@ -289,7 +289,7 @@ def clear_terminal_screen(self):
289289
def print_game_info(self):
290290
print (self.title)
291291
print ("")
292-
print ("Window Dimensions: {}x{}".format(self.SCREEN_WIDTH, self.SCREEN_HEIGHT))
292+
print (f"Window Dimensions: {self.SCREEN_WIDTH}x{self.SCREEN_HEIGHT}")
293293
print ("")
294294

295295
# Calcuate number of active sprites
@@ -298,12 +298,12 @@ def print_game_info(self):
298298
if sprite.state:
299299
active_sprites += 1
300300

301-
print ("Number of Sprites (Active / Total): {} / {}".format(active_sprites, len(Game.sprites)))
301+
print (f"Number of Sprites (Active / Total): {active_sprites} / {len(Game.sprites)}")
302302

303-
print ("Number of Labels: {}".format(len(Game.labels)))
304-
print ("Number of Buttons: {}".format(len(Game.buttons)))
303+
print (f"Number of Labels: {len(Game.labels)}")
304+
print (f"Number of Buttons: {len(Game.buttons)}")
305305
print ("")
306-
print ("Frames Per Second (Target): {}".format(self.fps))
306+
print (f"Frames Per Second (Target): {self.fps}")
307307
print ("")
308308
self.print_error_logs()
309309

@@ -334,7 +334,7 @@ def set_background(self, image):
334334
if image.endswith(".gif"):
335335
turtle.bgpic(image)
336336
else:
337-
Game.logs.append("Warning: Background image {} must be a gif.".format(image))
337+
Game.logs.append(f"Warning: Background image {image} must be a GIF.")
338338

339339
def set_fps(self, fps):
340340
self.fps = fps
@@ -363,7 +363,7 @@ def __init__(self,
363363
try:
364364
turtle.register_shape(shape)
365365
except:
366-
Game.logs.append("Warning: {} file missing from disk.".format(shape))
366+
Game.logs.append(f"Warning: {shape} file missing from disk.")
367367

368368
# Set placeholder shape
369369
shape = "square"
@@ -417,7 +417,7 @@ def set_image(self, image, width, height):
417417
try:
418418
turtle.register_shape(image)
419419
except:
420-
Game.logs.append("Warning: {} file missing from disk.".format(image))
420+
Game.logs.append(f"Warning: {image} file missing from disk.")
421421

422422
# Set placeholder shape
423423
image = "square"
@@ -436,7 +436,7 @@ def set_bounding_box(self, width, height):
436436
self.height = height
437437

438438
def click(self, x, y):
439-
print ("The sprite was clicked at ({},{})".format(x, y))
439+
print (f"The sprite was clicked at ({x},{y})")
440440

441441
def rotate_left(self, degrees):
442442
self.lt(degrees)
@@ -453,7 +453,7 @@ def go_backward(self, distance):
453453

454454
#Label Class
455455
class Label(turtle.Turtle):
456-
def __init__(self,text,color,x = 0,y = 0,font_name = "Arial",font_size = 12,font_type = "normal",align = "left"):
456+
def __init__(self,text,color,x = 0,y = 0,font_name = "commodore 64 pixelized",font_size = 12,font_type = "normal",align = "left"):
457457
turtle.Turtle.__init__(self)
458458
self.hideturtle()
459459
self.penup()
@@ -509,7 +509,7 @@ def __init__(self,
509509
try:
510510
turtle.register_shape(shape)
511511
except:
512-
Game.logs.append("Warning: {} file missing from disk.".format(shape))
512+
Game.logs.append(f"Warning: {shape} file missing from disk.")
513513

514514
# Set placeholder shape
515515
shape = "square"
@@ -530,7 +530,7 @@ def set_image(self, image):
530530
try:
531531
turtle.register_shape(shape)
532532
except:
533-
Game.logs.append("Warning: {} file missing from disk.".format(shape))
533+
Game.logs.append(f"Warning: {shape} file missing from disk.")
534534

535535
# Set placeholder shape
536536
shape = "square"
@@ -542,4 +542,4 @@ def set_image(self, image):
542542
self.onclick(self.click)
543543

544544
def click(self, x, y):
545-
print ("The button was clicked at ({},{})".format(x, y))
545+
print (f"The button was clicked at ({x},{y})")

Snake.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
pen.penup()
4545
pen.hideturtle()
4646
pen.goto(0, 260)
47-
pen.write("Score: O High Score: 0", align="center", font=("Courier", 24, "bold"))
47+
pen.write("Score: 0 High Score: 0", align="center", font=("commodore 64 pixelized", 20, "normal"))
4848

4949
# Functions
5050
def go_up():
@@ -103,7 +103,7 @@ def move():
103103
# Reset the delay
104104
delay = 0.1
105105
pen.clear()
106-
pen.write("Score: {} High Score: {}". format(score, high_score), align="center", font=("Courier", 24, "bold"))
106+
pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("commodore 64 pixelized", 20, "normal"))
107107

108108
# Check for collision with food
109109
if head.distance(food) < 20:
@@ -130,7 +130,7 @@ def move():
130130
high_score = score
131131

132132
pen.clear()
133-
pen.write("Score: {} High Score: {}". format(score, high_score), align="center", font=("Courier", 24, "bold"))
133+
pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("commodore 64 pixelized", 20, "normal"))
134134

135135
# Move the end segment first in reverse order
136136
for index in range(len(segments)-1, 0, -1):
@@ -166,7 +166,7 @@ def move():
166166
# Reset the delay
167167
delay = 0
168168
pen.clear()
169-
pen.write("Score: {} High Score: {}". format(score, high_score), align="center", font=("Courier", 24, "bold"))
169+
pen.write(f"Score: {score} High Score: {high_score}", align="center", font=("commodore 64 pixelized", 20, "normal"))
170170

171171
time.sleep(delay)
172172
wn.mainloop()

Space Invaders/main.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
score_pen.color("white")
4040
score_pen.penup()
4141
score_pen.goto(-290, 270)
42-
scorestring = "Score: {}".format(score)
43-
score_pen.write(scorestring, False, align="left", font=("Arial", 14, "normal"))
42+
scorestring = f"Score: {score}"
43+
score_pen.write(scorestring, False, align="left", font=("commodore 64 pixelized", 14, "normal"))
4444
score_pen.hideturtle()
4545

4646
# Create player
@@ -193,9 +193,9 @@ def play_sound(sound_file, time=0):
193193

194194
# Update score
195195
score += 10
196-
scorestring = "Score: {}".format(score)
196+
scorestring = f"Score: {score}"
197197
score_pen.clear()
198-
score_pen.write(scorestring, False, align="left", font=("Arial", 14, "normal"))
198+
score_pen.write(scorestring, False, align="left", font=("commodore 64 pixelized", 14, "normal"))
199199

200200
# Play sound
201201
play_sound("explosion.wav")

Space War/main.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
turtle.speed(0)
44
turtle.bgcolor("black")
5-
turtle.title("SpaceWar by Jonathan")
6-
turtle.bgpic("starfield.gif")
5+
turtle.title("SpaceWar")
6+
turtle.setup(700,700)
7+
turtle.bgpic("Python-Projects\Space War\starfield.gif")
78
turtle.ht()
89
turtle.setundobuffer(1)
910
turtle.tracer(0)
@@ -161,10 +162,10 @@ def draw_border(self):
161162

162163
def show_status(self):
163164
self.pen.undo()
164-
msg = "Score: %s" %(self.score)
165+
msg = f"Score: {self.score}"
165166
self.pen.penup()
166167
self.pen.goto(-300, 310)
167-
self.pen.write(msg, font=("Arial", 16, "normal"))
168+
self.pen.write(msg, font=("commodore 64 pixelized", 16, "normal"))
168169

169170
# Create game object
170171
game = Game()

TETRIS.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def draw_score(pen, score):
166166
pen.color("blue")
167167
pen.hideturtle()
168168
pen.goto(-75, 350)
169-
pen.write("Score: {}".format(score), move=False, align="left", font=("Arial", 24, "normal"))
169+
pen.write(f"Score: {score}", move=False, align="left", font=("commodore 64 pixelized", 24, "normal"))
170170

171171

172172
# Create the basic shape for the start of the game

0 commit comments

Comments
 (0)