Schiffe versenken Code
Verfasst: Samstag 18. Juni 2022, 23:52
Hallo Leute ich bin neu im Python Forum und bin Python Anfänger, ich habe einen Schiffe versenken Code Geschrieben jedoch funktioniert dieser jetzt nicht mehr, jedoch weiß ich nicht genau wo das Problem ist, könnte jemand bitte drüber schauen danke 
board = []
boardw = []
def player_one():
name = str(input("SP1 vergib dir einen Namen: "))
return name
z = player_one()
def player_two():
nametwo = str(input("SP2 vergib dir einen Namen: "))
return nametwo
zz = player_two()
waage = int(input((z)+ " geben Sie größe Waagerecht ein: "))
while waage > 10:
print("Das Feld darf nicht größer als 10 sein.")
waage = int(input((z)+ " geben Sie größe Waagerecht ein: "))
senk = int(input((z)+ " geben Sie größe Senkrecht ein: "))
while senk > 10:
print("Das Feld darf nicht größer als 10 sein.")
senk = int(input((z) +" geben Sie größe Senkrecht ein: "))
for x in range(senk):
board.append([" "]*waage)
def print_board(board):
for row in board:
print("|".join(row))
for x in range(senk):
boardw.append([" "]*waage)
def print_boardw(boardw):
for row in boardw:
print("|".join(row))
def playertwo_row(boardw):
ship_roww = int(input("Platzieren Sie Ihr Schiff1: "))
return (ship_roww)
def playertwo_col(boardw):
ship_colw = int(input("Platzieren Sie Ihr Schiff1: "))
return (ship_colw)
def playertwo_rowwe(boardw):
ship_rowwe = int(input("Platzieren Sie Ihr Schiff2: "))
return (ship_rowwe)
def playertwo_colwe(boardw):
ship_colwe = int(input("Platzieren Sie Ihr Schiff2: "))
return (ship_colwe)
def playertwo_rowwee(boardw):
ship_rowwee = int(input("Platzieren Sie Ihr Schiff3: "))
return (ship_rowwee)
def playertwo_colwee(boardw):
ship_colwee = int(input("Platzieren Sie Ihr Schiff3: "))
return (ship_colwee)
def anzahl_Schiffe():
ship = int(input("Mit wie vielen Schiffen wollen Sie spielen (Maximal 3)"))
while ship > 3:
print("Bitte beachten Sie, dass Sie nicht mehr als 3 Schiffe aussuchen dürfen.")
ship = int(input("Mit wie vielen Schiffen wollen Sie spielen (Maximal 3)"))
if ship == 1:
playertwo_row(boardw)
playertwo_col(boardw)
elif ship == 2:
playertwo_row(boardw)
playertwo_col(boardw)
playertwo_rowwe(boardw)
playertwo_colwe(boardw)
elif ship == 3:
playertwo_row(boardw)
playertwo_col(boardw)
playertwo_rowwe(boardw)
playertwo_colwe(boardw)
playertwo_rowwee(boardw)
playertwo_colwee(boardw)
anzahl_Schiffe()
def playerturnone(board,ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee):
print_board(board)
for turn in range(8):
print("Turn", turn + 1)
guess_roww = int(input((zz) + " Guess Row:"))
guess_colw = int(input((zz) + " Guess Col:"))
if guess_roww == ship_roww and guess_colw == ship_colw:
print("Congratulations! You sank my Battleship!")
print(playerturnone(board, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
elif guess_roww == ship_rowwe and guess_colw == ship_colwe:
print("Congratulations! You sank my Battleship!")
print(playerturnone(board, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
elif guess_roww == ship_rowwee and guess_colw == ship_colwee:
print("Congratulations! You sank my Battleship!")
print(playerturnone(board, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
else:
if (guess_roww < 0 or guess_roww > waage) or (guess_colw < 0 or guess_colw > senk):
print("Oops, that's not even in the ocean.")
elif (board[guess_roww][guess_colw] == "X"):
print("You guessed that one already.")
else:
print("You missed my battleship!")
board[guess_roww - 1][guess_colw - 1] = "X"
print(playerturnone(board, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
def playerturntwo(boardw, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee):
print_boardw(boardw)
for turn in range(8):
print("Turn", turn + 1)
guess_roww = int(input((zz)+" Guess Row:"))
guess_colw = int(input((zz)+" Guess Col:"))
if guess_roww == ship_roww and guess_colw == ship_colw:
print("Congratulations! You sank my Battleship!")
print(playerturntwo(boardw, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
elif guess_roww == ship_rowwe and guess_colw == ship_colwe:
print("Congratulations! You sank my Battleship!")
print(playerturntwo(boardw, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
elif guess_roww == ship_rowwee and guess_colw == ship_colwee:
print("Congratulations! You sank my Battleship!")
print(playerturntwo(boardw, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
else:
if (guess_roww < 0 or guess_roww > waage) or (guess_colw < 0 or guess_colw > senk):
print("Oops, that's not even in the ocean.")
elif (boardw[guess_roww][guess_colw] == "X"):
print("You guessed that one already.")
else:
print("You missed my battleship!")
boardw[guess_roww-1][guess_colw-1] = "X"
print(playerturntwo(boardw, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
print("Let's play Battleship!")
#kann nicht ausgeführt werden keine ahnung warum
Print(playerturnone(board, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))

board = []
boardw = []
def player_one():
name = str(input("SP1 vergib dir einen Namen: "))
return name
z = player_one()
def player_two():
nametwo = str(input("SP2 vergib dir einen Namen: "))
return nametwo
zz = player_two()
waage = int(input((z)+ " geben Sie größe Waagerecht ein: "))
while waage > 10:
print("Das Feld darf nicht größer als 10 sein.")
waage = int(input((z)+ " geben Sie größe Waagerecht ein: "))
senk = int(input((z)+ " geben Sie größe Senkrecht ein: "))
while senk > 10:
print("Das Feld darf nicht größer als 10 sein.")
senk = int(input((z) +" geben Sie größe Senkrecht ein: "))
for x in range(senk):
board.append([" "]*waage)
def print_board(board):
for row in board:
print("|".join(row))
for x in range(senk):
boardw.append([" "]*waage)
def print_boardw(boardw):
for row in boardw:
print("|".join(row))
def playertwo_row(boardw):
ship_roww = int(input("Platzieren Sie Ihr Schiff1: "))
return (ship_roww)
def playertwo_col(boardw):
ship_colw = int(input("Platzieren Sie Ihr Schiff1: "))
return (ship_colw)
def playertwo_rowwe(boardw):
ship_rowwe = int(input("Platzieren Sie Ihr Schiff2: "))
return (ship_rowwe)
def playertwo_colwe(boardw):
ship_colwe = int(input("Platzieren Sie Ihr Schiff2: "))
return (ship_colwe)
def playertwo_rowwee(boardw):
ship_rowwee = int(input("Platzieren Sie Ihr Schiff3: "))
return (ship_rowwee)
def playertwo_colwee(boardw):
ship_colwee = int(input("Platzieren Sie Ihr Schiff3: "))
return (ship_colwee)
def anzahl_Schiffe():
ship = int(input("Mit wie vielen Schiffen wollen Sie spielen (Maximal 3)"))
while ship > 3:
print("Bitte beachten Sie, dass Sie nicht mehr als 3 Schiffe aussuchen dürfen.")
ship = int(input("Mit wie vielen Schiffen wollen Sie spielen (Maximal 3)"))
if ship == 1:
playertwo_row(boardw)
playertwo_col(boardw)
elif ship == 2:
playertwo_row(boardw)
playertwo_col(boardw)
playertwo_rowwe(boardw)
playertwo_colwe(boardw)
elif ship == 3:
playertwo_row(boardw)
playertwo_col(boardw)
playertwo_rowwe(boardw)
playertwo_colwe(boardw)
playertwo_rowwee(boardw)
playertwo_colwee(boardw)
anzahl_Schiffe()
def playerturnone(board,ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee):
print_board(board)
for turn in range(8):
print("Turn", turn + 1)
guess_roww = int(input((zz) + " Guess Row:"))
guess_colw = int(input((zz) + " Guess Col:"))
if guess_roww == ship_roww and guess_colw == ship_colw:
print("Congratulations! You sank my Battleship!")
print(playerturnone(board, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
elif guess_roww == ship_rowwe and guess_colw == ship_colwe:
print("Congratulations! You sank my Battleship!")
print(playerturnone(board, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
elif guess_roww == ship_rowwee and guess_colw == ship_colwee:
print("Congratulations! You sank my Battleship!")
print(playerturnone(board, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
else:
if (guess_roww < 0 or guess_roww > waage) or (guess_colw < 0 or guess_colw > senk):
print("Oops, that's not even in the ocean.")
elif (board[guess_roww][guess_colw] == "X"):
print("You guessed that one already.")
else:
print("You missed my battleship!")
board[guess_roww - 1][guess_colw - 1] = "X"
print(playerturnone(board, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
def playerturntwo(boardw, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee):
print_boardw(boardw)
for turn in range(8):
print("Turn", turn + 1)
guess_roww = int(input((zz)+" Guess Row:"))
guess_colw = int(input((zz)+" Guess Col:"))
if guess_roww == ship_roww and guess_colw == ship_colw:
print("Congratulations! You sank my Battleship!")
print(playerturntwo(boardw, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
elif guess_roww == ship_rowwe and guess_colw == ship_colwe:
print("Congratulations! You sank my Battleship!")
print(playerturntwo(boardw, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
elif guess_roww == ship_rowwee and guess_colw == ship_colwee:
print("Congratulations! You sank my Battleship!")
print(playerturntwo(boardw, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
else:
if (guess_roww < 0 or guess_roww > waage) or (guess_colw < 0 or guess_colw > senk):
print("Oops, that's not even in the ocean.")
elif (boardw[guess_roww][guess_colw] == "X"):
print("You guessed that one already.")
else:
print("You missed my battleship!")
boardw[guess_roww-1][guess_colw-1] = "X"
print(playerturntwo(boardw, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))
print("Let's play Battleship!")
#kann nicht ausgeführt werden keine ahnung warum
Print(playerturnone(board, ship_roww, ship_colw, ship_rowwe, ship_colwe, ship_rowwee, ship_colwee))