I just started coding Java like a couple days ago, and I'm trying to make a simple text based RPG.

At this point, its doing OKAY... [I'll learn some new stuff while I go along]

So, I was wondering if there was any way I could rerun a section of a previous code while KEEPING all my ints (stats).

Like, if I die to a monster, it would be like

Code:
if (tries > 0) {
System.out.println("Would you like to retry (you have " +(3 - times)+ " trys left), [1] Yes [2] No");
reTry = scan.nextInt();
if (reTry == 1) {
times++;
new RPG().bearFight();
} else if (reTry == 2) {
System.out.println("Game over");
System.exit(0);
} else {
System.out.println("Please enter a valid number...");
}
But the problem with this is that it reruns the bearFight, but you don't have any HP or anything..., like all your stats are back to 0.

Here is my code... [I don't really use proper tabbing :s]

So its just one long continuous thing...

Any method of saving would be nice

Code:
import java.io.*;
import java.util.*;

public class RPG {

Random generator = new Random();
public String type;
public int str;
public int atk;
public int speed;
public int damage;
public int recoil;
public int miss;
public int NN;
public int flee1 = 0;
public int fleechance;
public int speed2;
public int meat;
public String elipse = "------------------------------------------------";
public int flee2 = 0;
public int healamount;
public int orkHP;
public int orkChoice;
public int HPmax;
public int special;
public int scene = 0;
public int flashlight;
public int scissors;
public int sleepbag;
public int CC;
public int inForest;
public int didContinue;
public int DD;

	public void ENT() {
		Scanner keyIn = new Scanner(System.in);
			//System.out.print("Press the enter key to continue");
		keyIn.nextLine();
			System.out.println("---------------------------------------------------------------");
}

	public static void main(String [] args) {
		new RPG().run();
	}
	public void run() {
        	Scanner scan = new Scanner (System.in);
		int choicetype;
		System.out.println("Press 1 to be an elf");
		System.out.println("Press 2 to be an ogre");
		System.out.println("Press 3 to be an eagle");
	choicetype = scan.nextInt();
		switch(choicetype) {
		case 1:
			str = 3;
			atk = 3;
			speed = 15;
			speed2 = 3;
			HPmax = 15;
		System.out.println("You are now an elf, stats:");
		System.out.println("Strength : "+str);
		System.out.println("Attack : "+atk);
		System.out.println("Health : "+HPmax);
		System.out.println("Speed : "+speed2);
			break;

		case 2:
			str = 4;
			atk = 1;
			speed = 16;
			speed2 = 1;
			HPmax = 16;
		System.out.println("You are now an ogre, stats:");
		System.out.println("Strength : "+str);
		System.out.println("Attack : "+atk);
		System.out.println("Health : "+HPmax);
		System.out.println("Speed : "+speed2);
			break;
		case 3:
			str = 1;
			atk = 3;
			speed = 17;
			speed2 = 5;
			HPmax = 17;
		System.out.println("You are now an eagle, stats:");
		System.out.println("Strength : "+str);
		System.out.println("Attack : "+atk);
		System.out.println("Health : "+HPmax);
		System.out.println("Speed : "+speed2);
			break;
		case 1337:
			str = 9001;
			atk = 4;
			speed = 1000;
			speed2 = 1;
			HPmax = 1000;
			break;
		}
		System.out.println("---------------------------------------------");

		System.out.println("Would you like to explore the forest [1] or the caves [2]");
	NN = scan.nextInt();
		if (NN != 1) {
		System.out.println("You don't have  a torch, so you decide to explore the forest and encounter a bear.");
		} else if (NN == 1) {
		System.out.println("You choose to explore the forest, as you explore, you encounter a bear");
		}
		int bearHP;
		bearHP = 20;
		while(bearHP > 0 && (flee1 == 0)) {
		System.out.println("Press 1 to fight, and 2 to flee");
		int atkflee = scan.nextInt();
		if (atkflee == 2) {
		fleechance = generator.nextInt((20 + speed2));
		if (fleechance < 20) {
		System.out.println("Unable to flee");
		recoil = generator.nextInt(3) + 2;
		speed = (speed - recoil);
		System.out.println("The provoked bear hits you for " +recoil+ " damage, you have " +speed+ " health.");
		} else if (fleechance >= 20) {
		flee1 = 1;
		bearHP = 0;
		}
		if (speed <= 0) {
		System.out.println("You died");
		System.exit(0);
		}
		} else if (atkflee == 1) {
		miss = generator.nextInt((12 - atk)) + 1;
		if (miss < 10) {
		damage = generator.nextInt(5) + str;
		}
		bearHP = (bearHP - damage);
		System.out.println("You hit the bear for " +damage+ " damage, he is now at " +bearHP+ " health.");
		recoil = generator.nextInt(3) + 2;
		speed = (speed - recoil);
		System.out.println("The enraged bear hits you back for " +recoil+ " damage, you have " +speed+ " health.");
		if (speed <= 0) {
		System.out.println("You died");
		System.exit(0);
		}
		} else {
		System.out.println("Please enter something valid");
				}
			}
			if (flee1 == 0) {
		System.out.println("-----------------------------------------------------");
		System.out.println("You have killed the bear, you are now at");
			HPmax = (HPmax + 3);
			speed = HPmax;
			atk = (atk + 1);
			str = (str + 1);
			speed2 = (speed2 + 2);
		System.out.println("Strength : "+str);
		System.out.println("Attack : "+atk);
		System.out.println("Health : "+HPmax);
		System.out.println("Speed : "+speed2);
		System.out.println("--------------------------------------------------------");
		System.out.println("You find some bear meat, you heal yourself and store the rest in your pack!");
			meat += 2;
ENT();
			}
			if (flee1 == 1) {
		System.out.println("You flee from the bear successfully!");
			}
		System.out.println("You spot a chest, [1] to open, [2] to continue");
		int chestchoice;
		chestchoice = scan.nextInt();
	if (chestchoice == 1) {
	System.out.println("You open the chest, suddenly an ork pops up!");
	orkHP = 34;
	while(orkHP > 0 && (flee2 == 0)) {
	System.out.println("[1]Fight [2]Flee [3]Heal [4] Special Attack");
		orkChoice = scan.nextInt();
				if (orkChoice == 1) {
			miss = generator.nextInt((14 - atk)) + 1;
			if (miss < 10) {
			damage = generator.nextInt(5) + str;
			} else if (miss >= 10) {
			damage = 0;
			System.out.println("You missed!");
			}
			special = (special + (damage * 2));
			orkHP = (orkHP - damage);
			System.out.println("You hit the ork for " +damage+ " damage, he is now at " +orkHP+ " health.");
			recoil = generator.nextInt(7) + 3;
			speed = (speed - recoil);
			System.out.println("The frustrated ork hits you back for " +recoil+ " damage, you have " +speed+ " health.");
			System.out.println("You now have " +special+ " percent special");
			if (speed <= 0) {
			System.out.println("You died.... better luck next time.");
			System.exit(0);
			}
			} else if (orkChoice == 2) {
			fleechance = generator.nextInt((20 + speed2));
			if (fleechance < 20) {
			System.out.println("Unable to flee");
			recoil = generator.nextInt(3) + 2;
			speed = (speed - recoil);
			System.out.println("The ork trying to guard his chest hits you for " +recoil+ " damage, you have " +speed+ " health.");
			} else if (fleechance >= 20) {
			flee2 = 1;
			orkHP = 0;
			}
			if (speed <= 0) {
			System.out.println("You died");
			System.exit(0);
			}
			} else if (orkChoice == 3) {
			healamount = 5;
			if ((meat > 0) && (((HPmax - healamount) + 1) > speed)) {
			System.out.println("You heal your health by " +healamount);
			speed = (speed + healamount);
			meat -= 1;
			} else if (meat == 0) {
			System.out.println("You have nothing to heal with!");
			} else {
			System.out.println("Healing would do you no good right now...");
			}
			} else if (orkChoice == 4) {
			damage = generator.nextInt(8) + str;
			if (special < 25) {
			System.out.println("You need 25% special before using a special ability");
			} else {
			special -= 25;
			orkHP = (orkHP - damage);
			System.out.println("You blind the ork, and hit him for " +damage+ " damage, he is now at " +orkHP+ " health.");
			int SS;
			SS = generator.nextInt(2) + 1;
				if (SS == 1){
			System.out.println("The dazzled ork is unable to fight back!");
				} else if (SS == 2) {
			recoil = generator.nextInt(4) + 1;
			speed = (speed - recoil);
			System.out.println("The dazzled ork manages to fight back and hits " +recoil+ " damage!");
				}
			System.out.println("You now have " +special+ " percent special left");
			}
		}
		}
		} else if (chestchoice == 2) {
		didContinue = 1;
		System.out.println("You can't seem to go any farther in the forest because it is too thick, maybe the chest contains something useful? [Enter]");
		ENT();
		System.out.println("You go back to the chest and find some scissors, you quickly hide as you hear something approaching...");
		scissors = 1;
		} else {
		System.out.println("Please enter something valid");
			}

		if (flee2 == 1) {

		System.out.println("You flee successfully, and you stumble across a flashlight, and find some scissors!");
		flashlight = 1;
		ENT();
		}
		if (flee2 == 0 && didContinue != 1) {
		HPmax += 3;
		str += 3;
		atk += 2;
		speed2 += 3;
		System.out.println(""+elipse+"");
		System.out.println("You defeted the ork! You feel more agile, stronger, more accurate!");
		System.out.println("Strength : "+str);
		System.out.println("Attack : "+atk);
		System.out.println("Health : "+HPmax);
		System.out.println("Speed : "+speed2);
		ENT();
		System.out.println("You find a sleeping sack behind the ogre, and there are some scissors and some spices + food in the chest!");
		System.out.println("As you make your way, you also stumble across a flashlight, and you throw away your rotten bear meat...");
		sleepbag = 1;
		flashlight = 1;
		scissors = 1;
		meat = 0;
		meat += 4;
		ENT();
		}
		while((CC != 1)) {
System.out.println("[1] Continue Exploring Forest [2] Return to cave [3] Sleep (Restore Health)");
		CC = scan.nextInt();
		if (CC == 1) {
		if (scissors != 1) {
		System.out.println("You can't explore through the thick forest without scissors!");
		} else {
		System.out.println("You explore the forest...");
		inForest = 1;
		}
		} else if (CC == 2) {
		if (flashlight != 1) {
		System.out.println("You still do not have a light source!");
		} else {
		System.out.println("You continue back to the cave...");
		ENT();
		System.out.println("Its warm... suddenly you hear something... ITS A DRAGON!");
			while(speed > 0) {
			System.out.println("[1]Fight [2]Flee [3]Heal [4]Special Attack");
		DD = scan.nextInt();
						if (DD == 1) {
						damage = generator.nextInt(3);
						recoil = generator.nextInt(200);
						System.out.println("You are barely able to hit the dragon, you damage the dragon for " +damage+ " health.");
						System.out.println("The mighty dragon blasts you for " +recoil+ " health");
						speed = (speed - recoil);
					} else if (DD == 2) {
						System.out.println("The mighty dragon blocks you with his great wings!");
					
					} else if (DD == 3) {
			healamount = 8;
			if ((meat > 0) && (((HPmax - healamount) + 1) > speed)) {
			System.out.println("You heal your health by " +healamount);
			speed = (speed + healamount);
			meat -= 1;
			} else if (meat == 0) {
			System.out.println("You have nothing to heal with!");
			} else {
			System.out.println("Healing would do you no good right now...");
			}
					
				} else if (DD == 4) {
					System.out.println("You can't manage to distract the dragon long enough to build up special!");
						}
					}
				System.out.println("The merciful dragon spared you...");

				}
		
			}else if (CC == 3) {
			if (sleepbag != 1) {
			System.out.println("You can't sleep on the ground...");
			} else {
			speed = HPmax;
			System.out.println("You sleep, you feel rejuvinated!");
			}
			}
		}
		
	}
}
Oh also, I'm having trouble with booleans.