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:

  1. begin loop
  2. get user input , store input string
  3. check if (input == "1") or else if (input == "2") condition
  4. check (playerhealth > 0) , move top of loop or exit loop

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -