Hey i'm trying to place a ship onto my grid but my translation function is trying to iterate over None type, if someone would write a simple horizontal ship placement in translation function i'm sure i can finish the rest, thank you!
class start(object):
def __init__(self):
self.GameT = int(raw_input("One Player (1) or Two Player (2): "))
self.Size = int(raw_input("What are the demenions of this game? (n X n): "))
if self.Size < 2:
self.Size = 10
self.Air = int(raw_input("How many Aircraft Carriers? (Size 5): "))
self.Bat = int(raw_input("How many Battleships? (Size 4): "))
self.Sub = int(raw_input("How many Submarines? (Size 3): "))
self.Cru = int(raw_input("How many Cruisers? (Size 3): "))
self.Des = int(raw_input("How many Destroyers? (Size 2): "))
class board(object):
def __init__(self):
pass
def gen(self, size):
board = [[0] * size] * size
return board
class player(object):
def __init__(self, board, ships):
shipcount = 0
for key in ships:
shipcount += ships[key]
self.ShipPlacement = {}
pass
def determine_hit(x, y, player):
if player[x][y-1] == 0:
player[x][y-1] = "M"
return "MISS!"
elif player[x][y-1] == 1:
player[x][y-1] = "H"
return "HIT!"
else:
return "Invalid"
def draw(board):
for row in board:
for column in row:
print column,
print ""
def translate(sc, sr, ec, er, board, size):
#************************************Horizontal********
if sr == er:
if sc < ec:
if ec - sc == size:
count = -1
print board[sc + count][sr - 1]
print board[sc + count][sr - 1] + 1
print board[sc + count][sr - 1] == 0
while count < size - 1:
if board[sc + count][sr - 1] == 0:
board[sc + count][sr - 1] = 5
print board
print sc + count, "KK"
print count
count += 1
if __name__ == "__main__":
settings = start()
player_board = board()
ships = {}
ships["Air"] = settings.Air
ships["Bat"] = settings.Bat
ships["Sub"] = settings.Sub
ships["Cru"] = settings.Cru
ships["Des"] = settings.Des
if settings.GameT == 1:
ships
p1board = player_board.gen(settings.Size)
print p1board[1][1]
human = player(p1board, ships)
cpuboard = player_board.gen(settings.Size)
cpu = player(cpuboard, ships)
#********************************Graphic representation***
draw(p1board)
#*************************************Ship Placement (attempt)*******
if settings.Air >= 1:
count = 1
while count <= settings.Air:
start_c = int(raw_input("Starting column for your Aircraft Carrier (Size: 5): "))
start_r = int(raw_input("Starting row for your Aircraft Carrier (Size: 5): "))
end_c = int(raw_input("Ending column for your Aircraft Carrier (Size: 5): "))
end_r = int(raw_input("Ending row for your Aircraft Carrier (Size: 5): "))
print p1board[1][1]
print end_c - start_c
print translate(start_c, start_r, end_c, end_r, p1board, 5)
print "here: "
draw(p1board)
count += 1
#************************************2 players***************
#if settings.GameT == 2:
# player1 = player_board.gen(settings.Size)
# player2 = player_board.gen(settings.Size)
# print player1
#print player2
prompt_exit = raw_input("Hit enter to exit")