frame.draw_sensors(player.position[0], player.position[1], player.angle, player.turret_current, player.color, player.sensors) return frame def get_debug_vars(self): return self.players[0].get_debug_vars() def is_running(self): active_tanks = 0 for p in self.players: active_tanks += 1 if active_tanks < 2 or self.turns_left <= 0: return False else: return True @staticmethod def get_intro(): return open("intro.md", "r").read() @staticmethod def default_prog_for_bot(language): if language == GameLanguage.LITTLEPY: return open("bot.lp", "r").read() if __name__ == '__main__': from CYLGame import run run(TanksGame)
return ConstMapping({"west": ord("a"), "east": ord("d"), "fire": ord("w"), "stay": ord("s"), "MOTHERSHIP_L": ord(SpaceInvaders.MOTHERSHIP_L), "MOTHERSHIP_C": ord(SpaceInvaders.MOTHERSHIP_C), "MOTHERSHIP_R": ord(SpaceInvaders.MOTHERSHIP_R), "INVADER_0": ord(SpaceInvaders.INVADER0), "INVADER_1": ord(SpaceInvaders.INVADER1), "INVADER_2": ord(SpaceInvaders.INVADER2), "BARRIER_1": ord(SpaceInvaders.BARRIER_1), "BARRIER_2": ord(SpaceInvaders.BARRIER_2), "BARRIER_3": ord(SpaceInvaders.BARRIER_3), "BARRIER_4": ord(SpaceInvaders.BARRIER_4), "MISSILE": ord(SpaceInvaders.MISSILE), "BULLET": ord(SpaceInvaders.BULLET), "PLAYER_L": ord(SpaceInvaders.PLAYER_L), "PLAYER_C": ord(SpaceInvaders.PLAYER_C), "PLAYER_R": ord(SpaceInvaders.PLAYER_R), "EMPTY": ord(' '), "OUT_OF_BOUNDS": ord(SpaceInvaders.OUT_OF_BOUNDS), "MAP_HEIGHT": SpaceInvaders.MAP_HEIGHT, "MAP_WIDTH": SpaceInvaders.MAP_WIDTH, }) if __name__ == '__main__': from CYLGame import run run(SpaceInvaders)
return bot_vars def get_map_array(self): map_array = [] for w in range(0, self.MAP_WIDTH): width_arr = [] for h in range(0, self.MAP_HEIGHT): if self.map[(w, h)] == ' ': width_arr.append(self.OPEN) else: width_arr.append(self.TAKEN) map_array.append(list(width_arr)) return map_array @staticmethod def get_move_consts(): consts = super(Tron, Tron).get_move_consts() consts["OPEN"] = Tron.OPEN consts["TAKEN"] = Tron.TAKEN consts["WALL"] = Tron.WALL return consts @staticmethod def get_number_of_players(): return 4 if __name__ == '__main__': from CYLGame import run run(Tron)
frame_buffer.set( self.current_position[0] + 4, self.MAP_HEIGHT - (self.current_position[1] + 1) + 4, self.current_pill[1]) if not self.running: lose_str = f"Good game! Your score: {self.score}" left_offset = ((self.SCREEN_WIDTH - len(lose_str)) // 2) frame_buffer.set(left_offset - 1, self.SCREEN_HEIGHT // 2 - 1, "\xC9") frame_buffer.set(left_offset - 1, self.SCREEN_HEIGHT // 2, "\xBA") frame_buffer.set(left_offset - 1, self.SCREEN_HEIGHT // 2 + 1, "\xC8") for i, c in enumerate(lose_str): frame_buffer.set(left_offset + i, self.SCREEN_HEIGHT // 2 + 1, "\xCD") frame_buffer.set(left_offset + i, self.SCREEN_HEIGHT // 2, c) frame_buffer.set(left_offset + i, self.SCREEN_HEIGHT // 2 - 1, "\xCD") frame_buffer.set(left_offset + len(lose_str), self.SCREEN_HEIGHT // 2 - 1, "\xBB") frame_buffer.set(left_offset + len(lose_str), self.SCREEN_HEIGHT // 2, "\xBA") frame_buffer.set(left_offset + len(lose_str), self.SCREEN_HEIGHT // 2 + 1, "\xBC") if __name__ == '__main__': from CYLGame import run run(DrCYL)
"FRUIT": ord(PacBot.STAR), "EMPTY": ord(PacBot.EMPTY), "PLAYER": ord(PacBot.PLAYER), "map_height": PacBot.MAP_HEIGHT, "map_width": PacBot.MAP_WIDTH, }) @staticmethod def map_distance(pos, target): pos_x, pos_y = pos tar_x, tar_y = target return math.sqrt((tar_x - pos_x) ** 2 + (tar_y - pos_y) ** 2) def get_score(self): return self.score def draw_screen(self, frame_buffer): if not self.running: self.print_game_over() # Update Status self.score_panel["Score"] = self.score for panel in self.panels: panel.redraw(frame_buffer) if __name__ == '__main__': from CYLGame import run run(PacBot, avg_game_func=max)
names.update({ord(Ski.JUMP): "jump"}) names.update({ord(Ski.HOUSE): "house"}) return names def get_score(self): return self.score def draw_screen(self, frame_buffer): # End of the game if self.turns >= self.MAX_TURNS: self.msg_panel.add("You are out of moves.") elif self.hp <= 0: self.msg_panel.add("You sustained too much damage!") if not self.running: self.msg_panel.add("GAME 0VER: Score:" + str(self.score)) # Update Status self.status_panel["Score"] = self.score self.status_panel["Move"] = str(self.turns) + " of " + str( self.MAX_TURNS) self.status_panel["HP"] = self.HEART * self.hp for panel in self.panels: panel.redraw(frame_buffer) if __name__ == '__main__': from CYLGame import run run(Ski)
self.status_panel["Score"] = self.get_score() for panel in self.panels: panel.redraw(frame_buffer) def get_score(self): return self.x + (self.pipes_passed * 50) @staticmethod def get_intro(): return open("resources/intro.md", "r").read() @staticmethod def default_prog_for_bot(language): if language == GameLanguage.LITTLEPY: return open("resources/flappy_bot.lp", "r").read() @staticmethod def get_move_consts(): return ConstMapping({ "flap": ord(" "), "up": ord("w"), "down": ord("s"), "glide": ord("d") }) if __name__ == '__main__': from CYLGame import run run(FlappyBird)