전투를 위해 while
루프를 사용하는 간단한 텍스트 기반 게임을 만들고 있습니다. 플레이어에게 무엇을하고 싶은지 물어보고 무기 나 인벤토리 (포션 등)를 사용할 수있는 옵션을 제공합니다. 인벤토리를 선택하여 보유하고있는 것을 보려면 어떻게해야 무기를 선택하고 대신 공격 할 수있는 옵션을 제공 할 수 있습니까? 나는 이라는 코드를 사용하여 pass
이라는 코드를 작성하려고 시도했다. 사용자가 back
을 입력하면 메뉴 시작 부분에 코드가 전송된다. 그러나 그것은 적의 공격을 끊임없이 반복 할 뿐이며 사용자가 아무 것도하지 못하도록합니다. 어떤 아이디어? 여기 내 전투 코드입니다 : 내가 다시 보낼 수 있도록하려면게임에서 플레이어의 상태 변화를 관리하는 방법은 무엇입니까?
바로 print "what will you do?"
줄 뒤에
def combat():
hero_hp = 1000000
enemy_hp = randint(5, 10)
enemy_name_test = randint(1,5)
enemy_weapon_test = randint(1,5)
enemy_name = list_of_enemys[enemy_name_test]
enemy_weapon = list_of_weapons[enemy_weapon_test]
while hero_hp > 0 and enemy_hp > 0:
print "The %s swings at you with a %s" % (enemy_name, enemy_weapon)
damage = randint(0, 10)
if damage == 0 :
print "the %s misses" %enemy_name
else :
hero_hp -= damage
print "The %s hits you with a %s for %d hit points you have %d hit points left" % (enemy_name, enemy_weapon, damage, hero_hp)
hero_hp -= damage
if hero_hp <= 0 :
print "you have been slain!"
close()
else :
print "What will you do?"
print inventory
player_choice = raw_input("> ")
if player_choice == '1' :
print hero_weapons
player_choice2 = raw_input("> ")
weapon = hero_weapons[player_choice2]
damage = randint(0, 10)
enemy_hp -= damage
print "You attack with %s for %d hit points" % (weapon, damage)
print "%s has %d hit points left" % (enemy_name, enemy_hp)
if enemy_hp <= 0 :
print "You have slain the %s" % enemy_name
else :
pass
else :
print hero_equipment
player_choice2 = raw_input("> ")
heal = randint(1, 10)
hero_equipment.pop(player_choice2)
print "you drink a potion and heal %s hit points" % heal
그냥 내가 궁금한 것이 무엇인지 궁금해하던가요? 나는 실수를 다시 피하고 싶다. – Delur
누군가는 "이 질문은 연구 노력을 보여주지 않으며 그것이 불분명하거나 유용하지 않다"고 느꼈습니다. '제어 명령문'에 대한 질문을 지정하기 위해 노력한다면 ... 검색 엔진으로 스스로 알아낼 수도 있고 다른 사람들이 쉽게 이해할 수도 있습니다. – clwhisk