2015-01-13 55 views
-3
print('\n'*50) 
from time import sleep, time 
from random import * 
print('hello, im your freind') 
print('I\'ll help you through journey if you type h') 
cont = input('CONTINUE?') 
class cls(): 
def mage(): 
    w = 5 
    rng = 5 
    spd = 2 
    c = 1 
    hp = 50 
    rideable = 0 
    g = 10 
def warrior(): 
    w = 10 
    rng = 3 
    spd = 1 
    c = 2 
    hp = 100 
    rideable = 0 

def archer(): 
    w = 7.5 
    rng = 10 
    spd = 1.5 
    c = 3 
    hp = 75 
    rideable = 0 
    print('y') 
def healer(): 
    w = 2.5 
    rng = 5 
    healpow = 5 
    c = 4 
    hp = 50 
    spd = 3 
    rideable = 0 
def robotic_horse(): 
    rideable = 1 
    w = 1 
    bspd = 10 
    hp = 50 
    c = 5 
    spd = 10 
class ecls(): 
def elf(): 
    ehp = 10 
    eatck = 5 
    espd = 5 
    erng = 7 
    ec = 4 
    erideable = 0 
def mech(): 
    ehp = 200 
    eatck = 10 
    espd = 0.5 
    erng = 2 
    ec = 1 
    erideable = 1 
    ebspd = 0.5 
def goblin(): 
    ehp = 25 
    eatck = 2.5 
    espd = 5 
    erng = 1 
    ec = 2 
    erideble = 0 
def gang(): 
    ehp = 300 
    eatck = 5 
    espd = 2.5 
    erng = 3 
    ec = 3 
    erideble = 5 
if cont == 'no': 
sleep(0) 
else: 
def fight(): 
    enemies = open('saveFile.txt','r').readlines(1) 
    print('\n'*50) 
    xp = 0 
    heals = 10 
    #choose class 
    print('Choose your Class:') 
    print('mage(1)') 
    print('warrior(2)') 
    print('archer(3)') 
    print('healer(4)') 
    chc = input('') 
    if chc == '1': 
     w = 5 
     rng = 5 
     spd = 2 
     c = 1 
     hp = 50 
     rideable = 5 
     g = 10 
    if chc == '2': 
     w = 10 
     rng = 3 
     spd = 1 
     c = 2 
     hp = 100 
     rideable = 5 
    if chc == '3': 
     w = 7.5 
     rng = 10 
     spd = 1.5 
     c = 3 
     hp = 75 
     rideable = 5 
    if chc == '4': 
     w = 2.5 
     rng = 5 
     healpow = 5 
     c = 4 
     hp = 50 
     spd = 3 
     rideable = 5 
    if chc == '5': 
     rideable = 5 
     w = 3 
     bspd = 10 
     hp = 50 
     c = 5 
     spd = 10 
     bw = 5 
    else: 
     w = 7.5 
     rng = 10 
     spd = 1.5 
     c = 3 
     hp = 75 
     rideable = 0 
    ehp = 10 
    ew = 5 
    espd = 5 
    erng = 7 
    ec = 4 
    erideable = 0 
    print('\n'*50) 
    ups = 10 
    eheals = 0 
    while enemies > 0 and hp > 0: 
     #Head Down Display or for short HDD 
     print('THIS IS THE HDD:') 
     print('health', hp) 
     print('enemy health', ehp) 
     print('upgrades', ups) 
     print('heals', heals) 
     print('enemies', enemies) 
     attack = input('attack(1) defend(2) heal(3) upgrade(4)') 
     if attack == '1': 
      ehp = ehp - (w + randint(-1, 1)) 
     if attack == '2': 
      ew = ew - .05 
     if attack == '3': 
      if heals == 0: 
       print('all out!') 
      else: 
       heals = heals - 1 
       hp = hp + 35 
     if attack == 'h': 
      print('attack attack\'s, defend defend\'s, heal heal\'s, upgrade upgrade\'s') 
     if attack == '4': 
      if ups < 1: 
       print('all out') 
      else: 
       ups = ups - 1 
       w = w + 1 
     if attack == 'save': 
       saveFile = open('saveFile.txt','w') 
       saveFile.write(enemies) 
     else: 
      ehp = ehp - (w + randint(-1, 1)) 
     if rideable < 5: 
      print('THIS IS THE HDD:') 
      print('health', hp) 
      print('enemy health', ehp) 
      print('upgrades', ups) 
      print('heals', heals) 
      print('enemies', enemies) 
      attack = input('attack(1) defend(2) heal(3) upgrade(4)') 
      if attack == '1': 
       ehp = ehp - (w + randint(-1, 1)) 
      if attack == '2': 
       ew = ew - .05 
      if attack == '3': 
       if heals == 0: 
        print('all out!') 
       else: 
        heals = heals - 1 
        hp = hp + 35 
      if attack == 'h': 
       print('attack attack\'s, defend defend\'s, heal heal\'s, upgrade upgrade\'s') 
      if attack == '4': 
       if ups < 1: 
        print('all out') 
       else: 
        ups = ups - 1 
        w = w + 1 
      if attack == 'save': 
       saveFile = open('saveFile.txt','w') 
       saveFile.write(enemies) 
      else: 
       ehp = ehp - (w + randint(-1, 1)) 
     if rideable < 4: 
      print('THIS IS THE HDD:') 
      print('health', hp) 
      print('enemy health', ehp) 
      print('upgrades', ups) 
      print('heals', heals) 
      print('enemies', enemies) 
      attack = input('attack(1) defend(2) heal(3) upgrade(4)') 
      if attack == '1': 
       ehp = ehp - (w + randint(-1, 1)) 
      if attack == '2': 
       ew = ew - .05 
      if attack == '3': 
       if heals == 0: 
        print('all out!') 
       else: 
        heals = heals - 1 
        hp = hp + 35 
      if attack == 'h': 
       print('attack attack\'s, defend defend\'s, heal heal\'s, upgrade upgrade\'s') 
      if attack == '4': 
       if ups < 1: 
        print('all out') 
       else: 
        ups = ups - 1 
        w = w + 1 
      if attack == 'save': 
       saveFile = open('saveFile.txt','w') 
       saveFile.write(enemies) 
      else: 
       ehp = ehp - (w + randint(-1, 1)) 
     if rideable < 3: 
      print('THIS IS THE HDD:') 
      print('health', hp) 
      print('enemy health', ehp) 
      print('upgrades', ups) 
      print('heals', heals) 
      print('enemies', enemies) 
      attack = input('attack(1) defend(2) heal(3) upgrade(4)') 
      if attack == '1': 
       ehp = ehp - (w + randint(-1, 1)) 
      if attack == '2': 
       ew = ew - .05 
      if attack == '3': 
       if heals == 0: 
        print('all out!') 
       else: 
        heals = heals - 1 
        hp = hp + 35 
      if attack == 'h': 
       print('attack attack\'s, defend defend\'s, heal heal\'s, upgrade upgrade\'s') 
      if attack == '4': 
       if ups < 1: 
        print('all out') 
       else: 
        ups = ups - 1 
        w = w + 1 
      if attack == 'save': 
       saveFile = open('saveFile.txt','w') 
       saveFile.write(enemies) 
      else: 
       ehp = ehp - (w + randint(-1, 1)) 
     if rideable < 2: 
      print('THIS IS THE HDD:') 
      print('health', hp) 
      print('enemy health', ehp) 
      print('upgrades', ups) 
      print('heals', heals) 
      print('enemies', enemies) 
      attack = input('attack(1) defend(2) heal(3) upgrade(4)') 
      if attack == '1': 
       ehp = ehp - (w + randint(-1, 1)) 
      if attack == '2': 
       ew = ew - .05 
      if attack == '3': 
       if heals == 0: 
        print('all out!') 
       else: 
        heals = heals - 1 
        hp = hp + 35 
      if attack == 'h': 
       print('attack attack\'s, defend defend\'s, heal heal\'s, upgrade upgrade\'s') 
      if attack == '4': 
       if ups < 1: 
        print('all out') 
       else: 
        ups = ups - 1 
        w = w + 1 
      if attack == 'save': 
       saveFile = open('saveFile.txt','w') 
       saveFile.write(enemies) 
      else: 
       ehp = ehp - (w + randint(-1, 1)) 
     if rideable < 1: 
      print('THIS IS THE HDD:') 
      print('health', hp) 
      print('enemy health', ehp) 
      print('upgrades', ups) 
      print('heals', heals) 
      print('enemies', enemies) 
      attack = input('attack(1) defend(2) heal(3) upgrade(4)') 
      if attack == '1': 
       ehp = ehp - (w + randint(-1, 1)) 
      if attack == '2': 
       ew = ew - .05 
      if attack == '3': 
       if heals == 0: 
        print('all out!') 
       else: 
        heals = heals - 1 
        hp = hp + 35 
      if attack == 'h': 
       print('attack attack\'s, defend defend\'s, heal heal\'s, upgrade upgrade\'s') 
      if attack == '4': 
       if ups < 1: 
        print('all out') 
       else: 
        ups = ups - 1 
        w = w + 1 
      if attack == 'save': 
       saveFile = open('saveFile.txt','w') 
       saveFile.write(enemies) 
      else: 
       ehp = ehp - (w + randint(-1, 1)) 
     #ENEMYS TURN 
     dec = randint(1, 3) 
     if ehp > 0: 
      if dec == 1: 
       hp = hp - ew 
      if dec == 2: 
       w = w - 0.25 
      if dec == 3: 
       if eheals < 10: 
        ehp = ehp + 1 
      erand = randint(1, 250) 
      if erand == 10: 
       print('New Enemy Spotted') 
       print('Enemy\'s Heals Restored') 
       print('Enemy\'s Health Restored') 
       print('He Attacks You Once') 
       print('Ouch!') 
       eheals = 0 
       if ec == 1: 
        heals = 10 
        ehp = 200 
        hp = hp - 25 
        eheals = 10 
       if ec == 2: 
        ehp = 25 
        hp = hp - 25 
        eheals = 10 
       if ec == 3: 
        ehp = 300 
        hp = hp - 25 
        eheals = 10 
       if ec == 4: 
        ehp = 10 
        hp = hp - 25 
        eheals = 10 
       print('New enemy Leaves') 
      rand = randint(1, 250) 
      if rand == 10: 
       print('New Freind Spotted') 
       print('Your\'s Upgrades Restored') 
       print('Your\'s Health Restored') 
       print('He Attacks The Enemy Once') 
       print('Yes!') 
       eheals = 0 
       if c == 1: 
        hp = 50 
        ups = 25 
        ehp = ehp - 25 
       if c == 2: 
        hp = 100 
        ups = 25 
        ehp = ehp - 25 
       if c == 3: 
        hp = 75 
        ups = 25 
        ehp = ehp - 25 
       if c == 4: 
        hp = 50 
        ups = 25 
        ehp = ehp - 25 
       if c == 5: 
        hp = 99999999 
        ups = 25 
        ehp = ehp - 25 
       print('New Freind Leaves') 
      rand = randint(1, 250) 
      if rand == 10: 
       print('New Freind Spotted') 
       if rideable > 0: 
        print('He Joins Your Team!') 
        rideable = rideable - 1 
        if c == 1: 
         hp = 50 
         ups = 25 
         ehp = ehp - 25 
        if c == 2: 
         hp = 100 
         ups = 25 
         ehp = ehp - 25 
        if c == 3: 
         hp = 75 
         ups = 25 
         ehp = ehp - 25 
        if c == 4: 
         hp = 50 
         ups = 25 
         ehp = ehp - 25 
        if c == 5: 
         hp = 99999999 
         ups = 25 
         ehp = ehp - 25 
     else: 
      heals = 10 
      eheals = 0 
      enemies = enemies - 1 
      print('you\'ve defeated him!') 
      print(enemies, ' left to go!') 
      print('looking for opponent') 
      sleep(randint(1, 10)) 
      enemy = randint(1, 4) 
      if enemy == 1: 
       ehp = 10 
       ew = 5 
       espd = 5 
       erng = 7 
       ec = 4 
       erideable = 0 
      if enemy == 2: 
       ehp = 200 
       ew = 10 
       espd = 0.5 
       erng = 2 
       ec = 1 
       erideable = 1 
       ebspd = 0.5 
      if enemy == 3: 
       ehp = 25 
       ew = 2.5 
       espd = 5 
       erng = 1 
       ec = 2 
       erideble = 0 
      if enemy == 4: 
       ehp = 300 
       ew = 5 
       espd = 2.5 
       erng = 3 
       ec = 3 
       erideble = 5 
     print('\n'*50) 
#MAIN GAME LOOP 
fight() 
print('\n'*50) 
print('score', hp) 

代码想出了这一点:类型错误:unorderable类型:列表()> INT()

Traceback (most recent call last): 
File "C:\Python34\war.py", line 464, in <module> 
fight() 
File "C:\Python34\war.py", line 146, in fight 
while enemies > 0 and hp > 0: 
TypeError: unorderable types: list() > int() 
+1

'file.readlines'返回一个列表,所以'enemies'是一个列表,'enemies> 0'会产生一个'TypeError'。 – mgilson

+0

'enemies'是一个列表。将列表与整数进行比较,你期望得到什么?你是否指len(敌人)> 0'? –

+2

'class's里面的所有'def's根本没有意义。你真的应该阅读python中的类。 –

回答

0

您似乎认为,enemies是一个整数(因为你从它的一个减去一个指向并在另一个比较它为零),但它是一个字符串列表。我想你可能要使它成为一个int,如下所示:

节约,而不是时,:

saveFile.write(enemies) 

使用:

saveFile.write(str(enemies) + '\n') 

重装代替时,:

enemies = open('saveFile.txt','r').readlines(1) 

使用:

enemies = int(open('saveFile.txt','r').readline().strip()) 
相关问题