/
DalekRL.py
executable file
·84 lines (63 loc) · 2.2 KB
/
DalekRL.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
#!/usr/bin/env python3
# system imports
import os
import sys
# libtcod
import libtcodpy as libtcod
# our imports
from interfaces import Position, TurnTaker
from ui import UI
from maps import Map
from player import Player
from errors import GameOverError, LevelWinError
SCREEN_SIZE = Position(80,50)
LIMIT_FPS = 10
RANDOM_SEED = 1999
MAP = None
PLAYER = None
# for now
if len(sys.argv)>1 and sys.argv[0].startswith('DalekRL') and len(sys.argv[1])>0:
RANDOM_SEED=int(sys.argv[1])-1
def init():
# init window
font = os.path.join(b'resources', b'consolas10x10_gs_tc.png')
libtcod.console_set_custom_font(font, libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(SCREEN_SIZE.x, SCREEN_SIZE.y, b'DalekRL')
libtcod.sys_set_fps(LIMIT_FPS)
# set default text palette # TODO: merge with UI class statics
libtcod.console_set_color_control(libtcod.COLCTRL_1,libtcod.red,libtcod.black)
libtcod.console_set_color_control(libtcod.COLCTRL_2,libtcod.dark_yellow,libtcod.black)
libtcod.console_set_color_control(libtcod.COLCTRL_3,libtcod.light_green,libtcod.black)
libtcod.console_set_color_control(libtcod.COLCTRL_4,libtcod.light_blue,libtcod.black)
libtcod.console_set_color_control(libtcod.COLCTRL_5,libtcod.purple,libtcod.black)
def reset(keep_player=False):
global SCREEN_SIZE, RANDOM_SEED, MAP, PLAYER
RANDOM_SEED += 1
UI.clear_all()
TurnTaker.clear_all()
if keep_player:
PLAYER.refresh_turntaker()
PLAYER.levels_seen += 1
else:
if not PLAYER is None:
print("Game Over")
print("%d evidence in %d turns; %d levels seen" %(len(PLAYER.evidence),PLAYER.turns,PLAYER.levels_seen))
PLAYER = Player()
if not MAP is None:
MAP.close()
del MAP
MAP = Map.random(RANDOM_SEED,SCREEN_SIZE-(0,4),PLAYER)
MAP.generate()
if __name__ == '__main__':
init()
# main loop
reset()
while not libtcod.console_is_window_closed():
print("-------------")
try:
# monster movement and items
TurnTaker.take_all_turns()
except GameOverError:
reset(False)
except LevelWinError:
reset(True)