def test_level(fn): level = Level() level.read(fn) solutions = level.solve() assert len(solutions) > 0 assert level.par == len(solutions[0])
def setUp(self): self.level = Level() self.room_a = Room(width=2, height=3) self.room_a.x, self.room_a.y = 0, 0 self.room_b = Room(width=2, height=1) self.room_b.x, self.room_b.y = 2, 3 for room in (self.room_a, self.room_b): self.level.add(room)
def __init__(self): pg.init() self.maze = Maze() pg.display.set_mode((WIDTH, HEIGHT)) pg.image.load(FL).convert() pg.image.load(WA).convert() pg.image.load(E).convert_alpha() pg.image.load(T).convert_alpha() pg.image.load(S).convert_alpha() pg.image.load(BG).convert_alpha() pg.image.load(PL).convert_alpha() pg.display.set_caption('The Maze') self.clock = pg.time.Clock() self.is_running = True self.SCREEN = pg.display.set_mode((WIDTH, HEIGHT)) self.fond = pg.image.load("./images/floor-tiles-20x20.png").convert() self.level = Level() self.run()
def setup (self): keyboard = mixin (KeyboardTask, AutoSender) ( DEFAULT_KEYMAP) base.setBackgroundColor (Vec4 (.4, .6, .9, 1)) self.events.connect (keyboard) self.events.event ('panda-escape').connect (self.kill) physics = Physics () boy = Boy (physics = physics, render = render) boy.set_position ((0, 70, 20)) level = Level (physics = physics, render = render) level.set_position ((0, 0, -100)) self.tasks.add (keyboard) self.tasks.add (boy) self.tasks.add (level) self.tasks.add (physics) boy.connect (SlowEntityFollower (base.camera)) keyboard.connect ( mixin (DelegatePlayerEntity, AutoReceiver) (delegate = boy)) plightnode = PointLight("point light") plightnode.setAttenuation (Vec3(1,0.0000005,0.0000001)) plight = render.attachNewNode (plightnode) plight.setPos (100, -100, 1000) alightnode = AmbientLight("ambient light") alightnode.setColor (Vec4(0.4,0.4,0.4,1)) alight = render.attachNewNode (alightnode) #render.setLight (alight) render.setLight (plight)
def start_game(): appium = webdriver.Remote(config.APPIUM_HOST, config.DESIRED_CAPABILITIES) unity = AltrunUnityDriver(appium, config.PLATFORM) main_menu = MainMenu(unity) main_menu.play_button.tap() return { "Appium": appium, "Unity": unity, "Game": Game(unity), "MainMenu": main_menu, "Level": Level(unity), "Player": Player(unity), "LevelCompleteMenu": LevelComplete(unity), }
class Play(GameState): """The GameState while actually playing a level.""" highlight = Renderable("resources/images/highlight.png", TILE_CENTER) win = Renderable("resources/images/cleared_screen.png", Point(605 / 2, 455 / 2), ignore_cam=True) restart = Renderable("resources/images/restart_button.png", Point(100, 0), ignore_cam=True) levels = Renderable("resources/images/levels_button.png", Point(0, 0), ignore_cam=True) def __init__(self, filepath): super(Play, self).__init__() self.filepath = filepath tileset = Tileset('resources/tileset/default.tset') self.level = Level(tileset, filepath) def logic(self, mouse): if mouse.clicked: scr = SCREEN.center * 2 # restart button if (scr.x - SCREEN.camera.x - mouse.pos.x <= 100 and SCREEN.camera.y + mouse.pos.y <= 65): self.next = Play(self.filepath) # levels button elif (SCREEN.camera.x + mouse.pos.x <= 100 and SCREEN.camera.y + mouse.pos.y <= 65): self.next = LevelPicker() else: # pass the win dialogs if self.level.win(): if (SCREEN.center - SCREEN.camera - mouse.pos).x > 0: self.next = Title() else: self.next = LevelPicker() # pass the click to the level tile = screen_to_iso(mouse.pos) self.level.tile_clicked(tile) self.level.knight.logic() def render(self, mouse): self.level.render() self.highlight.render(iso_to_screen(screen_to_iso(mouse.pos))) self.restart.render(Point((SCREEN.center * 2).x, 0)) self.levels.render(Point(0, 0)) if self.level.win(): self.win.render(SCREEN.center)
class Play(GameState): """The GameState while actually playing a level.""" highlight = Renderable("resources/images/highlight.png", TILE_CENTER) win = Renderable("resources/images/cleared_screen.png", Point(605/2, 455/2), ignore_cam=True) restart = Renderable("resources/images/restart_button.png", Point(100, 0), ignore_cam=True) levels = Renderable("resources/images/levels_button.png", Point(0, 0), ignore_cam=True) def __init__(self, filepath): super(Play, self).__init__() self.filepath = filepath tileset = Tileset('resources/tileset/default.tset') self.level = Level(tileset, filepath) def logic(self, mouse): if mouse.clicked: scr = SCREEN.center * 2 # restart button if (scr.x - SCREEN.camera.x - mouse.pos.x <= 100 and SCREEN.camera.y + mouse.pos.y <= 65): self.next = Play(self.filepath) # levels button elif (SCREEN.camera.x + mouse.pos.x <= 100 and SCREEN.camera.y + mouse.pos.y <= 65): self.next = LevelPicker() else: # pass the win dialogs if self.level.win(): if (SCREEN.center - SCREEN.camera - mouse.pos).x > 0: self.next = Title() else: self.next = LevelPicker() # pass the click to the level tile = screen_to_iso(mouse.pos) self.level.tile_clicked(tile) self.level.knight.logic() def render(self, mouse): self.level.render() self.highlight.render(iso_to_screen(screen_to_iso(mouse.pos))) self.restart.render(Point((SCREEN.center * 2).x, 0)) self.levels.render(Point(0, 0)) if self.level.win(): self.win.render(SCREEN.center)
class LevelGetRoomTest(TestCase): def setUp(self): self.level = Level() self.room_a = Room(width=2, height=3) self.room_a.x, self.room_a.y = 0, 0 self.room_b = Room(width=2, height=1) self.room_b.x, self.room_b.y = 2, 3 for room in (self.room_a, self.room_b): self.level.add(room) def test_get_nothing(self): self.assertEqual(self.level.get(x=128, y=128), set()) def test_get_one_room(self): self.assertEqual(self.level.get(x=0, y=0), set([self.room_a])) def test_get_multiple_rooms(self): self.assertEqual(self.level.get(width=2), set([self.room_a, self.room_b])) def test_get_with_nonexistent_kwargs(self): self.assertEqual(self.level.get(nonexistent_kwarg=True), set())
class LevelGenerateTest(TestCase): def setUp(self): self.level = Level() def test_generate_one_room(self): self.level.generate(num=1) self.assertEqual(len(self.level.rooms), 1) def test_generate_two_rooms(self): self.level.generate(num=2) self.assertEqual(len(self.level.rooms), 2) room_a, room_b = self.level.rooms a_x, a_y = room_a.x, room_a.y a_w, a_h = room_a.width, room_a.height b_x, b_y = room_b.x, room_b.y b_w, b_h = room_b.width, room_b.height self.assertTrue( (max(a_x, b_x) - min(a_x, b_x) <= max(a_w, b_w) + 1) or (max(a_y, b_y) - min(a_y, b_y) <= max(a_h, b_h) + 1)) def test_generate_eight_rooms(self): self.level.generate(num=8) self.assertEqual(len(self.level.rooms), 8)
def level(unity): return Level(unity)
class Game: def __init__(self): pg.init() self.maze = Maze() pg.display.set_mode((WIDTH, HEIGHT)) pg.image.load(FL).convert() pg.image.load(WA).convert() pg.image.load(E).convert_alpha() pg.image.load(T).convert_alpha() pg.image.load(S).convert_alpha() pg.image.load(BG).convert_alpha() pg.image.load(PL).convert_alpha() pg.display.set_caption('The Maze') self.clock = pg.time.Clock() self.is_running = True self.SCREEN = pg.display.set_mode((WIDTH, HEIGHT)) self.fond = pg.image.load("./images/floor-tiles-20x20.png").convert() self.level = Level() self.run() def run(self): self.SCREEN.blit(self.fond, (0, 0)) self.level.display(self.maze.tiles) self.count_display() self.main_loop() def count_display(self): # create a black surface and display it s = pg.Surface((300, 100)) s.fill((0, 0, 0)) self.SCREEN.blit(s, (20, 300)) # write object count white = (255, 255, 255) phrase = "nombre d'objets ramassés : " + str(self.maze.numb_objects) font = pg.font.SysFont("arial", 24) text = font.render(phrase, True, white) self.SCREEN.blit(text, (20, 310)) def main_loop(self): x = 0 y = 20 is_running = True while is_running: clock.tick(5) for event in pg.event.get(): if event.type == Kd and event.key == pg.K_RIGHT: if self.maze.move_macgyver("right"): SCREEN.blit(pg.image.load(FL).convert(), (x, y)) x += 1 * SIZE_SPRITE SCREEN.blit(pg.image.load(PL).convert_alpha(), (x, y)) elif event.type == Kd and event.key == pg.K_LEFT: if self.maze.move_macgyver("left"): SCREEN.blit(pg.image.load(FL).convert(), (x, y)) x -= 1 * SIZE_SPRITE SCREEN.blit(pg.image.load(PL).convert_alpha(), (x, y)) elif event.type == Kd and event.key == pg.K_UP: if self.maze.move_macgyver("up"): SCREEN.blit(pg.image.load(FL).convert(), (x, y)) y -= 1 * SIZE_SPRITE SCREEN.blit(pg.image.load(PL).convert_alpha(), (x, y)) elif event.type == Kd and event.key == pg.K_DOWN: if self.maze.move_macgyver("down"): SCREEN.blit(pg.image.load(FL).convert(), (x, y)) y += 1 * SIZE_SPRITE SCREEN.blit(pg.image.load(PL).convert_alpha(), (x, y)) if event.type == pg.QUIT: is_running = False self.count_display() pg.display.update() pg.quit()
import pygame as pg from pygame.locals import KEYDOWN as Kd from game.settings import E, T, S, FL, WA, BG, PL, WIDTH, HEIGHT, SIZE_SPRITE from game.level import Level from game.the_maze import Maze clock = pg.time.Clock() pg.display.set_caption('The Maze') level = Level() SCREEN = pg.display.set_mode((WIDTH, HEIGHT)) class Game: def __init__(self): pg.init() self.maze = Maze() pg.display.set_mode((WIDTH, HEIGHT)) pg.image.load(FL).convert() pg.image.load(WA).convert() pg.image.load(E).convert_alpha() pg.image.load(T).convert_alpha() pg.image.load(S).convert_alpha() pg.image.load(BG).convert_alpha() pg.image.load(PL).convert_alpha() pg.display.set_caption('The Maze') self.clock = pg.time.Clock() self.is_running = True self.SCREEN = pg.display.set_mode((WIDTH, HEIGHT)) self.fond = pg.image.load("./images/floor-tiles-20x20.png").convert() self.level = Level()
def __init__(self, filepath): super(Play, self).__init__() self.filepath = filepath tileset = Tileset('resources/tileset/default.tset') self.level = Level(tileset, filepath)
def __game(self): print("entering __game") levels = Level(self.graphics, "home") bobby = Bobby(self.graphics) finalrender = pygame.Surface( (levels.get_map_size()[0], levels.get_map_size()[1])) in_dial = False pnj_name = "null" dial_count = 1 state_to_return = "EXIT" goon = True while goon: #print(self.clock.get_fps()) deltatime = self.clock.tick(30) / 100.0 #events for event in pygame.event.get(): if event.type == QUIT: goon = False if in_dial: if event.type == pygame.KEYUP: if event.key == pygame.K_ESCAPE: in_dial = False pnj_name = "null" dial_count = 1 if event.key == pygame.K_RETURN: dial_count += 1 if dial_count > len( levels.chars[pnj_name]["dials"]): in_dial = False pnj_name = "null" dial_count = 1 else: levels.event(event) bobby.event(event) # updates bob_value = bobby.update(deltatime, levels.get_map_size(), levels) if bobby.get_state_to_return() == "MENU": state_to_return = "MENU" goon = False levels.update(bob_value, bobby) if levels.currentmap == "credits": goon = False state_to_return = "CREDITS" break if finalrender.get_width() != levels.get_map_size( )[0] or finalrender.get_height() != levels.get_map_size()[1]: finalrender = pygame.Surface( (levels.get_map_size()[0], levels.get_map_size()[1])) # draws finalrender.blit(levels.draw(), (0, 0)) b_x, b_y = bobby.get_pos() finalrender.blit(bobby.draw(), (b_x, b_y)) self.screen.blit( pygame.transform.scale(finalrender, (c.WINDOW_WIDTH, c.WINDOW_HEIGHT)), (0, 0)) if bob_value.split(' ')[0] == "pnj" and not in_dial: # or in_dial in_dial = True pnj_name = bob_value.split(' ')[1] elif in_dial: bobby_talk = False my_font = pygame.font.Font("res/ubuntumono-r.ttf", 22) my_string = levels.chars[pnj_name]["dials"][str(dial_count)] if my_string[0] == "*": bobby_talk = True my_string = "<Bobby> " + my_string[1:] else: my_string = "<" + pnj_name[0].upper( ) + pnj_name[1:] + "> " + my_string my_rect = pygame.Rect( (0, 0, c.WINDOW_WIDTH, c.WINDOW_HEIGHT / 4)) rendered_text = Dialog().render_textrect( my_string, my_font, my_rect, (216, 216, 216), (0, 0, 20, 225), 0) self.screen.blit( rendered_text, (0, c.WINDOW_HEIGHT - rendered_text.get_height())) # TODO: Change head if ":" or "*" if bobby_talk: head = pygame.transform.scale( self.graphics["bobby_head.png"], (175, rendered_text.get_height() + 50)) else: head = pygame.transform.scale( self.graphics[pnj_name + "_head.png"], (175, rendered_text.get_height() + 50)) self.screen.blit( head, (0, c.WINDOW_HEIGHT - rendered_text.get_height())) continue_font = my_font continue_font.set_italic(True) dial_left = "(" + str(dial_count) + "/" + str( len(levels.chars[pnj_name]["dials"])) + ")" continue_font_rendered = continue_font.render( "Press Enter to continue... " + dial_left, 1, (150, 150, 150)) self.screen.blit( continue_font_rendered, (c.WINDOW_WIDTH - continue_font_rendered.get_width(), c.WINDOW_HEIGHT - continue_font_rendered.get_height())) pygame.display.flip() print("exiting __game") return state_to_return
class LevelAddRoomTest(TestCase): def setUp(self): self.level = Level() def test_empty_level(self): self.assertEqual(self.level.rooms, set()) def test_level_with_one_room(self): room = Room(width=1, height=1) room.x, room.y = 0, 0 self.level.add(room) self.assertEqual(self.level.rooms, set([room])) def test_add_room_without_coordinates(self): room = Room(width=1, height=1) with self.assertRaises(Level.RoomCoordinatesRequired): self.level.add(room) def test_add_an_overlapping_room_with_matching_coordinates(self): room = Room(width=1, height=1) room.x, room.y = 0, 0 self.level.add(room) overlap_room = Room(width=1, height=1) overlap_room.x, overlap_room.y = 0, 0 with self.assertRaises(Level.RoomOverlap): self.level.add(overlap_room) def test_add_an_overlapping_room_with_positive_shift(self): room = Room(width=3, height=3) room.x, room.y = 0, 0 self.level.add(room) overlap_room = Room(width=2, height=2) overlap_room.x, overlap_room.y = 2, 2 with self.assertRaises(Level.RoomOverlap): self.level.add(overlap_room) def test_add_an_overlapping_room_with_negative_shift(self): room = Room(width=3, height=3) room.x, room.y = 3, 3 self.level.add(room) overlap_room = Room(width=2, height=2) overlap_room.x, overlap_room.y = 2, 2 with self.assertRaises(Level.RoomOverlap): self.level.add(overlap_room) def test_level_with_two_non_adjacent_rooms(self): for x, y in [(0, 0), (3, 3)]: room = Room(width=1, height=1) room.x, room.y = x, y self.level.add(room) self.assertEqual(len(self.level.rooms), 2) def test_two_diagonaly_adjacent_rooms(self): """ Rooms are not considered to be adjacent if they touch diagonaly. """ for x, y in [(0, 0), (1, 1)]: room = Room(width=1, height=1) room.x, room.y = x, y self.level.add(room) turf = iter(room.get(x=0, y=0)).next() self.assertEqual(turf.exits, {}) self.assertEqual(len(self.level.rooms), 2) def test_level_with_two_fully_adjacent_rooms(self): """Exits are added to adjacent turfs.""" a, b = Room(width=1, height=1), Room(width=1, height=1) a.x, a.y, b.x, b.y = 0, 0, 1, 0 self.level.add(a) self.level.add(b) turf_a = iter(a.get(x=0, y=0)).next() turf_b = iter(b.get(x=0, y=0)).next() self.assertEqual(len(self.level.rooms), 2) self.assertEqual(len(turf_a.exits), 1) self.assertEqual(len(turf_b.exits), 1) self.assertEqual(turf_a.exits[(1, 0)], turf_b) self.assertEqual(turf_b.exits[(-1, 0)], turf_a) def test_level_with_two_partially_adjacent_rooms(self): """Non-adjacent turfs do not become exits.""" a, b = Room(width=3, height=3), Room(width=3, height=3) a.x, a.y, b.x, b.y = 3, 1, 0, 0 self.level.add(a) self.level.add(b) exits = set([((0, 0), (2, 1)), ((0, 1), (2, 2))]) for ((a_x, a_y), (b_x, b_y)) in exits: turf_a = iter(a.get(x=a_x, y=a_y)).next() turf_b = iter(b.get(x=b_x, y=b_y)).next() self.assertEqual(len(turf_a.exits), 1) self.assertEqual(len(turf_b.exits), 1) self.assertEqual(turf_a.exits[(-1, 0)], turf_b) self.assertEqual(turf_b.exits[(1, 0)], turf_a) no_exits = { a: set([(0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]), b: set([(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)])} for room, coordinates in no_exits.items(): for (x, y) in coordinates: turf = iter(room.get(x=x, y=y)).next() self.assertEqual(len(turf.exits), 0) def test_level_with_three_adjacent_rooms(self): a, b, c = Room(width=1, height=1), Room(1, 1), Room(1, 1) a.x, a.y, b.x, b.y, c.x, c.y = 0, 0, 1, 0, 0, 1 for room in (a, b, c): self.level.add(room) turf_a = iter(a.get(x=0, y=0)).next() turf_b = iter(b.get(x=0, y=0)).next() turf_c = iter(c.get(x=0, y=0)).next() self.assertEqual(len(turf_a.exits), 2) for turf in (turf_b, turf_c): self.assertEqual(len(turf.exits), 1) self.assertEqual(turf_a.exits, {(1, 0): turf_b, (0, 1): turf_c}) self.assertEqual(turf_b.exits[(-1, 0)], turf_a) self.assertEqual(turf_c.exits[(0, -1)], turf_a)
Level( pygame.image.load("./assets/bgs/hometown.png"), "./assets/sounds/music/pallet_town.mp3", [ Entity([0, 0], [430, 75]), # level walls Entity([0, 0], [220, 720]), Entity([0, 560], [1080, 720]), Entity([1080 - 224, 0], [224, 720]), Entity([1080 - 434, 0], [434, 75]), Entity([315, 90], [140, 80]), # topleft house Entity([315, 90], [35, 110]), Entity([400, 90], [55, 110]), Entity([620, 90], [140, 80]), # topright house Entity([620, 90], [35, 110]), Entity([705, 90], [55, 110]), Entity([620, 310], [140, 80]), # bottomright house Entity([620, 310], [35, 110]), Entity([705, 310], [55, 110]), Entity([300, 310], [180, 80]), # oakslab Entity([300, 310], [65, 110]), Entity([415, 310], [65, 110]), ], [ ExitZone([430, 0], [220, 5], (0, 670), "route1", True, doMusicChange=True), # hometown to route 1 # ExitZone([360, 180], [35, 5], (527,570) , "oakslab", False), # hometown to topleft house ExitZone([375, 400], [35, 5], (527, 570), "oakslab", False, doMusicChange=True), # hometown to oakslab ], PokeZone()),
def setUp(self): self.level = Level()