Exemplo n.º 1
0
		//Battle method. Takes a lot of parameters and returns player
		public static Player Battle (Player x, Monster y, Weapon[] weapons)
		{
			/*Monster thisMonster;*/
			Weapon currentWeapon;
			string monsterMove = "";
			string playerResponse = "";
			bool chargeUp = false;
			while (y.health > 0 && x.health > 0) {	
				Random rando = new Random ();//create the new random
				int weaponFailure = rando.Next (1, 1000);//random chooses whether or not the player's weapon hits or misses
				//gets players response before if and else statements in battle


				playerResponse = getAttackResponse ("Attack or Defend?");
				while ((!playerResponse.Equals ("attack"))&&(!playerResponse.Equals ("defend"))) 
				{
					Console.WriteLine ("invalid response");
					playerResponse = getAttackResponse ("Attack or Defend?");
				}//close while player input is invalid

				if (chargeUp == true) {
		
					if (playerResponse.Equals ("attack")) 
					{
						//if(x.inventory.Count != 1)//if the players inventory isnt 1,
						//{							//ask what weapon they want to use.
							currentWeapon = x.getNewWeapon ();
						//}
						//if your weapon misfires, and the monster already charged up, you will take huge amounts of damage
						if (weaponFailure % currentWeapon.missrate != 0) {
							Console.WriteLine ("Your weapon missfired!");
							Console.WriteLine ("The " + y.name + " winds up and attacks you twice!");
							x.health = x.health - (y.damage * 2);
						}//close if

						else {
							Console.WriteLine ("You and your opponent both attacked each other. Woah! The monster's " +
								"attack seems to have done double the damage! " +
								"I would be careful....");
							x.health = x.health - (y.damage * 2);
							y.health = y.health - currentWeapon.power;
						}//close else


						Console.WriteLine ("Player health: " + x.health + ", Monster " +
							"Health: " + y.health);
					}//close if
					else {
						Console.WriteLine ("You defended the " + y.name + "'s charged attack! " +
							"The attack was so powerful that it seems as if it still did some damage. " +
							"Good thing you defended.");
						x.health = x.health - (y.damage / 2);
						Console.WriteLine ("Player health: " + x.health + ", Monster " +
							"Health: " + y.health);
						//if you defend, you only lose 1/4 of the health you would if you attacked
						//this is where defending would come in handy
					}//close else statement
					chargeUp = false;//monster does not charge up repeatedly
				}//close if statement chargeup == true

				//this else statement will execute as long as the monster isn't charging up. 
				else {
					//start the actual battle now.....
					Random random = new Random ();//create the new random
					int rand = random.Next (1, 100);//random generated to choose the monster's move

					//statements set the monsters move
					if (rand % 3 == 0) {//monster has 33% change of attacking normally
						monsterMove = "attack";//set monster move to attack
					}//close if
					else if (rand % 5 == 0) {//monster has 25% change of defending
						monsterMove = "defend";//set monster move to defend
					}//close else if
					else if (rand % 17 == 0) {//monster has 5% chance to do nothing
						monsterMove = "nothing";
					}//close else if
					else {
						monsterMove = "charge";
						chargeUp = true;
					}//close else statement

					//begin the battle after choosing the monsters actions and player actions
					if (playerResponse.Equals ("attack") && monsterMove.Equals ("attack")) 
					{
						//if(x.inventory.Count != 1)//if the players inventory isnt 1,
						//{							//ask what weapon they want to use.
							currentWeapon = x.getNewWeapon ();
						//}
						if (weaponFailure % currentWeapon.missrate != 0) {
							Console.WriteLine ("Your weapon missfired!");
							Console.WriteLine ("The " + y.name + " attacks you!");
							x.health = x.health - y.damage;
						}//close if statement

						else {
							// both attack, both lose health
							y.health = y.health - (currentWeapon.power / 2);
							x.health = x.health - (y.damage);
							Console.WriteLine ("You were both hit!");
						}//close else
						//display battle stats
						Console.WriteLine ("Player health: " + x.health + ", Monster " +
							"Health: " + y.health);
					}//close if
					
					else if (playerResponse.Equals ("attack") && monsterMove.Equals ("defend")) 
					{
						//if(x.inventory.Count != 1)//if the players inventory isnt 1,
						//{							//ask what weapon they want to use.
							currentWeapon = x.getNewWeapon ();
						//}
						if (weaponFailure % currentWeapon.missrate != 0) {
							Console.WriteLine ("Your weapon missfired!");
							Console.WriteLine ("Your attack on the " + y.name + " was futile!");
						}//close if statement
						else {
							// Monster defends, player attacks - loses half of player's attack
							y.health = y.health - (currentWeapon.power / 2);
							Console.WriteLine (y.name + " defended your attack!");
						}//close else


						Console.WriteLine ("Player health: " + x.health + ", Monster " +
							"Health: " + y.health);
					}//close else if
					
					else if (playerResponse.Equals ("defend") && monsterMove.Equals ("attack")) {
						// monster attacks, player defends - lose half of monster's attack
						x.health = x.health - (y.damage / 2);
						Console.WriteLine ("You defended " + y.name + "'s attack");
						Console.WriteLine ("Player health: " + x.health + ", Monster " +
							"Health: " + y.health);
					}//close else if
					else if (playerResponse.Equals ("defend") && monsterMove.Equals ("defend")) {
						// remove HALF of the monsters attack from the player's health
						Console.WriteLine ("You defended " + y.name + "'s attack");
						Console.WriteLine ("Player health: " + x.health + ", Monster " +
							"Health: " + y.health);
					}//close else if
					else if (playerResponse.Equals ("attack") && monsterMove.Equals ("charge")) {
						//if(x.inventory.Count != 1)//if the players inventory isnt 1,
						//{							//ask what weapon they want to use.
							currentWeapon = x.getNewWeapon ();
						//}
						if (weaponFailure % currentWeapon.missrate != 0) {
							Console.WriteLine ("Your weapon missfired!");
							Console.WriteLine ("It seems as if the " + y.name + " is up to something....");
						}//close if statement
						else {
							y.health = y.health - (currentWeapon.power);
							Console.WriteLine ("Your attack hit " + y.name + ".");
							if (y.health > 0) {
								Console.WriteLine ("It seems as if " + y.name + " is doing something....");
							}//close if
						}
						chargeUp = true;
					} else if (playerResponse.Equals ("attack") && monsterMove.Equals ("nothing")) {
						//if(x.inventory.Count != 1)//if the players inventory isnt 1,
						//{							//ask what weapon they want to use.
							currentWeapon = x.getNewWeapon ();
						//}
						if (weaponFailure % currentWeapon.missrate != 0) {
							Console.WriteLine ("Your weapon missfired!");
							Console.WriteLine ("It seems as if the " + y.name + " was confused anyway....");
						}//close if statement

						else {
							//just random so that the monster may die faster
							y.health = y.health - (currentWeapon.power / 2);
							Console.WriteLine ("You caught " + y.name + " off guard!");
							Console.WriteLine ("Player health: " + x.health + ", Monster " +
								"Health: " + y.health);
						}
					}//close else if
					else if (playerResponse.Equals ("defend") && monsterMove.Equals ("charge")) {
						Console.WriteLine ("You brace yourself, ready to defend.... Nothing Happens?");
						Console.WriteLine ("The monster seems as if it is planning something....");
						chargeUp = true;
					}//close else if
					else if (playerResponse.Equals ("defend") && monsterMove.Equals ("nothing")) {
						Console.WriteLine ("You brace yourself for your enemy's attack...");
						Console.WriteLine ("Nothing happens. It must've gotten confused.");
					}//close else if
					else {   //if both parties in the battle defend, nothing happens.
						Console.WriteLine ("You both defended, and nothing happened");
						Console.WriteLine ("Player health: " + x.health + ", Monster " +
							"Health: " + y.health);
					}//close else

				}//close else statement for Battle
			}//close while statement
			if (y.health <= 0)
				x.experience = x.experience + y.expgain;
			/// does something at the end of each battle: get a weapon, get health, or get nothing

		
			Random randoms = new Random ();//create the new random
			int randomNumber = randoms.Next (1, 3);
			if (randomNumber == 1) {
				Weapon thisweapon = GetRandomWeapon (weapons);
				Console.WriteLine ("You found a Weapon on the ground!");
				x.AddWeapon (thisweapon);
				Console.WriteLine (thisweapon.name + " has been added to your inventory.");
			}//close if
			else if (randomNumber == 2) {
				Console.WriteLine ("No wonder that monster put up such a fight... You found a health pack!");
				x.health = x.health + 20;
				Console.WriteLine ("Your health has been increated by 20 HP!");
			}//close else if
			else {
				Console.WriteLine ("The monster wasn't holding anything. ");
			}//close else


			if (x.health > 0 && y.name.Equals("SUPREME ALIEN") && y.health < 0) 
			{
				x.gameOver = true;
			}//close if

			return x;


		}//close battle
Exemplo n.º 2
0
		public static void Main (string[] args)
		{
			Plot.Intro();
			//Plot plot = new Plot();
			//bool cutscene = false;
			int userLocation = Game.GetDefaultLocation();
			
			Game.ShowWelcomeScreen(userLocation);


			Player P1 = new Player ("Player", 500, 0, false);


			Weapon[] weapons = Game.CreateWeapons();

			Weapon currentWeapon = new Weapon("Pistol", 5, 1);
			P1.AddWeapon(currentWeapon);
			//AddWeapon will add a certain weapon to a player's inventory if they dont already have that. 

			//took out the set difficulty here. 
				
			int level;


			while(!P1.gameOver)//while the player hasn't won the game,
			{
				Monster[] monsters = Game.createMonsters(P1);
				//if statements all coded with {} due to the fact that we are not sure if we are adding anything else there
				level = Game.getPlayerLevel (P1.experience);
				if(level == 1)
				{
					Console.WriteLine ("You are level " + level);
					P1 = Game.Battle (P1, monsters[1], weapons);
				}//close if
				else if(level == 2)
				{
					Console.WriteLine ("You are level " + level);
					P1 = Game.Battle(P1, monsters[2], weapons);
				}//close else if
				else if(level==3)
				{
					Console.WriteLine ("You are level " + level);
					P1 = Game.Battle (P1, monsters[3], weapons);
				}//close else if
				else if(level==4)
				{
					Console.WriteLine ("You are level " + level);
					Game.Battle (P1, monsters[4], weapons);
				}//close else if
				else
				{
					Console.WriteLine ("You are level " + level);
					Plot.Cutscene ();
					Game.Battle (P1, monsters[5], weapons);
				}//close else

				if(P1.health <= 0)
					P1.gameOver = true;

				if(!P1.gameOver)
				{//after the battle, ask the user where they want to go. 
					Game.ShowWelcomeScreen(userLocation);
					Game.displayStats(P1);
					int response = UI.PromptIntInRange("\nWhere should we go next? ", 1, 9);
					while(!Game.isValidMoveResponse(response, userLocation))
					{
						Console.WriteLine("You cant go there!");
						response = UI.PromptIntInRange("Where should we go? ", 1, 9);
					}//close while statement
					userLocation = response;
				}//close if gameOver
			}//close while game isn't over
			Plot.Endgame(P1);
			
			
			
			Console.ReadLine();
		}//close Main()