I want it to print a message and change some values when the mario.location values are equal to the coin.location values in python. Why isn't it doing that? It is just printing the regular input. Which is just printing the location values.
class mario:
x_location = 0
y_location = 0
z_location = 0
health = 3
class coin:
x = 1
y = 0
z = 1
rules = [mario.x_location == coin.x,
mario.y_location == coin.y,
mario.z_location == coin.z]
start = input('say yes: ').lower()
while start == 'yes':
command = input('').lower()
if command == 'w':
mario.x_location += 1
print(mario.x_location, mario.y_location, mario.z_location)
elif command == 's':
mario.x_location -= 1
print(mario.x_location, mario.y_location, mario.z_location)
elif command == 'a':
mario.z_location -= 1
print(mario.x_location, mario.y_location, mario.z_location)
elif command == 'd':
mario.z_location += 1
print(mario.x_location, mario.y_location, mario.z_location)
elif all(rules):
if mario.health == 3:
print('you collected a coin')
print('health: ', mario.health)
elif mario.health < 3:
print('You collected a coin and healed')
mario.health += 1
print('Health: ', mario.health)
You are only comparing the values one single time before even starting the while loop. You should be comparing the values every iteration, after a command is chosen.
while start == 'yes':
command = input('').lower()
if command == 'w':
mario.x_location += 1
print(mario.x_location, mario.y_location, mario.z_location)
elif command == 's':
mario.x_location -= 1
print(mario.x_location, mario.y_location, mario.z_location)
elif command == 'a':
mario.z_location -= 1
print(mario.x_location, mario.y_location, mario.z_location)
elif command == 'd':
mario.z_location += 1
print(mario.x_location, mario.y_location, mario.z_location)
rules = [mario.x_location == coin.x,
mario.y_location == coin.y,
mario.z_location == coin.z]
if all(rules):
if mario.health == 3:
print('you collected a coin')
print('health: ', mario.health)
elif mario.health < 3:
print('You collected a coin and healed')
mario.health += 1
print('Health: ', mario.health)
Sample run:
say yes: yes
w
1 0 0
a
1 0 -1
d
1 0 0
d
1 0 1
you collected a coin
health: 3
Related
I am making a program that makes a random Brainf*ck program in python and runs it. I have an interpreter and I need it to check for long loops (more than 5 seconds).
The interpreter is:
while i < len(code):
if code[i] == '<':
if pointerLocation > 0:
pointerLocation -= 1
elif code[i] == '>':
pointerLocation += 1
if len(array) <= pointerLocation:
array.append(0)
elif code[i] == '+':
array[pointerLocation] += 1
elif code[i] == '-':
if array[pointerLocation] > 0:
array[pointerLocation] -= 1
elif code[i] == '.':
print(array[pointerLocation], chr(array[pointerLocation]))
result += chr(array[pointerLocation])
elif code[i] == ',':
#x = input("Input (1 CHARACTER!):")
x = 'h'
#increase time if user inputs
t1 += 5
try:
y = int(x)
except ValueError:
y = ord(x)
array[pointerLocation] = y
elif code[i] == '[':
if array[pointerLocation] == 0:
open_braces = 1
while open_braces > 0 and i+1 < len(code):
i += 1
if code[i] == '[':
open_braces += 1
elif code[i] == ']':
open_braces -= 1
elif code[i] == ']':
# you don't need to check array[pointerLocation] because the matching '[' will skip behind this instruction if array[pointerLocation] is zero
open_braces = 1
while open_braces > 0:
if t > 5:
return [result,code,t]
print(123)
i -= 1
if code[i] == '[':
open_braces -= 1
elif code[i] == ']':
open_braces += 1
# i still gets incremented in your main while loop
i -= 1
i += 1
Sorry for the long snippet, but I do believe it is all neccessary.
Set up an alarm when you enter the loop for 5 seconds. Cancel it when you exit. If the signal triggers then you handle it.
A weaker version of this is to obtain the time when you enter the loop, then check on each iteration to see if it's more than 5 seconds on each iteration.
Essence of this code is to depict Rock, Paper and Scissors game using Python language basically with for loop and if...else statements. I used PyScripter to run the code on Python 3.7.2 as engine. The def main() and if __name__ == '__main__' are PyScripter codes for running the machine
import random
def main():
pass
if __name__ == '__main__':
main()
tie_sum, comp_sum, human_sum = 0, 0, 0
name = input('Enter your firstname here: ')
for i in range(5):
tie_sum += tie_sum
comp_sum += comp_sum
human_sum += human_sum
comp_guess = random.randint(1, 3)
print(f'The computer guess option is {comp_guess}')
human_guess = int(input('Enter 1 as (rock), 2 as (paper) or 3 as (scissors):'))
if comp_guess == 1 and human_guess == 3:
comp_sum += 1
elif comp_guess == 1 and human_guess is 2:
human_sum += 1
elif comp_guess == 2 and human_guess == 3:
human_sum += 1
elif comp_guess == 3 and human_guess == 1:
human_sum += 1
elif comp_guess == 3 and human_guess == 2:
comp_sum += 1
elif comp_guess == 2 and human_guess == 1:
comp_sum += 1
else:
tie_sum += 1
print(f'The number of tie in this game is {tie_sum}')
if comp_sum > human_sum:
print('The winner of this game is the Computer.')
print(f'The comp_sum is {comp_sum}')
elif comp_sum < human_sum:
print(f'The winner of this game is {name}.')
print(f'The human sum is {human_sum}')
else:
print('This game ends in tie.')
print(f'The tie sum is {tie_sum}')
The reason for that is the first three lines in the for loop. You are increasing the sum of computer, human and tie while checking the condition and when you the loop iterates again, it sums up again. Here's the modified code:
import random
def main():
pass
if __name__ == '__main__':
main()
tie_sum, comp_sum, human_sum = 0, 0, 0
name = input('Enter your firstname here: ')
for i in range(5):
comp_guess = random.randint(1, 3)
human_guess = int(input('Enter 1 as (rock), 2 as (paper) or 3 as (scissors):'))
print(f'The computer guess option is {comp_guess}')
if comp_guess == 1 and human_guess == 3:
comp_sum += 1
elif comp_guess == 1 and human_guess == 2:
human_sum += 1
elif comp_guess == 2 and human_guess == 3:
human_sum += 1
elif comp_guess == 3 and human_guess == 1:
human_sum += 1
elif comp_guess == 3 and human_guess == 2:
comp_sum += 1
elif comp_guess == 2 and human_guess == 1:
comp_sum += 1
else:
tie_sum += 1
print(f'The number of tie in this game is {tie_sum}')
if comp_sum > human_sum:
print('The winner of this game is the Computer.')
print(f'The comp_sum is {comp_sum}')
elif comp_sum < human_sum:
print(f'The winner of this game is {name}.')
print(f'The human sum is {human_sum}')
else:
print('This game ends in tie.')
print(f'The tie sum is {tie_sum}')
Also, there was another modification, the computer guess is supposed to be printed after human's guess. I fixed that too. Hope that helps.
I'm trying to make a script that receives a number of desired random numbers as input, and then generates and prints them.
However, my script adds the numbers instead of joining the strings. I would like for the strings to join so it would generate the pins like:
Enter the amount of lunch pins to generate:
10
26141
128111
937502
2436
56516
83623
246317
My code:
import random
PTG = int(input("Enter the amount of pins to generate: \n"))
PG = 0
PS = ""
while PTG > PG:
RN1 = random.randint(0, 9)
RN2 = random.randint(0, 9)
RN3 = random.randint(0, 9)
RN4 = random.randint(0, 9)
RN5 = random.randint(0, 10)
RN6 = random.randint(0, 10)
if RN1 == 0:
PS += "0"
elif RN1 == 1:
PS += "1"
elif RN1 == 2:
PS += "2"
elif RN1 == 3:
PS += "3"
elif RN1 == 4:
PS += "4"
elif RN1 == 5:
PS += "5"
elif RN1 == 6:
PS += "6"
elif RN1 == 7:
PS += "7"
elif RN1 == 8:
PS += "8"
elif RN1 == 9:
PS += "9"
elif RN2 == 0:
PS += "0"
elif RN2 == 1:
PS += "1"
elif RN2 == 2:
PS += "2"
elif RN2 == 3:
PS += "3"
elif RN2 == 4:
PS += "4"
elif RN2 == 5:
PS += "5"
elif RN2 == 6:
PS += "6"
elif RN2 == 7:
PS += "7"
elif RN2 == 8:
PS += "8"
elif RN2 == 9:
PS += "9"
if RN3 == 0:
PS += "0"
elif RN3 == 1:
PS += "1"
elif RN3 == 2:
PS += "2"
elif RN3 == 3:
PS += "3"
elif RN3 == 4:
PS += "4"
elif RN3 == 5:
PS += "5"
elif RN3 == 6:
PS += "6"
elif RN3 == 7:
PS += "7"
elif RN3 == 8:
PS += "8"
elif RN3 == 9:
PS += "9"
elif RN4 == 0:
PS += "0"
elif RN4 == 1:
PS += "1"
elif RN4 == 2:
PS += "2"
elif RN4 == 3:
PS += "3"
elif RN4 == 4:
PS += "4"
elif RN4 == 5:
PS += "5"
elif RN4 == 6:
PS += "6"
elif RN4 == 7:
PS += "7"
elif RN4 == 8:
PS += "8"
elif RN4 == 9:
PS += "9"
elif RN5 == 0:
PS += "0"
elif RN5 == 1:
PS += "1"
elif RN5 == 2:
PS += "2"
elif RN5 == 3:
PS += "3"
elif RN5 == 4:
PS += "4"
elif RN5 == 5:
PS += "5"
elif RN5 == 6:
PS += "6"
elif RN5 == 7:
PS += "7"
elif RN5 == 8:
PS += "8"
elif RN5 == 9:
PS += "9"
elif RN5 == 10:
PS += ""
elif RN6 == 0:
PS += "0"
elif RN6 == 1:
PS += "1"
elif RN6 == 2:
PS += "2"
elif RN6 == 3:
PS += "3"
elif RN6 == 4:
PS += "4"
elif RN6 == 5:
PS += "5"
elif RN6 == 6:
PS += "6"
elif RN6 == 7:
PS += "7"
elif RN6 == 8:
PS += "8"
elif RN6 == 9:
PS += "9"
print(PS)
PG += 1
PS = ""
Python version: 3.7.4
import random
# PTG = int(input("Enter the amount of pins to generate: \n"))
PTG = 10
PG = 0
PS = ""
while PTG > PG:
RN1 = random.randint(0, 9)
RN2 = random.randint(0, 9)
RN3 = random.randint(0, 9)
RN4 = random.randint(0, 9)
RN5 = random.randint(0, 10)
RN6 = random.randint(0, 10)
PS = str(RN1) + str(RN2) + str(RN3) + str(RN4) + str(RN5) + str(RN6)
print(int(PS))
PG += 1
When I understand your code right, you want to generate n pins with 6 digits. You can do that a lot easier than you want to:
number_of_pins = int(input("Enter the amount of pins to generate: \n"))
pins = []
for i in range(number_of_pins):
pins.append(str(random.randint(100_000, 999_999)))
print(" ".join(pins))
Explaination:
pins = [] makes a new empty list to store the pins
for i in range(n): executes the following indented block n times.
pins.append(random.randint(100_000, 999_999)) generates a random number and adds it to the list. 100000 is the first number with 6 digits and 999999 is the last. (The _ is just for readability). str() converts it to a string.
print(" ".join(pins)) joins all the pins and puts a space between.
Let's go through your code step by step:
First, notice that random.randint returns an int. Therefore you need to convert it to a String.
You can use the str() function in order to convert it to a string, for example:
str(random.randint(0, 9))+"9"
will return a string like 59 (for example).
Therefore, when initializing each random number, you need to do it the following way, for example:
RN1 = str(random.randint(0, 9))
Then, instead of checking the value of each random variable, you can just add them up:
PS = RN1 + RN2 + RN3 + RN4 + RN5 + RN6
Furthermore, instead of using six different variables to handle the random values, you can use a for loop for the first four which are from 0 to 9:
for x in range(4):
RN = str(random.randint(0, 9))
PS += RN
And then add the remaining two that are between 0 and 10:
PS += str(random.randint(0, 10))
PS += str(random.randint(0, 10))
I'm just wondering how I can make it so elif player_position == 1 will work. I want to check the value of the argument (pos) in function player_position() and execute code depending on its value. I've only been learning Python for about 1 month.
def player_position(pos):
position = pos
if position == goliath.spawn:
print('The Goliath Has Attacked!')
if goliath.accuracy == 1:
print('You Have Been Killed!')
else:
print('You Killed The Goliath!')
else:
print('Nothing Happens...')
def starting_room():
while True:
position_update = input('Enter A Direction: ')
if position_update == 'Forwards':
player_position(1)
elif position_update == 'Backwards':
player_position(3)
elif position_update == 'Left':
player_position(4)
elif position_update == 'Right':
player_position(2)
elif player_position == 1:
if position_update == 'Forwards':
print('Room 2')
elif position_update == 'Backwards':
player_position(0)
elif position_update == 'Left':
print('There Are Monsters In the Dark')
elif position_update == 'Right':
print('There Are Monsters In The Dark')
starting_room()
You're making a call to player_position, a function which does not return anything. Instead, assuming you want to keep track of the player's current position within your starting_room function, you'll want to keep track of the pos there.
Something like this: (note - you'll need to add more code to break out of the while loop - this code should allow you to keep track of the pos though)
def player_position(pos):
position = pos
if position == goliath.spawn:
print('The Goliath Has Attacked!')
if goliath.accuracy == 1:
print('You Have Been Killed!')
else:
print('You Killed The Goliath!')
else:
print('Nothing Happens...')
def starting_room():
pos = 0 #initialize the pos to 0
while True:
position_update = input('Enter A Direction: ')
if pos == 1: #check to see if current pos is 1
if position_update == 'Forwards':
print('Room 2')
#you may want to add "break" here to stop this while loop
elif position_update == 'Backwards':
pos = 0
elif position_update == 'Left':
print('There Are Monsters In the Dark')
elif position_update == 'Right':
print('There Are Monsters In The Dark')
elif position_update == 'Forwards':
pos = 1
elif position_update == 'Backwards':
pos = 3
elif position_update == 'Left':
pos = 4
elif position_update == 'Right':
pos = 2
player_position(pos) #call the player_position function with the current pos
starting_room()
Okay I'm not sure how to develop another board with hidden spaces for the computers ships per-se, and have it test for hits. Again I'm not even sure how I'm going to test for hits on the board I have now. Make note: The player turn function will be migrated to the computer board since you wouldn't be attacking your own ships. Here is the code. It may not be the best formatting (as in with Methods and objects and such) but I can polish it up a little later. Also would there be another way to make placing the ships all in one function? Or with the way I have it, will it have to stay that way?
class battleship(object):
def __init__(self):
self.board = [["O"] * 10, ["O"] * 10, ["O"] * 10, ["O"] * 10, ["O"] * 10, ["O"] * 10, ["O"] * 10, ["O"] * 10, ["O"] * 10, ["O"] * 10, ]
self.printboard()
self.placeAircraftCarrier()
self.placeBattleShip()
self.placeSubmarine()
self.placeDestroyer()
self.placePatrolBoat()
for i in range(100):
self.playerTurn()
def printboard(self):
print "Game Board\n"
print "1","2","3","4","5","6","7","8","9","10"
for row in self.board:
print "|".join(row)
def placeBattleShip(self):
while True:
self.vOrHPlacement = input("Would you like to place the Battleship (1) Vertically or (2)Horizontally?:")
if self.vOrHPlacement == 1 or self.vOrHPlacement == 2:
break
else:
print "You must press 1 or 2."
while True:
self.battleshipRow = input("With the head as the starting place what row would you like to place the Battleship (Takes 4 Spaces)?:")
self.battleshipCol = input("What column would you like to start the BattleShip at?:")
if self.vOrHPlacement == 1:
if self.battleshipRow > 7 or self.battleshipRow <= 0:
print "\nIf placing vertically you can only choose 1-7 for the row."
elif self.battleshipCol <= 0 or self.battleshipCol > 10:
print "You must choose 1 - 10 for a column."
elif self.board[self.battleshipRow - 1][self.battleshipCol - 1] == "X":
print "There is already a ship there."
else:
self.battleshipRow -= 2
self.battleshipCol -= 1
for i in range(4):
self.board[self.battleshipRow + 1][self.battleshipCol] = "X"
self.battleshipRow += 1
break
elif self.vOrHPlacement == 2:
if self.battleshipCol > 7 or self.battleshipCol <= 0:
print "\nIf placing horizontally you can only choose 1-7 for a column."
elif self.battleshipRow <= 0 or self.battleshipRow > 10:
print "\n You must choose 1 - 10 as a row choice."
elif self.board[self.battleshipRow - 1][self.battleshipCol - 1] == "X":
print "There is already a ship there."
else:
self.battleshipRow -= 1
self.battleshipCol -= 2
for i in range(4):
self.board[self.battleshipRow][self.battleshipCol + 1] = "X"
self.battleshipCol += 1
break
self.printboard()
def placeAircraftCarrier(self):
while True:
self.vOrHPlacement = input("Would you like to place the Aircraft Carrier (1) Vertically or (2)Horizontally?:")
if self.vOrHPlacement == 1 or self.vOrHPlacement == 2:
break
else:
print "You must press 1 or 2."
while True:
self.battleshipRow = input("With the head as the starting place what row would you like to place the Aircraft Carrier (Takes 5 Spaces)?:")
self.battleshipCol = input("What column would you like to start the Aircraft Carrier at?:")
if self.vOrHPlacement == 1:
if self.battleshipRow > 6 or self.battleshipRow <= 0:
print "\nIf placing vertically you can only choose 1-6 for the row."
elif self.battleshipCol <= 0 or self.battleshipCol > 10:
print "You must choose 1 - 10 for a column."
elif self.board[self.battleshipRow - 1][self.battleshipCol - 1] == "X":
print "There is already a ship there."
else:
self.battleshipRow -= 2
self.battleshipCol -= 1
for i in range(5):
self.board[self.battleshipRow + 1][self.battleshipCol] = "X"
self.battleshipRow += 1
break
elif self.vOrHPlacement == 2:
if self.battleshipCol > 6 or self.battleshipCol <= 0:
print "\nIf placing horizontally you can only choose 1-6 for a column."
elif self.battleshipRow <= 0 or self.battleshipRow > 10:
print "\n You must choose 1 - 10 as a row choice."
elif self.board[self.battleshipRow - 1][self.battleshipCol - 1] == "X":
print "There is already a ship there."
else:
self.battleshipRow -= 1
self.battleshipCol -= 2
for i in range(5):
self.board[self.battleshipRow][self.battleshipCol + 1] = "X"
self.battleshipCol += 1
break
self.printboard()
def placeSubmarine(self):
while True:
self.vOrHPlacement = input("Would you like to place the Submarine (1) Vertically or (2)Horizontally?:")
if self.vOrHPlacement == 1 or self.vOrHPlacement == 2:
break
else:
print "You must press 1 or 2."
while True:
self.battleshipRow = input("With the head as the starting place what row would you like to place the Submarine (Takes 3 Spaces)?:")
self.battleshipCol = input("What column would you like to start the Submarine at?:")
if self.vOrHPlacement == 1:
if self.battleshipRow > 8 or self.battleshipRow <= 0:
print "\nIf placing vertically you can only choose 1-8 for the row."
elif self.battleshipCol <= 0 or self.battleshipCol > 10:
print "You must choose 1 - 10 for a column."
elif self.board[self.battleshipRow - 1][self.battleshipCol - 1] == "X":
print "There is already a ship there."
else:
self.battleshipRow -= 2
self.battleshipCol -= 1
for i in range(3):
self.board[self.battleshipRow + 1][self.battleshipCol] = "X"
self.battleshipRow += 1
break
elif self.vOrHPlacement == 2:
if self.battleshipCol > 8 or self.battleshipCol <= 0:
print "\nIf placing horizontally you can only choose 1-8 for a column."
elif self.battleshipRow <= 0 or self.battleshipRow > 10:
print "\n You must choose 1 - 10 as a row choice."
elif self.board[self.battleshipRow - 1][self.battleshipCol - 1] == "X":
print "There is already a ship there."
else:
self.battleshipRow -= 1
self.battleshipCol -= 2
for i in range(3):
self.board[self.battleshipRow][self.battleshipCol + 1] = "X"
self.battleshipCol += 1
break
self.printboard()
def placeDestroyer(self):
while True:
self.vOrHPlacement = input("Would you like to place the Destroyer (1) Vertically or (2)Horizontally?:")
if self.vOrHPlacement == 1 or self.vOrHPlacement == 2:
break
else:
print "You must press 1 or 2."
while True:
self.battleshipRow = input("With the head as the starting place what row would you like to place the Destroyer (Takes 3 Spaces)?:")
self.battleshipCol = input("What column would you like to start the Destroyer at?:")
if self.vOrHPlacement == 1:
if self.battleshipRow > 8 or self.battleshipRow <= 0:
print "\nIf placing vertically you can only choose 1-8 for the row."
elif self.battleshipCol <= 0 or self.battleshipCol > 10:
print "You must choose 1 - 10 for a column."
elif self.board[self.battleshipRow - 1][self.battleshipCol - 1] == "X":
print "There is already a ship there."
else:
self.battleshipRow -= 2
self.battleshipCol -= 1
for i in range(3):
self.board[self.battleshipRow + 1][self.battleshipCol] = "X"
self.battleshipRow += 1
break
elif self.vOrHPlacement == 2:
if self.battleshipCol > 8 or self.battleshipCol <= 0:
print "\nIf placing horizontally you can only choose 1-8 for a column."
elif self.battleshipRow <= 0 or self.battleshipRow > 10:
print "\n You must choose 1 - 10 as a row choice."
elif self.board[self.battleshipRow - 1][self.battleshipCol - 1] == "X":
print "There is already a ship there."
else:
self.battleshipRow -= 1
self.battleshipCol -= 2
for i in range(3):
self.board[self.battleshipRow][self.battleshipCol + 1] = "X"
self.battleshipCol += 1
break
self.printboard()
def placePatrolBoat(self):
while True:
self.vOrHPlacement = input("Would you like to place the Patrol Boat (1) Vertically or (2)Horizontally?:")
if self.vOrHPlacement == 1 or self.vOrHPlacement == 2:
break
else:
print "You must press 1 or 2."
while True:
self.battleshipRow = input("With the head as the starting place what row would you like to place the Patrol Boat (Takes 2 Spaces)?:")
self.battleshipCol = input("What column would you like to start the Patrol Boat at?:")
if self.vOrHPlacement == 1:
if self.battleshipRow > 9 or self.battleshipRow <= 0:
print "\nIf placing vertically you can only choose 1-9 for the row."
elif self.battleshipCol <= 0 or self.battleshipCol > 10:
print "You must choose 1 - 10 for a column."
elif self.board[self.battleshipRow - 1][self.battleshipCol - 1] == "X":
print "There is already a ship there."
else:
self.battleshipRow -= 2
self.battleshipCol -= 1
for i in range(2):
self.board[self.battleshipRow + 1][self.battleshipCol] = "X"
self.battleshipRow += 1
break
elif self.vOrHPlacement == 2:
if self.battleshipCol > 9 or self.battleshipCol <= 0:
print "\nIf placing horizontally you can only choose 1-9 for a column."
elif self.battleshipRow <= 0 or self.battleshipRow > 10:
print "\n You must choose 1 - 10 as a row choice."
elif self.board[self.battleshipRow - 1][self.battleshipCol - 1] == "X":
print "There is already a ship there."
else:
self.battleshipRow -= 1
self.battleshipCol -= 2
for i in range(2):
self.board[self.battleshipRow][self.battleshipCol + 1] = "X"
self.battleshipCol += 1
break
self.printboard()
def playerTurn(self):
while True:
self.row = input("What row coordinate would you like to hit?:")
self.column = input("What column coordinate would you like to hit?")
if self.row > 10 or self.row < 0:
print "You must pick a row coordinate between 1 and 10."
elif self.column > 10 or self.column < 0:
print "You must pick a column coordinate between 1 and 10."
elif self.board[self.row - 1][self.column - 1] == "*":
print "You have already hit there."
else:
self.board[self.row - 1][self.column - 1] = "*"
break
self.printboard()
b = battleship()
You need a lot of code organisation. I would suggest keeping Classes free from any sort of looping or inputs! Input stuff from the user & then add that to the class instance, not the other way round. Organize your code & add documentation to it so that others can help you.
You can do some stuff like this
class BattleShip:
""" Ship object container"""
def __init__(self, position_x, position_y, size):
""" Necessary variables for the ship go here """
self.position_x = position_x
self.position_y = position_y
self.size = size
def contains(self, position_x, position_y):
""" Returns true if supplied point lies inside this ship """
# code
def destroy(self, position_x, position_y):
""" Destroys the ship's point supplied if it contains it """
assert self.contains(position_x, position_y)
# Now update the gameboard
# code
def isCompletelyDestroyed(self):
""" Returns True if ship is completely destoryed else False """
# code
class GameBoard:
""" The container for the ships """
def __init__(self, size):
"""Initialize clean GameBoard depending on size, etc """
self.occupied = "+" # representation for ships
self.destroyed = 'x' # representation for destroyed area
self.clear = '-' # representation for clear water
def printBoard(self):
""" Print the current gameboard state """
def update(self, ship):
""" Updates the gameboard according to updated ship """
# Now do the mainloop
while game_not_over:
# run game