def __init__(self, width=400, height=300, bgColor=(0, 0, 0)): self.width = width self.height = height self.bgColor = bgColor self.enemyFireId = pygame.USEREVENT+1 pygame.init() self.screen = pygame.display.set_mode((self.width, self.height)) self.myTank = MyTank(self.screen) self.bullets = Group() self.clock = Clock() self.enemys = Group() self.enemyBullets = Group() for i in range(1, 5): enemy = EnemyTank(75 * i, 30) self.enemys.add(enemy) self.bomb = Bomb() # 游戏结束的标志 self.stop = False # 设置定时器 pygame.time.set_timer(self.enemyFireId,800) # 游戏结束显示的文字 myFont = pygame.font.SysFont("simhei", 24) self.fontImage = myFont.render("游戏结束!", True, (0, 255, 0))
def test_explode(self): game_display = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) arena = Arena() bomb = Bomb((112, 45), 2, arena) bomb.explode() self.assertEqual(bomb.state, BombState.EXPLODING)
def test_get_range(self): game_display = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) arena = Arena() _range = 3 bomb = Bomb((112, 45), _range, arena) self.assertEqual(bomb.get_range(), _range)
def create_bombs(ai_settings, screen, bombs): if len(bombs) == 0: bomb = Bomb(ai_settings, screen) bomb_width = bomb.rect.width for bomb_number in range(2): bomb = Bomb(ai_settings, screen) bomb.x = bomb_width + 10 * bomb_width * random.random() bomb.rect.x = bomb.x bombs.add(bomb)
def explode(self, bird): for i in xrange(0, random.randint(5, 10)): b = Bomb(bird) bird.add_bomb(b) b.timeout = 1600 b.rect.x = self.rect.x b.rect.y = self.rect.y - 32 * gl.RESIZE_FACTOR b.launch(random.randint(-200 * gl.RESIZE_FACTOR, 200 * gl.RESIZE_FACTOR), -random.randint(50 * gl.RESIZE_FACTOR, 300 * gl.RESIZE_FACTOR)) self.rect = pygame.rect.Rect(10000, 10000, 0, 0)
def fire_bomb(ai_settings, screen, stats, sb, link, bombs, clock): """if bombs on screen are less than the limit, create a new instance of Bomb and add it to the bombs Group. also decrease the scoring multiplier by two. begin the timer for the bomb""" if len(bombs) < ai_settings.bomb_limit: stats.multiplier = 1 sb.prep_multiplier() new_bomb = Bomb(ai_settings, screen, link) bombs.add(new_bomb) new_bomb.timer = pygame.time.get_ticks()
def test_update_explosion_in_matrix(self): game_display = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) arena = Arena() arena.arena_matrix = self.get_default_arena() bomb = Bomb((22, 0), 2, arena) bomb.state = BombState.EXPLODING arena.update_explosion_in_matrix(bomb) matrix = arena.get_arena() self.assertEqual(matrix[1][1], TileType.FLAME)
def explode(self, bird): for i in xrange(0, random.randint(5, 10)): b = Bomb(bird) bird.add_bomb(b) b.timeout = 1600 b.rect.x = self.rect.x b.rect.y = self.rect.y - 32 * gl.RESIZE_FACTOR b.launch( random.randint(-200 * gl.RESIZE_FACTOR, 200 * gl.RESIZE_FACTOR), -random.randint(50 * gl.RESIZE_FACTOR, 300 * gl.RESIZE_FACTOR)) self.rect = pygame.rect.Rect(10000, 10000, 0, 0)
def get_bombs(data): bombs = [] for bombData in data['Bombs']: roundsUntilExplodes = int(bombData['RoundsUntilExplodes']) parsedLocation = get_location_from_string(bombData['Location']) location = Location(parsedLocation[0], parsedLocation[1]) explosionRadius = int(bombData['ExplosionRadius']) bomb = Bomb(roundsUntilExplodes, location, explosionRadius) bomb.print_debug() bombs.append(bomb) return bombs
class Simulation: def __init__(self, num_modules: int, minutes: int = 0, seconds: int = 0): self.bomb = Bomb(num_modules, minutes, seconds) def pass_time(self) -> bool: if self.bomb.is_solved(): return False if self.bomb.has_strikes(3): return False return self.bomb.pass_time() def take_action(self, module_index): self.bomb.module_action(module_index)
def fire(self): if (len(Bomb.bombs) == 0): self.save1 = self.pos bomb = Bomb(self.save1) if (len(Bomb.bombs) == 1): self.save2 = self.pos bomb = Bomb(self.save2) if (len(Bomb.bombs) == 2): self.save3 = self.pos bomb = Bomb(self.save3) if (len(Bomb.bombs) < 1): Bomb.bombs.append(bomb) self.lifecount += 50
def __init__(self): pygame.init() pygame.mixer.init() self.screen = pygame.display.set_mode((896, 896)) self.screen_rect = self.screen.get_rect() self.font = pygame.font.Font(None, 50) self.font2 = pygame.font.Font(None, 25) self.won = False self.lost = False pygame.display.set_caption("Bobby The Destroyer") self.clock = pygame.time.Clock() this_folder = os.path.dirname(os.path.abspath(__file__)) my_file = os.path.join(this_folder, 'maze_old.txt') self.level = Level(self.screen, my_file) self.player = Player(self.screen, 1, 1, self.level) self.guard = Guard(self.screen, 12, 1, self.player, self.level) self.bombs = [] self.numfin = 0 self.bombs.append(Bomb(self.screen, 3, 5, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 3, 8, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 10, 7, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 10, 6, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 12, 2, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 12, 10, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 7, 3, self.player, self.guard)) self.bombs.append(Bomb(self.screen, 7, 10, self.player, self.guard)) self.game_active = True self.bg = PhotoRect(self.screen, "background", 896, 896)
def move(self): b = self.board self.step += 1 i, ln = 0, len(self.chek_lst) while i < ln and ln: self.chek_lst[i] -= 1 if not self.chek_lst[i]: self.list_bomb[i].die() del self.list_bomb[i], self.chek_lst[i] ln = len(self.chek_lst) i += 1 if self.step == 240: bx, by = b.get_coords((b.get_cell((self.rect.x, self.rect.y)))) bomb = Bomb(self.group, bx, by) bomb.resize(30) self.list_bomb.append(bomb) self.chek_lst.append(randint(300, 390)) self.step = 0 if not self.y and not self.x: while True: self.y = randint(1, (len(self.board.wall_map) - 3)) self.x = randint(1, (len(self.board.wall_map[0]) - 3)) if not self.board.wall_map[self.y][self.x]: self.x, self.y = self.board.get_coords((self.x, self.y)) break ls = (self.rect.x, self.rect.y) if self.y == self.rect.y and self.rect.x == self.x: self.x = self.y = 0 elif self.y == self.rect.y: if self.x > self.rect.x: if 'black' == b.get_color(b.get_cell((ls[0] + 30, ls[1]))): self.rect = self.rect.move(1, 0) else: self.x = self.rect.x elif self.x < self.rect.x: if 'black' == b.get_color(b.get_cell((ls[0] - 1, ls[1]))): self.rect = self.rect.move(-1, 0) else: self.x = self.rect.x else: if self.y > self.rect.y: if 'black' == b.get_color(b.get_cell((ls[0], ls[1] + 30))): self.rect = self.rect.move(0, 1) else: self.y = self.rect.y elif self.y < self.rect.y: if 'black' == b.get_color(b.get_cell((ls[0], ls[1] - 1))): self.rect = self.rect.move(0, -1) else: self.y = self.rect.y
def put_bomb(self, id_char): if id_char in self.__chars: char = self.__chars[id_char] if char.put_bomb(): x, y = char.get_position() x = round(x / Server.wall_factor) * Server.wall_factor y = round(y / Server.wall_factor) * Server.wall_factor model_bomb = self.__model_bomb[char.get_id_bomb_model()] bomb = Bomb( char.get_orientation(), [x, y], model_bomb.get_id(), [53, 53], 255, id_char, model_bomb.get_s_power() + char.get_power_bomb_add(), model_bomb.get_s_timer()) self.__bombs[bomb.get_id()] = bomb
def startgame(BNE): """ this method starts the game """ nextstep = time.time() + 1 # value to make enemies move automatically flag = 0 # bomb is not there on the board B.score = 0 while True: inp = input_to() if inp == 'q': break if inp == 'w': BNE = B.moveup(BNE, 1) os.system('clear') # clears screen or refreshes printboard(BNE) if inp == 's': BNE = B.movedown(BNE, 1) os.system('clear') printboard(BNE) if inp == 'a': BNE = B.moveleft(BNE, 1) os.system('clear') printboard(BNE) if inp == 'd': BNE = B.moveright(BNE, 1) os.system('clear') printboard(BNE) if flag != 1: # bomb is not placed if inp == 'b': boom = Bomb(B.x_pos, B.y_pos, 1) if flag == 0: bomb_start = time.time() BNE = boom.placebomb(BNE) flag = 1 os.system('clear') printboard(BNE) if flag == 1: # bomb is there on board if time.time() - bomb_start > 3: # if it has been more than 3 sec BNE = boom.explode(BNE, EMB, B) # after placing bomb flag = 0 os.system('clear') printboard(BNE) time.sleep(0.3) # shows board with e's for 0.3 sec os.system('clear') printboard1() if time.time() >= nextstep: nextstep = nextstep + 1 for i in EMB.enemies: BNE = i.randommove(BNE, B) os.system('clear') printboard(BNE)
def main(): bomb = Bomb() # Create a new bomb instance, which stores indicator/battery/other info # Pick a module while True: curr_module = input("What module would you like to solve? Your options are:\n\n"\ "Simple Wires / Button / Keypads / Simon Says / Who's on First\n"\ "Memory / Morse Code / Complicated Wires / Wire Sequences\n"\ "Maze / Passwords / Knobs / Quit\n\n") if curr_module.lower() == 'simple wires': simple_wires = SimpleWires() simple_wires.start_simple_wires(bomb) if curr_module.lower() == 'button': button = Button() button.start_button(bomb) if curr_module.lower() == 'keypads': keypads = Keypads() keypads.start_keypads() if curr_module.lower() == 'simon says': simon_says = SimonSays() simon_says.start_simon_says(bomb) if curr_module.lower() == 'who\'s on first': whos_on_first = WhosOnFirst() whos_on_first.start_whos_on_first() if curr_module.lower() == 'memory': memory = Memory() memory.start_memory(bomb) if curr_module.lower() == 'morse code': morse_code = MorseCode() morse_code.start_morse_code() if curr_module.lower() == 'complicated wires': complicated_wires = ComplicatedWires() complicated_wires.start_complicated_wires(bomb) if curr_module.lower() == 'wire sequences': wire_sequences = WireSequences() wire_sequences.start_wire_sequences() if curr_module.lower() == 'maze': maze = Maze() maze.start_maze() if curr_module.lower() == 'passwords': passwords = Passwords() passwords.start_passwords(bomb) if curr_module.lower() == 'knobs': knobs = Knobs() knobs.start_knobs() if curr_module.lower() == 'quit': break
def eventHandler(self): key = pygame.key.get_pressed() if self.player.isAlive: if key[pygame.K_LEFT]: self.player.walkCount += 1 self.player.walking = Directions["LEFT"] self.player.looking = Directions["LEFT"] self.player.moveLeft() elif key[pygame.K_RIGHT]: self.player.walkCount += 1 self.player.walking = Directions["RIGHT"] self.player.looking = Directions["RIGHT"] self.player.moveRight() elif key[pygame.K_UP]: self.player.walkCount += 1 self.player.walking = Directions["UP"] self.player.looking = Directions["UP"] self.player.moveUp() elif key[pygame.K_DOWN]: self.player.walkCount += 1 self.player.walking = Directions["DOWN"] self.player.looking = Directions["DOWN"] self.player.moveDown() # da modificare elif key[pygame.K_SPACE]: self.bombs.append( Bomb(self.player.x, self.player.y, self.screen)) else: self.player.walkCount = 0 self.player.walking = Directions["STAY"]
def player_attacks(self, player, new_pos_x, new_pos_y): """ function which returns a game object that would be create if player attacks and then moves :param player: :param new_pos_x: :param new_pos_y: :return: """ game_copy_attacks = deepcopy(self) player_copy = game_copy_attacks.get_player_by_name(player) if player_copy.bomb_dropped is None: # player drops a bomb game_copy_attacks.table[player_copy.position[0]][player_copy.position[1]] = 'b' new_bomb = Bomb(position=player_copy.position, owner=player_copy) player_copy.bomb_dropped = new_bomb game_copy_attacks.bombs.append(new_bomb) else: # player activates the bomb dropped game_copy_attacks.table[player_copy.position[0]][player_copy.position[1]] = ' ' for bomb in game_copy_attacks.bombs: if bomb.owner.player_name == player and not bomb.activated: bomb.activate(game_copy_attacks) break if game_copy_attacks.table[new_pos_x][new_pos_y] == 'p': game_copy_attacks.found_protection(player_copy, new_pos_x, new_pos_y) else: game_copy_attacks.not_found_protection(player_copy, new_pos_x, new_pos_y) return game_copy_attacks, player_copy
def bomb (pi_settings, screen, ship, bombs): #Create new bullet and add add it to bullets group if len(bombs) < pi_settings.bombs_allowed: new_bomb = Bomb(pi_settings, screen, ship) bombs.add(new_bomb) shoot_sound.play() pi_settings.bombs_allowed -= 1
def render(): playerInput = "none" playerInput = get_char() time.sleep(fps) # player input # if playerInput in ("W", "w"): bomberman.moveUp(board.gameBoard, emptySpace) elif playerInput in ("D", "d"): bomberman.moveRight(board.gameBoard, emptySpace) elif playerInput in ("A", "a"): bomberman.moveLeft(board.gameBoard, emptySpace) elif playerInput in ("S", "s"): bomberman.moveDown(board.gameBoard, emptySpace) elif playerInput in ("B", "b"): board.bombs.append( Bomb(2, 4, bomberman.position_row, bomberman.position_col)) board.bombs[-1].show(board.gameBoard) elif playerInput in ("P", "p"): board.powerUp() elif playerInput in ("Q", "q"): print("BYE BYE ,SEE YOU SOON") bomberman.die() elif playerInput is None: pass # player input # board.operate(bomberman, wall, emptySpace)
def plant_bomb(self, map, time, bombs, bonuses): if self.bomb_limit > 0: bomb_posX = round(self.posX / 4) bomb_posY = round(self.posY / 4) # do not plant bomb on existing bomb for bomb in bombs: if bomb.posX == bomb_posX and bomb.posY == bomb_posY: return False #prevent bomb being planted in front of character if self.direction == 0: if self.posY / (4 * bomb_posY) < 1: return False elif self.direction == 1: if self.posX / (4 * bomb_posX) < 1: return False elif self.direction == 2: if self.posY / (4 * bomb_posY) > 1: return False elif self.direction == 3: if self.posX / (4 * bomb_posX) > 1: return False bomb = Bomb(self.bomb_range, round(self.posX / 4), round(self.posY / 4), map, self, time, bonuses) self.bomb_limit -= 1 bombs.append(bomb) map[bomb.posX][bomb.posY] = 3 return True
def tick(self, playfield): if not self.alive: return if (self.cooldown > 0): self.cooldown -= 1 current_tile = playfield[self.y][self.x] if current_tile.exploding > 0: self.alive = False current_tile.setPlayer(None) return old_pos = [self.x, self.y] if (self.intent == 'U'): self.y -= 1 elif (self.intent == 'D'): self.y += 1 elif (self.intent == 'L'): self.x -= 1 elif (self.intent == 'R'): self.x += 1 elif (self.intent == 'B' and self.cooldown == 0): if current_tile.bomb == None: current_tile.bomb = Bomb(self.x, self.y, playfield) cooldown = 50 new_tile = playfield[self.y][self.x] if new_tile.isPassable(): playfield[old_pos[1]][old_pos[0]].setPlayer(None) new_tile.setPlayer(self) else: self.x = old_pos[0] self.y = old_pos[1]
def __init__(self, level=1): level = Level(level) self.score = 0 grid = Grid(config.rows, config.cols) wall = Wall(grid) bomberman = Bomberman(config.init_row, config.init_col, grid) monsters = [] for i in range(len(level.monsters_row)): monsters.append( Monster(level.monsters_row[i], level.monsters_col[i], grid)) blocks = self.block_arrangement(grid) for i in range(10): pass bombs = [] count = 0 while True: count = count + 1 if count is not level.monsters_speed_factor else 0 if count is level.monsters_speed_factor: if len(bombs) > 0: for bomb in bombs: bomb.seconds_left = bomb.seconds_left - 1 grid.matrix[bomb.row][bomb.col] = 'bomb' + str( bomb.seconds_left) if bomb.seconds_left is 0: bomb.explode(grid) bombs.remove(bomb) self.check_if_dead(monsters, bomberman, grid) self.check_if_block_destroyed(blocks, grid) for monster in monsters: monster.move(grid) self.check_if_dead(monsters, bomberman, grid) grid.display() self.print_score() k = self.input_to() if k == 'x': bombs.append(Bomb(bomberman.row, bomberman.col, grid)) elif k == 'q': exit(0) elif k in ['w', 'a', 's', 'd', 'i', 'j', 'k', 'l']: bomberman.move(k, grid) grid.display() self.print_score()
def plot_bomb(self, grid, radius, timelimit, det): ''' plot bomb function plots a new bomb and appends the bomb to active array of the bomberman attribute. ''' new_bomb = Bomb([radius, timelimit, det], 3, self.get_lefttop_x(), self.get_lefttop_y()) self.active.append(new_bomb) return grid
def solve(bomb: Bomb, display: str = None): cprint('Caesar Cipher', 'yellow', attrs=['reverse']) offset = 0 if bomb.serial_has_vowel(): offset -= 1 offset += bomb.batteries if bomb.serial_last_digit() % 2 == 0: offset += 1 if 'CAR' in bomb.get_all_indicators(): offset += 1 if 'PARALLEL' in bomb.get_all_ports() and 'NSA' in bomb.lit_indicators: offset = 0 cprint('Offset: ' + str(offset), 'green') if display: cipher = CaesarCipher(display, offset=offset) cprint(cipher.encoded, 'cyan')
def handle_line(self, line): line = line.strip() matcher = LOG_REGEX.match(line) if matcher is None: return msg = LogMessage(line) # check to see if we're transition states. do so if neeeded if self._handle_state_transition(msg): # write_state_file() if self.curr_state == STATE_IN_BOMB: # we have just init the bomb self.bomb = Bomb() return # state has changed, nothing else to do # TODO: fix this garbage if msg.get_generator_settings() is not None: self.bomb.time, self.bomb.max_strikes = msg.get_generator_settings() if msg.is_strike(): self.bomb.strikes += 1 if msg.is_bomb_start(): self.bomb.start_bomb() # check to see if this is a message from a bomb component if msg.component == 'Rules' or msg.component in FINISHED_COMPONENT_MAPPINGS: self._set_component(msg) if msg.is_bomb_seed(): # found the bomb's seed self.bomb.seed = msg.msg[26:] if msg.is_new_component(): comp = msg.is_new_component() self.bomb.modules_remaining.append(INITIALIZED_COMPONENT_MAPPINGS[comp]) if msg.is_explosion(): self.bomb.stop_bomb() self.bomb_state_message = random.choice(self.failure_messages) self.curr_state = STATE_LOST if msg.is_win(): self.bomb.stop_bomb() self.bomb_state_message = random.choice(self.success_messages) self.curr_state = STATE_WIN if msg.is_module_complete(): # self.last_module is the one that is done try: self.bomb.modules_remaining.remove(self.last_module) except ValueError: #TODO: F**K pass self.bomb.modules_solved.append(self.last_module) pass
def handle_events(): global BoundingBox global Bossdie events = get_events() for event in events: if event.type == SDL_QUIT: game_framework.quit() else: if (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE): game_framework.quit() else: player.handle_event(event) if event.type == SDL_KEYDOWN and event.key == SDLK_SPACE and player.state != 0: if map.kind != 3: player.missile_sound.play() newmissile = Missile(player.x, player.y) if player.missile_level == 1: newmissile.level = 0 if player.missile_level == 2: newmissile.level = 1 Player_missile.append(newmissile) else: ui.playerlife = 2 Bossdie = 0 close_canvas() game_framework.change_state(start_state) if event.type == SDL_KEYDOWN and event.key == SDLK_b and player.state!= 0: if ui.bomb != 0: newbomb = Bomb(player.x, player.y) newbomb.angle = 3 bomb.append(newbomb) newbomb = Bomb(player.x, player.y) newbomb.angle = -3 newbomb.angle = -3 bomb.append(newbomb) ui.bomb -= 1 if event.type == SDL_KEYDOWN and event.key == SDLK_h and player.state != 0: if BoundingBox == 0: BoundingBox = 1 elif BoundingBox == 1: BoundingBox = 0 if event.type == SDL_KEYDOWN and event.key == SDLK_q: ui.score =205
def create_bombs(setting, screen, bombs): """ 创建随机bombs """ #生成大于10个不重复的二维数组,如果数组长度小于10则再次生成直到数组长度大于10为止 num = 0 while num < 10: random_number_0 = [[random.randint(0, 8) for i in range(2)] for j in range(12)] #将列表转换为tuple,再通过set去重复数据 random_number = list(set([tuple(t) for t in random_number_0])) num = len(random_number) for value in range(10): bomb = Bomb(setting, screen) bomb_width = bomb.rect.width bomb.x = 1.5 + bomb_width * random_number[value][0] bomb.rect.y = (setting.screen_height - setting.number_rows * 30) + bomb.rect.height * random_number[value][1] bomb.rect.x = bomb.x bombs.add(bomb)
def test_put_bomb_in_backpack_and_get_bomb_index(self): level = Level('level1.txt') for b in level.BomberMan: bm = b bm.backpack.append(Bomb(bm, power=2)) index = level.put_bomb_and_get_bomb_index() self.assertEqual(Point(1, 1), level.Bombs[index].position) self.assertEqual(2, level.Bombs[index].power) self.assertEqual(0, len(bm.backpack)) self.assertTrue(level.Bombs[index].is_active)
def getShot(self): shot = [] shot.append( Bomb(self.bullet_image, self.screen, self.rect, self.config.bullet_speed, self.bullet_anim, rotation=180)) return shot
def drop_bomb(ai_settings, screen, ship, aliens, bombs): #select a random alien from the list of aliens abp = list(aliens) if len(abp) > 0: alien_bomb_prepped = choice(abp) for alien in aliens.copy(): if alien_bomb_prepped.rect.x == ship.rect.x and len(bombs) < ai_settings.bombs_allowed: new_bomb = Bomb(ai_settings, screen, alien_bomb_prepped) bombs.add(new_bomb) pygame.mixer.Sound.play(bomb_sound)
def release_bomb(self): if self.has_bomb: released_up = time.time() time_elapsed = released_up - self.pressed_down_start target_y = self.screen_height - time_elapsed * 200 # 100 pixels for every second held self.has_bomb = False del self.powerups[Bomb.name] self.pressed_down_start = None self.bomb.sprite = Bomb(self.rect.centerx,self.screen_height,target_y)
def detect_collision(screen, ship, ship_bullets, enemys, enemys_bullets, bombs, setting, score): # 爆炸时播放音效 music = "images/bomb.wav" pygame.mixer.Sound(music) pygame.mixer.Sound(music).set_volume(0.1) # 检测到击中敌机 hit = pygame.sprite.groupcollide(enemys, ship_bullets, True, True) if hit: for enemy in hit: pygame.mixer.Sound(music).play() # 加分并检测是否刷新最高分 setting.score += setting.points score.render_score() if setting.score > setting.high_score: setting.high_score = setting.score score.render_high_score() # 播放爆炸动画 enemy_rect = enemy.rect bomb = Bomb(screen) bomb.set_pos(enemy_rect.x, enemy_rect.y) bombs.add(bomb) bomb.visible = True # 检测到我方飞机被击中就清空屏幕,减少一条命,判断游戏状态 if pygame.sprite.spritecollideany(ship, enemys) \ or pygame.sprite.spritecollideany(ship, enemys_bullets): enemys.empty() enemys_bullets.empty() pygame.mixer.Sound(music).play() bomb = Bomb(screen) bomb.set_pos(ship.rect.x, ship.rect.y) bombs.add(bomb) bomb.visible = True setting.live -= 1 if setting.live > 0: ship.put() else: setting.game_active = False
def test_bomb_explode(self): temp_bomb = Bomb(3, 11, 11, game.grid, game.enemy_list[0]) game.bombs.append(temp_bomb) game.update_bombs(2980) self.assertEqual(1, len(game.bombs)) self.assertEqual(20, temp_bomb.time) game.update_bombs(50) self.assertEqual(0, len(game.bombs)) self.assertEqual(1, len(game.explosions))
def move(self, level): #Character read from imput function''' getch = _Getch() key = getch() return_value = 0 '''Movement accordind to keys''' if key is 'w': return_value = self.move_bomberman(-1, 0) elif key is 's': return_value = self.move_bomberman(+1, 0) elif key is 'a': return_value = self.move_bomberman(0, -1) elif key is 'd': return_value = self.move_bomberman(0, +1) elif key is 'q': return -2 '''If pressed q exit the game right there''' '''Function to handle the bomb and its timers''' if self.bombs == 1: # Decrease yhe bomb timer self.p_bomb.tick_tick(self.x, self.y, level) b.game[self.p_bomb.x][self.p_bomb.y] = 'B' # If time is over call the neighbour function which displays # explosion around the bomb if (self.p_bomb.time_bomb == 0): # Displays the board and calls the neighbour also # call the function so that it calls the explosion and checks # for different objects around the bomb temp = self.p_bomb.tick_tick(self.x, self.y, level) # Set the bombs to 0 and del the bomb object self.bombs = 0 del self.p_bomb if temp is -1: return -1 elif (key is 'b') and self.bombs == 0: '''Add new bomb if the key is b and bombs are 0''' self.p_bomb = Bomb(self.x, self.y, time.time()) b.game[self.p_bomb.x][self.p_bomb.y] = 'B' self.bombs = 1 # Returns return_value which stores the status of the moves return return_value
def __create_sprites(self): # Create background sprite group bg1 = Background(BACKGROUND_IMAGE_PATH) bg2 = Background(BACKGROUND_IMAGE_PATH, True) self.__background_group = pygame.sprite.Group(bg1, bg2) # Create player sprite group self.__player = Player(PLAYER_IMAGE_PATH_STAY, speed=PLAYER_SPEED) self.__player_group = pygame.sprite.Group(self.__player) # Create enemy sprite group self.__enemy_group = pygame.sprite.Group() self.__enemy_missile_group = pygame.sprite.Group() # Create bomb sprite group self.__bomb = Bomb() self.__bomb_text = self.__bomb.get_text() self.__bomb_group = pygame.sprite.Group(self.__bomb) # Create bomb supply group self.__bomb_supply_group = pygame.sprite.Group() # Create missile supply group self.__missile_supply_group = pygame.sprite.Group()
def _create_m67 (game, data) : m67 = Bomb (default='images/m67.png') m67.set_anchor_points (grip=(7,7)) m67.set_pos (_get_coords (data)) m67.set_name ("m67") return m67
a = True if data_s[3] == "True" else False b = True if data_s[4] == "True" else False #debug #print(x, y, z) #print(a, b) return x, y, z, a, b mc = Minecraft.create() try: playerPos = mc.player.getTilePos() craftPos = playerPos.clone() craftPos.y += 10 craftPos.z += 20 craft = XWingFighter(craftPos) bomb = Bomb() while True: x, y, z, a, b = read_microbit_data() if a: if craft.flying: craft.stop() else: craft.fly(0.15) if b: bpos = craft.craftShape.position bpos.y - 2 bomb.drop(bpos.x, bpos.y, bpos.z, 0.1) if x > 750: craft.turn(10) if x > 500:
class KTANEParser: def __init__(self, state_file, modules_file, defused_file, success_messages, failure_messages): self.curr_state = STATE_OUT_OF_BOMB self.last_module = None self.bomb = None self.bomb_state_message = None self.state_file = state_file self.modules_file = modules_file self.defused_file = defused_file self.success_messages = success_messages self.failure_messages = failure_messages t = threading.Timer(0.5, self._write_state_file) t.start() def _handle_state_transition(self, msg): if msg.is_init_bomb(): self.curr_state = STATE_IN_BOMB return True elif msg.is_game_ended_prematurely(): self.bomb.stop_bomb() self.curr_state = STATE_OUT_OF_BOMB return True elif msg.is_round_end() and self.curr_state != STATE_LOST and self.curr_state != STATE_WIN: self.curr_state = STATE_OUT_OF_BOMB return True return False def _set_component(self, msg): if msg.component in FINISHED_COMPONENT_MAPPINGS: self.last_module = FINISHED_COMPONENT_MAPPINGS[msg.component] return # special case for "RULES" TODO: BITSIM PLZ FIX if "countdown timer" in msg.msg: self.last_module = 'Button' return if "same label you pressed in stage" in msg.msg: self.last_module = 'Memory' return if "Snipped wire" in msg.msg: self.last_module = 'Wire Sequence' return def handle_line(self, line): line = line.strip() matcher = LOG_REGEX.match(line) if matcher is None: return msg = LogMessage(line) # check to see if we're transition states. do so if neeeded if self._handle_state_transition(msg): # write_state_file() if self.curr_state == STATE_IN_BOMB: # we have just init the bomb self.bomb = Bomb() return # state has changed, nothing else to do # TODO: fix this garbage if msg.get_generator_settings() is not None: self.bomb.time, self.bomb.max_strikes = msg.get_generator_settings() if msg.is_strike(): self.bomb.strikes += 1 if msg.is_bomb_start(): self.bomb.start_bomb() # check to see if this is a message from a bomb component if msg.component == 'Rules' or msg.component in FINISHED_COMPONENT_MAPPINGS: self._set_component(msg) if msg.is_bomb_seed(): # found the bomb's seed self.bomb.seed = msg.msg[26:] if msg.is_new_component(): comp = msg.is_new_component() self.bomb.modules_remaining.append(INITIALIZED_COMPONENT_MAPPINGS[comp]) if msg.is_explosion(): self.bomb.stop_bomb() self.bomb_state_message = random.choice(self.failure_messages) self.curr_state = STATE_LOST if msg.is_win(): self.bomb.stop_bomb() self.bomb_state_message = random.choice(self.success_messages) self.curr_state = STATE_WIN if msg.is_module_complete(): # self.last_module is the one that is done try: self.bomb.modules_remaining.remove(self.last_module) except ValueError: #TODO: F**K pass self.bomb.modules_solved.append(self.last_module) pass def _write_state_file(self): if self.curr_state == STATE_OUT_OF_BOMB: bomb_state = 'Not in a bomb' modules = '' solved = '' elif self.curr_state == STATE_LOST: bomb_state = self.bomb_state_message modules = '' solved = '' elif self.curr_state == STATE_WIN: bomb_state = self.bomb_state_message modules = '' solved = '' elif self.bomb is not None: if len(self.bomb.modules_remaining) > 0: modules = 'Modules: %s' % ', '.join(self.bomb.modules_remaining) else: modules = 'Modules:' if len(self.bomb.modules_solved) > 0: solved = 'Solved: %s' % ', '.join(self.bomb.modules_solved) else: solved = 'Solved:' bomb_state = 'In a bomb with seed: %s (time = %s)' % (self.bomb.seed, self.bomb.get_formatted_time()) state_file = open(self.state_file, 'w') # print "Writing %s to state file" % bomb_state state_file.write(bomb_state) state_file.close() module_file = open(self.modules_file, 'w') # print "Writing %s to modules file" % modules module_file.write(modules) module_file.close() solved_file = open(self.defused_file, 'w') # print "Writing %s to solved file" % solved solved_file.write(solved) solved_file.close() t = threading.Timer(0.1, self._write_state_file) t.start()
def test_current_state(self): game_display = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) arena = Arena() bomb = Bomb((112, 45), 2, arena) self.assertEqual(bomb.current_state(), BombState.TICKING)