Skip to content

Instantly share code, notes, and snippets.

@spotco
Created April 24, 2013 10:35
Show Gist options
  • Select an option

  • Save spotco/5451224 to your computer and use it in GitHub Desktop.

Select an option

Save spotco/5451224 to your computer and use it in GitHub Desktop.
JAVRPG
import java.io.*;
import java.util.Random;
//so unoptimized it isnt even funny
public class JavRPG {
public static void main(String args[]) {
//Intro
int level = 1;
int gold = 0;
int health = 10;
int exp = 0;
int maxhealth = 10;
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
ascII();
System.out.println("Welcome to JavRPG!v1.0.1FinalA");
System.out.println();
System.out.println("Enter your name:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String name = null;
try {
name = br.readLine();
}
catch (IOException e) {
System.out.println("ERROR!");
System.exit(1);
}
//debug mode
try {
int i9 = Integer.parseInt(name);
if (i9 == 5992) {
System.out.println("DEBUG MODE ACTIVATED");
System.out.println("Enter exp.");
//exp debug
BufferedReader nu = new BufferedReader(new InputStreamReader(System.in));
String expstring = null;
try {
expstring = nu.readLine();
}
catch (IOException e) {
System.out.println("ERROR!");
System.exit(1);
}
exp = Integer.parseInt(expstring);
//health debug
System.out.println("Enter max health.");
BufferedReader nv = new BufferedReader(new InputStreamReader(System.in));
String healthstring = null;
try {
healthstring = nv.readLine();
}
catch (IOException e) {
System.out.println("ERROR!");
System.exit(1);
}
maxhealth = Integer.parseInt(healthstring);
//gold debug
System.out.println("Enter gold.");
BufferedReader nx = new BufferedReader(new InputStreamReader(System.in));
String goldstring = null;
try {
goldstring = nx.readLine();
}
catch (IOException e) {
System.out.println("ERROR!");
System.exit(1);
}
gold = Integer.parseInt(goldstring);
//name debug
System.out.println("Enter name.");
BufferedReader nz = new BufferedReader(new InputStreamReader(System.in));
String namestring = null;
try {
name = nz.readLine();
}
catch (IOException e) {
System.out.println("ERROR!");
System.exit(1);
}
}
}
catch (NumberFormatException nfe) {}
//end debug mode
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println();
System.out.println("Welcome, "+name+", to the world of JavRPG.");
System.out.println("For your whole life, you've only had one goal.");
System.out.println("Reach level 10 and defeat the final boss.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("Who or what is this final boss?");
System.out.println("Maybe it killed your parents, destroyed your village or kidnapped your girlfriend.");
System.out.println("It doesn't matter. Just make up your own reason here.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("Every adventure has a starting point, and yours is no different.");
System.out.println("It's a farming village, of the generic and boring sort.");
System.out.println("It has, however, a large population of low level monsters ready for you to slaughter.");
System.out.println("There's nowhere better to start your grand quest.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("You have reached: the starting village.");
//end intro
//main menu loop
//variables: name, level, health, gold, exp, maxhealth
//menu1 (main menu selection)
for (int menu1 = 0; level <= 4; menu1 += 0) { //game currently ends at level 11, <= 2
//exp to level converter
//1 4 18 32 50 72 98 128 162 200
int levelcheck = level; //level up checker
if (exp >= 200) {
level = 10; }
else if (exp >= 162) {
level = 9; }
else if (exp >= 128) {
level = 8; }
else if (exp >= 98) {
level = 7; }
else if (exp >= 72) {
level = 6; }
else if (exp >= 50) {
level = 5; }
else if (exp >= 32) {
level = 4; }
else if (exp >= 18) {
level = 3; }
else if (exp >= 4) {
level = 2; }
else { level = 1; }
if (levelcheck < level) {
System.out.println("You have reached level "+level+"!");
}
levelcheck = 0;
pressAnyKey();
//death clause
if (health <= 0) {
System.out.println("You have died!");
System.exit(1);
}
//blankspace creator MAY BUG, CHECK THIS
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
if (level >= 5) {
System.out.println("Upon reaching level 5, a new area has become available to you.");
System.out.println("Monsters are stronger there, but the rewards are likewise greater.");
System.out.println("You will head there after one more day. Prepare yourself.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println(); }
}
System.out.println("You are "+name+", level "+level+" ("+exp+" exp) adventurer.");
System.out.println("You are at the village.");
System.out.println("You have "+health+"/"+maxhealth+" HP, "+gold+" gold.");
int x = menuSelection(menu1);
//int x = menu final selection
if (x == 1) {
//Fightloop
fightFlavor();
health = fightLoop(health);
gold = goldLoop(gold);
exp = expLoop(exp);
menu1 = 0;
x = 0;
} else if (x == 2) {
//restloop 3 gold
System.out.println("A stay at the inn here costs 3 gold.");
if (gold <= 2) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You stay the night.");
gold = gold - 3;
health = maxhealth;
}
} else if (x == 3) {
//Shoploop
if (maxhealth <=10)
//10hp
{ System.out.println("The equipment upgrades here cost 5 gold.");
if (gold <= 4) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You buy the equipment upgrades. Goodbye old wooden sword!");
maxhealth = maxhealth + 5; gold = gold - 5; } }
else if (maxhealth <=15)
//15hp
{ System.out.println("The next equipment upgrade here costs 10 gold.");
if (gold <= 9) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You buy the equipment upgrades. Goodbye broken leather armor!");
maxhealth = maxhealth +5; gold = gold - 10; } }
else if (maxhealth <=20)
//20hp
{ System.out.println("The next equipment upgrade here costs 15 gold.");
if (gold <= 14) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You buy the equipment upgrades. Goodbye tarnished copper shortsword!");
maxhealth = maxhealth +5; gold = gold - 15; } }
else if (maxhealth <=25)
//25hp
{ System.out.println("The next equipment upgrade here costs 20 gold.");
if (gold <= 19) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You buy the equipment upgrades. Goodbye battered leather buckler!");
maxhealth = maxhealth +5; gold = gold - 20; } }
else {
System.out.println("There are no more equipment upgrades here."); }
} else {
System.out.println("Unrecognized command. You do nothing."); //loops back
} //end menu if/else statement
} //end of LOW TIER LOOP game for loop
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("You travel for several days, finally arriving at the second stage of your quest to slay the final boss.");
System.out.println("This is a large town whose economy is based mainly in the comings and goings of adventurers like you.");
System.out.println("The local monster population is likewise more prepared.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("You have reached: the town.");
//TIER 2 LOOP NOTE THAT THIS STUFF IS COPIED
for (int menu1 = 0; level <= 9; menu1 += 0) {
int levelcheck = level; //level up checker
if (exp >= 200) {
level = 10; }
else if (exp >= 162) {
level = 9; }
else if (exp >= 128) {
level = 8; }
else if (exp >= 98) {
level = 7; }
else if (exp >= 72) {
level = 6; }
else if (exp >= 50) {
level = 5; }
else if (exp >= 32) {
level = 4; }
else if (exp >= 18) {
level = 3; }
else if (exp >= 4) {
level = 2; }
else { level = 1; }
if (levelcheck < level) {
System.out.println("You have reached level "+level+"!");
}
levelcheck = 0;
pressAnyKey();
//TIER2death clause
if (health <= 0) {
System.out.println("You have died!");
System.exit(1);
}
//TIER2blankspace creator MAY BUG, CHECK THIS
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
if (level >= 10) {
System.out.println("Upon finally reaching level 10, the final boss's tower has become available to you.");
System.out.println("This will be the greatest challenge you have ever faced.");
System.out.println("You will head there after one more day. Prepare yourself.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println(); }
}
System.out.println("You are "+name+", level "+level+" ("+exp+" exp) warrior.");
System.out.println("You are at the town.");
System.out.println("You have "+health+"/"+maxhealth+" HP, "+gold+" gold.");
int x = menuSelection(menu1);
//int x = menu final selection
if (x == 1) {
//TIER2Fightloop
fightFlavorTier2();
health = fightLoopTier2(health);
gold = goldLoopTier2(gold);
exp = expLoopTier2(exp);
menu1 = 0;
x = 0;
} else if (x == 2) {
//TIER2restloop 6 gold
System.out.println("A stay at the inn here costs 5 gold.");
if (gold <= 4) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You stay the night.");
gold = gold - 5;
health = maxhealth;
}
} else if (x == 3) {
//TIER2Shoploop
if (maxhealth <=25)
//15hp
{ System.out.println("The equipment upgrades here cost 15 gold.");
if (gold <= 14) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You buy the equipment upgrades. Goodbye bronze longsword!");
maxhealth = maxhealth + 5; gold = gold - 15; } }
else if (maxhealth <=30)
//20hp
{ System.out.println("The next equipment upgrade here costs 20 gold.");
if (gold <= 19) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You buy the equipment upgrades. Goodbye iron chainmail!");
maxhealth = maxhealth +5; gold = gold - 20; } }
else if (maxhealth <=35)
//30hp
{ System.out.println("The next equipment upgrade here costs 30 gold.");
if (gold <= 29) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You buy the equipment upgrades. Goodbye enchanted leather boots!");
maxhealth = maxhealth +5; gold = gold - 30; } }
else if (maxhealth <=40)
//40hp
{ System.out.println("The next equipment upgrade here costs 40 gold.");
if (gold <= 39) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You buy the equipment upgrades. Goodbye steel greatsword!");
maxhealth = maxhealth +5; gold = gold - 40; } }
else if (maxhealth <=45)
//40hp
{ System.out.println("The next equipment upgrade here costs 50 gold.");
if (gold <= 49) {
System.out.println("You don't have enough gold!");
} else {
System.out.println("You buy the equipment upgrades. Goodbye enchanted mageweave cloak!");
maxhealth = maxhealth +5; gold = gold - 50; } }
else {
System.out.println("There are no more equipment upgrades here."); }
} else {
System.out.println("Unrecognized command. You do nothing."); //loops back
} //end menu if/else statement
}//end TIER 2 LOOP NOTE THAT THIS STUFF WAS COPIED
//final dungeon here QTE EVENTS
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("You travel for days on end. This is the final stage of your grand quest to slay the final boss.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("You have reached: the tower of the final boss.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("Before you lies a nearly endless maze of platforming, dungeon crawling and locked door puzzles.");
System.out.println("After what seems like dozens of hours, you reach a fairly climatic spot with what appears to be a save crystal.");
System.out.println("You prepare yourself for what appears to be...the final boss.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("As you enter, the eerie sound of organs fills the room.");
System.out.println("An effeminately dressed man stands before you, with his back turned.");
System.out.println("What do you do?");
System.out.println("1-Draw your weapon.");
System.out.println("2-Wait and see.");
BufferedReader zr = new BufferedReader(new InputStreamReader(System.in));
String a7 = null;
int choice1 = 0;
try {
a7 = zr.readLine();
}
catch (IOException e) {
System.out.println("ERROR!");
System.exit(1);
} //super special original try/catch
try {
choice1 = Integer.parseInt(a7); }
catch (NumberFormatException nfe)
{}
if (choice1 == 1) {
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("As you move to draw your weapon,");
System.out.println("the figure turns and a beam of light shoots directly at you!");
System.out.println("You are knocked back by the force of the beam, taking 15 damage.");
health = health - 15;
System.out.println("Your current hp is "+health+".");
pressAnyKey();
} else {
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("You wait for the figure to make a move.");
System.out.println("He turns, slowly.");
System.out.println("\"I've been waiting for you.\" He starts.");
System.out.println("He continues on a long monologue about destiny and the fate of the world.");
pressAnyKey();
}
//death clause
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("A epic battle ensues between you and this figure.");
System.out.println("Many epic abilities were activated, and many potions/herbs/food used.");
System.out.println("You take 15 damage.");
health = health - 15;
System.out.println("Your current hp is "+health+".");
pressAnyKey();
if (health <= 0) {
System.out.println("After a devastating critical, the enemy gains the upper hand!");
System.out.println("You've run out of potions, herbs and food.");
System.out.println("You've come so far, only to fail now...");
System.out.println("You have died.");
System.exit(1);
}
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("After a long and tough battle, the enemy finally falls.");
System.out.println("But instead of rejoice, you feel a sense of dread.");
System.out.println("The organ music rapidly changes to a epic chanting backed by a 30-piece orchestra.");
System.out.println("A light surrounds you as you see your true final boss.");
System.out.println("Before you stands god himself.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("As you approach him, he reaches out his hand towards you.");
System.out.println("In it, a light so bright that it is unbearable to look at.");
System.out.println("What do you do?");
System.out.println("1-Approach him.");
System.out.println("2-Get out of the way!");
BufferedReader ur = new BufferedReader(new InputStreamReader(System.in));
String a9 = null;
int choice2 = 0;
try {
a9 = ur.readLine();
}
catch (IOException e) {
System.out.println("ERROR!");
System.exit(1);
} //super special original try/catch
try {
choice2 = Integer.parseInt(a9); }
catch (NumberFormatException nfe)
{}
if (choice2 == 1) {
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("As you approach, foolheartedly, towards the light.");
System.out.println("The light focuses into a beam, aimed right at you!");
if (choice1 == 1) {
System.out.println("You fell for this twice in a row!");
}
System.out.println("It hits you square on, causing 15 damage.");
health = health - 15;
System.out.println("Your current hp is "+health+".");
pressAnyKey();
} else {
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("You quickly duck out of the way.");
System.out.println("Just in time too, because a beam just shot out of his hand.");
pressAnyKey();
}
if (health <= 0) {
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("After a devastating critical, the enemy gains the upper hand!");
System.out.println("You've run out of potions, herbs and food.");
System.out.println("You've come so far, only to fail now...");
System.out.println("You have died.");
System.exit(1);
}
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("You close the distance upon him. The real battle has begun.");
health = health - 4;
pressAnyKey();
if (health <= 0) {
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("After a devastating critical, the enemy gains the upper hand!");
System.out.println("You've run out of potions, herbs and food.");
System.out.println("You've come so far, only to fail now...");
System.out.println("You have died.");
System.exit(1);
}
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("A long, epic fight ensues. By the end, you have only "+health+"hp left.");
System.out.println("How far you have come since the days of killing rats and other petty mobs.");
System.out.println("In the end, even god himself is no match for your fighting skill.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("You have slain god.");
System.out.println("He doesn't even give gold or exp.");
System.out.println("It seems like a shallow victory.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("With the final boss gone, you have no more goal.");
System.out.println("You have nothing to work for.");
System.out.println("Your life is essentially pointless.");
System.out.println("All your work was essentially for nothing.");
pressAnyKey();
for (int blankSpace = 0; blankSpace <=11; blankSpace++) {
System.out.println();
}
System.out.println("The End.");
System.out.println("Created by spotco.");
System.out.println("Try debug mode! Name = 5992.");
} //end of main method
public static int menuSelection(int menu1) {
System.out.println("Actions:");
System.out.println("1-Fight");
System.out.println("2-Rest");
System.out.println("3-Shop");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String a1 = null;
try {
a1 = br.readLine();
}
catch (IOException e) {
System.out.println("ERROR!");
System.exit(1);
} //super special original try/catch
try {
menu1 = Integer.parseInt(a1); }
catch (NumberFormatException nfe)
{}
return (menu1);
}
public static int fightLoop(int health) {
//TIER 1 DAMAGE CALCULATOR
//health = health - 1;
Random randomGenerator = new Random();
int damage = randomGenerator.nextInt(4);
damage = damage + 1;
System.out.println("You take "+damage+" damage!");
health = health - damage;
return (health);
}
public static int goldLoop(int gold) {
//gold generator TIER 1
Random randomGenerator = new Random();
int rgold = randomGenerator.nextInt(2);
int agold = rgold + 1;
System.out.println("You find "+agold+" gold!");
gold = gold + agold;
return (gold);
}
public static void fightFlavor() {
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(4);
if (randomInt == 0) {
System.out.println("You fight an enraged farm animal.");
} else if (randomInt == 1) {
System.out.println("You fight a giant rat.");
} else if (randomInt == 2) {
System.out.println("You fight a blue jelly.");
} else if (randomInt == 3) {
System.out.println("You fight a dusty skeleton.");
} else if (randomInt == 4) {
System.out.println("You fight a rare named mob.");
} else {
System.out.println("You fight a legendary debug mob.");
}
}
public static void pressAnyKey() {
try {
System.out.println("Press \"enter\" once to continue.");
BufferedReader aqz = new BufferedReader(new InputStreamReader(System.in));
String s = aqz.readLine();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
public static int expLoop(int exp) {
//exp generator TIER 1
Random randomGenerator = new Random();
int rexp = randomGenerator.nextInt(3);
int aexp = rexp + 1;
System.out.println("You recieve "+aexp+" exp!");
exp = exp + aexp;
return (exp);
}
public static void ascII() {
System.out.println(" ___________ ___ ___ ___");
System.out.println(" / / / \\ \\ \\ / /");
System.out.println(" ---- --- / _ \\ \\ \\ / /");
System.out.println(" / / / / \\ \\ \\ \\ / /");
System.out.println(" / / / /___\\ \\ \\ \\ / / ");
System.out.println("___ / / / _____ \\ \\ \\/ / RPG");
System.out.println("\\ \\-- / / / \\ \\ \\ / ");
System.out.println(" \\_____/ /__/ \\__\\ ____ ");
}
//TIER 2 CONTENT
public static int fightLoopTier2(int health) {
Random randomGenerator = new Random();
int damage = randomGenerator.nextInt(8);
damage = damage + 2;
System.out.println("You take "+damage+" damage!");
health = health - damage;
return (health);
}
public static int goldLoopTier2(int gold) {
Random randomGenerator = new Random();
int rgold = randomGenerator.nextInt(4);
int agold = rgold + 2;
System.out.println("You find "+agold+" gold!");
gold = gold + agold;
return (gold);
}
public static void fightFlavorTier2() {
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(4);
if (randomInt == 0) {
System.out.println("You fight an green goblin.");
} else if (randomInt == 1) {
System.out.println("You fight a monstrous zombie.");
} else if (randomInt == 2) {
System.out.println("You fight a earth giant.");
} else if (randomInt == 3) {
System.out.println("You fight a lava demon.");
} else if (randomInt == 4) {
System.out.println("You fight a rare named mob.");
} else {
System.out.println("You fight a legendary debug mob.");
}
}
public static int expLoopTier2(int exp) {
Random randomGenerator = new Random();
int rexp = randomGenerator.nextInt(8);
int aexp = rexp + 2;
System.out.println("You recieve "+aexp+" exp!");
exp = exp + aexp;
return (exp);
} //end tier 2 content
}
@judders96
Copy link
Copy Markdown

Cool stuff man, definitely gave me a couple ideas on stuff I might integrate.. thanks! -OP from /prog/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment