Пример #1
0
    def starting_positions_ships(self):
        '''
        Method to put starting coordinate on board
        '''
        ocean_player = Ocean()
        os.system('clear')
        print(ocean_player)
        for key in self.player_ships:

            print("Enter coordinates of" + " " + key)
            print("(1) Horizontal\n(2) Vertical")

            is_connect = True
            while is_connect:

                horizontal = input("Select direction:\n")

                if horizontal == "1":
                    horizontal = True
                elif horizontal == "2":
                    horizontal = False
                else:
                    continue

                numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]

                position_x = input("Enter x position:")

                while position_x not in numbers:
                    position_x = input("Enter x position:")

                position_y = input("Enter y position:")

                while position_y not in numbers:
                    position_y = input("Enter y position:")

                position_x = int(position_x)
                position_y = int(position_y)

                positions = (position_x, position_y, self.player_ships[key],
                             horizontal)

                if ocean_player.board[positions[1]][positions[0] -
                                                    1].is_empty is False:
                    print("WRONG CORDS!")
                    continue

                else:

                    is_connect = False

            self.starting_positions.append(positions)
            os.system('clear')

            ocean_player.preview_ships(*positions)
            ocean_player.add_ships(*positions)

            print(ocean_player)

        return self.starting_positions
Пример #2
0
def main():
    '''
    Function for main menu, create ships, shooting - playing the game
    Parameters:
    -----------
    chose_number = int
    '''
    os.system('clear')
    main_menu()
    chose_number = input("Enter number:\n")

    if chose_number == '1':
        os.system('clear')

        new_player1 = input("Enter name of player 1:\n")
        new_player2 = input("Enter name of player 2:\n")

        ship1 = player.Player(new_player1)
        new_ships1 = ship1.starting_positions_ships()

        ocean_player1 = Ocean()
        for s in new_ships1:
            ocean_player1.add_ships(*s)

        ship2 = player.Player(new_player2)
        new_ships2 = ship2.starting_positions_ships()

        ocean_player2 = Ocean()
        for s in new_ships2:
            ocean_player2.add_ships(*s)

        os.system('clear')
        print("GOOD LUCK")
        while True:

            turn = 1

            while turn == 1:
                radius = range(1, 11)
                print("==================================")
                print("Your ships", new_player1)
                print("==================================")
                print(ocean_player1)
                shot = (int(input("Enter x:\n")), int(input("Enter y:\n")))
                if shot[0] not in radius or shot[1] not in radius:
                    continue

                os.system('clear')
                ocean_player1.shot(shot[0], shot[1])
                print(ocean_player1)
                pauza = input()
                os.system('clear')
                turn = 2

            while turn == 2:
                radius = range(1, 11)
                print("==================================")
                print("Your ships", new_player2)
                print("==================================")
                print(ocean_player2)
                shot = (int(input("Enter x:\n")), int(input("Enter y:\n")))
                if shot[0] not in radius or shot[1] not in radius:
                    continue

                os.system('clear')
                ocean_player2.shot(shot[0], shot[1])
                print(ocean_player2)
                pauza = input()
                os.system('clear')

                break

    else:
        print('Wrong sign, try again')