def __init__(self): self.board = [[None for j in range(8)] for i in range(8)] self.pieces = [] # set white board pieces = [] for i in range(8): pieces.append(Pawn(i, 1, COLOR.WHITE)) pieces.append(Rook(0, 0, COLOR.WHITE)) pieces.append(Rook(7 ,0, COLOR.WHITE)) pieces.append(Knight(1, 0, COLOR.WHITE)) pieces.append(Knight(6, 0, COLOR.WHITE)) pieces.append(Bishop(2, 0, COLOR.WHITE)) pieces.append(Bishop(5, 0, COLOR.WHITE)) pieces.append(King(3, 0, COLOR.WHITE)) pieces.append(Queen(4, 0, COLOR.WHITE)) #set black peices for i in range(8): pieces.append(Pawn(i, 6, COLOR.BLACK)) pieces.append(Rook(0, 7, COLOR.BLACK)) pieces.append(Rook(7 ,7, COLOR.BLACK)) pieces.append(Knight(1, 7, COLOR.BLACK)) pieces.append(Knight(6, 7, COLOR.BLACK)) pieces.append(Bishop(2, 7, COLOR.BLACK)) pieces.append(Bishop(5, 7, COLOR.BLACK)) pieces.append(King(3, 7, COLOR.BLACK)) pieces.append(Queen(4, 7, COLOR.BLACK)) for _piece in pieces: self.pieces.append(_piece) self.board[_piece._x][_piece._y] = _piece
def add_pieces(self): """ Appends the proper pieces and locations to each team list. Team lists are used to get the possible moves and easily check the capture status of a piece. """ self.wp.append(King(4, 7, True)) self.wp.append(Queen(3, 7, True)) self.wp.append(Rook(0, 7, True)) self.wp.append(Rook(7, 7, True)) self.wp.append(Knight(1, 7, True)) self.wp.append(Knight(6, 7, True)) self.wp.append(Bishop(2, 7, True)) self.wp.append(Bishop(5, 7, True)) for i in range(8): self.wp.append(Pawn(i, 6, True)) self.bp.append(King(4, 0, False)) self.bp.append(Queen(3, 0, False)) self.bp.append(Rook(0, 0, False)) self.bp.append(Rook(7, 0, False)) self.bp.append(Knight(1, 0, False)) self.bp.append(Knight(6, 0, False)) self.bp.append(Bishop(2, 0, False)) self.bp.append(Bishop(5, 0, False)) for i in range(8): self.bp.append(Pawn(i, 1, False))
def init_board(self): new_b = [] for i in range(64): # white if i == 0 or i == 7: new_b.append(Tile(Rook('W'))) elif i == 1 or i == 6: new_b.append(Tile(Knight('W'))) elif i == 2 or i == 5: new_b.append(Tile(Bishop('W'))) elif i == 3: new_b.append(Tile(Queen('W'))) elif i == 4: new_b.append(Tile(King('W'))) elif i >= 8 and i <= 15: new_b.append(Tile(Pawn('W'))) # black elif i == 56 or i == 63: new_b.append(Tile(Rook('B'))) elif i == 57 or i == 62: new_b.append(Tile(Knight('B'))) elif i == 58 or i == 61: new_b.append(Tile(Bishop('B'))) elif i == 59: new_b.append(Tile(Queen('B'))) elif i == 60: new_b.append(Tile(King('B'))) elif i >= 48 and i <= 55: new_b.append(Tile(Pawn('B'))) # empty else: new_b.append(Tile()) return new_b
def parse(fin): white_pieces = [] black_pieces = [] with open(fin, "r") as file_in: lines = file_in.read().splitlines() for line in lines: if int(line[-1:]) > 0: for idx in range(0, int(line[-1:])): if (line[-7:-2] == 'WHITE'): temp = line[:-8] if (temp == 'BISHOP'): white_pieces.append(Bishop(Position(), True)) elif (temp == 'KNIGHT'): white_pieces.append(Knight(Position(), True)) elif (temp == 'QUEEN'): white_pieces.append(Queen(Position(), True)) elif (temp == 'ROOK'): white_pieces.append(Rook(Position(), True)) elif (line[-7:-2] == 'BLACK'): temp = line[:-8] if (temp == 'BISHOP'): black_pieces.append(Bishop(Position(), False)) elif (temp == 'KNIGHT'): black_pieces.append(Knight(Position(), False)) elif (temp == 'QUEEN'): black_pieces.append(Queen(Position(), False)) elif (temp == 'ROOK'): black_pieces.append(Rook(Position(), False)) file_in.close() return white_pieces, black_pieces
def _init_pieces(self): if not self._positions: king = King(color=self._color) self._positions.update({str(king.position): king}) queen = Queen(color=self._color) self._positions.update({str(queen.position): queen}) for i in range(1, 9): pawn = Pawn(self._color, col=i) self._positions.update({str(pawn.position): pawn}) knight = Knight(self._color, col=2) self._positions.update({str(knight.position): knight}) knight = Knight(self._color, col=7) self._positions.update({str(knight.position): knight}) rook = Rook(self._color, col=1) self._positions.update({str(rook.position): rook}) rook = Rook(self._color, col=8) self._positions.update({str(rook.position): rook}) bishop = Bishop(self._color, col=3) self._positions.update({str(bishop.position): bishop}) bishop = Bishop(self._color, col=6) self._positions.update({str(bishop.position): bishop})
def fill_board(self): for key in self.__letter_mapping: self[key + '7'] = Pawn(BLACK, self) self[key + '2'] = Pawn(WHITE, self) self['A1'] = Rook(WHITE, self) self['H1'] = Rook(WHITE, self) self['A8'] = Rook(BLACK, self) self['H8'] = Rook(BLACK, self) self['B1'] = Knight(WHITE, self) self['G1'] = Knight(WHITE, self) self['B8'] = Knight(BLACK, self) self['G8'] = Knight(BLACK, self) self['C1'] = Bishop(WHITE, self) self['F1'] = Bishop(WHITE, self) self['C8'] = Bishop(BLACK, self) self['F8'] = Bishop(BLACK, self) self['D1'] = Queen(WHITE, self) self['D8'] = Queen(BLACK, self) self['E1'] = King(WHITE, self) self['E8'] = King(BLACK, self)
def test_knight_jump(self, test_board, test_white_knight): assert test_board assert test_white_knight assert test_white_knight.current_space # Place Knights on the two spaces in front of the test Knight to check that the # test Knight is able to jump over them, i.e. their presence along the Knight's movement # path do not prevent the Knight from legally making the move, and that the # pieces along the path remain where they were after the Knight is done with its move. current_space = test_white_knight.current_space ahead = test_board.get_space(current_space.file, current_space.rank + 1) two_ahead = test_board.get_space(current_space.file, current_space.rank + 2) target = test_board.get_space(chr(ord(current_space.file) + 1), current_space.rank + 2) first_obstacle_knight = Knight(PieceColor.WHITE) first_obstacle_knight.place(ahead) second_obstacle_knight = Knight(PieceColor.BLACK) second_obstacle_knight.place(two_ahead) test_white_knight.move(target) assert test_white_knight.current_space is target assert first_obstacle_knight.current_space is ahead assert second_obstacle_knight.current_space is two_ahead
def setBoard(self, fen): row, column = 0, 0 for character in fen: if character == 'R': self.addPiece(Rook(column, row, 'w', self.board.board)) column += 1 elif character == 'r': self.addPiece(Rook(column, row, 'b', self.board.board)) column += 1 elif character == 'N': self.addPiece(Knight(column, row, 'w', self.board.board)) column += 1 elif character == 'n': self.addPiece(Knight(column, row, 'b', self.board.board)) column += 1 elif character == 'B': self.addPiece(Bishop(column, row, 'w', self.board.board)) column += 1 elif character == 'b': self.addPiece(Bishop(column, row, 'b', self.board.board)) column += 1 elif character == 'P': self.addPiece(Pawn(column, row, 'w', self.board.board)) column += 1 elif character == 'p': self.addPiece(Pawn(column, row, 'b', self.board.board)) column += 1 elif character == 'K': self.addPiece(King(column, row, 'w', self.board.board)) column += 1 elif character == 'k': self.addPiece(King(column, row, 'b', self.board.board)) column += 1 elif character == 'Q': self.addPiece(Queen(column, row, 'w', self.board.board)) column += 1 elif character == 'q': self.addPiece(Queen(column, row, 'b', self.board.board)) column += 1 elif character == '/': column = 0 row += 1 else: if character >= '1' and character <= '9': column += int(character) elif character == ' ': i = fen.index(character) + 1 self.whitesTurn = True if fen[i] == 'w' else False return
def __init__(self): self._running = True self.screen = pygame.display.set_mode((self.W, self.H)) pygame.display.set_caption('Lovag') self.bg = Background(self.W, self.H, self.sizeFaktorX, self.sizeFaktorY) self.kn = Knight(self.W, self.H, self.sizeFaktorX, self.sizeFaktorY) self.clock = None
def check_encounter(self, hero): #randomized value to determine if a user meets a enemy if (randint(0, 100) <= (self.encounter_rate * 100)): #create new enemy and pop a name from the list #if the list is empty then enter the final boss if (len(self.enemy_names) > 0): enemy_temp = self.enemy_names.pop() enemy = None _type = enemy_temp["type"] _name = enemy_temp["name"] if (_type == "warrior"): print("You have encountered {} the warrior".format(_name)) enemy = Warrior(_name, False) elif (_type == "knight"): print("You have encountered {} the knight".format(_name)) enemy = Knight(_name, "", False) elif (_type == "sorceress"): print( "You have encountered {} the sorceress".format(_name)) enemy = Sorceress(_name, False) elif (_type == "theif"): print("You have encountered {} the theif".format(_name)) enemy = Theif(_name, False) for i in range(hero.level + self.level_inc): enemy.level_up() return hero.enter_battle(enemy) else: return self.summon_boss(hero) print("Nothing around here...") return True
def play(self): self.player = Knight() self.occupy_huts() # 确认木屋全部检查过 acquire_hut_count = 0 # 游戏人物及人物血量 self.show_game_mission() self.player.show_health(bold=True) # 开始War while acquire_hut_count < 5: # 玩家选择攻占的木屋 idx = self._process_user_choice() # 开始占据木屋 self.player.acquire_hut(self.huts[idx-1]) # 结束条件 if self.player.health_meter <= 0: print("You Lose, Better luck next time!") break if self.huts[idx-1].is_acquire: acquire_hut_count += 1 if acquire_hut_count == 5: print("Congratulation for you! You Win!!!")
def test_knight_attacks(self): knight1 = Knight(Colour.WHITE, (4, 4)) pawn1 = Pawn(Colour.WHITE, (3, 6)) pawn2 = Pawn(Colour.BLACK, (3, 2)) pawn3 = Pawn(Colour.BLACK, (3, 3)) self.assertEquals(set(knight1.list_attacks([pawn1, pawn2, pawn3])), set([(3, 2)]))
def play(self): """Metoda za pokretanje igre. Metoda se pokreće iz glavnog programa. Stavite opis metode, parametre i atribute, seealso i todo. """ self.player = Knight() self._occupy_huts() acquired_hut_counter = 0 self.show_game_mission() self.player.show_health(bold=True) while acquired_hut_counter < 5: try: idx = self._process_user_choice() self.player.acquire_hut(self.huts[idx - 1]) if self.player.health_meter <= 0: print_bold("Izgubili ste :(") break if self.huts[idx - 1].is_acquired: acquired_hut_counter += 1 except KeyboardInterrupt: print('nKorisnik je izašao iz igre.') # izadji iz programa sys.exit(1) if acquired_hut_counter == 5: print_bold("Cestitke! Pobijedili ste!!!")
def test_white_knight(test_board): starting_file = "b" starting_rank = 1 starting_space = test_board.get_space(starting_file, starting_rank) test_knight = Knight(PieceColor.WHITE) test_knight.place(starting_space) return test_knight
def test_black_knight(test_board): starting_file = "b" starting_rank = 8 starting_space = test_board.get_space(starting_file, starting_rank) test_knight = Knight(PieceColor.BLACK) test_knight.place(starting_space) return test_knight
def action(self): factory = self.__outer.unit() garrison = factory.structure_garrison() if garrison: direction = random.choice(list(bc.Direction)) if self.__outer._gc.can_unload(factory.id, direction): self.__outer._gc.unload(factory.id, direction) location = factory.location.map_location().add(direction) unit = self.__outer._gc.sense_unit_at_location(location) if unit: # TODO: Add other unit types' tree containers strategy.Strategy.getInstance().removeInProduction( unit.unit_type) strategy.Strategy.getInstance().addUnit(unit.unit_type) if unit.unit_type == bc.UnitType.Worker: self.__outer._my_units.append( Worker(unit.id, self.__outer._gc, self.__outer._maps, self.__outer._my_units)) elif unit.unit_type == bc.UnitType.Knight: self.__outer._my_units.append( Knight(unit.id, self.__outer._gc)) elif unit.unit_type == bc.UnitType.Healer: self.__outer._my_units.append( Healer(unit.id, self.__outer._gc, self.__outer._maps)) elif unit.unit_type == bc.UnitType.Ranger: self.__outer._my_units.append( Ranger(unit.id, self.__outer._gc)) elif unit.unit_type == bc.UnitType.Mage: self.__outer._my_units.append( Mage(unit.id, self.__outer._gc, self.__outer._maps)) self._status = bt.Status.SUCCESS
def process_send_knights_orders(self): if self.orders.__len__() > 0: order = self.orders[0] self.gs.add_knight(Knight(order.road, self.team, self.gs)) order.knights_to_send -= 1 if order.knights_to_send == 0: self.orders.remove(order)
def play(self): """Workhorse method to play the game. Controls the high level logic to play the game. This is called from the main program to begin the game execution. """ self.player = Knight() self._occupy_huts() acquired_hut_counter = 0 self.show_game_mission() self.player.show_health(bold=True) while acquired_hut_counter < 5: idx = self._process_user_choice() self.player.acquire_hut(self.huts[idx-1]) if self.player.health_meter <= 0: print_bold("YOU LOSE :( Better luck next time") break if self.huts[idx-1].is_acquired: acquired_hut_counter += 1 if acquired_hut_counter == 5: print_bold("Congratulations! YOU WIN!!!")
def test_attack_by_hand(self): # in-line setup knight = Knight(100) # exercise pain = knight.attack_power() # verify self.assertEqual(pain, Hand().attack_power())
def setUp(self): """Overrides the setUp fixture of the superclass. This method is called just before the calling each unit test. Here, it creates instances of Knight for use by various unit tests. .. seealso:: :py:meth:`TestCase.tearDown` """ self.knight = Knight()
def set_board(self): """Sets up the arena board Returns: Knights and items """ logger.info('\nWelcome to Battling Knight!') logger.info('\nSetting up the Arena') self.arena = Arena() board_pos = self.arena.board pos_r = board_pos[0][0] pos_y = board_pos[0][7] pos_b = board_pos[7][0] pos_g = board_pos[7][7] pos_axe = board_pos[2][2] pos_dagger = board_pos[2][5] pos_magic_staff = board_pos[5][2] pos_helmet = board_pos[5][5] self.R = Knight('R', 'red', pos_r) self.Y = Knight('Y', 'yellow', pos_y) self.B = Knight('B', 'blue', pos_b) self.G = Knight('G', 'green', pos_g) self.axe = Item('A', 'axe', 1, pos_axe) self.dagger = Item('D', 'dagger', 2, pos_dagger) self.magic_staff = Item('M', 'magic_staff', 3, pos_magic_staff) self.helmet = Item('H', 'helmet', 4, pos_helmet) pos_r.knight = self.R pos_y.knight = self.Y pos_b.knight = self.B pos_g.knight = self.G pos_axe.items.append(self.axe) pos_dagger.items.append(self.dagger) pos_magic_staff.items.append(self.magic_staff) pos_helmet.items.append(self.helmet) return (self.arena, self.R, self.Y, self.B, self.G, self.axe, self.dagger, self.magic_staff, self.helmet)
def test_attack_by_knife(self): # in-line setup knight = Knight(100) knight.arms = Knife() # exercise pain = knight.attack_power() # verify self.assertEqual(pain, Knife().attack_power())
def main(): """Executes the main application.""" # Instantiate the x & y co-ordinates. Note that 9 and 9 are 'off the board' and therefore invalid. x = 9 y = 9 # Take x & y User input. For error tolerance, Loop until we receive a valid input (i.e. cannot start the Knight 'off' the board). while (x < 1 or x > BOARD_SIZE) or (y < 1 or y > BOARD_SIZE): x, y = input( "Enter the Knight's starting position as X & Y co-ordinates (1-" + str(BOARD_SIZE) + ") separated by a space (e.g. 4 4): ").split() x, y = [int(x), int(y)] if x < 1 or x > BOARD_SIZE: print("ERROR::Invalid input: x must be 1-" + str(BOARD_SIZE)) if y < 1 or y > BOARD_SIZE: print("ERROR::Invalid input: y must be 1-" + str(BOARD_SIZE)) print() # Create a Knight object at the given X,Y input. knight = Knight(x, y) # Instantiate the board. The Knight's initial position (input) is given with move 1. board = Board(BOARD_SIZE) board.place_knight(1, knight.x, knight.y) # Test for all valid possible moves and special cases. for current_move in range(2, MAX_MOVES + 1): num_possibilities, next_x, next_y = get_num_possibilities( knight, board) min_exits_idx = 0 #index of minimum number of exits # If there are no possibilities left, then end the tour prematurely. Special case that doesn't come up often. if num_possibilities == 0: print("The knight's tour ended prematurely at (" + str(knight.x + 1) + "," + str(knight.y + 1) + ") during move #" + str(current_move - 1) + ".") print() break # If there's more than 1 move possible, find next tile with the # fewest number of exits. This is the core of Warndorff's Rule. elif num_possibilities > 1: exits = find_min_exits(board, num_possibilities, next_x, next_y) min_exits_idx = get_idx_smallest_num_exits(num_possibilities, exits) # Move the knight, marking its location on the board. knight.move(next_x[min_exits_idx], next_y[min_exits_idx]) board.place_knight(current_move, knight.x, knight.y) # Print the board to the console. The board is represented as a move map. board.print_board()
def create_standard_game(self): from bishop import Bishop from king import King from knight import Knight from pawn import Pawn from queen import Queen from rook import Rook self.set_piece(Rook(0, Alliance.WHITE)) self.set_piece(Knight(1, Alliance.WHITE)) self.set_piece(Bishop(2, Alliance.WHITE)) self.set_piece(Queen(3, Alliance.WHITE)) self.set_piece(King(4, Alliance.WHITE)) self.set_piece(Bishop(5, Alliance.WHITE)) self.set_piece(Knight(6, Alliance.WHITE)) self.set_piece(Rook(7, Alliance.WHITE)) self.set_piece(Pawn(8, Alliance.WHITE)) self.set_piece(Pawn(9, Alliance.WHITE)) self.set_piece(Pawn(10, Alliance.WHITE)) self.set_piece(Pawn(11, Alliance.WHITE)) self.set_piece(Pawn(12, Alliance.WHITE)) self.set_piece(Pawn(13, Alliance.WHITE)) self.set_piece(Pawn(14, Alliance.WHITE)) self.set_piece(Pawn(15, Alliance.WHITE)) self.set_piece(Pawn(48, Alliance.BLACK)) self.set_piece(Pawn(49, Alliance.BLACK)) self.set_piece(Pawn(50, Alliance.BLACK)) self.set_piece(Pawn(51, Alliance.BLACK)) self.set_piece(Pawn(52, Alliance.BLACK)) self.set_piece(Pawn(53, Alliance.BLACK)) self.set_piece(Pawn(54, Alliance.BLACK)) self.set_piece(Pawn(55, Alliance.BLACK)) self.set_piece(Rook(56, Alliance.BLACK)) self.set_piece(Knight(57, Alliance.BLACK)) self.set_piece(Bishop(58, Alliance.BLACK)) self.set_piece(Queen(59, Alliance.BLACK)) self.set_piece(King(60, Alliance.BLACK)) self.set_piece(Bishop(61, Alliance.BLACK)) self.set_piece(Knight(62, Alliance.BLACK)) self.set_piece(Rook(63, Alliance.BLACK)) self.set_move_alliance(Alliance.WHITE)
def __init__(self) -> None: """Setup the board with all the pieces on the starting positions.""" self._squares: Dict[str, Square] = { coord: Square(coord) for coord in map("".join, itertools.product(self._FILES, self._RANKS)) } self["a8"].piece = Rook(Color.BLACK) self["b8"].piece = Knight(Color.BLACK) self["c8"].piece = Bishop(Color.BLACK) self["d8"].piece = Queen(Color.BLACK) self["e8"].piece = King(Color.BLACK) self["f8"].piece = Bishop(Color.BLACK) self["g8"].piece = Knight(Color.BLACK) self["h8"].piece = Rook(Color.BLACK) self["a1"].piece = Rook(Color.WHITE) self["b1"].piece = Knight(Color.WHITE) self["c1"].piece = Bishop(Color.WHITE) self["d1"].piece = Queen(Color.WHITE) self["e1"].piece = King(Color.WHITE) self["f1"].piece = Bishop(Color.WHITE) self["g1"].piece = Knight(Color.WHITE) self["h1"].piece = Rook(Color.WHITE) for file in self._FILES: self[f"{file}7"].piece = Pawn(Color.BLACK) self[f"{file}2"].piece = Pawn(Color.WHITE) # Set the adjacent Square nodes for each Square. for i in range(8): for j in range(8): sq = self._get(i, j) sq["n"] = self._get(i, j + 1) sq["e"] = self._get(i + 1, j) sq["s"] = self._get(i, j - 1) sq["w"] = self._get(i - 1, j) sq["ne"] = self._get(i + 1, j + 1) sq["se"] = self._get(i + 1, j - 1) sq["sw"] = self._get(i - 1, j - 1) sq["nw"] = self._get(i - 1, j + 1)
def knight_detail(name): knight = Knight(name) page = '<body>' page += f"<h1>{knight.name}</h1>" page += f"<h2>{knight.title}</h1>" page += f"<h2>{knight.quest}</h1>" page += f"<h2>{knight.color}</h1>" page += f"<h2>{knight.comment}</h1>" home_link = url_for('index') page += f"<a href={home_link}>Return to main page</a>" page += "</body>" return page
def load_knight(hue): knight_x, knight_y = self.map.get_coordinates(9 * hue, 9 * hue) direction = hue and Direction.WEST or Direction.SOUTH knight = Knight(knight_x, knight_y, direction) knight.zindex = 10 knight.color = 255 - (150 * hue), 255 - (150 * ((hue + 1) % 2)), 255 mage_x, mage_y = self.map.get_coordinates(7 * hue + 1, 7 * hue + 1) mage = Mage(mage_x, mage_y, direction) mage.zindex = 10 mage.color = 255 - (150 * hue), 255 - (150 * ((hue + 1) % 2)), 255 return [knight, mage]
def enter(): gfw.world.init(['bg_base', 'bg_back', 'bg_platform', 'platform', 'enemy', 'hornet', 'needle', 'knight', 'slash', 'bg_front', 'ui']) bg_base = FixedBackground('res/map/base.png') gfw.world.add(gfw.layer.bg_base, bg_base) bg_back = FixedBackground('res/map/back.png') gfw.world.add(gfw.layer.bg_back, bg_back) bg_platform = FixedBackground('res/map/platform.png') gfw.world.add(gfw.layer.bg_platform, bg_platform) bg_front = FixedBackground('res/map/front.png') gfw.world.add(gfw.layer.bg_front, bg_front) global platform platform = Platform('res/map/platform.json') for r in platform.rects: r.bg = bg_platform gfw.world.add(gfw.layer.platform, r) crawlid = Crawlid() crawlid.bg = bg_platform gfw.world.add(gfw.layer.enemy, crawlid) global knight knight = Knight() knight.bg = bg_platform bg_back.target = knight bg_platform.target_bg = bg_back bg_front.target_bg = bg_back bg_back.update() bg_platform.update() bg_front.update() gfw.world.add(gfw.layer.knight, knight) global frame frame = Frame(knight) gfw.world.add(gfw.layer.ui, frame) global hornet hornet = Hornet() hornet.bg = bg_platform hornet.target = knight gfw.world.add(gfw.layer.hornet, hornet) global bgm, opening_sting, enemy_damaged bgm = gfw.sound.load_m('res/Sound/cave_wind_loop.mp3') opening_sting = gfw.sound.load_w('res/Sound/S75 Opening Sting-08.wav') enemy_damaged = gfw.sound.load_w('res/Sound/enemy_damage.wav') opening_sting.set_volume(50) bgm.repeat_play() opening_sting.play()
def _occupy_huts(self, n=5): occupants = ['friend', 'enemy', None] for i in range(n): computer_choose = random.choice(occupants) if computer_choose == 'friend': name = 'friend' + str(i + 1) self.huts.append(Hut(i + 1, Knight(name))) elif computer_choose == 'enemy': name = 'enemy' + str(i + 1) self.huts.append(Hut(i + 1, OrcRider(name))) else: self.huts.append(Hut(i + 1, computer_choose))
def choose_hero(): #Choose your hero print(""" 1. Warrior A hero with great strength and the ability to enhance that strength through anger 2. Knight The noblest of heroes, a true defensive powerhouse, armed with a sheild and healing magic, this hero shines in defense 3. Theif Not the typical hero candidate, but a powerful one nonetheless, with the ability to sneak and deal heavy damage on an opponent of much greater and lesser strength 4. Sorceress A powerful mage hero who's abilities are not limited to their skillset of multiple magic types but the ability to create their own spell with the possibility of dealing huge damage """) choice = 0 while(1): try: choice = int(input("Choose what kind of hero you want to be: ")) if(choice > 0 and choice < 5): name = input("Please enter your name: ") if(choice == 1): #warrior return Warrior(name) break elif(choice == 2): #knight familia = input("As a knight you must have a family name: ") return Knight(name, familia) break elif(choice == 3): #theif return Theif(name) break elif(choice == 4): #sorceress return Sorceress(name) break else: print("Please enter a number between 1 and 4") except ValueError: print("Please enter a whole number")