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()
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()
def __init__(self,owner,item_power,item_colour=libtcod.green,bar_colour=libtcod.dark_green): count_to = int( 30 - 10*item_power ) self.bar = HBar(None, None, bar_colour, libtcod.dark_grey, True, False, str(self), str.ljust) self.bar.is_visible = False Item.__init__(self,owner,item_power,item_colour) CountUp.__init__(self,count_to,count_to) TurnTaker.__init__(self,100,False) self.is_chargable = True
def __init__(self, pos): Floor.__init__(self, pos) Talker.__init__(self) Shouter.__init__(self, 30) TurnTaker.__init__(self,0) Trap.__init__(self) self.add_phrases(None,["** BORK! BORK! **","** BEEEEEEE! **"],0.9,True) self.show_probability = 0.05
def activate(self,activator=None): if not self.full(): print ("%s still on cooldown, %d turns remaining"%(self,self.count_to-self.count)) # still on cooldown return False self.reset(0) # was -1 because we immediately inc() TurnTaker.add_turntaker(self) return True
def __init__(self, pos): Floor.__init__(self, pos) Talker.__init__(self) Shouter.__init__(self, 30) TurnTaker.__init__(self, 0) Trap.__init__(self) self.add_phrases(None, ["** BORK! BORK! **", "** BEEEEEEE! **"], 0.9, True) self.show_probability = 0.05
def __init__(self, pos): Tile.__init__(self, pos, Door.CLOSED['symbol'], Door.CLOSED['colour'], Door.CLOSED['walkcost'], Door.CLOSED['transparency']) CountUp.__init__(self, Door.CLOSED['timer']) TurnTaker.__init__(self,5) self.unseen_symbol = Door.CLOSED['symbol'] # always shows as closed when can't be seen self.state = Door.CLOSED self.bar = HBar(Position(pos.x-1,pos.y-1),3,Door.CLOSED['barcolour'],libtcod.darkest_grey) self.bar.max_value = self.count_to-1 self.bar.timeout = 5.0 self._trying_to_open = False
def __init__(self,owner,item_power,valid_slot,item_colour=libtcod.cyan,bar_colour=libtcod.dark_cyan): self.bar = HBar(None, None, bar_colour, libtcod.dark_grey, True, False, str(self), str.ljust) self.bar.is_visible = False SlotItem.__init__(self,owner,item_power,valid_slot,item_colour,bar_colour) count_to = int( 50 + 100*item_power ) CountUp.__init__(self,count_to) TurnTaker.__init__(self,100,False) self.is_active = False self.is_chargable = True
def activate(self,activator=None): if not RunDownItem.activate(self): return False if self.is_active: TurnTaker.add_turntaker(self.owner) else: TurnTaker.clear_turntaker(self.owner) return True
def refresh_turntaker(self): TurnTaker.refresh_turntaker(self) for i in self.items + list(self.slot_items.values()): # switch off active rundownitem items before level transition if isinstance(i,RunDownItem) and i.is_active: print("switching off %s" % i) i.activate() elif isinstance(i,TurnTaker): i.refresh_turntaker() # TODO: this isn't great :( if hasattr(i,'bar') and isinstance(i.bar,UI): i.bar.refresh_ui_list()
def __init__(self, pos): Tile.__init__(self, pos, Door.CLOSED['symbol'], Door.CLOSED['colour'], Door.CLOSED['walkcost'], Door.CLOSED['transparency']) CountUp.__init__(self, Door.CLOSED['timer']) TurnTaker.__init__(self, 5) self.unseen_symbol = Door.CLOSED[ 'symbol'] # always shows as closed when can't be seen self.state = Door.CLOSED self.bar = HBar(Position(pos.x - 1, pos.y - 1), 3, Door.CLOSED['barcolour'], libtcod.darkest_grey) self.bar.max_value = self.count_to - 1 self.bar.timeout = 5.0 self._trying_to_open = False
def refresh_turntaker(self): TurnTaker.refresh_turntaker(self) for i in self.items + list(self.slot_items.values()): # switch off active rundownitem items before level transition if isinstance(i, RunDownItem) and i.is_active: print("switching off %s" % i) i.activate() elif isinstance(i, TurnTaker): i.refresh_turntaker() # TODO: this isn't great :( if hasattr(i, 'bar') and isinstance(i.bar, UI): i.bar.refresh_ui_list()
def __init__(self, pos=None): Mappable.__init__(self, pos, '@', libtcod.white) StatusEffect.__init__(self) TurnTaker.__init__(self, 1) HasInventory.__init__( self, 3, (SlotItem.HEAD_SLOT, SlotItem.BODY_SLOT, SlotItem.FEET_SLOT)) LightSource.__init__(self, 2, 0.1) self.items = [None, None, None] self.slot_items = { SlotItem.HEAD_SLOT: None, SlotItem.BODY_SLOT: None, SlotItem.FEET_SLOT: None, } self.turns = 0 self.evidence = [] self.levels_seen = 1 # init items (must be done this way to invoke any pickup triggers) # - inv items self.pickup(Item.random(None, self, 2, 1.5)) self.pickup(Item.random(None, self, 1)) # - slot items self.pickup(NightVisionGoggles(self)) self.pickup(NinjaSuit(self)) self.pickup(RunningShoes(self)) self.KEYMAP = { 'k': self.move_n, 'j': self.move_s, 'h': self.move_w, 'l': self.move_e, 'y': self.move_nw, 'u': self.move_ne, 'b': self.move_sw, 'n': self.move_se, '.': self.do_nothing, '1': self.use_item1, '2': self.use_item2, '3': self.use_item3, '4': self.use_head, '5': self.use_body, '6': self.use_feet, 'Q': sys.exit, 'R': self.reset_game, ' ': self.interact, 'd': self.drop, 'L': self.debug_lighting, }
def __init__(self,pos=None): Mappable.__init__(self,pos,'@',libtcod.white) StatusEffect.__init__(self) TurnTaker.__init__(self,1) HasInventory.__init__(self,3,(SlotItem.HEAD_SLOT,SlotItem.BODY_SLOT,SlotItem.FEET_SLOT)) LightSource.__init__(self,2,0.1) self.items = [None,None,None] self.slot_items = { SlotItem.HEAD_SLOT: None, SlotItem.BODY_SLOT: None, SlotItem.FEET_SLOT: None, } self.turns = 0 self.evidence = [] self.levels_seen = 1 # init items (must be done this way to invoke any pickup triggers) # - inv items self.pickup(Item.random(None,self,2,1.5)) self.pickup(Item.random(None,self,1)) # - slot items self.pickup(NightVisionGoggles(self)) self.pickup(NinjaSuit(self)) self.pickup(RunningShoes(self)) self.KEYMAP = { 'k': self.move_n, 'j': self.move_s, 'h': self.move_w, 'l': self.move_e, 'y': self.move_nw, 'u': self.move_ne, 'b': self.move_sw, 'n': self.move_se, '.': self.do_nothing, '1': self.use_item1, '2': self.use_item2, '3': self.use_item3, '4': self.use_head, '5': self.use_body, '6': self.use_feet, 'Q': sys.exit, 'R': self.reset_game, ' ': self.interact, 'd': self.drop, 'L': self.debug_lighting, }
def activate(self,activator=None): if self.is_active: # deactivate an active item self.is_active = False TurnTaker.clear_turntaker(self) return True elif self.full(): # can't activate one that's run out return False else: self.is_active = True TurnTaker.add_turntaker(self) self.inc(4) # activation costs 4 + 1 for the first turn; discouraging flickering self.take_turn() # so takes effect straight away if any turn taking behaviour return True
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)
def __init__(self,pos,symbol,colour): Mappable.__init__(self,pos,symbol,colour) TurnTaker.__init__(self,10) StatusEffect.__init__(self)
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)
def take_turn(self): if self.inc(): TurnTaker.clear_turntaker(self) return True return False