def test_mario_collision_with_enemy_side(): GAME = Game(99, 100, 1) mario = GAME.player enemy = Enemy(GAME, 33, 31, 6) GAME.codes[33] = enemy enemy.dir = 0 GAME.screen.position(enemy) mario.move(1) assert mario.lives == 0
def test_large_mario_collision_with_enemy(): GAME = Game(99, 100, 1) mario = GAME.player mario.resize(1) enemy = Enemy(GAME, 33, 31, 6) GAME.codes[33] = enemy enemy.dir = 0 GAME.screen.position(enemy) mario.move(1) assert mario.get_size() == (3, 3)
def __init__(self): self._arts = Arts() self._vars = Vars() self._scn_gen = SceneGenerator() self._abv_gnd = 0 self._e1 = Enemy() _, self._width = Scenes().get_init_dim() self._em = 0 self._mario_place = 0 self._b1 = Bullet() self._bsjump_cord = 20 self._bsjump_corddef = self._bsjump_cord self._pipe_place = ((self._width * 4) - 10)
def add_more(self): """Add more elements""" if self.player[0].scoreboard.score > 200 and \ len(self._storage["bossenemy"]) < 1: for typ in self._storage: for ele in self._storage[typ]: ele.remove(self) self._storage[typ].remove(ele) self.add_game(BossEnemy(self.height, self.width)) for i in self._storage["bossenemy"]: i.show(self) elif self.player[0].scoreboard.score < 200: for typ in self._storage: if len(self._storage[typ]) < 7: rint = randint(0, 15) if rint == 3: if typ == "enemy": self.add_game(Enemy(self.height, self.width)) elif typ == "platform": self.add_game(Platform(self.height, self.width)) elif typ == "coin": self.add_game(Coin(self.height, self.width)) elif typ == "lake": self.add_game(Lake(self.height, self.width)) elif typ == "cloud": self.add_game(Cloud(self.height, self.width)) elif typ == "brick": self.add_game(Brick(self.height, self.width)) elif rint in range(3, 8): if typ == "cloud": self.add_game(Cloud(self.height, self.width)) elif typ == "brick": self.add_game(Brick(self.height, self.width))
def test_mario_collision_with_enemy_top(): GAME = Game(99, 100, 1) mario = GAME.player mario.move(3) mario.vertical() mario.vertical() mario.vertical() mario.vertical() mario.vertical() mario.vertical() mario.vertical() print(mario.jstate) enemy = Enemy(GAME, 33, 31, 4) GAME.codes[33] = enemy GAME.screen.position(enemy) mario.vertical() mario.vertical() mario.vertical() mario.vertical() mario.vertical() mario.vertical() mario.vertical() print(mario.get_loc()) assert enemy.lives <= 0 assert GAME.points > 0
def test_enemy_collision_with_brick(): GAME = Game(99, 100, 1) enemy = Enemy(GAME, 33, 31, 6) GAME.screen.gmap[30:33, 2:4] = 6 enemy.move() enemy.move() enemy.move() enemy.move() assert enemy.dir == 1
def generate_enemy(self): ''' Creates an enemy ''' if random() < configs.PROB_ENEMY: copy_j = self.screen.offset + configs.DIM_J - randrange(10) copy_i = 1 mush = Enemy(self, self.count, copy_i, copy_j) self.screen.position(mush) self.codes[self.count] = mush self.count += 1 if self.level == 2 and self.player.j == 50: boss = Boss(self, 999, 8, 50) self.screen.position(boss) self.codes[999] = boss
def main(): """ Game Engine """ os.system('tput reset') screen_height, screen_width = ROWS - 2 * MARGINY, COLUMNS - 2 * MARGINX board = Board(screen_height, screen_width) board.add_game(Enemy(screen_height, screen_width)) board.add_game(Mario(screen_width, screen_height)) i = 8 while i: board.add_game( Brick(screen_height, screen_width, randint(4, screen_width - 5))) i = i - 1 i = 5 while i: board.add_game( Cloud(screen_height, screen_width, randint(4, screen_width - 6))) i = i - 1 sys.stdout.write(Style.BRIGHT + Back.YELLOW + pos(2, 0) + "SUPER MARIO".center(COLUMNS)) board.render() game_on = True char = " " while game_on: board.player[0].scoreboard.show_score() board.player[0].move(char, board) board.update_enemys() board.update_bullets() if char == 'q': sys.stdout.write(Back.RED + pos(ROWS - 2, 0) + "We got a quitter".center(COLUMNS)) game_on = False char = get_input() board.add_more() board.player[0].scoreboard.score_update("time")
class EnemyTest(TestCase): """ Class to test the Player class """ def setUp(self): self.player = Enemy(30, 30) self.board = Board(40, 40) self.board.add_game(self.player) self.player.is_exist = 1 def test_move_left(self): """ Tests if position changes when function move_left called """ prev_x_current = self.player.get_coord()[0] self.player.move_left(self.board) self.assertEqual(prev_x_current - 1, self.player.get_coord()[0]) def test_move_right(self): """ Tests if position changes when function move_right called """ prev_x_current = self.player.get_coord()[0] self.player.move_right(self.board) self.assertEqual(prev_x_current + 1, self.player.get_coord()[0]) def test_move(self): """ Tests if position changes when function move called """ prev_x_current = self.player.get_coord()[0] self.player.move(self.board) self.assertEqual(prev_x_current - 1, self.player.get_coord()[0])
def setUp(self): self.player = Enemy(30, 30) self.board = Board(40, 40) self.board.add_game(self.player) self.player.is_exist = 1
class ControlCenter(): """This is docstring """ def __init__(self): self._arts = Arts() self._vars = Vars() self._scn_gen = SceneGenerator() self._abv_gnd = 0 self._e1 = Enemy() _, self._width = Scenes().get_init_dim() self._em = 0 self._mario_place = 0 self._b1 = Bullet() self._bsjump_cord = 20 self._bsjump_corddef = self._bsjump_cord self._pipe_place = ((self._width * 4) - 10) #self._steps_taken_back = 0 def controls(self, way, jump_cord, life, score): """This is docstring """ #### Controls w -> jump d -> forward a -> back_wards #### _for nothing it return the same thing again self._abv_gnd = (5 - abs(jump_cord)) * 2 if random.randint(0, 100) < 1: self._scn_gen.put_pipe() if way == 'd': moved_scene = self._scn_gen.move_forward_world_scene() self._pipe_place -= 3 elif way == 'a': moved_scene = self._scn_gen.move_back_world_scene() self._pipe_place += 1 elif way == 'w': moved_scene = self._scn_gen.ret_world() if jump_cord == 5: jump_cord -= 1 else: moved_scene = self._scn_gen.ret_world() mario_placed = np.copy(moved_scene) mario_placed = self._scn_gen.put_mario(mario_placed, self._abv_gnd, 0) life = self.dist_mario_enemy(jump_cord, life) # if(self._pipe_place>0): # mario_placed = self.put_pipe(mario_placed,self._pipe_place-self._width) if (self._em == 0 and random.randint(0, 20) < 2): self._em = 1 self._e1.set_alive() self._e1.set_enemy_place(self._width * 4 - 10) if self._em == 1: mario_placed, score = self.plce_enemy(mario_placed, score) return mario_placed, jump_cord, life, score def plce_enemy(self, enemy_less, score): """This is docstring """ if self._e1.is_alive() == 0: return enemy_less self._e1.set_enemy_height(0) _, bre = self._arts.get_enemy_dim() if self._e1.get_flag(): dist = self._width * self._vars.get_mult_patches() - bre - 2 self._e1.set_enemy_place(dist) self._e1.set_enemy_place(self._e1.get_enemy_place() - 2) if self._e1.get_enemy_place() == 0: score += 10 self._e1.die() if self._e1.get_enemy_place() > self._width: dist = self._e1.get_enemy_place() - 2 else: dist = self._e1.get_enemy_place() + 3 self._e1.set_enemy_place(dist) enemy_placed = self._scn_gen.put_enemy(enemy_less, self._e1.get_enemy_height(), dist) return enemy_placed, score def dist_mario_enemy(self, jump_cord, life): """This is docstring """ dist = self._e1.get_enemy_place() if (jump_cord == 5 and dist == self._width): life -= 1 if ((jump_cord == -4 or jump_cord == -5) and (dist >= self._width - 3 and dist <= self._width + 3)): self._e1.die() self._em = 0 return life def place_boss_enemy(self, way, jump_cord, life, game_win): """This is docstring """ mario_above_ground = (5 - abs(jump_cord)) * 2 boss_above_ground = (self._bsjump_corddef - abs(self._bsjump_cord)) self._bsjump_cord -= 2 if self._bsjump_cord < -self._bsjump_corddef: self._bsjump_cord = self._bsjump_corddef scene = np.copy(self._scn_gen.ret_world()) if way == 'd': self._mario_place += 2 # if(self._mario_place>= self._width*3): # game_win =1 # return scene,jump_cord,life,game_win if self._mario_place + 5 > self._width * 3: return scene, jump_cord, life, 1 elif way == 'a': self._mario_place -= 2 elif way == 'w': if jump_cord == 5: jump_cord -= 1 mario_placed = self._scn_gen.put_mario(scene, mario_above_ground, self._mario_place) mario_placed = self._scn_gen.put_boss_enemy(mario_placed, boss_above_ground, self._width * 3) if (self._b1.bltpst() == 0 and random.randint(0, 10) < 7 and boss_above_ground < 10): self._b1.fire(boss_above_ground, self._width * 3) if self._b1.bltpst() == 1: length, bre = self._b1.get_bullet_cor() self._b1.move_blt() mario_placed = self._scn_gen.put_bult(mario_placed, length, bre) if (mario_above_ground + 3 >= length and mario_above_ground <= length and self._mario_place + 3 <= bre and self._mario_place >= bre): life -= 1 return mario_placed, jump_cord, life, game_win