BleepingComputer.com: Object Variable Issues

Jump to content

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

Object Variable Issues

#1 User is offline   sausage 

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

Posted 07 November 2008 - 06:50 PM

So, as with my adventure game stated in my last 4 posts, I have implemented objects that don't want to work with variables. I am just trying to make sre it's possible to use variables stated in other methods for example:

import java.util.*;
  

		class BattleGob extends BattleAttempt2
		{
			public void Battle()
	{
		if (cclass<=1)
		{
			while (health >0)
		{
			while (monster >0)
			{
			  //all 1000 lines in here 
			}
		  }
	   }
	}
}


That is the code for the method.
This is the code for the main thing

import java.util.*;

public class BattleAttempt2
{
	public static void main(String[] args)
	{
		BattleGob battle = new BattleGob();
		int health = 20;
		int monster = 20;
		int roll;
		int damage;
		int option;
		int spell1 = 5;
		int spell2 = 5;
		int spell3 = 5;
		int spell4 = 5;
		int spell5 = 2;
		int count = 10;
		int rejuv = 0;
		int cclass;
		String cclassname;
		String name;
		Scanner keyboard = new Scanner(System.in);
		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();
		//More program after this and method Battle is called in there


I get an error in the method saying "Cannot find variable 'cclass'"

Please don't yell at me for too many posts in a week... I'm a nerd with very little java experience :thumbsup:
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.

#2 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 07 November 2008 - 07:14 PM

Nobody is going to yell at you for trying to learn a new skill, especially as long as you are showing us that you are working on the code. I really need to see all of your code though, because I am not sure exactly what you are doing. In which class is your main method, and why are you using inheritance? Are you using an IDE at all?
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#3 User is offline   sausage 

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

Posted 07 November 2008 - 07:23 PM

1) WTF is an IDE
2) My code is about 1200 lines long

If you reall want to see my whole code..... Here it is.... I guess

import java.util.*;

public class BattleAttempt2
{
	public static void main(String[] args)
	{
		BattleGob battle = new BattleGob();
		int health = 20;
		int monster = 20;
		int roll;
		int damage;
		int option;
		int spell1 = 5;
		int spell2 = 5;
		int spell3 = 5;
		int spell4 = 5;
		int spell5 = 2;
		int count = 10;
		int rejuv = 0;
		int cclass;
		String cclassname;
		String name;
		Scanner keyboard = new Scanner(System.in);
		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");
		battle.Battle();
		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("Spell points and health have been restored");
					health = 20;
					spell1 = 5;
					spell2 = 5;
					spell3 = 5;
					spell4 = 5;
					spell5 = 2;
					  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");
					}
				
		}
	}


This is the main game part of it

import java.util.*;
  

		class BattleGob extends BattleAttempt2
		{
			public void Battle()
	{
		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;	
		}
	}

}
}


So that's my code... like I said... 1200 or 1300 lines....
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