好的,我正在努力制作一个程序,让我对外星人和人类有一定的健康和弹药。我需要它们进行十轮。我希望他们随机进行十轮比赛。我是python的新手,所以我有一些想通了,但我没有弄明白。我需要知道我到底做错了什么以及如何做到这一点。
class Alien(object):
"""Time to shoot the Player"""
def __init__(self,name,health,ammo):
self.name = name
name = input("What would you like to name your Alien?:")
self.health = 75
self.ammo = 50
def _str_(self):
return self.name
def blast(self,enemy):
import random
ammunition = random.randrange(5)
if ammunition >2
self.ammo(health)
print(self.name,"has shot the Player.")
print("He has",self.ammo,"ammo left.")
elif self.ammo == 0:
print(self.name,"is out of ammo.")
def health(self,health):
import random
shoot = random.randrange(10)
if shoot > 5
self.health(ammo)
if self.health >0:
print(self.name,"has been shot down. He has",self.health,"health left.")
elif self.health == 0
print("Im already dead. There's no way you can kill me again!!!")
class Player(object):
"""Time to shoot the Alien"""
def __init__(self,ammo,health,name):
self.name = name
name = input("What would you like to name your player?:")
self.ammo = 50
self.health = 75
def _str_(self):
return self.name
def blast(self,enemy):
import random
ammunition = random.randrange(5)
if ammuntion >2
self.ammo(health)
print (self.name,"has shot the alien.")
print ("He has",self.ammo,"ammo left.")
elif self.ammo == 0:
print(self.name,"is out of ammo.")
def health(self,health):
import random
shoot = random.randrange(10)
if shoot > 5
self.health(ammo)
if self.health >0:
print(self.name,"has been wounded. He has",self.health,"health left.")
elif self.health == 0:
print("I'm already dead. There's no way you can kill me again!!!")
这是我的两个课程。
答案 0 :(得分:2)
我想我知道你在找什么。我记得为我的大二学年写了一个类似的课程,希望这会有所帮助。
class Player(object):
""" A player in a shooter game. """
def __init__(self,ammo):
self.ammo = ammo
self.lose = False
def blast(self, enemy):
if self.lose:
print "You were unsuccessful and did not kill the alien!\nNow the Earth was destroyed thanks to you."
else:
print "The player blasts an enemy."
if self.ammo > 0:
self.ammo -= 1
print "Your ammunition count is reduced by 1."
print "The alien took 1 damage! You've done it!\n"
enemy.die()
else:
if enemy.health == 0:
print "They're already dead, yo."
else:
self.lose = True
print "The alien has more health than you have ammo."
print "You run out of ammo and die!"
class Alien(object):
""" An alien in a shooter game. """
def __init__(self, health):
self.health = health
def die(self):
if self.health > 1:
self.health -= 1
print "Is that all you've got??\n"
elif self.health == 1:
self.health -= 1
print "Oh no im gonna die"
else:
print "The alien is already dead. What you're doing is unneccessary."
# main
print "\tThe Death of an Alien\n"
#same health and ammo
print "\n-----You have 6 counts of ammo.-----"
print "-----The alien has 6 health.-----\n"
hero = Player(6)
invader = Alien(6)
for i in range(6):
hero.blast(invader)
#lower health than ammo
print "\n-----You have 6 counts of ammo.-----"
print "-----The alien has 5 health.-----\n"
hero = Player(6)
invader = Alien(5)
for i in range(6):
hero.blast(invader)
#lower ammo than health
print "\n-----You have 5 counts of ammo.-----"
print "-----The alien has 6 health.-----\n"
hero = Player(5)
invader = Alien(6)
for i in range(6):
hero.blast(invader)
raw_input("\n\nPress the enter key to exit.")