habe mich jetzt mal mit diesem einfachen Spielchen beschaeftigt und wollte ein paar Sachen drin haben, was jetzt endlich auch geklappt hat.
Erstmal der code ....
Code: Alles auswählen
### modules ###
import random
import time
### variables ###
stars = "*******************************************************"
figures = ("p", "r", "s")
game = True
### intro ###
print()
print(); time.sleep(0.5)
print(stars); time.sleep(0.5)
print(stars); time.sleep(0.5)
print("***** P A P E R **** R O C K **** S C I S S O R S *****"); time.sleep(0.5)
print(stars); time.sleep(0.5)
print(stars); time.sleep(0.5)
print(); time.sleep(0.5)
### the main game ###
### intro ###
while game:
print("choose if u want to fight with paper, rock or scissors "); time.sleep(1)
print("-type 'p' for paper, 'r' for rock or 's' for scissors- "); time.sleep(1)
players_choice_one = input()
print()
for l in players_choice_one:
players_figure = []
ais_figure = []
if l != "r" and l != "p" and l != "s":
print(stars); time.sleep(0.5)
print(" Seems u made a mistake, huh?! "); time.sleep(1)
print(stars); time.sleep(0.5)
print(); time.sleep(0.5)
print(" anyway ... wanna to have a second try? "); time.sleep(1)
break
else:
for l in players_choice_one:
if l == "r":
players_figure.append("rock")
elif l == "p":
players_figure.append("paper")
else:
players_figure.append("scissors")
ais_choice_one = random.choice(figures)
for s in ais_choice_one:
if s == "r":
ais_figure.append("rock")
elif s == "p":
ais_figure.append("paper")
else:
ais_figure.append("scissors")
### comparison ###
for i in players_figure:
for n in ais_figure:
if i == n :
print(stars)
print(" It's a tie, PC has also chosen " + n); time.sleep(0.5)
print(stars)
print(); time.sleep(0.5)
break
elif i == "rock" and n != "paper":
print(stars)
print(" U won against PC's " + n + " = )"); time.sleep(0.5)
print(stars)
print(); time.sleep(0.5)
break
elif i == "paper" and n != "scissors":
print(stars)
print(" U won against PC's " + n + " =) "); time.sleep(0.5)
print(stars)
print(); time.sleep(0.5)
break
elif i == "scissors" and n != "rock":
print(stars)
print(" U won against PC's " + n + " =) "); time.sleep(0.5)
print(stars)
print(); time.sleep(0.5)
break
else:
print(stars)
print(" Nah ... too sad ... better luck next time :) ")
print(" PC has chosen " + n); time.sleep(0.5)
print(stars)
print(); time.sleep(0.5)
### reapeater ###
decision = ""
while decision not in ("y", "n"):
print(" type in 'y' if u want continue playing "); time.sleep(1)
print(" 'n' if u want to leave "); time.sleep(1)
decision = input()
print()
if (decision != "y"):
print(stars)
print(" *** BYE BYE *** BYE BYE *** "); time.sleep(1)
print(stars)
print()
print()
game = False
Meine Fragen waeren nun ...
1. an welchen Stellen koennte man die Zeilenzahl deutlich reduzieren (also, abgesehen von den "optischen" lines natuerlich), sprich welche deutlich effektiveren Ansaetze gaebe es?
2. warum sind Ausgabezeilen verrutscht (zumindest in der cmd), wenn man eine Verkettung einfuegt?
3. wo muss ich nachsehen, um Infos zur "Textbearbeitung" inPython zu bekommen?
mir faellt bestimmt noch was ein
Vielen DANK Euch!! lG