und danke erst einmal an alle die sich die Zeit für mein Problem nehmen.
Ich habe ein simples Kartenspiel erstellt, aber bin noch nicht so vertiert was Python angeht und weiß nicht,
warum mein Programm nach einer gewissen Zeit abbricht. Da ich nicht weiß wie man die Dateien anhängen kann und es zu viele Bilder wären, habe ich die beiden Dateien mit in diese Nachricht gepackt. Ich will im Prinzip erreichen, dass alle Karten in meinem Deck ausgespielt werden und dann ein Gesammtsieger ermittelt wird. Nach ein paar ausgespielten Karten bricht das Programm aber ab, wie könnte ich das am Besten mit Schleifen lösen bzw. was sind meine Fehler? (Die Fehlermeldung ist im Bild zu sehen: https://ibb.co/vq4bVpJ , ist ein Link für ImgBB)
Danke
Cards.py:
# cards
import random
import time
# definition of the deck
deck = [["Warrior",12,10,False],["Guard",7,6,False],["Wizard",15,5,False], \
["Witch",13,9,False], ["Thief",8,4,False],["Dragon",15,14,False], \
["Dwarf",10,11,False],["Mercenary",11,8,False], \
["Witcher",13,13,False],["Assassin",12,10,False], \
["Troll",9,13, False],["Basilisk",11,14,False],["Ork",13,12],["Centaur",23,1], ["Jester",1,3],["Giant",15,15]]
# main menu
def show_menu():
print("Menu")
print("====")
print("0: Quit")
print("1: show card")
print("2: add your own card to deck")
print("3: Start a new game")
print("4: Show Card Deck")
choice = -1
while not(choice in [0,1,2,3,4,5]):
choice = int(input("Your choice "))
return choice
# show a card
def show_card(number):
# card_name
first_line = "║ " + deck[number][0]
while len(first_line)<25:
first_line = first_line+" "
first_line = first_line + "║"
second_line = "║ offense power: " + str(deck[number][1])
while len(second_line)<25:
second_line = second_line+" "
second_line = second_line + "║"
third_line = "║ defense power: " + str(deck[number][2])
while len(third_line)<25:
third_line = third_line+" "
third_line = third_line + "║"
#
print("╔════════════════════════╗")
print(first_line)
print("╠════════════════════════╣")
print("║ ║")
print(second_line)
print("║ ║")
print(third_line)
print("║ ║")
print("╚════════════════════════╝")
#show all cards
def show_deck():
for i in range(0,len(deck)-1):
show_card(i)
# add a card to deck
def add_card():
print(" ")
cardname=input("Choose the name of your card")
defense=input("Choose the defense power of your char")
offense=input("Choose the offense power of your char")
new_card=[name, defense, offense]
deck.append(new_card)
# reset for new game: set all cards as non-played,
def deck_reset():
for card in deck:
card[3] = False
return len(deck)
# play a card
def play_card(rest):
number = random.randint(0,len(deck)-1)
while deck[number][3]==True:
number = random.randint(0,len(deck)-1)
deck[number][3] = True
show_card(number)
return deck[number], rest-1
#def play_random(rest):
#random_point = random.choice(card_points)
#random_sign = random.choice(card_signs)
#random_card = random_point,random_sign
#print(random_card, show_card)
#Abfrage der Karten im Deck
e = len(deck)
#start a new game
def starta_game():
while e >=0:
for i in range(1):
random1_card = random.choice(deck)
print("You are playing the card: ", random1_card)
#time.sleep(2)
for i in range(1):
random2_card = random.choice(deck)
print("The computer is playing the card: ", random2_card)
#time.sleep(2)
computer = random2_card
player = random1_card
winnerscore = 0
winnerscore = random2_card[1]-random1_card[2]
print("What an exciting battle!...", "difference: ", winnerscore, "...The fight is over.")
#time.sleep(1)
#points
ComputerPoints = 0
PlayerPoints = 0
if winnerscore >=0:
print("The computer beated you")
#time.sleep(2)
deck.remove(random2_card)
deck.remove(random1_card)
print("The cards were removed from the deck and the next round will start")
#time.sleep(2)
ComputerPoints = ComputerPoints+1
print("The Computer has ", ComputerPoints, "point/s.")
#time.sleep(1)
print("You have ", PlayerPoints, "point/s.")
#time.sleep(1)
for i in range(1):
random2_card = random.choice(deck)
print("The computer is playing the card, because he won the last round: ", random2_card)
#time.sleep(2)
for i in range(1):
random1_card = random.choice(deck)
print("You are playing the card: ", random1_card)
#time.sleep(2)
computer = random2_card
player = random1_card
winnerscore = 0
winnerscore = random1_card[1]-random2_card[2]
print("What an exciting battle!...", "difference: ", winnerscore, "...The fight is over.")
if winnerscore >=0:
print("You have won the round.")
#time.sleep(2)
deck.remove(random2_card)
deck.remove(random1_card)
print("The cards were removed from the deck and the next round will start")
#time.sleep(2)
ComputerPoints = ComputerPoints+1
print("The Computer has ", ComputerPoints, "point/s.")
#time.sleep(1)
print("You have ", PlayerPoints, "point/s.")
#time.sleep(1)
elif winnerscore >0:
print("The Computer beated you.")
#time.sleep(2)
deck.remove(random2_card)
deck.remove(random1_card)
print("The cards were removed from the deck and the next round will start")
#time.sleep(2)
ComputerPoints = ComputerPoints+1
print("The Computer has ", ComputerPoints, "point/s.")
#time.sleep(1)
print("You have ", PlayerPoints, "point/s.")
#time.sleep(1)
#___________________________________________________________________________________________________________
elif winnerscore <=0:
print("You won

#time.sleep(2)
deck.remove(random2_card)
deck.remove(random1_card)
print("The cards were removed from the deck and the next round will start.")
#time.sleep(2)
PlayerPoints2 = PlayerPoints+1
print("You have ", PlayerPoints, "point/s.")
#time.sleep(1)
print("The Computer has ", ComputerPoints, "point/s.")
#time.sleep(1)
for i in range(1):
random1_card = random.choice(deck)
print("You are playing a card, because you won the last round: ", random1_card)
#time.sleep(2)
for i in range(1):
random2_card = random.choice(deck)
print("The computer is playing the card: ", random2_card)
#time.sleep(2)
computer = random2_card
player = random1_card
winnerscore = 0
winnerscore = random2_card[1]-random1_card[2]
print("What an exciting battle!...", "difference: ", winnerscore, "...The fight is over.")
if winnerscore >=0:
print("The Computer beated you.")
print("The Computer beated you.")
#time.sleep(2)
deck.remove(random2_card)
deck.remove(random1_card)
print("The cards were removed from the deck and the next round will start")
#time.sleep(2)
ComputerPoints = ComputerPoints+1
print("The Computer has ", ComputerPoints, "point/s.")
#time.sleep(1)
print("You have ", PlayerPoints, "point/s.")
#time.sleep(1)
elif winnerscore <0:
print("You have won the round.")
print("The Computer beated you.")
#time.sleep(2)
deck.remove(random2_card)
deck.remove(random1_card)
print("The cards were removed from the deck and the next round will start")
#time.sleep(2)
ComputerPoints = ComputerPoints+1
print("The Computer has ", ComputerPoints, "point/s.")
#time.sleep(1)
print("You have ", PlayerPoints, "point/s.")
#time.sleep(1)
if PlayerPoints>ComputerPoints:
print("You have won :>")
elif ComputerPoints>PlayerPoints:
print("The Computer won :<, try it again :>")
main.py:
# battlecards
import cards
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# main
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
action = -1
while action !=0:
action = cards.show_menu()
if action == 1:
card_number = int(input("Which card? "))
cards.show_card(card_number)
elif action == 2:
#cards.add_card()
print("add a card")
cards.add_card()
elif action==3:
# start a new game
print("Start a new game")
print("Card Deck")
cards.starta_game()
elif action==4:
#show all cards
print("Show all Cards in deck")
cards.show_deck()