Top

Java Text RPG


Java Code

Please Register to submit score.
Bookmark and Share
Average Score  0.0 (of 0 scores)
Date Added  Oct 03, 2009
Last Updated  Feb 01, 2010
Tags  code  file  flat  java  open  rpg  source  text 

Description

Level up in this fun game. Create a character and you're good to go! Iron sword does nothing but heal potion heals you.. for 20.

So yeah.. you can save/load your progress. Earn exp and fight random mosnters. As you gain more levels, you will be able to fight more monsters and earn more exp and gold and schtuff.



CODE IS UPDATED & WORKS AS OF...
DECEMBER 6, 2009

(m)ove now works.

Grab the Code

    /**
    DUNGEON CRAWL PROJECT
    Mystik RPG
    Programmer: Dan Jasnowski
    Date started: 9.24.2009


    TO DO LIST -----------------------------------------

    [weapons]
    ADD TO DAMAGE METER USING ZEROS AND OTHER MODIFIERS (WITH WEAPONS?)
    ADD WEAPONS TO SHOPS
    ADD LEVEL BEFORE BUYING WEAPONS


    FEATURES -------------------------------------------

    Battle with monsters according to your level
    Buy a heal potion to heal you
    Answer riddles to battle bosses
    Get through 10 doors to win the game

    -=----

    CODE TO END GAME

    but..
    if intRoom > 10 {
       f1.delete(). // delete stats file to start over game
       displayWinMessage();
    }
    **/

            import java.io.*;
            import java.util.*;
            import java.lang.*;

            public class game extends Thread
            {
             private static String fightAgain; // variable for if you wanna fight again
             private static String fightDec; // what they type.. ex y/n
             private static String globalCom = " What would you like to do?\n\n<m>ove | <b>uy | <s>tats | <r>ules | <q>uit"; // global message
             private static File f1 = new File("stats.txt"); //global stats file
             private static String fightDuring; // the option what you pick during a fight
             private static Random generator = new Random(); // another random gen


             private static String level;  // your level (not really used to my knowledge)
             private static String newexp; // your new experience (after battles)
             /** Chance numbers of monster encounter **/
             private static FileOutputStream out; // declare a file output object
             private static PrintStream p; // declare a print stream object

             // WEAPON START
             private static String weapon[] ={"Dagger", "Sword", "Pitchfork", "Battleaxe", "Spear", "Scimitar", "Warhammer", "Orc Blade", "Greataxe", "Flail"}; // name of weapons
             private static int weaplvl[] = {1,5,12,26,38,50,64,77,86,94}; // level needed to buy/wear
             private static int weapcost[] = {10,110,460,700,1120,4500,7000, 12000, 20000,42000}; // how much the weapon costs
             // WEAPON END ****** Never got around to adding the weapon system in... :(

             private static String monsters[] = {"Rat", "Goblin", "Skeleton", "Ogre", "Troll", "Orc", "Human", "Chuck Norris"};
             private static int monlevelnum[] = {3,8,13,18,26,39,40,63};
             private static String monlevel[] = {"3","8","13","18","26","39","40","63"};
             private static int monhit[] = {3,5,8,14,17,21,29,40}; // the highest a monster can hit
             private static int mon_hp[] = {12,20,32,43,56,69,82,100}; // the monster hp
             private static int aBase; // your attack base
             private static int attackBase; // another one? (not sure if i had to use this...)
             private static String aSBase; // the attack base in string format
             private static String monexp; // monster experience
             private static String mondmg; // monster damage/hit
             private static int randomNum; // random number for choosing different monsters per encounter
             private static String yourAnswer; // the answers for riddles
             private static String bossName; // the boss names
             private static String bossLevel; // the boss level
             private static String bossRiddle; // the riddle the boss gives
             private static String bossAnswer; // the boss answer
             private static String bossAnswer2; // the boss answer 2nd answer;
             private static String bossAnswer3; // the boss answer 3rd answer
             private static int bossHp; // the boss health points
             private static int bossHit; // how much a boss hits
             private static int intBossLevel; // the boss level in number format
             private static String Msg; // the message you get for traps
             private static Random rand = new Random(); // univseral random number variable



    // monster exp gain
          public static String monexp(int w) {
          int total_exp=(w)*4/2;
          String monexp = Integer.toString(total_exp);
          return monexp;
          }
    // monster damage
          public static String mondmg(int d) {
          game game = new game();

          int monhitlvl =  (d)+3;
          String mondmg = Integer.toString(monhitlvl);
          return mondmg;
          }
    // user damage (decrapitated -- I use aBase now)
          public static String userdmg(int d) {
          game game = new game();
          String mylevel = game.lines(2,2);
          int mynumlevel = Integer.parseInt(mylevel);
          int total_damangeyou=d*6+mynumlevel;
          String userdmg = Integer.toString(total_damangeyou);
          return userdmg;
          }
    // generated gold for battle earnings
          public static String gengold(int w) {
          int total_gold_earn=(w)*5/2;
          String goldEarn = Integer.toString(total_gold_earn);
          return goldEarn;
          }



    // used to locate a line number in the stats file
               public String lines(int start, int end)
               {
                  String info = "";
                  BufferedReader in;
                  try
                  {
                     in = new BufferedReader (new FileReader("stats.txt"));
                      for (int i = 0; i < start; i++) { info = in.readLine(); }
                      for (int i = start; i < end + 1; i++)
                      {
                         info = in.readLine();
                      }
                      in.close();
                  }
                  catch (IOException ioe)
                  {
                     System.out.println("An unexpected error occured." + ioe.getMessage());
                  }//end catch errors
                  return info;
               }

    // the random loot method...
        public static void randomGold() throws InterruptedException {
          game gold = new game();


                  String uname = gold.lines(0,0);
                  String get_gold = gold.lines(1,1);
                  String lvl = gold.lines(2,2);
                  String exp = gold.lines(3,3);
                  String room = gold.lines(4,4);
                  String currenthp = gold.lines(5,5);
            String maxhp = gold.lines(6,6);
            String steps = gold.lines(7,7);
           int stepsInt = Integer.parseInt(gold.lines(7,7));
           int myintlevel = Integer.parseInt(gold.lines(2,2));
           int intGold = Integer.parseInt(gold.lines(1,1));
           int newIntSteps = stepsInt+1;
             String newStrSteps = Integer.toString(newIntSteps);

             // the higher your level.. the more loot you'll be able to win!
    int goldFound = 0;
    if (myintlevel < 10) {
    goldFound = rand.nextInt(30);
    }else if (myintlevel <15) {
    goldFound = rand.nextInt(80);
    }else if (myintlevel <20) {
    goldFound = rand.nextInt(175);
    }else if (myintlevel <25) {
    goldFound = rand.nextInt(365);
    }
    //converting...
    String StrGoldFound = Integer.toString(goldFound);
    int newGoldNow = goldFound+intGold;
    String StrGoldNow = Integer.toString(newGoldNow);

    String newStrGold = Integer.toString(newGoldNow);
    // displat message
    System.out.println("You've found "+StrGoldFound+" gold coins!\nYou now have "+StrGoldNow+" gold coins!");
                       try {
                         out = new FileOutputStream("stats.txt");
                         p = new PrintStream( out );
                         p.println(uname);
                         p.println(newStrGold); // gold
                         p.println(lvl);   // level
                         p.println(exp);
                         p.println(room);   // room
                         p.println(currenthp);   // current hp
                         p.println(maxhp);   // max hp
                         p.println(newStrSteps); // steps taken
                         p.close();
                      }catch (IOException ioe) {
                     System.out.println("An unexpected error occured.");
                  }

    doMain();

       }
    // game over screen...ends battle and you died.
        public static void youLose()
        {
          if (f1.exists() == true) {
           System.out.println("\t __     __                _ _          _ _ ");
           System.out.println("\t \\ \\   / /               | (_)        | | |");
           System.out.println("\t  \\ \\_/ /___  _   _    __| |_  ___  __| | |");
           System.out.println("\t   \\   // _ \\| | | |  / _` | |/ _ \\/ _` | |");
           System.out.println("\t    | || (_) | |_| | | (_| | |  __/ (_| |_|");
           System.out.println("\t    |_| \\___/ \\__,_|  \\__,_|_|\\___|\\__,_(_)");
           System.out.println("\n\n\t\tYou must now start over...");
        // Attempt to delete it
        boolean success = f1.delete();

    }
        } // end YouLose
        public static void rules() throws InterruptedException
        {
           System.out.println("      +---------------------------------------------------------------------+");
                 System.out.println("      |                          Rules of the Game                          |");
                 System.out.println("      +---------------------------------------------------------------------+");
                 System.out.println("      In Mystik, it's all about choosing when to fight and answer riddles...,");
                 System.out.println("      You will go through a series of 10 rooms. Each room has one boss and ");
                 System.out.println("      one riddle you must solve. Before you reach the boss, you must solve");
                 System.out.println("      the riddle. But before you reach the riddle, you'll have to go to through ");
                 System.out.println("      several random encounters. They can be a random battle with monsters,");
                 System.out.println("      a deadly trap, or maybe even some free loot! As you progress each room");
                 System.out.println("      you will find that there are more types of monsters you can kill");
                 System.out.println("      \n      The more EXP you earn, the stronger you get and the easier it will be");
                 System.out.println("      for you to kill monsters and bosses. Along the road of your epic journey");
                 System.out.println("      you will find it valueable to buy items to aid in your combat. Good luck.");
    System.out.println("      ----------------------------------------------------------------------- \n\n");
    doMain();
        }


               public static void printIntro () // INTRO METHOD ******************************************************
               {

    game game = new game();
    if (f1.exists() == true ) {
             String goldEarn = game.lines(1,1);
                String mylevel = game.lines(2,2);
                int myintlevel = Integer.parseInt(mylevel);
                String charexp = game.lines(3,3);
    }
                    if (f1.exists() == true)
                         {
                        xp();
                }
                  System.out.println("\t\t\t      Welcome to...\n");
                  System.out.println("\t\t      ___  ___          _   _ _    ");
                  System.out.println("\t\t      |  \\/  |         | | (_) |   ");
                  System.out.println("\t\t      | .  . |_   _ ___| |_ _| | __");
                  System.out.println("\t\t      | |\\/| | | | / __| __| | |/ /");
                  System.out.println("\t\t      | |  | | |_| \\__ \\ |_| |   < ");
                  System.out.println("\t\t      \\_|  |_/\\__, |___/\\__|_|_|\\_\\");
                  System.out.println("\t\t               __/ |               ");
                  System.out.println("\t\t              |___/                \n");

                  // try
                   //   {
                         if (f1.exists() == true)
                         {

                        //sleep(500);
                                 System.out.println("\n\t\tName: " + game.lines(0,0));
                                 System.out.println("\t\tLevel: "+ game.lines(2,2));
                                 System.out.println("\t\tEXP: " + game.lines(3,3));
                                 System.out.println("\t\tHealth: " + game.lines(5,5)+"/" + game.lines(6,6));
                                 System.out.println("\t\tRoom " + game.lines(4,4));
                                 System.out.println("\t\tSteps Taken " + game.lines(7,7));
                            System.out.println("\n");
                        }
                 //    }
            //catch (InterruptedException e) { }
            }

               public static void main(String args[]) throws InterruptedException // MAIN METHOD *******************************************************
               {

        printIntro();  // print intro screen
        doMain(); // go to actual "main" method

               }//end main method



    private static void move() throws InterruptedException{ // MOVE SECTION ********************************************************************
               game game = new game();


    int moveRoll = rand.nextInt(50);

    if (moveRoll > 35) {
       battle();
    }else if (moveRoll > 30) {
       randomGold();
    }else if (moveRoll > 20) {
       trap();
    }else if (moveRoll > 5) {
       randomGold();
    }else if (moveRoll > 0 ) {
       System.out.println("\nNothing happens, as you move.\n");
       doMain();
    }


          }

            private static void trap() throws InterruptedException { // TRAP SECTION *****************************************************************
       game gold = new game();

             int intHpLoss=0;
             String StrHpLoss;

             String uname = gold.lines(0,0);
             String get_gold = gold.lines(1,1);
             String lvl = gold.lines(2,2);
             String getexp = gold.lines(3,3);
             String room = gold.lines(4,4);
             String currenthp = gold.lines(5,5);
             int numberhp = Integer.parseInt(currenthp);
             String maxhp = gold.lines(6,6);
             String steps = gold.lines(7,7);
             int stepsInt = Integer.parseInt(gold.lines(7,7));
             int intNewSteps = stepsInt+1;

              int trapRoll = rand.nextInt(40);

             if (trapRoll > 30) {
                intHpLoss = 7;
                StrHpLoss = "7";
                Msg = "\nYou feel a sharp spinning blade slide below your feet! You've been sliced by blades at feet-point!\nYou lose "+StrHpLoss+" HP.";
             }else if (trapRoll > 20) {
                intHpLoss = 10;
                StrHpLoss = "10";
                Msg = "\nYou feel multiplate sharp jabs. It's a flock of arrows!\n\nYou lose "+StrHpLoss+" HP.\n";
             }else if (trapRoll > 10) {
                intHpLoss = 15;
                StrHpLoss = "15";
                Msg = "\nYou feel the ground get hot... you've burned your feet!\n\nYou lose "+StrHpLoss+" HP.\n";
             }else if (trapRoll > 0) {
                intHpLoss = 20;
                StrHpLoss = "20";
                Msg = "\nYou fall into a large pit. You hit your head against the gravel floor taking a devasting hit.\n\nYou lose "+StrHpLoss+" HP.\n";
          }
          System.out.println("Hi!" +Msg);
          int newNumberHp = numberhp-intHpLoss;
          String strNumberHp = Integer.toString(newNumberHp);
          String newStrSteps = Integer.toString(stepsInt);

                try {

                out = new FileOutputStream("stats.txt");

                p = new PrintStream( out );
                p.println(uname);
                p.println(get_gold);
                p.println(lvl);
                p.println(getexp);
                p.println(room);
                p.println(strNumberHp);
                p.println(maxhp);
                p.println(newStrSteps);
                p.close();
                }catch (IOException ioe)
                {
                System.out.println("An unexpected error occured.");
                }//end catch errors
                   doMain();
          }//end of trap

            private static void doMain() throws InterruptedException{ // DO MAIN ********************************************************************
               game game = new game();


                     BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));




                      InputStreamReader istream = new InputStreamReader(System.in) ;
                      BufferedReader bufRead = new BufferedReader(istream);
                       if (f1.exists() == true)
                         {
    int intStepsTaken = Integer.parseInt(game.lines(7,7));
    // if user steps is more than 10... go to boss fight
    if (intStepsTaken > 10) {
    bossBattle();
    }
    }
                      try
                      {

                         if (f1.exists() == false)
                         {
                           System.out.println("\n\nWhat is your name?");
                           String name = bufRead.readLine();
                           //print the data entered by the user
                           System.out.println("\nWelcome to Mystik, " + name +"...\n\nYou feel light headed as you wake up from a room with no doors. You feel cold and sleepy yet you manage to stumble onto your feet.");
                            Thread.sleep(500);
                           System.out.println("\nYou then go through the trapdoor and discover a long and trecherous road...\n\n");
                           out = new FileOutputStream("stats.txt");
                           p = new PrintStream( out );
                           p.println(name);
                           p.println("75"); // gold
                           p.println("1");   // level
                           p.println("0");   // exp
                           p.println("1");   // room
                           p.println("100");   // current hp
                           p.println("100");   // max hp
                           p.println("1");   // steps taken for room
                           p.close();
                        }

                         System.out.println(globalCom);
                         String choice = bufRead.readLine();



                         if (choice.equalsIgnoreCase("f"))
                         {
                            battle();
                         }else if(choice.equalsIgnoreCase("m"))
                         {
                            move();
                         }else if (choice.equalsIgnoreCase("s")) {
                                         System.out.println("\n----------------------------------------");
                            System.out.println("|\tCharacter name: " + game.lines(0,0)+"\t       |");
                            System.out.println("|\tGold: " + game.lines(1,1)+"          \t       |");
                            System.out.println("|\tHP: " + game.lines(5,5)+"/" + game.lines(6,6)+"\t\t       |");
                            System.out.println("|\tCurrent Level: "+game.lines(2,2)+"  \t       |");
                            System.out.println("|\tEXP: " + game.lines(3,3)+"           \t       |");
                            System.out.println("|\tCurrent Room: " + game.lines(4,4)+"   \t      |");
                            System.out.println("|\tSteps taken: " + game.lines(7,7)+"   \t      |");
                            System.out.println("----------------------------------------\n\n");
              System.out.println(globalCom);
                                                     String statin = bufRead.readLine();
                                                                 if (statin.equalsIgnoreCase("b") == true)
                                                                {
                                                    buyItems();
                                                    }else if (statin.equalsIgnoreCase("f") == true)
                                                    {
                                        battle();
                                                    }else if (statin.equalsIgnoreCase("r") == true)
                                                    {
                                        rules();
                        }else if (statin.equalsIgnoreCase("m") == true)
                                                    {
                                        move();
                        }

                        }else if (choice.equalsIgnoreCase("b") == true )
                        {

            buyItems();
                        }else if (choice.equalsIgnoreCase("r") == true )
                        {

            rules();
                        }else {
                           quit();

                        }


                      //buy stuff

                     //end stuff
                     } //end try
                     catch (IOException ioe)
                     {
                       System.out.println("An unexpected error occured.");
                  }//end catch errors
               }

            public static void quit() throws InterruptedException {

                            InputStreamReader istream = new InputStreamReader(System.in) ;
                      BufferedReader bufRead = new BufferedReader(istream);

               System.out.println("\nDo you really want to quit? (Y/N)\n");
                                 try {
                                 String ansquit = bufRead.readLine();

                                 if (ansquit.equalsIgnoreCase("Y") == true)
                                 {
                                    System.out.println("\nSee ya next time!\n");
                              }else{
                           doMain();
                        }
                           }
                           catch (IOException ioe) {
                       System.out.println("An unexpected error occured.");
                  }//end catch errors
            }

            public static void buyItems() throws InterruptedException { // BUY METHOD *******************************************************



               game gold = new game();

                     FileOutputStream out; // declare a file output object
                     PrintStream p; // declare a print stream object


            String uname = gold.lines(0,0);
            String get_gold = gold.lines(1,1);
            String lvl = gold.lines(2,2);
            String exp = gold.lines(3,3);
            String room = gold.lines(4,4);
            String currenthp = gold.lines(5,5);
            String maxhp = gold.lines(6,6);
            String steps = gold.lines(7,7);

            int newgold = Integer.parseInt(get_gold);
            int getHp = Integer.parseInt(currenthp);

    int newf;
                         InputStreamReader istream = new InputStreamReader(System.in) ;
                      BufferedReader bufRead = new BufferedReader(istream);

                              System.out.println("What would you like to buy? (Type <q>uit to go back) \n1. <i>ron sword \n2. <h>eal potion \n");
                              try {


                              String buy = bufRead.readLine();
                              if (buy.equalsIgnoreCase("q") == true) {
                            System.out.println("\nYou walk out of the store empty handed...\n");
                              doMain();

                         }else if (buy.equalsIgnoreCase("i") == true)
                              {

            out = new FileOutputStream("stats.txt");
            if (newgold >= 1) {
            System.out.println("You bought an iron sword!");
                                                p = new PrintStream( out );
                                     newf = newgold-100;
                                                p.println(uname);
                                                p.println(newf);
                                                p.println(lvl);
                                                p.println(exp);
                                                p.println(room);
                                                p.println(currenthp);
                                                p.println(maxhp);
                                                p.println(steps);
                                                p.close();
                                 doMain();
                              }else{
                            p = new PrintStream( out );
                            newf = newgold;
                            p.println(uname);
                            p.println(newf);
                            p.println(lvl);
                            p.println(exp);
                            p.println(room);
                            p.println(currenthp);
                            p.println(maxhp);
                            p.println(steps);
                            p.close();
                                 System.out.println("\nInsufficent funds!\n");
                                 doMain();
                              }
                              }
                              else if (buy.equalsIgnoreCase("h") == true)
                                             {
            out = new FileOutputStream("stats.txt");
            int cost = 15;
            newf = newgold-cost;
            if (newf >= 1) {

               int hpheal = 20;
               int healed_hp = hpheal+getHp;

    String strGold = Integer.toString(newf);
    String strHp = Integer.toString(healed_hp);
            System.out.println("\nAfter buying the heal potion, you drink it.\nYou were healed for "+hpheal+" HP.");
                   p = new PrintStream( out );

                         p.println(uname);
                         p.println(strGold);
                         p.println(lvl);
                         p.println(exp);
                         p.println(room);
                         p.println(strHp);
                         p.println(maxhp);
                         p.println(steps);
                         p.close();
                                 doMain();
                              }else{
                         p = new PrintStream( out );

                         p.println(uname);
                         p.println(newgold);
                         p.println(lvl);
                         p.println(exp);
                         p.println(room);
                         p.println(currenthp);
                         p.println(maxhp);
                         p.println(steps);
                         p.close();

                                 System.out.println("\nInsufficent funds!\n");

                              }
                                                doMain();
                              }
                              else if (buy.equalsIgnoreCase("schtuff") == true)
                                             {
                                                System.out.println("You bought schtuff... You just wasted money becauase you didn't get in back in return!");
                           doMain();
                           }else{
                              System.out.println("You didn't type anything or typed in them item wrong. Therefor you haven't bought anything.");
                              doMain();
                           }
                        }catch (IOException ioe)
                     {
                       System.out.println("An unexpected error occured.");
                  }//end catch errors
                        }

            public static void battleDone()  throws InterruptedException{ // BATTLE DONE METHOD *************************************************************
                   InputStreamReader istream = new InputStreamReader(System.in) ;
                   BufferedReader bufRead = new BufferedReader(istream);
                  System.out.println("\n\nBattle has finished.\n\nFight again?\n<Y/N>");
                  try {
                  fightAgain = bufRead.readLine();
               }

                     catch (IOException ioe)
                     {
                       System.out.println("An unexpected error occured.");
                  }//end catch errors
                       if (fightAgain.equalsIgnoreCase("Y"))
                            {
                               battle();
                            }else if (!fightAgain.equalsIgnoreCase("Y"))
                           {
                                        doMain();
                            }//end if typed FIGHT
               }



        public static String get (String[] array) {
            int rnd = generator.nextInt(array.length);
            return array[rnd];
        }

    private static Random rd = null;

      public static int[] random(int[] src)
    {
        if(src == null){
       return null;
      }

      rd = new Random();
       int[] tmp = new int[src.length];

      int num = src.length;


      int index;

      for(int i = 0;i < src.length;i++)
      {

       index = Math.abs(rd.nextInt()) % num;
        tmp[i] = src[index];
          src[index] = src[num - 1];
          num--;
      }
      return tmp;
    }

    public static void bossBattle() throws InterruptedException // BOSS BATTLE METHOD ***********************************************************
                      {
    if (f1.exists() == true) {
                         Random diceRoller = new Random();
                                    Random monsterRoller = new Random();
                                    Random getMonster = new Random();
                                    Random getExp = new Random();
                                    Random runAway = new Random();
                                      int total_rounds = 0;

                                      int running = runAway.nextInt(30);

                              game gold = new game();

                             InputStreamReader istream = new InputStreamReader(System.in) ;
                               BufferedReader bufRead = new BufferedReader(istream);
                                       FileOutputStream out; // declare a file output object
                                       PrintStream p; // declare a print stream object


                              String uname = gold.lines(0,0);
                              String get_gold = gold.lines(1,1);
                               int intGold = Integer.parseInt(gold.lines(1,1));
                              String lvl = gold.lines(2,2);
                        String getexp = gold.lines(3,3);
                        int exp = Integer.parseInt(gold.lines(3,3));
                        int lvlnum = Integer.parseInt(gold.lines(2,2));
                              String room = gold.lines(4,4);
                              String currenthp = gold.lines(5,5);
                              int numberhp = Integer.parseInt(currenthp);
                        String maxhp = gold.lines(6,6);
                        String steps = gold.lines(7,7);
                        int stepsInt = Integer.parseInt(gold.lines(7,7));
                        int roomInt = Integer.parseInt(gold.lines(4,4));

                        int getMaxHp = Integer.parseInt(gold.lines(6,6));

            int my_hp = numberhp;

                                      int typeMonster = getMonster.nextInt(10);

           int monlvl = rand.nextInt(10);
            int cmonster = rand.nextInt((9+1)+ monlvl);

          String ret = get(monsters);
          String glvl = get(monlevel);




    game game = new game();

                String goldEarn = game.lines(1,1);
                String mylevel = game.lines(2,2);
                int myintlevel = Integer.parseInt(mylevel);
                String charexp = game.lines(3,3);
                String stepsStr = game.lines(7,7);
                            String strRoom = game.lines(4,4);
                int intRoom = Integer.parseInt(strRoom);



    Random rand = new Random();







    //do Riddle

    if (stepsInt < 10) {

       if (intRoom == 1) {
       bossName = "Dust Goblin";
       bossLevel = "12";
       intBossLevel =12;
       bossRiddle = "I am lighter than a feather, yet no one can hold me for very long. What am I?";
       bossAnswer = "breath";
       bossAnswer2 = "air";
       bossAnswer3 = "wind";
       bossHp = 40;
       bossHit = 3;
       }else if (intRoom == 2) {
       bossName = "Elemental Spirit";
       bossLevel = "24";
       bossRiddle = "What is as big as you are and yet does not weigh anything? ";
       bossAnswer = "your shadow";
       bossAnswer2 = "shadow";
       bossAnswer3 = "my shadow";
       bossHp = 50;
       bossHit = 5;
       }else if (roomInt == 3) {
       bossName = "Steel Skeleton";
       bossLevel = "35";
       intBossLevel =35;
       bossRiddle = "Paul’s height is six feet, he’s an assistant at a meat shop, and wears size 9 shoes. What does he weigh?";
       bossAnswer = "meat";
       bossAnswer2 = "meat";
       bossAnswer3 = "meat";
       bossHp = 60;
       bossHit = 7;
       }else if (intRoom == 4) {
       bossName = "Wind Rat";
       bossLevel = "47";
       intBossLevel =47;
       bossRiddle = "When you have me, you feel like sharing me. But, if you do share me, you don’t have me. What am I? ";
       bossAnswer = "secret";
       bossAnswer2 = "a secret";
       bossAnswer3 = "secret";
       bossHp = 70;
       bossHit = 9;
       }else if (intRoom == 5) {
       bossName = "Chuck Norris";
       bossLevel = "56";
       intBossLevel =56;
       bossRiddle = "What is broken every time someone speaks?";
       bossAnswer = "silence";
       bossAnswer2 = "silent";
       bossHp = 80;
       bossHit = 11;
       bossAnswer3 =  "silence";
       }else if (intRoom == 6) {
       bossName = "Grass Ogre";
       bossLevel = "68";
       intBossLevel =68;
       bossRiddle = "How many letters are in the alphabet?";
       bossAnswer = "eleven";
       bossAnswer2 = "11";
       bossAnswer3 = "eleven letters";
       bossHp = 90;
       bossHit = 13;
       }else if (intRoom == 7) {
       bossName = "Chief Troll";
       bossLevel = "75";
       intBossLevel =75;
       bossRiddle = "You can hold it without using your hands or arms. What is it? ";
       bossAnswer = "breath";
       bossAnswer2 = "my breath";
       bossAnswer3 = "your breath";
       bossHp = 100;
       bossHit = 15;
       }else if (intRoom == 8) {
       bossName = "Earth Orc";
       bossLevel = "83";
       intBossLevel =83;
       bossRiddle = "How many times can you subtract 5 from 25?";
       bossAnswer = "once";
       bossAnswer2 = "one time";
       bossAnswer3 = "one";
       bossHp = 110;
       bossHit = 17;
       }else if (intRoom == 9) {
       bossName = "Indian Chieftan";
       bossLevel = "91";
       intBossLevel =91;
       bossRiddle = "What gets wetter and wetter the more it dries?";
       bossAnswer = "towel";
       bossAnswer2 = "a towel";
       bossAnswer3= "towels";
       bossHp = 120;
       bossHit = 19;
       }else if (intRoom == 10) {
       bossName = "The Joker";
       bossLevel = "99";
       intBossLevel =99;
       bossRiddle = "Imagine you live in a city block. There are 4 houses. The red man live in the Red house, the blue man lives in the blue house, the black man lives in the black house... who's live in the white house?";
       bossAnswer = "presidents";
       bossAnswer2 = "president";
       bossAnswer3 = "the president";
       bossHp = 130;
       bossHit = 50;
       bossHit = 21;
    }

    String monsterName = bossName;

    int monsterHit = bossHit;

    int mon_level = intBossLevel;
    int monster_hp = bossHp;

    int mydamage = myintlevel;

    String monster = monsterName;

    String riddleAns = "";
    System.out.println("As you approach the final step in a ninja-like walk pattern, you feel a hard\nsurface infront of you. It's a door! You try to open the door but fail. On top \nsays its covered in a big golden number "+strRoom+"...");
    System.out.println("\nAll of the sudden, the door displays a riddle...");
    System.out.println("\n"+bossRiddle);
      try {
    riddleAns = bufRead.readLine();
    } //end try
                     catch (IOException ioe)
                     {
                       System.out.println("An unexpected error occured.");
                  }//end catch errors
    if (riddleAns.equalsIgnoreCase(bossAnswer) || (riddleAns.equalsIgnoreCase(bossAnswer2)) || (riddleAns.equalsIgnoreCase(bossAnswer3)))
                                        {
                                  System.out.println("\n+-----------+");
                                  System.out.println("|  CORRECT  |");
                                  System.out.println("+-----------+");
                                  System.out.println("\nCongratulations, you are correct. Now, it's time to fight me...\n");




                                       try {
                                            System.out.println("You encountered the Room "+strRoom+" Boss! Level "+bossLevel+" "+bossName+"!\n\nWhat do you want to do?\n\n1. <F>ight\n2. <R>un Away");
                              fightDec = bufRead.readLine();
                           }
                        catch (IOException ioe)
                        {
                        System.out.println("An unexpected error occured.");
                        }//end catch errors
                             if (fightDec.equalsIgnoreCase("r"))
                                        {

                        System.out.println("\nYou can't run away from a boss battle!");
                        doMain();

                        }
                             if (fightDec.equalsIgnoreCase("f"))
                                        {

        // MONSTER INFO ********************************************************************************************************
                              while (monster_hp > 0 || my_hp > 0)
                                { // while either monster or user's hp is 1 or higher... do this
    if (total_rounds >= 1) {
    try {
                             System.out.println("\n\nWhat do you want to do?\n\n1. (F)ight\n2. (R)un away");

                                                   fightDuring = bufRead.readLine();
                                                }
                                             catch (IOException ioe)
    { System.out.println("An unexpected error occured."); }//end catch errors
    }
    xp();
                            String getuserhit = aSBase;
                            int intMyHit = rand.nextInt(10);
                            int my_hit = intMyHit;
                            String strMyHit = Integer.toString(intMyHit);


                            String getmonhit = mondmg(monsterHit);
                            int monster_hit = rand.nextInt(Integer.parseInt(getmonhit));

                                    int mon_hp = monster_hp - 4;
                                    int new_hp = my_hp - monster_hit;

                                    if (mon_hp <= 0)
                                    { // if monster's hp is below zero.. set to zero
                                        mon_hp = 0;
                                    }
                                    if (new_hp <= 0)
                                    { // if user's hp is below zero.. set to zero
                                        new_hp = 0;
                                    }

                                    //display monster messages
                                    if (mon_hp > 0)
                                    {
                                        System.out.println(monster+" hit for " + monster_hit + "\nYOUR Old HP: " + my_hp + "\nYOUR New HP: " + new_hp + "\n\n----\n");
                                    }

                                    //end monster messages

                                    if (new_hp > 0)
                                    {
                                        System.out.println("YOU hit for " + strMyHit + "\n"+monster+"'s Old HP: " + monster_hp + "\n"+monster+"'s New HP: " + mon_hp + "\n\n----\n");
                                    }

                                    if (mon_hp <= 0)
                                    {
                                    int getHp = Integer.parseInt(currenthp);

                           int finalHp = new_hp;
                        ;

                     int newgoldearned = Integer.parseInt(gengold(intBossLevel));
                     int monsterexpearn = Integer.parseInt(monexp(intBossLevel));


        String killMsg = "\nYou gained "+monexp(intBossLevel)+" EXP.\n";
        String coinMsg = "You earned "+gengold(intBossLevel)+" gold.\n";
        int finalEXP = exp+monsterexpearn;
        int finalGold = intGold+newgoldearned;


                           try {
        System.out.println(killMsg);
        System.out.println(coinMsg);
        int newIntSteps = 0;
        int newIntRoom = intRoom+1;
        String newStrSteps = Integer.toString(newIntSteps);
        String newStrRoom = Integer.toString(newIntRoom);
                           out = new FileOutputStream("stats.txt");

                                       p = new PrintStream( out );
                                       p.println(uname);
                                       p.println(finalGold);
                                       p.println(level);
                                       p.println(finalEXP);
                                       p.println(newStrRoom);
                                       p.println(finalHp);
                                       p.println(maxhp);
                                       p.println(newStrSteps);
                                       p.close();
                                 }catch (IOException ioe)
                                 {
                                   System.out.println("An unexpected error occured.");
                  }//end catch errors
                                        System.out.println("Your Final HP " + new_hp + ". You killed the monster! It took " + total_rounds + " times for you to kill it.");
                                    }


                                                    int healedHp = getMaxHp;
                                                    int coinLose;
                                                    int expLose;
                                                    String lostExpMsg;
                                                    String lostCoinMsg;
                                                    int lostEXP;
                                                    int lostGold;
                                                    int ifLostExp;
                            if (typeMonster > 5)   {
                           coinLose = 9;
                           expLose = 16;
                           lostExpMsg = "\nYou lost "+expLose+" EXP.\n";
                           lostCoinMsg = "You lost "+coinLose+" gold.\n";
                           lostEXP = exp-expLose;
                           lostGold = intGold-coinLose;
                           }else{
                            coinLose = 14;
                           expLose = 20;
                           lostExpMsg = "\nYou lost "+expLose+" EXP.\n";
                           lostCoinMsg = "You lost "+coinLose+" gold.\n";
                           lostEXP = exp-expLose;
                           ifLostExp = lostEXP;
                           if (ifLostExp < 0) {
                              lostEXP = 0;
                           }else{
                           lostEXP = exp-expLose;
                        }
                           lostGold = intGold-coinLose;
            }
                                    if (new_hp <= 0)
                                    {

                                        System.out.println(monster+"'s Final HP " + mon_hp + ". You died! It took " + total_rounds + " times to defeat you.");
                                    youLose();
                                    System.out.println("\n"+lostExpMsg+"\n"+lostCoinMsg);


                                    try {

              int newIntSteps = stepsInt-2;
                 String newStrSteps = Integer.toString(newIntSteps);

                                    out = new FileOutputStream("stats.txt");
                             p = new PrintStream( out );
                             p.println(uname);
                             p.println(lostGold);
                             p.println(level);
                             p.println(lostEXP);
                             p.println(room);
                             p.println(healedHp);
                             p.println(healedHp);
                             p.println(newStrSteps);
                                    p.close();
                          }catch (IOException ioe)
                                 {
                                   System.out.println("An unexpected error occured.");
                  }//end catch errors
                   System.out.println("\nYou lay on the ground for a minute, weak and dazed. You accept defeat while the "+monster+" loots your gold. An hour passes by and you have regained full health.\n");
                  doMain();
                                    }

                                    if (mon_hp <= 0)
                                    {
                                        System.out.println("\nGreat scott! You've defeated the boss! You're going onto the next room!\n");
                                        doMain();
                                        break;
                                    }
                                    monster_hp = mon_hp;
                                    my_hp = new_hp;
                                    total_rounds++; // add new round to total rounds

    //if (fightDuring.equalsIgnoreCase("f")) { battle(); }
                                } //end while


                         }
                         }else{
                         try {
                         int newIntSteps = stepsInt-2;
                         String newStrSteps = Integer.toString(newIntSteps);

                         out = new FileOutputStream("stats.txt");

                         p = new PrintStream( out );
                         p.println(uname);
                         p.println(get_gold);
                         p.println(level);
                         p.println(getexp);
                         p.println(room);
                         p.println(currenthp);
                         p.println(maxhp);
                         p.println(newStrSteps);
                         p.close();
                         }catch (IOException ioe)
                         {
                         System.out.println("An unexpected error occured.");
                         }//end catch errors
                         System.out.println("\nYou're wrong. The door zaps you and you jump back 2 steps...\n");
                                                doMain();
                                                }
    }
    }
            }//end battle method



                   public static void battle() throws InterruptedException // BATTLE METHOD ***********************************************************
                      {

                         Random diceRoller = new Random();
                                    Random monsterRoller = new Random();
                                    Random getMonster = new Random();
                                    Random getExp = new Random();
                                    Random runAway = new Random();
                                      int total_rounds = 0;

                                      int running = runAway.nextInt(30);

                              game gold = new game();

                             InputStreamReader istream = new InputStreamReader(System.in) ;
                               BufferedReader bufRead = new BufferedReader(istream);
                                       FileOutputStream out; // declare a file output object
                                       PrintStream p; // declare a print stream object


                              String uname = gold.lines(0,0);
                              String get_gold = gold.lines(1,1);
                               int intGold = Integer.parseInt(gold.lines(1,1));
                              String lvl = gold.lines(2,2);
                        String getexp = gold.lines(3,3);
                        int exp = Integer.parseInt(gold.lines(3,3));
                        int lvlnum = Integer.parseInt(gold.lines(2,2));
                              String room = gold.lines(4,4);
                              String currenthp = gold.lines(5,5);
                              int numberhp = Integer.parseInt(currenthp);
                        String maxhp = gold.lines(6,6);
                        String steps = gold.lines(7,7);
                        int stepsInt = Integer.parseInt(gold.lines(7,7));

                        int getMaxHp = Integer.parseInt(gold.lines(6,6));

            int my_hp = numberhp;

                                      int typeMonster = getMonster.nextInt(10);

           int monlvl = rand.nextInt(10);
            int cmonster = rand.nextInt((9+1)+ monlvl);

          String ret = get(monsters);
          String glvl = get(monlevel);




    game game = new game();

                String goldEarn = game.lines(1,1);
                String mylevel = game.lines(2,2);
                int myintlevel = Integer.parseInt(mylevel);
                String charexp = game.lines(3,3);


    Random rand = new Random();


    if (myintlevel < 10) {
    randomNum = rand.nextInt(1);
    }else if (myintlevel <15) {
    randomNum = rand.nextInt(3);
    }else if (myintlevel <20) {
    randomNum = rand.nextInt(5);
    }else if (myintlevel <25) {
    randomNum = rand.nextInt(7);
    }


    String monsterName = monsters[randomNum];
    int monsterLevel = monlevelnum[randomNum];
    int monsterHit = monhit[randomNum];

    int mon_level = monsterLevel;
    int monster_hp = mon_hp[randomNum];

    int mydamage = myintlevel;

    String monster = monsterName;

    int runRisk;

                                       try {
                                            System.out.println("You encountered a Level "+mon_level+" "+monsterName+"!\n\nWhat do you want to do?\n\n1. <F>ight\n2. <R>un Away");
                              fightDec = bufRead.readLine();
                           }
                        catch (IOException ioe)
                        {
                        System.out.println("An unexpected error occured.");
                        }//end catch errors
                             if (fightDec.equalsIgnoreCase("r"))
                                        {
                                          //if (runRisk > running) {
                        System.out.println("\nYou ran away!");
                        doMain();
                        //}else{
                        //   fightDec.equalsIgnoreCase("fight");
                        //}
                        }else{
                             if (fightDec.equalsIgnoreCase("f"))
                                        {

        // MONSTER INFO ********************************************************************************************************
                              while (monster_hp > 0 || my_hp > 0)
                                { // while either monster or user's hp is 1 or higher... do this
    if (total_rounds >= 1) {
    try {
                             System.out.println("\n\nWhat do you want to do?\n\n1. (F)ight\n2. (R)un away");

                                                   fightDuring = bufRead.readLine();
                                                }
                                             catch (IOException ioe)
    { System.out.println("An unexpected error occured."); }//end catch errors
    }
    xp();

                            String getuserhit = aSBase;



    Random myHitFinal = new Random();
    int myNewAttack = myintlevel+4;
    int my_hit = myHitFinal.nextInt(myNewAttack); // generate random number of attack base
    String strMyHit = Integer.toString(my_hit);
                            String getmonhit = mondmg(monsterHit);
                            int monster_hit = rand.nextInt(Integer.parseInt(getmonhit));

                                    int mon_hp = monster_hp - my_hit;
                                    int new_hp = my_hp - monster_hit;

                                    if (mon_hp <= 0)
                                    { // if monster's hp is below zero.. set to zero
                                        mon_hp = 0;
                                    }
                                    if (new_hp <= 0)
                                    { // if user's hp is below zero.. set to zero
                                        new_hp = 0;
                                    }

                                    //display monster messages
                                    if (mon_hp > 0)
                                    {
                                        System.out.println(monster+" hit for " + monster_hit + "\nYOUR Old HP: " + my_hp + "\nYOUR New HP: " + new_hp + "\n\n----\n");
                                    }

                                    //end monster messages

                                    if (new_hp > 0)
                                    {
                                        System.out.println("YOU hit for " + strMyHit + "\n"+monster+"'s Old HP: " + monster_hp + "\n"+monster+"'s New HP: " + mon_hp + "\n\n----\n");
                                    }

                                    if (mon_hp <= 0)
                                    {
                                    int getHp = Integer.parseInt(currenthp);

                           int finalHp = new_hp;
                        ;

                     int newgoldearned = Integer.parseInt(gengold(monsterLevel));
                     int monsterexpearn = Integer.parseInt(monexp(monsterLevel));


        String killMsg = "\nYou gained "+monexp(monsterLevel)+" EXP.\n";
        String coinMsg = "You earned "+gengold(monsterLevel)+" gold.\n";
        int finalEXP = exp+monsterexpearn;
        int finalGold = intGold+newgoldearned;


                           try {
        System.out.println(killMsg);
        System.out.println(coinMsg);
        int newIntSteps = stepsInt+1;
        String newStrSteps = Integer.toString(newIntSteps);
                           out = new FileOutputStream("stats.txt");

                                       p = new PrintStream( out );
                                       p.println(uname);
                                       p.println(finalGold);
                                       p.println(level);
                                       p.println(finalEXP);
                                       p.println(room);
                                       p.println(finalHp);
                                       p.println(maxhp);
                                       p.println(newStrSteps);
                                       p.close();
                                 }catch (IOException ioe)
                                 {
                                   System.out.println("An unexpected error occured.");
                  }//end catch errors
                                        System.out.println("Your Final HP " + new_hp + ". You killed the monster! It took " + total_rounds + " times for you to kill it.");
                                    }


                                                    int healedHp = getMaxHp;
                                                    int coinLose;
                                                    int expLose;
                                                    String lostExpMsg;
                                                    String lostCoinMsg;
                                                    int lostEXP;
                                                    int lostGold;
                                                    int ifLostExp;
                            if (typeMonster > 5)   {
                           coinLose = 9;
                           expLose = 16;
                           lostExpMsg = "\nYou lost "+expLose+" EXP.\n";
                           lostCoinMsg = "You lost "+coinLose+" gold.\n";
                           lostEXP = exp-expLose;
                           lostGold = intGold-coinLose;
                           }else{
                            coinLose = 14;
                           expLose = 20;
                           lostExpMsg = "\nYou lost "+expLose+" EXP.\n";
                           lostCoinMsg = "You lost "+coinLose+" gold.\n";
                           lostEXP = exp-expLose;
                           ifLostExp = lostEXP;
                           if (ifLostExp < 0) {
                              lostEXP = 0;
                           }else{
                           lostEXP = exp-expLose;
                        }
                           lostGold = intGold-coinLose;
            }
                                    if (new_hp <= 0)
                                    {

                                        System.out.println(monster+"'s Final HP " + mon_hp + ". You died! It took " + total_rounds + " times to defeat you.");
                                    youLose();
                                    System.out.println("\n"+lostExpMsg+"\n"+lostCoinMsg);


                                    try {

              int newIntSteps = stepsInt-1;
                 String newStrSteps = Integer.toString(newIntSteps);

                                    out = new FileOutputStream("stats.txt");
                             p = new PrintStream( out );
                             p.println(uname);
                             p.println(lostGold);
                             p.println(level);
                             p.println(lostEXP);
                             p.println(room);
                             p.println(healedHp);
                             p.println(healedHp);
                             p.println(newStrSteps);
                                    p.close();
                          }catch (IOException ioe)
                                 {
                                   System.out.println("An unexpected error occured.");
                  }//end catch errors
                   System.out.println("\nYou lay on the ground for a minute, weak and dazed. You accept defeat while the "+monster+" loots your gold. An hour passes by and you have regained full health.\n");
                  doMain();
                                    }

                                    if (mon_hp <= 0)
                                    {
                                        battleDone();
                                        break;
                                    }
                                    monster_hp = mon_hp;
                                    my_hp = new_hp;
                                    total_rounds++; // add new round to total rounds

    //if (fightDuring.equalsIgnoreCase("f")) { battle(); }
                                } //end while

                            } // end not running away
                         }
            }//end battle method


           public static void xp() {

        game exp = new game();
        int myExp = Integer.parseInt(exp.lines(3,3));
        int myLvl = Integer.parseInt(exp.lines(2,2));
       int aBase = myLvl+4;
    if (myExp >=0 && myExp < 14 ) {
    level = "1";
    } else if (myExp > 14 && myExp < 31 ) {
    level = "2";
    } else if (myExp > 31 && myExp < 49 ) {
    level = "3";
    } else if (myExp > 49 && myExp < 70 ) {
    level = "4";
    } else if (myExp > 70 && myExp < 93 ) {
    level = "5";
    } else if (myExp > 93 && myExp < 118 ) {
    level = "6";
    } else if (myExp > 118 && myExp < 146 ) {
    level = "7";
    } else if (myExp > 146 && myExp < 178 ) {
    level = "8";
    } else if (myExp > 178 && myExp < 212 ) {
    level = "9";
    } else if (myExp > 212 && myExp < 250 ) {
    level = "10";
    } else if (myExp > 250 && myExp < 292 ) {
    level = "11";
    } else if (myExp > 292 && myExp < 338 ) {
    level = "12";
    } else if (myExp > 338 && myExp < 390 ) {
    level = "13";
    } else if (myExp > 390 && myExp < 446 ) {
    level = "14";
    } else if (myExp > 446 && myExp < 508 ) {
    level = "15";
    } else if (myExp > 508 && myExp < 577 ) {
    level = "16";
    } else if (myExp > 577 && myExp < 652 ) {
    level = "17";
    } else if (myExp > 652 && myExp < 736 ) {
    level = "18";
    } else if (myExp > 736 && myExp < 827 ) {
    level = "19";
    } else if (myExp > 827 && myExp < 928 ) {
    level = "20";
    } else if (myExp > 928 && myExp < 1039 ) {
    level = "21";
    } else if (myExp > 1039 && myExp < 1162 ) {
    level = "22";
    } else if (myExp > 1162 && myExp < 1297 ) {
    level = "23";
    } else if (myExp > 1297 && myExp < 1445 ) {
    level = "24";
    } else if (myExp > 1445 && myExp < 1609 ) {
    level = "25";
    } else if (myExp > 1609 && myExp < 1789 ) {
    level = "26";
    } else if (myExp > 1789 && myExp < 1988 ) {
    level = "27";
    } else if (myExp > 1988 && myExp < 2207 ) {
    level = "28";
    } else if (myExp > 2207 && myExp < 2448 ) {
    level = "29";
    } else if (myExp > 2448 && myExp < 2714 ) {
    level = "30";
    } else if (myExp > 2714 && myExp < 3007 ) {
    level = "31";
    } else if (myExp > 3007 && myExp < 3330 ) {
    level = "32";
    } else if (myExp > 3330 && myExp < 3686 ) {
    level = "33";
    } else if (myExp > 3686 && myExp < 4078 ) {
    level = "34";
    } else if (myExp > 4078 && myExp < 4511 ) {
    level = "35";
    } else if (myExp > 4511 && myExp < 4988 ) {
    level = "36";
    } else if (myExp > 4988 && myExp < 5514 ) {
    level = "37";
    } else if (myExp > 5514 && myExp < 6094 ) {
    level = "38";
    } else if (myExp > 6094 && myExp < 6734 ) {
    level = "39";
    } else if (myExp > 6734 && myExp < 7439 ) {
    level = "40";
    } else if (myExp > 7439 && myExp < 8218 ) {
    level = "41";
    } else if (myExp > 8218 && myExp < 9076 ) {
    level = "42";
    } else if (myExp > 9076 && myExp < 10023 ) {
    level = "43";
    } else if (myExp > 10023 && myExp < 11068 ) {
    level = "44";
    } else if (myExp > 11068 && myExp < 12220 ) {
    level = "45";
    } else if (myExp > 12220 && myExp < 13492 ) {
    level = "46";
    } else if (myExp > 13492 && myExp < 14895 ) {
    level = "47";
    } else if (myExp > 14895 && myExp < 16443 ) {
    level = "48";
    } else if (myExp > 16443 && myExp < 18151 ) {
    level = "49";
    } else if (myExp > 18151 && myExp < 20036 ) {
    level = "50";
    } else if (myExp > 20036 && myExp < 22116 ) {
    level = "51";
    } else if (myExp > 22116 && myExp < 24411 ) {
    level = "52";
    } else if (myExp > 24411 && myExp < 26945 ) {
    level = "53";
    } else if (myExp > 26945 && myExp < 29741 ) {
    level = "54";
    } else if (myExp > 29741 && myExp < 32826 ) {
    level = "55";
    } else if (myExp > 32826 && myExp < 36232 ) {
    level = "56";
    } else if (myExp > 36232 && myExp < 39992 ) {
    level = "57";
    } else if (myExp > 39992 && myExp < 44141 ) {
    level = "58";
    } else if (myExp > 44141 && myExp < 48721 ) {
    level = "59";
    } else if (myExp > 48721 && myExp < 53776 ) {
    level = "60";
    } else if (myExp > 53776 && myExp < 59356 ) {
    level = "61";
    } else if (myExp > 59356 && myExp < 65516 ) {
    level = "62";
    } else if (myExp > 65516 && myExp < 72316 ) {
    level = "63";
    } else if (myExp > 72316 && myExp < 79822 ) {
    level = "64";
    } else if (myExp > 79822 && myExp < 88108 ) {
    level = "65";
    } else if (myExp > 88108 && myExp < 97255 ) {
    level = "66";
    } else if (myExp > 97255 && myExp < 107352 ) {
    level = "67";
    } else if (myExp > 107352 && myExp < 118500 ) {
    level = "68";
    } else if (myExp > 118500 && myExp < 130806 ) {
    level = "69";
    } else if (myExp > 130806 && myExp < 144391 ) {
    level = "70";
    } else if (myExp > 144391 && myExp < 159389 ) {
    level = "71";
    } else if (myExp > 159389 && myExp < 175947 ) {
    level = "72";
    } else if (myExp > 175947 && myExp < 194226 ) {
    level = "73";
    } else if (myExp > 194226 && myExp < 214406 ) {
    level = "74";
    } else if (myExp > 214406 && myExp < 236685 ) {
    level = "75";
    } else if (myExp > 236685 && myExp < 261282 ) {
    level = "76";
    } else if (myExp > 261282 && myExp < 288437 ) {
    level = "77";
    } else if (myExp > 288437 && myExp < 318417 ) {
    level = "78";
    } else if (myExp > 318417 && myExp < 351516 ) {
    level = "79";
    } else if (myExp > 351516 && myExp < 388058 ) {
    level = "80";
    } else if (myExp > 388058 && myExp < 428402 ) {
    level = "81";
    } else if (myExp > 428402 && myExp < 472944 ) {
    level = "82";
    } else if (myExp > 472944 && myExp < 522120 ) {
    level = "83";
    } else if (myExp > 522120 && myExp < 576413 ) {
    level = "84";
    } else if (myExp > 576413 && myExp < 636355 ) {
    level = "85";
    } else if (myExp > 636355 && myExp < 702535 ) {
    level = "86";
    } else if (myExp > 702535 && myExp < 775601 ) {
    level = "87";
    } else if (myExp > 775601 && myExp < 856271 ) {
    level = "88";
    } else if (myExp > 856271 && myExp < 945335 ) {
    level = "89";
    } else if (myExp > 945335 && myExp < 1043668 ) {
    level = "90";
    } else if (myExp > 1043668 && myExp < 1152235 ) {
    level = "91";
    } else if (myExp > 1152235 && myExp < 1272100 ) {
    level = "92";
    } else if (myExp > 1272100 && myExp < 1404440 ) {
    level = "93";
    } else if (myExp > 1404440 && myExp < 1550553 ) {
    level = "94";
    } else if (myExp > 1550553 && myExp < 1711872 ) {
    level = "95";
    } else if (myExp > 1711872 && myExp < 1889981 ) {
    level = "96";
    } else if (myExp > 1889981 && myExp < 2086627 ) {
    level = "97";
    } else if (myExp > 2086627 && myExp < 2303739 ) {
    level = "98";
    } else if (myExp > 2303739) {
        level = "99";
        }

    aSBase = Integer.toString(aBase);
          String uname = exp.lines(0,0);
               String get_gold = exp.lines(1,1);

                int intGold = Integer.parseInt(exp.lines(1,1));
               String lvl = exp.lines(2,2);
          String getexp = exp.lines(3,3);
          int numbexp = Integer.parseInt(exp.lines(3,3));
               String room = exp.lines(4,4);
               String currenthp = exp.lines(5,5);
               int numberhp = Integer.parseInt(currenthp);
          String maxhp = exp.lines(6,6);
           String steps = exp.lines(7,7);
           int stepsInt = Integer.parseInt(exp.lines(7,7));
             int newIntSteps = stepsInt+1;
             String newStrSteps = Integer.toString(newIntSteps);

          int getMaxHp = Integer.parseInt(exp.lines(6,6));

        try {
          out = new FileOutputStream("stats.txt");
          p = new PrintStream( out );
          p.println(uname);
          p.println(get_gold); // gold
          p.println(level);   // level
             if (myExp < 0) {
                p.println(0);
                }else{
                p.println(getexp);
          }
          p.println(room);   // room
          p.println(currenthp);   // current hp
          p.println(maxhp);   // max hp
          p.println(steps); // steps taken.
          p.close();
       }catch (IOException ioe)
                                 {
                                   System.out.println("An unexpected error occured.");
                  }//end catch errors

        }


            } //end class header

Comments

  (4)  RSS
Ghost-writer
Comments: 359
 
Java Snippet:  Java Text RPG
Posted Oct 15, 2009
why does nobody comment on java scripts :( they are ever so sexy. Can i code this game in msl?
Joshuaxiong1
Comments: 126
 
Java Snippet:  Java Text RPG
Posted Nov 16, 2009
--------------------Configuration: game - JDK version 1.6.0_17 <Default> - <Default>--------------------
java.lang.ClassCastException: game cannot be cast to java.applet.Applet
at sun.applet.AppletPanel.createApplet(AppletPanel.java:785)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
at sun.applet.AppletPanel.run(AppletPanel.java:368)
at java.lang.Thread.run(Thread.java:619)
Joshuaxiong1
Comments: 126
 
Java Snippet:  Java Text RPG
Posted Nov 16, 2009
nvm...

Welcome to...

___ ___ _ _ _
| \/ | | | (_) |
| . . |_ _ ___| |_ _| | __
| |\/| | | | / __| __| | |/ /
| | | | |_| \__ \ |_| | <
\_| |_/\__, |___/\__|_|_|\_\
__/ |
|___/
Hawkee
Comments: 1,122
 
Java Snippet:  Java Text RPG
Posted Dec 17, 2009
Pretty neat. I appreciate seeing snippets of this scope being posted.

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  

Bottom