def game(): ships = [] xdim, ydim = GUI.askforboardsize() board = Board(xdim, ydim) GUI.printboard(board) while True: size, xpos, ypos, allign = GUI.askforshiptoplace() ship = whichshiptocreate(int(size), allign) if board.oktoplaceship(int(ypos), int(xpos), ship): board.placeshipat(int(ypos), int(xpos), ship) ships.append(ship) next = input( "Would you like to continue providing ships yes/no = 1/0 respectively: " ) if next.isdigit(): if next == "0": break elif next == "1": continue else: print("Bad choose!") break else: print("Bad data. End of providing ships!") while len(ships) > 0: row, col = GUI.wheretoshot() _, text = board.shootat(row, col) print(text) GUI.printboard(board) if "sink" in text: ships.pop() print("Congratulations you sink all the ships! Game over! ")
def __init__(self, configuration_of_ships): self.__num_of_shoots = 0 self.__board = Board() self.__generator_of_ship = GeneratorOfShip(self.__board) self.__ships = list() for num_of_decks in configuration_of_ships: self.__ships.append( self.__generator_of_ship.create_ship(num_of_decks)) db.creat_shema()
def __init__(self, screen): """ Set up the game. Params: screen, root pygame surface. """ # Create the main screen surface. self.__screen = screen self.__screen.fill((0, 0, 85)) # Fill the background with colour. # Initialize Board self.__board_surface = pygame.Surface(BOARD_SIZE) self.__board_rect = self.__board_surface.get_rect() self.__board_rect.x, self.__board_rect.y = BOARD_POS # Font filepath. topaz_filepath = pygame.font.match_font(FONTFAMILY) # Create the font for the title. self.__title_font = pygame.font.Font(topaz_filepath, 30) # Create the title and center it so that it displays above the board. self.__title = Title(self.__screen, self.__title_font, "", 300, 50, True, True, red) # Creating the Buttons offset = 150 x = SCREEN_W // 2 y = SCREEN_H - 50 # Font for the buttons. self.__button_font = pygame.font.Font(topaz_filepath, 15) # Restart button for restarting the game, but keeping the same gamemode. self.__restart_button = Button(self.__screen, self.__button_font, 100, 30, x - offset, y, "RESTART", True, (light_red, red), (white, black)) # Quit button for backing out into the main menu. self.__quit_button = Button(self.__screen, self.__button_font, 100, 30, x + offset, y, "BACK", True, (light_red, red), (white, black)) # Single player variables self.__computer_peice = None # The computer's peice. self.__player_peice = None # The player's peice. # State variables self.__wait = True # Display the screen before running the minimax algorithm. self.__finished = False self.__board = Board() # Create an empty 3x3 board. self.__win = self.__is_draw = self.__game_over = self.__visible = False self.__current_peice = CROSS # The first peice to make a move.
def __restart(self): """ Restart the game state with the previous settings, i.e. computer_peice, player_peice stay the same. """ self.__screen.fill(black) # Fill screen black self.__board = Board() # Create new empty board. # Reset game state. self.__wait = True self.__winfo = self.__win = self.__is_draw = self.__game_over = False # Reset to the default starting peice: Nought. self.__current_peice = CROSS # Reset the button state. self.__restart_button.reset() self.__quit_button.reset()
def init_round(self): self.end_round() self.chips = create_chips_without_double(self.highest_double, self.current_double) random.shuffle(self.chips) for player in self.players: chips = [] for i in range(self.n_chips_per_player): chips.append(self.chips.pop()) player.init_turn(chips) self.board = Board(len(self.players), self.current_double, self.chips) self.current_double -= 1
def __reset(self): """ Completely reset the game state. """ self.__screen.fill(black) # Fill the screen with black. self.__board = Board() # Create an empty 3x3 board. self.__wait = True self.__win = self.__is_draw = self.__game_over = self.__visible = False # Reset variables used in singleplayer self.__computer_peice = self.__player_peice = None # Reset to the default starting peice: Nought. self.__current_peice = CROSS # Reset the button state. self.__restart_button.reset() self.__quit_button.reset()
def main(): not_quit = True while not_quit: menu_input = input() board = Board() board.display_table() if check_input(menu_input) == "exit": not_quit = False if check_input(menu_input) == "start": pX, pO = parse_input(menu_input) pX = build_player(pX, "X", board) pO = build_player(pO, "O", board) game = TicTacToeGame(board, pX, pO) game.play() else: print("Bad parameters!")
def setUp(self): self.board = Board(10, 10) self.horizontalShip = HorizontalShip(4) self.verticalShip = VerticalShip(3)
def __init__(self): self.board = Board() self.totems = [Totem("{0:04b}".format(i)) for i in range(16)]
def __init__(self): self.board = Board() self.turn = 1 self.result = 0