class BoardGame(object): def __init__(self): self.players = (Player(0), Player(1)) self._initialize_board() self.display = Display(self.board) self.display.render() def _initialize_board(self): self.board = Board(*self.players) def start(self): players = cycle(self.players) while True: try: player = players.next() print "PLAYER {}".format(player.id) while True: move = player.request_move() if self.board.valid_move(move, player): break print "Invalid move. Try again!" self.board.move(move) self.display.render() print print "PIECES REMAINING {}".format(self.board.get_stats()) print except (KeyboardInterrupt, EOFError): print sys.exit()
def main(): """Run the main part.""" mappy = Mappy() screen = Display(mappy) macgyver = Angus(mappy) loop = True # main loop play = True # allow moves while loop: for event in pygame.event.get(): if event.type == 12: # pygame.QUIT: loop = False if event.type == 2: if event.key == 113: # Q loop = False if play: screen.message = False # del instruction msg first move if event.key == K_DOWN: macgyver.move("DOWN") if event.key == K_UP: macgyver.move("UP") if event.key == K_RIGHT: macgyver.move("RIGHT") if event.key == K_LEFT: macgyver.move("LEFT") # compare items' position to MacGyver's if mappy.macgyver == mappy.ether: macgyver.ether = True mappy.ether = None if mappy.macgyver == mappy.needle: macgyver.needle = True mappy.needle = None if mappy.macgyver == mappy.tube: macgyver.tube = True mappy.tube = None if mappy.macgyver == mappy.guardian: # test if inventory is full if not macgyver.is_inventory_full(): screen.message = "LOOSE" play = False if mappy.macgyver == mappy.exit: screen.message = "WIN" play = False screen.refresh_screen()
#*-*coding:utf-8*-* import pygame if __name__ == "__main__": pygame.init() win = pygame.display.set_mode((1350,700)) pygame.display.set_caption("10Jumps") filename = 'game_assets/monsterboy_assets.png' #clock = pygame.time.Clock() #font = pygame.font.SysFont("Comic Sans Ms", 20) from gui import Display display = Display(win, filename) display.run()
def __init__(self): self.players = (Player(0), Player(1)) self._initialize_board() self.display = Display(self.board) self.display.render()
def test_stop_loose(self): mappy = Mappy() screen = Display(mappy) screen.message = "LOOSE"
def test_stop_win(self): mappy = Mappy() screen = Display(mappy) screen.message = "WIN"
def test_display(self): mappy = Mappy() screen = Display(mappy)