/
__main__.py
91 lines (71 loc) · 2.05 KB
/
__main__.py
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
#!/usr/bin/python
import pygame
import colors
import flower as f
import event as e
import manager as m
import rabbit as r
import terrain as t
import unit as u
TITLE = "It's Game Time!"
FPS = 60
def init():
pygame.init()
m.init()
t.init()
u.init()
def main():
# Initialize everything
init()
# Setup the screen
size = t.screen_size()
screen = pygame.display.set_mode(size)
pygame.display.set_caption(TITLE)
# Initialize clock
clock = pygame.time.Clock()
# Initialize background
screen.fill(colors.BLACK)
pygame.display.flip()
while True:
dt = clock.tick( FPS ) / 1000.
# Handle events and change state as necessary
for event in pygame.event.get():
m.process( event )
for event in e.Event.get():
m.process( event )
# Update all units
for unit in u.all():
unit.update( dt )
flower_count = 0
rabbit_count = 0
for unit in u.all():
if isinstance(unit, f.Flower):
flower_count += 1
if isinstance(unit, r.Rabbit):
rabbit_count += 1
# Redraw screen
screen.fill(colors.BLACK)
for terrain in t.all():
terrain.draw(screen)
for unit in u.all():
unit.draw(screen)
pygame.display.flip()
# End game condition
if rabbit_count == 0:
pygame.font.init()
font = pygame.font.SysFont("Monospace",100)
win = font.render("You win!!!",1,colors.BLUE)
screen.blit(win,(0,0))#self.terain
pygame.display.flip()
pygame.time.wait(5000)
m.quit( None )
if flower_count == 0:
pygame.font.init()
font = pygame.font.SysFont("Monospace",100)
lose = font.render("You lose!!!",1,colors.RED)
screen.blit(lose,(0,0))#self.terain
pygame.display.flip()
pygame.time.wait(5000)
m.quit( None )
if __name__ == '__main__':
main()