def direction(): main_space = maze.get_current_space() for i in list_dir: if user_input == i: if check_valid_move(list_dir[i]): maze.move(list_dir[i]) maze.look_around() else: print("There is a wall/!")
def move(self, w): dst = maze.move(self.pos, w) val = self.go_to(dst) if val == maze.FINISH: return self.push("YOU WIN !, but wait, did you SEE the treasure ?") if val == maze.EMPTY: self.pos = dst return self.push("Ok ! Continue !") self.push("Can't go there ... ")
def test_move_north(self, mock_input_loop): self.assertEqual(move([2, 2]), [1, 2])
def test_output_dead_end(self, mock_stdout, mock_input_loop): expected_output = 'You\'ve reached a dead end! Best not to continue past here ' \ 'or you will likely be eaten by a grue...\n' move([0, 0]) self.assertEqual(mock_stdout.getvalue(), expected_output)
def test_move_west(self, mock_input_loop): self.assertEqual(move([2, 2]), [2, 1])
def test_move_south(self, mock_input_loop): self.assertEqual(move([2, 2]), [3, 2])
player = ch.player_init(d,maze) exit = ch.exit_init(d,player,maze_e) boss = ch.boss_init(d,player,exit,maze_b) message() m.pmaze(d,maze,'p') while True: c = getch.getch() # c = Getch() if c=='q': sys.exit(0) if c=='w': m.move(d,maze_b) now = m.nowpos(d,maze) if now[0]==0: print('Don\'t go up! You want to DIE?') m.pmaze(d,maze,'p') else: x = now[0] y = now[1] maze[x][y]=0 maze[x-1][y]=1 stat = m.check(d,maze,maze_e,maze_b) cont = m.gameover(stat) if cont == 1: m.restart(d,maze,maze_e,maze_b,player,exit,boss) elif cont == 0 : print('GoodBye~')