BleepingComputer.com: New Problems......

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

New Problems...... Return variables?

#1 User is offline   sausage 

  • Forum Regular
  • PipPipPip
  • Find Topics
  • Group: Members
  • Posts: 317
  • Joined: 01-November 08
  • Gender:Male
  • Location:Louisville Colorado

  Posted 09 November 2008 - 08:16 PM

So I got the object variable thing worked out by keeping the methods in the same class but now variables don't change after running the methods

Here is my code:
import java.util.*;

public class BattleAttempt2
{
	private static Scanner keyboard = new Scanner(System.in);
	public static void main(String[] args)
	{

		int health = 20;
		int monster = 20;
		int roll=0;
		int damage=0;
		int option=0;
		int spell1 = 5;
		int spell2 = 5;
		int spell3 = 5;
		int spell4 = 5;
		int spell5 = 2;
		int count = 10;
		int rejuv = 0;
		int cclass = 0;
		String cclassname;
		String name;
		int exp = 0;
		String answer;
		
		System.out.println("Choose your class: ");
		System.out.println("1) Fighter (+2 base attack +4 damage no healing or magic spells)");
		System.out.println("2) Theif (+1 base attack no bonus damage two attacks no magic or healing)");
		System.out.println("3) Mage (No bonuses to attack or damage healing and magic spells)");
		
		cclass = keyboard.nextInt();
		if (cclass <=1)
		cclassname = "Fighter";
		else if (cclass <=2)
		cclassname = "Theif";
		else
		cclassname= "Mage";
		System.out.println("");
		System.out.println("Welcome to the world of 'Insert Name Here'");
		System.out.println("Based on your choice you will start out as a lowly " + cclassname);
		System.out.println("");
		try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
		System.out.println("Hopefully you will live long enough to grow the ranks");
		System.out.println("of our society and become a powerful warlord");
		System.out.println("");
		try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
		System.out.println("Enter your name:");
		name = keyboard.next();
		try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
		System.out.println("Unfortunately due to the untimeliness of a goblin attack");
		System.out.println("you are stuck inside a goblin encampment as a prisoner of war");
		System.out.println("");
		try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
		System.out.println("One of the goblins walks up to you");
		System.out.println("");
		try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
		System.out.println("'" + cclassname + ", Surrender your alliance to 'insert race here'");
		System.out.println(" or we will be forced to kill you!'");
		System.out.println("");
		try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
		System.out.println("1) My name is " + name + "!");
		System.out.println("2) NEVER!");
		option = keyboard.nextInt();
		try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
		if (option<=1)
		{
		System.out.println("Your name is unimportant " + cclassname);
		System.out.println("What is important is you won't surrender we are forced to kill you.");
		}
		else
		System.out.println("Then we will have to kill you.");
		System.out.println("They open your cage to let you out");
		try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
		System.out.println("Entering combat against: Goblin Captain");
		BattleGobCap(health,monster,roll,damage,option,spell1,spell2,spell3,spell4,spell5,count ,rejuv,cclass,exp);
		if (health <=0)
		{
			System.out.println("");
			try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
			System.out.println("As you fall to the ground you see a man in shiny armor");
			try
					{
						Thread.sleep(5000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("");
			System.out.println("Almost instantaneously you wake up in the same place you just were");
			System.out.println("Standing over you is a knight in shiny armor");
			try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
			System.out.println("Lying next to you is what looks to be the goblin captain bleeding on the ground.");
			try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("");
					System.out.println("Knight: 'Don't worry about him. He won't be causing any more trouble.");
		}
		else
		{
			System.out.println("As the goblin dies you hear a loud battle cry");
			  try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("");
					System.out.println("You look over to see a knight in shiny armor killing off all the goblins");
					  try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("");
					System.out.println("You look down at the goblin");
				}
		try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("");
					System.out.println("In a last dying breath the goblin says:");
					System.out.println("This is not over.  By my words... you.... will... not.... survive...");
					  try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("health has been restored");
					health = 20;
					
					  try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("Let's get you out of here before more goblins show up");
					  try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You leave the camp undetected");
					System.out.println("");
					  try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The day ends");
					System.out.println("");
					  try
					{
						Thread.sleep(6000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You wake up to a nice hot breakfast");
					System.out.println("");
					  try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("Knight: Your glad I showed up... you would be dead by now");
					System.out.println("");
					System.out.println("1) Uh... thanks?");
					System.out.println("2) Thanks!");
					System.out.println("3) I think I could've handled myself");
					option = keyboard.nextInt();
					  try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("");
					if(option<=1)
					{
						System.out.println("You dont seem too enthusiastic about your life");
						System.out.println("I could kill you right now if I wanted to");
					}
					else if(option<=2)
					{
						System.out.println("Anytime, just don't think I can look out for you");
						System.out.println("I have official business for the king of 'Insert Town Here'");
					}
					else
					{
						System.out.println("No matter how powerful you think you are");
						System.out.println("Remember that it's always important to have friends");
						System.out.println("I saved your life and don't deny me that");
					  
						try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("");
					System.out.println("You had no chance against that many goblins, not at your skill.");
					System.out.println("Get your head out of the clouds and accept it");
				}
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
				
					System.out.println("Knight: 'So, where do we go now'");
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					
					System.out.println("1) Mountains (Training Fight.... means nothing for the moment)");
					System.out.println("2) Continue on towards 'Insert Town Here");
				option = keyboard.nextInt();
				if(option<=1)
				{
				do{
					monster = 20;
					BattleGobCap(health,monster,roll,damage,option,spell1,spell2,spell3,spell4,spell5,count ,rejuv,cclass,exp);
			System.out.println("Would you like to move on?");
			answer = keyboard.next();
		}while(answer.equalsIgnoreCase("no"));
	}
		
			
			
			
				else
				{
					
					System.out.println("You continue your journey forwards");
					System.out.println("Spell points and health restored");
					health = 20;
					spell1 = 5;
					spell2 = 5;
					spell3 = 5;
					spell4 = 5;
					spell5 = 2;
					answer="yes";
				}
			while(answer.equalsIgnoreCase("no"));
				
				
				}
				
		
	
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	private static double BattleGobCap(int health,int monster,int roll,int damage,int option,int spell1,int spell2,int spell3,int spell4,int spell5,int count ,int rejuv,int cclass,int exp) {
		
		if (cclass<=1)
		{
			while (health >0)
		{
			while (monster >0)
			{
				
				System.out.println("1) Attack (12 attack roll 1d6+4 damage)");
				System.out.println("2) Smite (10 attack roll 1d3+2 damage " + spell1 + " smite points left)");
				System.out.println("3) Kick (always hits 1d2 damage " + spell2 + " kicks left)");

				option = keyboard.nextInt();
				try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
				if (option <= 1)
				{
				roll = (int) (20*Math.random()) + 1;
				System.out.println("Your attack roll: " + roll);
				System.out.println("");
				if (roll >= 12)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You hit the goblin");
					damage = (int) (6*Math.random()) + 1;
					damage = damage+4;
					System.out.println("It takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You missed the goblin");
					System.out.println("");
				}
			}
			else if (option <=2)
			{
				if (spell1 > 0)
				{
				spell1--;
				System.out.println("You Smite the goblin");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("Your attack roll: " + roll);
				System.out.println("");
				if (roll >= 10)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You hit the goblin");
					damage = (int) (3*Math.random()) + 1;
					damage = damage+2;
					System.out.println("It takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You missed the goblin");
					System.out.println("");
				}
				
			}
			else
			System.out.println("Spell points exhausted");
		}
			else if (option <=3)
			{
				if (spell2 > 0)
				{
				spell2--;
				System.out.println("You kick the goblin");
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					
					damage = (int) (2*Math.random()) + 1;
					System.out.println("It takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					System.out.println("");
				
				}
							   
			}
			else
			System.out.println("Spell points exhausted");
		
			
				if (monster <= 0)
				{
					System.out.println("The goblin is now dead");
					
				}
				try
				{
					Thread.sleep(2000);
				}
				catch(InterruptedException e)
				{
					e.printStackTrace();
				}
				if(monster >0)
				{
				option = (int) (4*Math.random()) + 1;
				if (option <= 1)
				{
					
				roll = (int) (20*Math.random()) + 1;
				System.out.println("The goblin's attack roll: " + roll);
				System.out.println("");
				if (roll >= 14)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin hits you");
					damage = (int) (6*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("You now have " + health + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin missed");
					System.out.println("");
				}
			}
			else if (option <=2)
			{
				System.out.println("The goblin casts Lifesteal");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("The goblin's attack roll: " + roll);
				System.out.println("");
				if (roll >= 10)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin hits you");
					damage = (int) (3*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("You now have " + health + " health left");
					System.out.println("");
					System.out.println("The goblin gains " + damage + " health");
					monster = monster + damage;
					System.out.println("It now has " + monster + " health left");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin missed you");
					System.out.println("");
				}
			}
			else if (option <=3)
			{
				System.out.println("The goblin casts Fireball");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("The goblins attack roll: " + roll);
				System.out.println("");
				if (roll >= 16)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin hits you");
					damage = (int) (8*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("you now have " + health + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin missed you");
					System.out.println("");
				}
			}
			else
			{
				
				   
					System.out.println("The goblin casts magic missle");
					damage = (int) (2*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("You now have " + health + " health left");
					System.out.println("");
				
				
				
			}
				 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
				if (health <= 0)
				{
					System.out.println("You have died");
					break;
				}
			}
		}
	break;  
	}
	}
	else if (cclass <=2)
	{
		while (health >0)
		{
			while (monster >0)
			{
				
				System.out.println("");
				System.out.println("1) Attack (18 attack roll 2d6+4 damage)");
				System.out.println("2) Single Strike (12 attack roll 1d6+2 damage ");
				System.out.println("3) Flurry (Two weapon attack damage decreased by 6 14 attack roll 2d6-2 damage " + spell2 + " spell points left)");
				System.out.println("4) Assassinate (17 attack roll 1d20+2 damage " + spell5 + " spell points left)");
				System.out.println("5) Stab (Always hits 1d2+1 damage " + spell4 + " spell point left)");
				
				option = keyboard.nextInt();
				try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
				if (option <= 1)
				{
				roll = (int) (20*Math.random()) + 1;
				System.out.println("Your attack roll: " + roll);
				System.out.println("");
				if (roll >= 18)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You hit the goblin");
					damage = (int) (12*Math.random()) + 2;
					damage = damage + 4;
					System.out.println("It takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You missed the goblin");
					System.out.println("");
				}
			}
			else if (option <=2)
			{
				if (spell1 > 0)
				{
				spell1--;
				System.out.println("You use Single Strike");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("Your attack roll: " + roll);
				System.out.println("");
				if (roll >= 12)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You hit the goblin");
					damage = (int) (6*Math.random()) + 1;
					damage = damage + 2;
					System.out.println("It takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You missed the goblin");
					System.out.println("");
				}
				
			}
			else
			System.out.println("Spell points exhausted");
		}
			else if (option <=3)
			{
				if (spell2 > 0)
				{
				spell2--;
				System.out.println("You use flurry");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("Your attack roll: " + roll);
				System.out.println("");
				if (roll >= 14)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You hit the goblin");
					damage = (int) (12*Math.random()) + 2;
					damage = damage - 2;
					System.out.println("It takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You missed the goblin");
					System.out.println("");
				}
				
			}
			else
			System.out.println("Spell points exhausted");
		}
			else if (option <= 4)
			{
				if (spell5 > 0)
				{
					
					spell5--;
					System.out.println("You use assassinate");
					roll = (int) (20*Math.random()) + 1;
					System.out.println("Your attack roll: " + roll);
					System.out.println("");
					if (roll>=18)
					{
					damage = (int) (20*Math.random()) + 1;
					damage = damage + 2;
					System.out.println("The goblin takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					System.out.println("");
				}
				else
				{
				   try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You miss the goblin");
				}
			}
				else
				System.out.println("Spell points exhausted");
			}
				
				
				
			
			else if (option <= 5)
			{
				if (spell4 > 0)
				{
				spell4--;
				System.out.println("You use stab");
				damage = (int) (2*Math.random()) + 1;
				damage = damage + 1;
				System.out.println("The goblin takes " + damage + " damage");
				System.out.println("");
				System.out.println("It now has " + monster + " health left");
			}
			else
			System.out.println("Spell points exhausted");
		}
		   
				if (monster <= 0)
				{
					System.out.println("The goblin is now dead");
				}
				try
				{
					Thread.sleep(2000);
				}
				catch(InterruptedException e)
				{
					e.printStackTrace();
				}
				if (monster >0)
				{
				option = (int) (4*Math.random()) + 1;
				if (option <= 1)
				{
				roll = (int) (20*Math.random()) + 1;
				System.out.println("The goblin's attack roll: " + roll);
				System.out.println("");
				if (roll >= 14)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin hits you");
					damage = (int) (6*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("You now have " + health + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin missed");
					System.out.println("");
				}
			}
			else if (option <=2)
			{
				System.out.println("The goblin casts Lifesteal");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("The goblin's attack roll: " + roll);
				System.out.println("");
				if (roll >= 10)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin hits you");
					damage = (int) (3*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("You now have " + health + " health left");
					System.out.println("");
					System.out.println("The goblin gains " + damage + " health");
					monster = monster + damage;
					System.out.println("It now has " + monster + " health left");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin missed you");
					System.out.println("");
				}
			}
			else if (option <=3)
			{
				System.out.println("The goblin casts Fireball");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("The goblins attack roll: " + roll);
				System.out.println("");
				if (roll >= 16)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin hits you");
					damage = (int) (8*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("you now have " + health + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin missed you");
					System.out.println("");
				}
			}
			else
			{
				
				   
					System.out.println("The goblin casts magic missle");
					damage = (int) (2*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("You now have " + health + " health left");
					System.out.println("");
				
				
				
			}
				 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
				if (health <= 0)
				{
					System.out.println("You have died");
					break;
				}
			}
		}
	break;	
	}
	}
	else
	{
	System.out.println("You have encountered a goblin");
		
		while (health >0)
		{
			while (monster >0)
			{
				if (count <= 0)
				{
					System.out.println("You have stopped regenerating");
					rejuv = 0;
					count = 10;
					System.out.println("");
				}
				if (rejuv >=1)
				{
					System.out.println("");
					System.out.println("You have gained 1 health due to regeneration");
					health++;
					System.out.println("You now have " + health + " health left");
					System.out.println("You have "+count+" turns left of regeneration");
					count--;
					System.out.println("");
				}
				System.out.println("");
				System.out.println("1) Attack (14 attack roll 1d6 damage)");
				System.out.println("2) Lifesteal (10 attack roll 1d3 damage damage added to life " + spell1 + " spell points left)");
				System.out.println("3) Fireball (16 attack roll 1d8 damage " + spell2 + " spell points left)");
				System.out.println("4) Magic Missile (always hits 1d2 damage " + spell3 + " spell points left)");
				System.out.println("5) Minor Heal (1d8 healing " + spell4 + " spell point left)");
				System.out.println("6) Regeneration (1 health per turn for 10 turns " + spell5 + " spell points left)");
				option = keyboard.nextInt();
				try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
				if (option <= 1)
				{
				roll = (int) (20*Math.random()) + 1;
				System.out.println("Your attack roll: " + roll);
				System.out.println("");
				if (roll >= 14)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You hit the goblin");
					damage = (int) (6*Math.random()) + 1;
					System.out.println("It takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You missed the goblin");
					System.out.println("");
				}
			}
			else if (option <=2)
			{
				if (spell1 > 0)
				{
				spell1--;
				System.out.println("You cast Lifesteal");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("Your attack roll: " + roll);
				System.out.println("");
				if (roll >= 10)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You hit the goblin");
					damage = (int) (3*Math.random()) + 1;
					System.out.println("It takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					System.out.println("");
					System.out.println("You gain " + damage + " health");
					health = health + damage;
					System.out.println("You now have " + health + " health left");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You missed the goblin");
					System.out.println("");
				}
				
			}
			else
			System.out.println("Spell points exhausted");
		}
			else if (option <=3)
			{
				if (spell2 > 0)
				{
				spell2--;
				System.out.println("You cast Fireball");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("Your attack roll: " + roll);
				System.out.println("");
				if (roll >= 16)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You hit the goblin");
					damage = (int) (8*Math.random()) + 1;
					System.out.println("It takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("You missed the goblin");
					System.out.println("");
				}
				
			}
			else
			System.out.println("Spell points exhausted");
		}
			else if (option <= 4)
			{
				if (spell3 > 0)
				{
					spell3--;
					System.out.println("You cast magic missle");
					damage = (int) (2*Math.random()) + 1;
					System.out.println("The goblin takes " + damage + " damage");
					monster = monster - damage;
					System.out.println("");
					System.out.println("It now has " + monster + " health left");
					System.out.println("");
				}
				else
				System.out.println("Spell points exhausted");
			}
				
				
				
			
			else if (option <= 5)
			{
				if (spell4 > 0)
				{
				spell4--;
				roll = (int) (8*Math.random()) + 1;
				System.out.println("You heal yourself for " + roll + " points of damage");
				System.out.println("");
				health = health + roll;
				System.out.println("You now have " + health + " health left");
			}
			else
			System.out.println("Spell points exhausted");
		}
			else
			{
				if (spell5 > 0)
				{
				spell5--;
				System.out.println("You cast regeneration");
				System.out.println("You are now regenerating health");
				rejuv = 1;
			}
			else
			System.out.println("Spell points exhausted");
			}
				if (monster <= 0)
				{
					System.out.println("The goblin is now dead");
					break;
				}
				try
				{
					Thread.sleep(2000);
				}
				catch(InterruptedException e)
				{
					e.printStackTrace();
				}
				if (monster>0)
				{
				option = (int) (4*Math.random()) + 1;
				if (option <= 1)
				{
				roll = (int) (20*Math.random()) + 1;
				System.out.println("The goblin's attack roll: " + roll);
				System.out.println("");
				if (roll >= 14)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin hits you");
					damage = (int) (6*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("You now have " + health + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin missed");
					System.out.println("");
				}
			}
			else if (option <=2)
			{
				System.out.println("The goblin casts Lifesteal");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("The goblin's attack roll: " + roll);
				System.out.println("");
				if (roll >= 10)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin hits you");
					damage = (int) (3*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("You now have " + health + " health left");
					System.out.println("");
					System.out.println("The goblin gains " + damage + " health");
					monster = monster + damage;
					System.out.println("It now has " + monster + " health left");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin missed you");
					System.out.println("");
				}
			}
			else if (option <=3)
			{
				System.out.println("The goblin casts Fireball");
				roll = (int) (20*Math.random()) + 1;
				System.out.println("The goblins attack roll: " + roll);
				System.out.println("");
				if (roll >= 16)
				{
					try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin hits you");
					damage = (int) (8*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("you now have " + health + " health left");
					System.out.println("");
				
				}
				else
				{
					 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
					System.out.println("The goblin missed you");
					System.out.println("");
				}
			}
			else
			{
				
				   
					System.out.println("The goblin casts magic missle");
					damage = (int) (2*Math.random()) + 1;
					System.out.println("You take " + damage + " damage");
					health = health - damage;
					System.out.println("");
					System.out.println("You now have " + health + " health left");
					System.out.println("");
				
				
				
			}
				 try
					{
						Thread.sleep(2000);
					}
					catch(InterruptedException e)
					{
						e.printStackTrace();
					}
				if (health <= 0)
				{
					System.out.println("You have died");
					break;
				}
				}
			}
		System.out.println("Exiting combat");
		break;	
		}
	}
	monster = 20;
return(health);

}
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


}


So after BattleGobCap is run I think it's supposed to transfer the health variable back to the main method (The return statement) but I'm not quite sure (I used the internet for this study)
But as you can see I use an if statement right after calling the method BattleGobCap stating that if health<=0 then have a knight kill the goblin captain and ressurect you (Implied but not directly stated in dialog)
When I purposely get myself killed it just goes to the statement if health is >0 so the "As the goblin dies, you hear a loud battle cry" etc, even though your dead.

Help?
If I'm posting, I probably have something horribly wrong with my computer, there's no obvious explanation for it, that's just the way it is.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users