-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
85 lines (70 loc) · 2.18 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
import os
import random
from game.casting.actor import Actor
from game.casting.artifact import Artifact
from game.casting.cast import Cast
from game.directing.director import Director
from game.services.keyboard_service import KeyboardService
from game.services.video_service import VideoService
from game.shared.color import Color
from game.shared.point import Point
FRAME_RATE = 12
MAX_X = 900
MAX_Y = 600
CELL_SIZE = 15
FONT_SIZE = 15
COLS = 60
ROWS = 40
CAPTION = "GREED"
DATA_PATH = os.path.dirname(os.path.abspath(__file__)) + "/data/messages.txt"
WHITE = Color(255, 255, 255)
DEFAULT_ARTIFACTS = 25
def main():
# create the cast
cast = Cast()
# create the banner
banner = Actor()
banner.set_text("")
banner.set_font_size(FONT_SIZE)
banner.set_color(WHITE)
banner.set_position(Point(CELL_SIZE, 0))
cast.add_actor("banners", banner)
# create the robot
x = int(MAX_X / 2)
y = int(MAX_Y / 2)
position = Point(x, 585)
robot = Actor()
robot.set_text("#")
robot.set_font_size(FONT_SIZE)
robot.set_color(WHITE)
robot.set_position(position)
cast.add_actor("robots", robot)
# create the artifacts
with open(DATA_PATH) as file:
data = file.read()
messages = data.splitlines()
for n in range(DEFAULT_ARTIFACTS):
text = chr(random.randint(33, 126))
message = messages[n]
x = random.randint(1, COLS - 1)
y = (0)
position = Point(x, y)
position = position.scale(CELL_SIZE)
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
color = Color(r, g, b)
artifact = Artifact()
artifact.set_text(text)
artifact.set_font_size(FONT_SIZE)
artifact.set_color(color)
artifact.set_position(position)
artifact.set_message(message)
cast.add_actor("artifacts", artifact)
# start the game
keyboard_service = KeyboardService(CELL_SIZE)
video_service = VideoService(CAPTION, MAX_X, MAX_Y, CELL_SIZE, FRAME_RATE)
director = Director(keyboard_service, video_service)
director.start_game(cast)
if __name__ == "__main__":
main()