c# - How can i tell my Program to "re-do" diffrent Actions (chosen by User-Input) after it is done, till the do-while Requirement is set? -
im beginner in c# , im working on console application, want program able read input of user , execute orders until has 0 hp. basicly gonna "fighting-game".
my problem now, can ask user input once(and execute input program once got). want add additional fighting options aswell, im stuck here.
static void main(string[] args) { int playerhealth = 100; int playerdamagesword = 10; int playerdamagefire = 10; int playerheal = 20; int enemyhealth = 100; console.writeline("hey! enter character name!"); string name = console.readline(); console.clear(); console.writeline("okay! " + name + " have encountered enemy! action choose?\n1.sword-attack\n2.fire-attack\n3.heal\n8.flee\n9.quit\n" ); string input = console.readline(); { if (input == "1") { console.writeline("you hit opponment 10 damage!"); enemyhealth = enemyhealth - 10; console.writeline("your opponment hit 10 damage!"); playerhealth = playerhealth - 10; console.writeline("your current hp: " + playerhealth); console.writeline("opponment current hp: " + enemyhealth); } else if (input == "2") { console.writeline("you healed 20 hp"); playerhealth = playerhealth + 20; console.writeline("your current hp: " + playerhealth); console.writeline("opponment current hp: " + enemyhealth); } } while (playerhealth > 0);
you close, need move input read loop so:
string input; { input = console.readline(); if (input == "1") { console.writeline("you hit opponment 10 damage!"); enemyhealth = enemyhealth - 10; console.writeline("your opponment hit 10 damage!"); playerhealth = playerhealth - 10; console.writeline("your current hp: " + playerhealth); console.writeline("opponment current hp: " + enemyhealth); } else if (input == "2") { console.writeline("you healed 20 hp"); playerhealth = playerhealth + 20; console.writeline("your current hp: " + playerhealth); console.writeline("opponment current hp: " + enemyhealth); } } while (playerhealth > 0);
what do:
- begin loop
- get user input , store
input
string - check
if (input == "1")
orelse if (input == "2")
condition - check
(playerhealth > 0)
, move top of loop or exit loop
Comments
Post a Comment