def create_hero(self, x, y): self.hero = self.my_view.draw_entity(self.my_view.char_down, [x, y]) self.heroEntity = Hero() self.heroEntity.id = self.hero self.chars_on_screen.append(self.hero) self.my_view.hero_hud(self.heroEntity)
def spawn(self, player_name, entity): self.player_name = player_name self.entity = entity.lower() self.spawned.append(self.player_name) if self.entity == "orc": self.entity = "O" self.player1 = Orc(player_name, 1000, 2) print('') print("{} is fighting with:".format(player_name)) self.player1.equip_weapon(give_weapon()) else: self.entity = "H" self.player1 = Hero(player_name, 1000, "The NutCracker") print('') print("{} is fighting with:".format(player_name)) self.player1.equip_weapon(give_weapon()) for i in range(len(self.dungeon_map)): for j in range(len(self.dungeon_map[i])): if self.dungeon_map[i][j] == "S": self.dungeon_map[i][j] = self.entity self.cords.setdefault(self.player_name, []).append(i) self.cords.setdefault(self.player_name, []).append(j) return True return False
def __init__(self): # self.game_status() self.my_map = Map() self.my_view = View(self.my_map.map1) self.combat = Fight_engine() self.my_view.root.bind("<KeyPress>", self.on_key_press) self.creatures = [Boss(0, 7, "boss")] self.get_random_skeletons() self.get_units() self.hero = Hero(0, 0, "hero-down") self.hero.unit_id = self.my_view.draw_game_object(0, 0, "hero-down") self.movement_count = 0 self.delete_dead_creature() self.hud() self.my_view.start()
def __init__(self): root = Tk() canvas_height = 720 canvas_width = 820 self.hud_x = 720 self.hud_y = 0 self.canvas = Canvas(root, width=canvas_width, height=canvas_height, bg = "#957740") self.map = Map() self.map.draw_map(self.canvas) self.skeleton_number = 3 self.spots = self.map.create_enemy_spots(self.skeleton_number + 1) self.skeletons = [] self.create_skeletons() self.add_skeleton_coordinates() self.add_key_to_skeleton() self.draw_skeletons() self.boss = Boss(self.canvas) self.boss.draw(self.spots[-1]) self.boss.x = self.spots[-1][0] self.boss.y = self.spots[-1][1] self.boss_is_dead = False self.enemies = [] self.enlist_enemies() self.deleted_enemies = [] self.hero = Hero(self.canvas) self.hero.draw(0, 0) self.hero_has_key = False self.hud = Hud() self.hud.draw_hud(self.canvas, self.hud_x, self.hud_y, self.hero.level, self.hero.hp, self.hero.dp, self.hero.sp) self.enemy_stat_onscreen = False self.hero_can_move = True root.bind("<KeyPress>", self.on_key_press) self.arrows = { "up": ["Up", 0, -1], "down": ["Down", 0, 1], "right": ["Right", 1, 0], "left": ["Left", -1, 0] } self.canvas.pack() root.mainloop()
def __init__(self): root = Tk() canvas_height = 720 canvas_width = 780 canvas = Canvas(root, width=canvas_width, height=canvas_height) self.map = Map() self.map.draw_map(canvas) self.hero = Hero(canvas) self.hero.create_hero() self.skeleton = Skeleton(canvas) self.skeleton_number = 3 self.spawn_spots = self.map.create_spawn_spots(self.skeleton_number) self.skeleton.spawn_skeleton(self.spawn_spots[:-1]) root.bind("<KeyPress>", self.on_key_press) canvas.pack(padx=1, pady=0.6) root.mainloop()
def __init__(self, config, state_stack): self.config = config self.level = self.generate_first_level() self.current_level = 0 self.levels = [self.level] hero_start = self.level.get_random_floor_tile() self.hero = Hero(hero_start.x, hero_start.y) self.player = GameInputController(self) self.level.entities.append(self.hero)
def __init__(self): root = Tk() canvas_height = 700 canvas_width = 720 canvas = Canvas(root, width=canvas_width, height=canvas_height) self.map = Map() self.map.draw_map(canvas) self.hero = Hero(canvas) self.hero.draw_hero(0, 0) self.hero.update_entity(self.hero.hero_down) self.skeleton = Skeleton(canvas) self.boss = Boss(canvas) self.skel_num = 3 self.coordinates = self.map.create_random_coordinates(self.skel_num + 1) self.skeleton.draw_skeleton(self.coordinates[:-1]) self.boss.draw_boss(self.coordinates[-1]) self.hud = Hud() self.hud.draw_hud(canvas, 0, 650) root.bind("<KeyPress>", self.on_key_press) canvas.pack() root.mainloop()
def __init__(self): self.size = 720 self.root = Tk() self.root.configure(background ='black') self.hud = 200 self.canvas = Canvas(self.root, width=self.size+self.hud, height=self.size,bg="green",bd=0) self.floor = PhotoImage(file="floor.png") self.wall = PhotoImage(file="wall.png") self.char_down = PhotoImage(file="hero-down.png") self.char_up = PhotoImage(file="hero-up.png") self.char_right = PhotoImage(file="hero-right.png") self.char_left = PhotoImage(file="hero-left.png") self.skeleton = PhotoImage(file="skeleton.png") self.boss = PhotoImage(file="boss.png") self.hero = Hero() self.warlock = Boss() self.bones = Skeleton() self.canvas.pack() self.canvas.focus_set()
def __init__(self): self.my_map = Map() self.my_hero = Hero() # self.boss = Boss() self.root = Tk() self.size = 720 self.field_size = 72 self.root.title("Elder Scrolls: The Wanderer") self.canvas = Canvas(self.root, width = self.size + 200, height = self.size, background = '#663300') self.floor = PhotoImage(file = 'floor.png') self.wall = PhotoImage(file = 'wall.png') self.hero_down = PhotoImage(file = 'hero-down.png') self.hero_up = PhotoImage(file = 'hero-up.png') self.hero_right = PhotoImage(file = 'hero-right.png') self.hero_left = PhotoImage(file = 'hero-left.png') self.skeleton_pic = PhotoImage(file = 'skeleton.png') self.boss_pic = PhotoImage(file = 'boss.png') self.root.bind('<KeyPress>', self.on_key_press) self.canvas.pack() self.canvas.focus_set()
class Game: def __init__(self): self.my_view = Display() self.game_map = Map() self.my_view.draw_map(self.game_map.game_map_source) self.chars_on_screen = [] self.enemies_on_screen = [] self.create_hero(0, 0) self.create_enemy() self.my_view.root.bind("<KeyPress>", self.on_key_press) self.my_view.root.bind("<space>", self.on_space_press) self.my_view.starter() def create_hero(self, x, y): self.hero = self.my_view.draw_entity(self.my_view.char_down, [x, y]) self.heroEntity = Hero() self.heroEntity.id = self.hero self.chars_on_screen.append(self.hero) self.my_view.hero_hud(self.heroEntity) def create_enemy(self): self.skeleton1 = self.my_view.draw_entity(self.my_view.skeleton, self.random_spawn()) self.chars_on_screen.append(self.skeleton1) self.skeleton2 = self.my_view.draw_entity(self.my_view.skeleton, self.random_spawn()) self.chars_on_screen.append(self.skeleton2) self.skeleton3 = self.my_view.draw_entity(self.my_view.skeleton, self.random_spawn()) self.chars_on_screen.append(self.skeleton3) self.boss = self.my_view.draw_entity(self.my_view.boss, self.random_spawn()) self.chars_on_screen.append(self.boss) obj = Boss() obj.id = self.boss self.enemies_on_screen.append(obj) self.bossEntity = obj obj = Skeleton() obj.id = self.skeleton1 self.enemies_on_screen.append(obj) obj = Skeleton() obj.id = self.skeleton2 self.enemies_on_screen.append(obj) obj = Skeleton() obj.id = self.skeleton3 self.enemies_on_screen.append(obj) print(self.chars_on_screen) print(self.skeleton1) def random_spawn(self): coords = [0, 0] while self.is_occupied(coords[0], coords[1]) or self.game_map.get_wall_coords( coords[0] * 72, coords[1] * 72) == 1: coords[0] = randint(0, 9) coords[1] = randint(0, 8) return coords def is_occupied(self, x, y): for image in self.chars_on_screen: coords = self.my_view.canvas.coords(image) its_occupied = coords[0] == x and coords[1] == y if its_occupied: break return its_occupied def get_entity_on_pos(self, x, y): for image in self.enemies_on_screen: coords = self.my_view.canvas.coords(image.id) its_occupied = coords[0] == x and coords[1] == y if its_occupied: return image return 0 def meet_with_someone(self, x, y): entity = self.get_entity_on_pos(x, y) if entity == 0: return entity if (entity == self.bossEntity): self.my_view.boss_hud(self.bossEntity) else: self.my_view.skeleton_hud(entity) return entity def move(self, dx, dy): self.my_view.canvas.move(self.hero, dx * 72, dy * 72) def on_key_press(self, e): coords = self.my_view.canvas.coords(self.hero) if (e.keysym == 'Up'): self.my_view.canvas.itemconfigure(self.hero, image=self.my_view.char_up) if coords[1] > 0 and not self.game_map.get_wall_coords( coords[0], coords[1] - 72) == 1: self.meet_with_someone(coords[0], coords[1] - 72) self.move(0, -1) elif (e.keysym == 'Down'): self.my_view.canvas.itemconfigure(self.hero, image=self.my_view.char_down) if coords[1] < 648 and not self.game_map.get_wall_coords( coords[0], coords[1] + 72) == 1: self.meet_with_someone(coords[0], coords[1] + 72) self.move(0, 1) elif (e.keysym == 'Right'): self.my_view.canvas.itemconfigure(self.hero, image=self.my_view.char_right) if coords[0] < 648 and not self.game_map.get_wall_coords( coords[0] + 72, coords[1]) == 1: self.meet_with_someone(coords[0] + 72, coords[1]) self.move(1, 0) elif (e.keysym == 'Left'): self.my_view.canvas.itemconfigure(self.hero, image=self.my_view.char_left) if coords[0] > 0 and not self.game_map.get_wall_coords( coords[0] - 72, coords[1]) == 1: self.meet_with_someone(coords[0] - 72, coords[1]) self.move(-1, 0) def on_space_press(self, e): coords = self.my_view.canvas.coords(self.hero) entity = self.meet_with_someone(coords[0], coords[1]) self.fight(entity) self.my_view.hero_hud(self.heroEntity) def fight(self, entity): self.heroEntity.strike_entity(entity) entity.strike_entity(self.heroEntity)
class Map(): """docstring for Map""" def __init__(self, dng_map): self.dng_map = dng_map self.dungeon_map = self.dng_map.map_to_matrix() self.max_path_UpDown = len(self.dungeon_map) - 1 self.max_path_LeftRight = len(self.dungeon_map[0]) - 1 self.cords = {} self.spawned = [] def spawn(self, player_name, entity): self.player_name = player_name self.entity = entity.lower() self.spawned.append(self.player_name) if self.entity == "orc": self.entity = "O" self.player1 = Orc(player_name, 100, 2) print('') print("{} is fighting with:".format(player_name)) self.player1.equip_weapon(self.give_weapon()) else: self.entity = "H" self.player2 = Hero(player_name, 100, "The NutCracker") print('') print("{} is fighting with:".format(player_name)) self.player2.equip_weapon(self.give_weapon()) for i in range(len(self.dungeon_map)): for j in range(len(self.dungeon_map[i])): if self.dungeon_map[i][j] == "S": self.dungeon_map[i][j] = self.entity self.cords.setdefault(self.player_name, []).append(i) self.cords.setdefault(self.player_name, []).append(j) return True return False def get_cords(self, name): return '{} is on cords {}'.format(name, self.cords[name]) def move(self, name, direction): self.UpDown = self.cords[name][0] self.LeftRight = self.cords[name][1] if direction == "right" and self.dungeon_map[self.UpDown][self.LeftRight + 1] != "#" and 0 <= self.LeftRight <= self.max_path_LeftRight: self.LeftRight += 1 self.cords[name][1] = self.LeftRight # print("position updated") elif direction == "left" and self.dungeon_map[self.UpDown][self.LeftRight - 1] != "#" and 0 <= self.LeftRight <= self.max_path_LeftRight: self.LeftRight -= 1 self.cords[name][1] = self.LeftRight # print("position updated") elif direction == "up" and self.dungeon_map[self.UpDown - 1][self.LeftRight] != "#" and 0 <= self.UpDown <= self.max_path_UpDown: self.UpDown -= 1 self.cords[name][0] = self.UpDown # print("position updated") elif direction == "down" and self.dungeon_map[self.UpDown + 1][self.LeftRight] != "#" and 0 <= self.UpDown <= self.max_path_UpDown: self.UpDown += 1 self.cords[name][0] = self.UpDown # print("position updated") else: print("Illigal move") return False # print(self.get_cords(name)) self.fight_time() return True def fight_time(self): if self.cords[self.spawned[0]] == self.cords[self.spawned[1]]: print('') print("Its time for fight. Lets Bet!") print('') self.its_show_time = Fight(self.player1, self.player2) self.its_show_time.simulate_fight() def give_weapon(self): TheFist = Weapon("Anger Fist", 35, 0.3) TheBlades = Weapon("Ilidan Blades", 20, 0.25) GladiatorKnife = Weapon("Axill Sword", 15, 0.5) TheRebornMace = Weapon("Trojan Mace", 50, 0.15) ThunderKick = Weapon("Chuck Noriss Enlightment", 80, 1) PitLord = Weapon("Black Hole", 50, 0.1) Ruthless = Weapon("Bitch Slap", 45, 0.4) select_weapon = randint(0, 6) weapons = [TheFist, TheBlades, GladiatorKnife, TheRebornMace, ThunderKick, PitLord, Ruthless] print(weapons[select_weapon].model) return weapons[select_weapon]
class Game(object): def __init__(self): root = Tk() canvas_height = 720 canvas_width = 780 canvas = Canvas(root, width=canvas_width, height=canvas_height) self.map = Map() self.map.draw_map(canvas) self.hero = Hero(canvas) self.hero.create_hero() self.skeleton = Skeleton(canvas) self.skeleton_number = 3 self.spawn_spots = self.map.create_spawn_spots(self.skeleton_number) self.skeleton.spawn_skeleton(self.spawn_spots[:-1]) root.bind("<KeyPress>", self.on_key_press) canvas.pack(padx=1, pady=0.6) root.mainloop() def on_key_press(self, e): if (e.keysym == 'Up'): self.hero.change_image(self.hero.hero_up) if self.map.is_in_border_floor(self.hero.x, self.hero.y - 1) == True: self.hero.move(0, -1) elif (e.keysym == 'Down'): self.hero.change_image(self.hero.hero_down) if self.map.is_in_border_floor(self.hero.x, self.hero.y + 1) == True: self.hero.move(0, 1) elif (e.keysym == 'Left'): self.hero.change_image(self.hero.hero_left) if self.map.is_in_border_floor(self.hero.x - 1, self.hero.y) == True: self.hero.move(-1, 0) elif (e.keysym == 'Right'): self.hero.change_image(self.hero.hero_right) if self.map.is_in_border_floor(self.hero.x + 1, self.hero.y) == True: self.hero.move(1, 0)
class Game(object): def __init__(self): root = Tk() canvas_height = 720 canvas_width = 820 self.hud_x = 720 self.hud_y = 0 self.canvas = Canvas(root, width=canvas_width, height=canvas_height, bg = "#957740") self.map = Map() self.map.draw_map(self.canvas) self.skeleton_number = 3 self.spots = self.map.create_enemy_spots(self.skeleton_number + 1) self.skeletons = [] self.create_skeletons() self.add_skeleton_coordinates() self.add_key_to_skeleton() self.draw_skeletons() self.boss = Boss(self.canvas) self.boss.draw(self.spots[-1]) self.boss.x = self.spots[-1][0] self.boss.y = self.spots[-1][1] self.boss_is_dead = False self.enemies = [] self.enlist_enemies() self.deleted_enemies = [] self.hero = Hero(self.canvas) self.hero.draw(0, 0) self.hero_has_key = False self.hud = Hud() self.hud.draw_hud(self.canvas, self.hud_x, self.hud_y, self.hero.level, self.hero.hp, self.hero.dp, self.hero.sp) self.enemy_stat_onscreen = False self.hero_can_move = True root.bind("<KeyPress>", self.on_key_press) self.arrows = { "up": ["Up", 0, -1], "down": ["Down", 0, 1], "right": ["Right", 1, 0], "left": ["Left", -1, 0] } self.canvas.pack() root.mainloop() def on_key_press(self, e): if self.hero_can_move == True: for i in self.arrows.keys(): if e.keysym == self.arrows[i][0]: self.hero.configure(i) if self.map.is_wall(self.hero.x + self.arrows[i][1] * self.map.tile_size,\ self.hero.y + self.arrows[i][2] * self.map.tile_size) == False: self.hero.move(self.arrows[i][1] * self.map.tile_size, self.arrows[i][2] * self.map.tile_size) if self.boss.hp > 0 and [self.hero.x, self.hero.y] != self.spots[-1]: self.spots[-1] = self.boss.move(self.spots) for i in range(self.skeleton_number): if self.skeletons[i].hp > 0 and [self.hero.x, self.hero.y] != self.spots[i]: self.spots[i] = self.skeletons[i].move(self.spots) self.check_after_arrows() if(e.keysym == "space") and [self.hero.x, self.hero.y] in self.spots: self.fight(self.hero, self.enemies[self.spots.index([self.hero.x, self.hero.y])]) def check_after_arrows(self): if [self.hero.x, self.hero.y] in self.spots and [self.hero.x, self.hero.y] not in self.deleted_enemies and self.enemy_stat_onscreen == False: self.hud.draw_enemy_stat(self.canvas, self.hud_x, self.hud_y, self.enemies[self.spots.index([self.hero.x, self.hero.y])]) self.enemy_stat_onscreen = True self.hero_can_move = False if [self.hero.x, self.hero.y] not in self.spots and self.enemy_stat_onscreen == True: self.hud.clear_enemy_stat(self.canvas) self.enemy_stat_onscreen = False def create_skeletons(self): for i in range(self.skeleton_number): self.skeletons.append(Skeleton(self.canvas)) def add_key_to_skeleton(self): self.skeletons[randint(0, self.skeleton_number - 1)].key = True def add_skeleton_coordinates(self): for i, skeleton in zip(self.spots, self.skeletons): skeleton.x = i[0] skeleton.y = i[1] def draw_skeletons(self): for i, skeleton in zip(range(self.skeleton_number), self.skeletons): skeleton.draw(i) def enlist_enemies(self): for skeleton in self.skeletons: self.enemies.append(skeleton) self.enemies.append(self.boss) def is_strike(self, attacker, defender): var = attacker.sp + 2 * attacker.dice() > defender.dp print(var) return var def strike(self, attacker, defender): print("before first strike attacker.hp: ", attacker.hp, "defender.hp: ", defender.hp) if self.is_strike(attacker, defender): print("def hp", defender.hp) dice = attacker.dice() print("dice", dice) print("att sp: ", attacker.sp) print("def dp", defender.dp) defender.hp -= (attacker.sp + 2 * dice) - defender.dp print("after strike attacker.hp: ", attacker.hp, "defender.hp: ", defender.hp) def fight(self, fighter_1, fighter_2): while fighter_1.hp > 0 and fighter_2.hp > 0: self.strike(fighter_1, fighter_2) if fighter_1.hp > 0 and fighter_2.hp > 0: fighter_1, fighter_2 = fighter_2, fighter_1 self.hud.update_hud() self.hud.update_enemy_stat() if self.hero.hp > 0: self.level_up() self.deleted_enemies.append([self.hero.x, self.hero.y]) self.hero_can_move = True if self.boss.hp <= 0: self.boss.delete() self.boss_is_dead = True self.enter_next_area() for i in self.skeletons: if fighter_2 == i: #needs to be checked if i.key == True: self.hero_has_key = True self.hud.draw_inventory(self.canvas, self.hud_x, self.hud_y) i.delete(self.spots.index([self.hero.x, self.hero.y])) self.enter_next_area() else: self.hud.update_hud() self.hud.update_enemy_stat() print("Game over") def level_up(self): self.hero.max_hp += self.hero.dice() self.hero.dp += self.hero.dice() self.hero.sp += self.hero.dice() self.hero.level += 1 self.canvas.delete(self.hud.hud1) self.canvas.delete(self.hud.hud2) self.canvas.delete(self.hud.hud3) self.canvas.delete(self.hud.hud4) self.hud.draw_hud(self.canvas, 720, 0, self.hero.level, self.hero.hp, self.hero.dp, self.hero.sp) def enter_next_area(self): if self.hero_has_key == True and self.boss_is_dead == True: self.hud.next_level(self.canvas, 150, 150) self.hero_can_move = False
class Game(object): def __init__(self): root = Tk() canvas_height = 700 canvas_width = 720 canvas = Canvas(root, width=canvas_width, height=canvas_height) self.map = Map() self.map.draw_map(canvas) self.hero = Hero(canvas) self.hero.draw_hero(0, 0) self.hero.update_entity(self.hero.hero_down) self.skeleton = Skeleton(canvas) self.boss = Boss(canvas) self.skel_num = 3 self.coordinates = self.map.create_random_coordinates(self.skel_num + 1) self.skeleton.draw_skeleton(self.coordinates[:-1]) self.boss.draw_boss(self.coordinates[-1]) self.hud = Hud() self.hud.draw_hud(canvas, 0, 650) root.bind("<KeyPress>", self.on_key_press) canvas.pack() root.mainloop() def on_key_press(self, e): if (e.keysym == 'Up'): self.hero.update_entity(self.hero.hero_up) if self.map.is_wall(self.hero.x, self.hero.y - self.map.tile_size) == False: self.hero.move(0, -self.map.tile_size) elif (e.keysym == 'Down'): self.hero.update_entity(self.hero.hero_down) if self.map.is_wall(self.hero.x, self.hero.y + self.map.tile_size) == False: self.hero.move(0, +self.map.tile_size) elif (e.keysym == 'Right'): self.hero.update_entity(self.hero.hero_right) if self.map.is_wall(self.hero.x + self.map.tile_size, self.hero.y) == False: self.hero.move(+self.map.tile_size, 0) elif (e.keysym == 'Left'): self.hero.update_entity(self.hero.hero_left) if self.map.is_wall(self.hero.x - self.map.tile_size, self.hero.y) == False: self.hero.move(-self.map.tile_size, 0)
class Map(): """docstring for Map""" def __init__(self, dng_map): self.dng_map = dng_map self.dungeon_map = self.dng_map.map_to_matrix() self.max_path_UpDown = len(self.dungeon_map) - 1 self.max_path_LeftRight = len(self.dungeon_map[0]) - 1 self.cords = {} self.spawned = [] def spawn(self, player_name, entity): self.player_name = player_name self.entity = entity.lower() self.spawned.append(self.player_name) if self.entity == "orc": self.entity = "O" self.player1 = Orc(player_name, 1000, 2) print('') print("{} is fighting with:".format(player_name)) self.player1.equip_weapon(give_weapon()) else: self.entity = "H" self.player1 = Hero(player_name, 1000, "The NutCracker") print('') print("{} is fighting with:".format(player_name)) self.player1.equip_weapon(give_weapon()) for i in range(len(self.dungeon_map)): for j in range(len(self.dungeon_map[i])): if self.dungeon_map[i][j] == "S": self.dungeon_map[i][j] = self.entity self.cords.setdefault(self.player_name, []).append(i) self.cords.setdefault(self.player_name, []).append(j) return True return False def get_cords(self, name): return '{} is on cords {}'.format(name, self.cords[name]) def move(self, name, direction): self.UpDown = self.cords[name][0] self.LeftRight = self.cords[name][1] if direction == "right" and self.dungeon_map[self.UpDown][self.LeftRight + 1] != "#" and 0 <= self.LeftRight <= self.max_path_LeftRight: self.LeftRight += 1 self.cords[name][1] = self.LeftRight # print("position updated") elif direction == "left" and self.dungeon_map[self.UpDown][self.LeftRight - 1] != "#" and 0 <= self.LeftRight <= self.max_path_LeftRight: self.LeftRight -= 1 self.cords[name][1] = self.LeftRight # print("position updated") elif direction == "up" and self.dungeon_map[self.UpDown - 1][self.LeftRight] != "#" and 0 <= self.UpDown <= self.max_path_UpDown: self.UpDown -= 1 self.cords[name][0] = self.UpDown # print("position updated") elif direction == "down" and self.dungeon_map[self.UpDown + 1][self.LeftRight] != "#" and 0 <= self.UpDown <= self.max_path_UpDown: self.UpDown += 1 self.cords[name][0] = self.UpDown # print("position updated") else: print("Illigal move") return False # print(self.get_cords(name)) self.fight_time() return True def fight_time(self): if self.dungeon_map[self.UpDown][self.LeftRight] == 'P': print('') print("Its time for fight. Lets Bet!") print('') self.enemy = Python(10) self.its_show_time = Fight(self.player1, self.enemy) self.its_show_time.simulate_fight() elif self.dungeon_map[self.UpDown][self.LeftRight] == 'A': print('') print("Its time for fight. Lets Bet!") print('') self.enemy = Anaconda(10, (4, 1.5)) self.its_show_time = Fight(self.player1, self.enemy) self.its_show_time.simulate_fight() def item(self): item = randint(0, 1) if self.dungeon_map[self.UpDown][self.LeftRight] == 'I': if item == 0: self.player1.equip_weapon(give_weapon()) else: self.player1.take_healing()
class Game: def __init__(self): # self.game_status() self.my_map = Map() self.my_view = View(self.my_map.map1) self.combat = Fight_engine() self.my_view.root.bind("<KeyPress>", self.on_key_press) self.creatures = [Boss(0, 7, "boss")] self.get_random_skeletons() self.get_units() self.hero = Hero(0, 0, "hero-down") self.hero.unit_id = self.my_view.draw_game_object(0, 0, "hero-down") self.movement_count = 0 self.delete_dead_creature() self.hud() self.my_view.start() def get_random_skeletons(self): skeletons = randint(20, 25) while skeletons > 0: x = randint(1, 9) y = randint(1, 9) valid = self.my_map.cell_validation(x, y) if valid: can_insert_skeleton = True for creature in self.creatures: if x == creature.position_x and y == creature.position_y: can_insert_skeleton = False if can_insert_skeleton: self.creatures.append(Skeleton(x, y, "skeleton")) skeletons -= 1 def get_units(self): for unit in self.creatures: unit.unit_id = self.my_view.draw_game_object(unit.position_x, unit.position_y, unit.image) def on_key_press(self, e): if not self.hero.enemy_to_kill: if e.keysym == "Up" or e.keysym == "Down" or e.keysym == "Left" or e.keysym == "Right": self.move_hero(e.keysym) self.check_if_meeting() elif self.hero.enemy_to_kill: if e.keysym == "space": self.check_if_meeting() def move_hero(self, direction): if direction == "Up" or direction == "Down" or direction == "Left" or direction == "Right": self.move_counter() self.facing = self.my_view.images["hero-" + direction.lower()] self.my_view.canvas.itemconfigure(self.hero.unit_id, image=self.facing) self.valid = self.check_direction_validity(direction, self.hero) if direction == "Up" and self.valid: self.my_view.canvas.move(self.hero.unit_id, 0, -72) self.hero.move(direction) elif direction == "Down" and self.valid: self.my_view.canvas.move(self.hero.unit_id, 0, 72) self.hero.move(direction) elif direction == "Left" and self.valid: self.my_view.canvas.move(self.hero.unit_id, -72, 0) self.hero.move(direction) elif direction == "Right" and self.valid: self.my_view.canvas.move(self.hero.unit_id, 72, 0) self.hero.move(direction) def move_counter(self): self.movement_count += 1 if self.movement_count == 2: for creature in self.creatures: direction = creature.random_move() self.monster_move_check(creature, direction) self.movement_count = 0 def monster_move_check(self, creature, direction): if_valid = self.check_direction_validity(direction, creature) if if_valid: self.move_enemies(creature, direction) def move_enemies(self, creature, direction): self.my_view.canvas.itemconfigure(creature.unit_id, image=self.my_view.images[creature.image]) if direction == "Up": self.my_view.canvas.move(creature.unit_id, 0, -72) creature.move(direction) elif direction == "Down": self.my_view.canvas.move(creature.unit_id, 0, 72) creature.move(direction) elif direction == "Left": self.my_view.canvas.move(creature.unit_id, -72, 0) creature.move(direction) elif direction == "Right": self.my_view.canvas.move(creature.unit_id, 72, 0) creature.move(direction) def check_direction_validity(self, direction, guy): if direction == "Up": self.validity = self.my_map.cell_validation(guy.position_x, guy.position_y - 1) elif direction == "Down": self.validity = self.my_map.cell_validation(guy.position_x, guy.position_y + 1) elif direction == "Left": self.validity = self.my_map.cell_validation(guy.position_x - 1, guy.position_y) elif direction == "Right": self.validity = self.my_map.cell_validation(guy.position_x + 1, guy.position_y) return self.validity def check_if_meeting(self): for creature in self.creatures: if self.hero.position_x == creature.position_x and self.hero.position_y == creature.position_y: self.hero.enemy_to_kill = creature self.my_view.battle_hud(creature.stats()) self.combat.battle_on(self.hero, creature, self.my_view, self.hero.enemy_to_kill) elif self.hero.enemy_to_kill: self.my_view.canvas.delete(self.my_view.battle_hud_id) self.hero.enemy_to_kill = None def delete_dead_creature(self): self.my_view.canvas.delete(self.combat.dead_creature) self.my_view.root.after(100, self.delete_dead_creature) def hud(self): self.my_view.hud(self.hero.stats()) def game_status(self): if self.is_going == False: pass