这是我的程序。[内联代码:]
import pygame, sys
import random
class Player1:
def __init__(self, firstName, lastName, points):
self.firstName = firstName
self.lastName = lastName
self.points = points
def __repr__(self):
return "%s %s" % (self.firstName, self.lastName)
def __int__(self):
return self.points
def __add__(self, other):
try:
self.points += other
return Person(points)
except AttributeError:
print "error"
raw_input
class Player2:
def __init__(self, firstName2, lastName2, points2):
self.firstName2 = firstName2
self.lastName2 = lastName2
self.points2 = points2
def __repr__(self):
return "%s %s" % (self.firstName2, self.lastName2)
def __int__(self):
return self.points2
def __add__(self, other):
try:
self.points += other
return Person(points)
except AttributeError:
print "error"
raw_input
def rollDie(sides):
r = random.randint(1,sides)
return r
def takeTurn(player):
points = int(player)
if int(player) < 100:
keepRolling = 1
print
raw_input("%s <press enter to begin turn>" % (player))
while keepRolling == 1:
r = rollDie(6)
print "%s rolled a " % (player) + str(r)
print
if r == 1:
points = str(int(player))
print "%s your points are now " % (player) + `points` + " because you rolled a 1."
keepRolling = 0
print "Turn over"
print
else:
points += r
print "%s your points are now " % (player) + `points`
kR = input("Keep rolling?(0=no 1=yes): ")
if kR == 1:
print
keepRolling = 1
else:
keepRolling = 0
print "%s your points are now " % (player) + `points`
print "turn over"
print
else:
print
print "Congradulations %s you have won the Game of Thrones..... I mean pig. Yeah, pig." % (player)
print
raw_input("%s, press any key to exit the game.........") % (player)
sys.exit()
return points
def intro():
print "This is the game of pig."
print
print "Each player has to roll a six-sided die"
print "until they get a 1, reach 100, or want to stop."
print "If they roll a 1, they get nothing."
print "When prompted, press 1 to roll, 2 to skip."
def main():
player11 = raw_input("What is Player 1's first name? -> ")
player12 = raw_input("Last name? -> ")
player21 = raw_input("Player 2's first name? -> ")
player22 = raw_input("Last name? -> ")
desiredT = input("How many turns do you want? ")
player1 = Player1(player11, player12, 0) #I need the point from take turn to change these zeros
player2 = Player2(player21, player22, 0)
def correctInfo():
verify = raw_input("Is this info correct? Player 1 is %s: Player2 is %s? [y,n] -> " % (player1, player2))
if verify == "y":
print
elif verify == "n":
print
print
main()
else:
print "Not a valid input"
print
correctInfo()
def turns(t):
for i in range(t):
takeTurn(player1) #how do I get the point from here to change the class?
takeTurn(player2)
if int(player1) > int(player2):
print
print "%s has won with %s points." % (player1, int(player1))
print
else:
print
print "%s has won with %s points." % (player2, int(player2))
print
raw_input("press any key to exit.............")
correctInfo()
intro()
turns(desiredT)
main()
相关领域有评论。我只需要弄清楚如何获得
return points
在 takeTurn() 结束时改变
player1 = Player1(firstName, lastName, 0)
在 main() 中,零是需要改变的