import java.io.*; import java.util.*; import java.text.*; public class MUD { final static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); final static Random generator = new Random(); static boolean[][] map = new boolean[3][3]; static int xposition = 0, yposition = 0; static String name = ""; static int exp = 0, lvl = 0, hpc = 0, hpm = 0, mpc = 0, mpm = 0, str = 0, def = 0, strbns = 0, defbns = 0, arm = 0, wep = 0; static int enexp = 0, enlvl = 0, enhpc = 0, enhpm = 0, enmpc = 0, enmpm = 0, enstr = 0, endef = 0, enstrbns = 0, endefbns = 0, enarm = 0, enwep = 0; static boolean battle = false; static String item1 = " noitemA", item2 = " noitemB", item3 = " noitemC"; public static void main(String[] args) throws IOException { String action = ""; logon(); mapgen(); statsgen(); while (true) { disphud(); action = input(); // Reorder If-Statement if (action.length() == 6) { if (action.charAt(0) == 'm' && action.charAt(1) == 'o' && action.charAt(2) == 'v' && action.charAt(3) == 'e' && action.charAt(4) == ' ') { if (battle != true) { movement(action.charAt(5)); } else { System.out.println("Cannot move while engaged"); } } else { System.out.println("Invalid Command"); } } else if (action.length() == 4) { if (action.equals("bolt")) { if (battle != true) { System.out.println("Cannot bolt unless engaged"); } else { bolt(); } } else { System.out.println("Invalid Command"); } } } } public static String input() throws IOException { System.out.print(">> "); String action = stdin.readLine(); System.out.println(); return action; } public static void logon() throws IOException { System.out.println("Beginning Credits and Jiggers here"); System.out.println(); System.out.println("Please enter your name: "); name = input(); } public static void disphud() { // clear screen NumberFormat formatter7 = new DecimalFormat("0000000"); NumberFormat formatter3 = new DecimalFormat("000"); NumberFormat formatter2 = new DecimalFormat("00"); String exps = formatter7.format(exp); String hpcs = formatter3.format(hpc); String hpms = formatter3.format(hpm); String mpcs = formatter3.format(mpc); String mpms = formatter3.format(mpm); String lvls = formatter2.format(lvl); String strs = formatter2.format(str); String defs = formatter2.format(def); String enexps = formatter7.format(enexp); String enhpcs = formatter3.format(enhpc); String enhpms = formatter3.format(enhpm); String enmpcs = formatter3.format(enmpc); String enmpms = formatter3.format(enmpm); String enlvls = formatter2.format(enlvl); String enstrs = formatter2.format(enstr); String endefs = formatter2.format(endef); if (battle == true) { System.out.print("****" + name.toUpperCase()); for (int x = 0; x <= 74 - name.length(); x++) { System.out.print("*"); } System.out.println(); } else { System.out.print("****" + name.toUpperCase()); for (int x = 0; x <= 49 - name.length(); x++) { System.out.print("*"); } System.out.println(); } System.out.print("****LEVELMAP*************STATUS*************OBJECT****"); if (battle == true) { System.out.println(" ******ENEMY-STATUS******"); } else { System.out.println(); } for (int x = 0; x < 3; x++) { System.out.print("* "); for (int y = 0; y < 3; y++) { if (xposition == x && yposition == y) { System.out.print(" xx "); } else { if (map[x][y] == true) { System.out.print(" "); } else { System.out.print("----"); } } } System.out.print(" **"); if (x == 0) { System.out.print(" HPS: " + hpcs + "/" + hpms + "|LVL: " + lvls + " **"); System.out.print("[1]:" + item1 + "*"); if (battle == true) { System.out.print(" * HPS: " + enhpcs + "/" + enhpms + "|LVL: " + enlvls + " *"); } } if (x == 1) { System.out.print(" MPS: " + mpcs + "/" + mpms + "|STR: " + strs + " **"); System.out.print("[2]:" + item2 + "*"); if (battle == true) { System.out.print(" * MPS: " + enmpcs + "/" + enmpms + "|STR: " + enstrs + " *"); } } if (x == 2) { System.out.print(" EXP: " + exps + "|DEF: " + defs + " **"); System.out.print("[3]:" + item3 + "*"); if (battle == true) { System.out.print(" * EXP: " + enexps + "|DEF: " + endefs + " *"); } } System.out.println(); } if (battle == true) { for (int x = 0; x < 79; x++) { if (x == 54) { System.out.print(" "); } else { System.out.print("*"); } } System.out.println(); System.out.println("* :: [bolt] :: " + " *"); for (int x = 0; x < 79; x++) { System.out.print("*"); } } else { for (int x = 0; x < 54; x++) { System.out.print("*"); } System.out.println(); System.out.println("* :: [move] :: " + " *"); for (int x = 0; x < 54; x++) { System.out.print("*"); } } System.out.println(); } public static void statsgen() { exp = 4750 + (generator.nextInt(60) * 5); lvl = exp / 1000; hpm = (lvl * 80) + (generator.nextInt(lvl * 2) * 5); mpm = (lvl * 40) + (generator.nextInt(lvl * 1) * 5); str = lvl / 2; def = lvl / 2; hpc = hpm; mpc = mpm; } public static void statsupd() {} public static void regenhp(int heal) { hpc += heal; if (hpc >= hpm) { hpc = hpm; } } public static void regenmp(int heal) { mpc += heal; if (mpc >= mpm) { mpc = mpm; } } public static int damage() { int base = ((lvl * lvl * str) / 200) + lvl; double rand = generator.nextDouble(); int damage = base * (int)rand; return damage; } public static void hit(int dam) { hpc -= dam; } public static void mapgen() { while (true) { for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { if (generator.nextInt(2) == 0) { map[x][y] = true; } else { map[x][y] = false; } } } map[0][0] = true; if (map[0][1] != false || map[1][0] != false) { break; } } } public static void movement(char dir) { boolean north = false, east = false; boolean south = false, west = false; if (xposition !=0) { if (map[xposition-1][yposition] == true) { north = true; } } if (xposition != 2) { if (map[xposition+1][yposition] == true) { south = true; } } if (yposition != 2) { if (map[xposition][yposition+1] == true) { east = true; } } if (yposition != 0) { if (map[xposition][yposition-1] == true) { west = true; } } if (dir == 'n') { if (north != true) {System.out.println("You can't move that way"); } else { xposition -= 1; randombatt(); return; } } if (dir == 's') { if (south != true) {System.out.println("You can't move that way"); } else { xposition += 1; randombatt(); return; } } if (dir == 'e') { if (east != true) {System.out.println("You can't move that way"); } else { yposition += 1; randombatt(); return; } } if (dir == 'w') { if (west != true) {System.out.println("You can't move that way"); } else { yposition -= 1; randombatt(); return; } } if (dir != 'n' && dir != 's' && dir != 'w' && dir != 'e') { System.out.println("Please enter a valid direction"); } } public static void bolt() { if (generator.nextInt(100) + 1 >= 25) { while (true) { int a = generator.nextInt(3); int b = generator.nextInt(3); if (a == xposition && b == yposition) {} else if (map[a][b] != false) { System.out.println("Bolt Successful"); battle = false; xposition = a; yposition = b; break; } } } else { System.out.println("Bolt Unsuccessful"); } } public static void randombatt() { if (generator.nextInt(100) + 1 >= 75) { battle(); battle = true; } } public static void battle() { System.out.println("Random Battle"); } }