def generate_boards(b: Board): #Add 1 General g = General() b.insert(g) #Add other vessels for i in range(5): ship = Submarine() b.insert(ship) ship = Jet() b.insert(ship) ship = Destroyer() b.insert(ship)
from Submarine import * # Create the board sub = Submarine(False) # Move forward for 10 seconds sub.Dive(5) sleep(5) sub.Rise(7) # Turn ClockWise # sub.ClockWiseTurn(60) # Turn CounterClockWise # sub.CounterClockWiseTurn(60) #Set the motor to go back for 10 seconds # sub.UpdateMotorSpeed([75,False,75,False,None]) # sleep(10) # Stop the motor sub.UpdateMotorSpeed([0, True, 0, True, 0, True]) print("Turning Off") sleep(2) sub.ShutDown()
from Submarine import * # Create the board sub = Submarine(True) sleep(30) # Stop the motor sub.UpdateMotorSpeed([0, True, 0, True, sub._servoAngle]) # Turn the sub off sub.ShutDown() print("Turning Off") sleep(2)
def place_submarines(self): # Place "Carrier": is_carrier_placed = False while not is_carrier_placed: horiz_or_vert = random.randint(0, 1) if horiz_or_vert == 0: rand_col = random.randint(0, 1) rand_row = random.randint(0, 9) location_list = [(rand_col * 5, rand_row), (rand_col * 5 + 1, rand_row), (rand_col * 5 + 2, rand_row), (rand_col * 5 + 3, rand_row), (rand_col * 5 + 4, rand_row)] if horiz_or_vert == 1: rand_col = random.randint(0, 9) rand_row = random.randint(0, 1) location_list = [(rand_col, rand_row * 5), (rand_col, rand_row * 5 + 1), (rand_col, rand_row * 5 + 2), (rand_col, rand_row * 5 + 3), (rand_col, rand_row * 5 + 4)] my_carrier = Submarine("Carrier") is_carrier_placed = self.player_board.place_submarine_on_board( my_carrier, location_list) # Place "Battleship": is_battleship_placed = False while not is_battleship_placed: horiz_or_vert = random.randint(0, 1) if horiz_or_vert == 0: rand_col = random.randint(0, 1) rand_row = random.randint(0, 9) location_list = [(rand_col * 5, rand_row), (rand_col * 5 + 1, rand_row), (rand_col * 5 + 2, rand_row), (rand_col * 5 + 3, rand_row)] if horiz_or_vert == 1: rand_col = random.randint(0, 9) rand_row = random.randint(0, 1) location_list = [(rand_col, rand_row * 5), (rand_col, rand_row * 5 + 1), (rand_col, rand_row * 5 + 2), (rand_col, rand_row * 5 + 3)] my_battleship = Submarine("Battleship") is_battleship_placed = self.player_board.place_submarine_on_board( my_battleship, location_list) # Place "Cruiser": is_cruiser_placed = False while not is_cruiser_placed: horiz_or_vert = random.randint(0, 1) if horiz_or_vert == 0: rand_col = random.randint(0, 1) rand_row = random.randint(0, 9) location_list = [(rand_col * 5, rand_row), (rand_col * 5 + 1, rand_row), (rand_col * 5 + 2, rand_row)] if horiz_or_vert == 1: rand_col = random.randint(0, 9) rand_row = random.randint(0, 1) location_list = [(rand_col, rand_row * 5), (rand_col, rand_row * 5 + 1), (rand_col, rand_row * 5 + 2)] my_cruiser = Submarine("Cruiser") is_cruiser_placed = self.player_board.place_submarine_on_board( my_cruiser, location_list) # Place "Submarine": is_submarine_placed = False while not is_submarine_placed: horiz_or_vert = random.randint(0, 1) if horiz_or_vert == 0: rand_col = random.randint(0, 1) rand_row = random.randint(0, 9) location_list = [(rand_col * 5, rand_row), (rand_col * 5 + 1, rand_row), (rand_col * 5 + 2, rand_row)] if horiz_or_vert == 1: rand_col = random.randint(0, 9) rand_row = random.randint(0, 1) location_list = [(rand_col, rand_row * 5), (rand_col, rand_row * 5 + 1), (rand_col, rand_row * 5 + 2)] my_submarine = Submarine("Submarine") is_submarine_placed = self.player_board.place_submarine_on_board( my_submarine, location_list) # Place "Destroyer": is_destroyer_placed = False while not is_destroyer_placed: horiz_or_vert = random.randint(0, 1) if horiz_or_vert == 0: rand_col = random.randint(0, 1) rand_row = random.randint(0, 9) location_list = [(rand_col * 5, rand_row), (rand_col * 5 + 1, rand_row)] if horiz_or_vert == 1: rand_col = random.randint(0, 9) rand_row = random.randint(0, 1) location_list = [(rand_col, rand_row * 5), (rand_col, rand_row * 5 + 1)] my_destroyer = Submarine("Destroyer") is_destroyer_placed = self.player_board.place_submarine_on_board( my_destroyer, location_list)
from Submarine import * # Create the board sub = Submarine(True) sub.Forward(5) # Set the depth to 10 # sub.ChangeDepth(10) # Turn ClockWise # sub.ClockWiseTurn(60) # Turn CounterClockWise # sub.CounterClockWiseTurn(60) #Set the motor to go back for 10 seconds # sub.UpdateMotorSpeed([75,False,75,False,None]) # sleep(10) # Stop the motor sub.UpdateMotorSpeed([0, True, 0, True, 0, True]) print("Turning Off") sleep(2) sub.ShutDown()
from MessageBoard import MessageBoard from threading import Thread, Lock from time import sleep from Ptr import ptr from Turn90DegreeCW import Turn90DegreeCW from Submarine import * # Create the board board = MessageBoard() sub = Submarine(board) # Start the board messageBoardThread = Thread(target=board.ReadSerial) messageBoardThread.start() sleep(2) sub.SendLeftSpeedPacket(0, True) sub.SendRightSpeedPacket(0, True) sleep(3) board.CloseBoard() sub.ShutDown()
from MessageBoard import MessageBoard from threading import Thread, Lock from time import sleep from Ptr import ptr from Turn90DegreeCW import Turn90DegreeCW from Submarine import * # Create the board board = MessageBoard() sub = Submarine(board) # Start the board messageBoardThread = Thread(target=board.ReadSerial) messageBoardThread.start() sleep(18000) board.CloseBoard() sub.ShutDown()