Login
...or Sign up
Home
Search
Search Code Snippets
Search People
Code Snippets of
link
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int heroHitPoints, monsterHitPoints, attackDamage; int difference; string battlechoice; Random rand; Console.WriteLine("You are facing a monster"); //this is outside the loop so that it will only print once heroHitPoints = 30;// our variables are assigned ouside monsterHitPoints = 25;//so that each loop won't "heal" them do { rand = new Random(); Console.Write(@" ************************************************ Your hero has {0}hp and the monster has {1}hp ************************************************", heroHitPoints, monsterHitPoints); Console.Write(@" __________________________ Please Choose an action: (A)ttack (D)efend (R)un (E)at __________________________"); Console.WriteLine(); battlechoice = Console.ReadLine(); switch (battlechoice) { case "a": case "A"://this way a or A work attackDamage = rand.Next(3, 7);//get our damage monsterHitPoints -= attackDamage;//subtract the damage Console.WriteLine("The hero attacks!"); Console.WriteLine("The monster loses {0}hp", attackDamage); break; case "d": case "D": Console.WriteLine("The Hero Defends"); break; default://defaults always a good idea with user input Console.WriteLine("Sorry that choice was invalid and the monster takes a cheap shot"); break; case "r": case "R": Console.WriteLine("You flee and take {0} damage, your hp is now {1}", attackDamage = rand.Next(1, 2), heroHitPoints -= attackDamage); break; case "e": case "E": Console.WriteLine("You wander around and spot an apple."); difference = rand.Next(2, 10); heroHitPoints += difference; Console.WriteLine("You consume the apple and it gives " + difference + " health."); break; } Console.WriteLine(); if (monsterHitPoints > 0)//if the monster is still alive { Console.WriteLine("The Monster Attacks!"); attackDamage = rand.Next(3, 7);//get a random number if (battlechoice == "d" || battlechoice == "D") { //this is so that defend has some sort of benefit attackDamage /= 2; } heroHitPoints -= attackDamage;//subtract the damage Console.WriteLine("The Hero loses {0}hp", attackDamage); } Console.WriteLine("Press Enter to Continue"); Console.ReadLine(); Console.Clear();//this clears the screen so that we don't have the //last turns info on it. } while (heroHitPoints > 0 && monsterHitPoints > 0); if (heroHitPoints > 0) { Console.WriteLine("You have defeated the monster"); } else { Console.WriteLine("The monster has defeated you"); } Console.ReadLine(); } } }
monsters
Uploaded on
6/5/2010 5:01:42 PM
0 comments
Programming Language:
C#
1
Help
Help by email
What is Naslu?
|
About Naslu
|
Contact
|
Terms of Use
|
Downloads
|
Webprogramacion.com
|
Blog
|
Top
Links
Select language:
Español
|
English
© 2009 naslu.com