Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.joejoe.rpg;
- import javax.swing.JOptionPane;
- public class Game {
- public static String command, commandAttack, commandShop;
- public static int monsterRat = 100;
- public static int monsterWeasel = 110;
- public static int monsterBear = 120;
- public static int hp = 100;
- public static int level = 0;
- public static int mana = 10;
- public static int expTotal = 0;
- public static int goldTotal = 0;
- public static int arrow, shuriken, bomb, hpPotion,
- mpPotion, potion, items;
- public static int commandItem, commandBuy;
- public static boolean running = false;
- public static Client frame;
- public static String[] choices;
- public static void main(String[] args) {
- new Save();
- frame = new Client();
- frame.setVisible(true);
- sendMessage("start");
- }
- public static String getStringInput() {
- return JOptionPane.showInputDialog("");
- }
- public static int getIntegerInput() {
- String userInput = JOptionPane.showInputDialog("");
- char[] chars = userInput.toCharArray();
- for (char c : chars) {
- if (c > 47 && c < 58) {
- } else {
- return -1;
- }
- }
- return Integer.valueOf(userInput);
- }
- // ******************************************
- public static void append(String text) {
- Client.textArea.append(text);
- }
- public static void appendLine(String text) {
- Client.textArea.append(text + "\n");
- }
- public static void appendLine() {
- Client.textArea.append("\n");
- }
- // ******************************************
- static String gameState = "started";
- public static void setState(String state) {
- gameState = state;
- }
- public static String getState() {
- return gameState;
- }
- public static void userInput(String input) {
- switch (gameState) {
- /**
- * **** GAME JUST STARTED *****
- */
- case "started":
- choices = getPossibleUserInput(gameState);
- for (String choice : choices) {
- if (input.equals(choice)) {
- startOfTheGame(choice);
- break;
- }
- }
- break;
- /**
- * *************************************************************
- */
- case "huntRat":
- choices = getPossibleUserInput(gameState);
- for (String choise : choices) {
- if (input.equals(choise)) {
- Monsters.huntRat(choise);
- break;
- }
- }
- break;
- case "huntWeasel":
- choices = getPossibleUserInput(gameState);
- for (String choise : choices) {
- if (input.equals(choise)) {
- Monsters.huntWeasel(choise);
- }
- }
- break;
- case "huntBear":
- choices = getPossibleUserInput(gameState);
- for (String choise : choices) {
- if (input.equals(choise)) {
- Monsters.huntBear(choise);
- }
- }
- break;
- case "gameOver":
- choices = getPossibleUserInput(gameState);
- for (String choise : choices) {
- if (input.equals(choise)) {
- gameOver(choise);
- }
- }
- break;
- default:
- break;
- }
- }
- public static String[] getPossibleUserInput(String gameState) {
- switch (gameState) {
- /**
- * ************************************************************** THESE
- * ARE POSSIBLE INPUTS FOR START POSITION OF THE GAME
- * **************************************************************
- */
- case "started":
- return new String[] { "Hunt", "Shop", "Sleep", "Stats", "LevelUp",
- "Inventory","Save", "Exit", "Admin", "hunt", "shop", "sleep",
- "stats", "levelup", "inventory","save", "exit" };
- /**
- * *************************************************************
- */
- case "huntRat":
- return new String[] { "1", "2", "4" };
- /**
- * *************************************************************
- */
- case "huntWeasel":
- return new String[] { "1", "2", "4" };
- /**
- * *************************************************************
- */
- case "huntBear":
- return new String[] { "1", "2", "4" };
- /**
- * *************************************************************
- */
- case "gameOver":
- return new String[] { "Yes", "No" };
- /**
- * *************************************************************
- */
- default:
- return null;
- }
- }
- private static void startOfTheGame(String choice) {
- switch (choice.toLowerCase()) {
- case "hunt":
- hunt();
- break;
- case "shop":
- shop();
- break;
- case "sleep":
- sleep();
- break;
- case "stats":
- stats();
- break;
- case "levelup":
- levelUp();
- break;
- case "inventory":
- inventory();
- break;
- case "save":
- new Save();
- sendMessage("save");
- sendMessage("menu");
- break;
- case "exit":
- new Save();
- System.exit(0);
- break;
- case "admin":
- admin();
- break;
- }
- }
- private static void hunt() {
- int monsterChance = (int) (1 + Math.random() * 100 - 1 + 1);
- if (monsterChance <= 50) {
- gameState = "huntRat";
- sendMessage("rat");
- sendMessage("combatChoose");
- }
- if (monsterChance <= 90 && monsterChance > 50) {
- gameState = "huntWeasel";
- sendMessage("weasel");
- sendMessage("combatChoose");
- }
- if (monsterChance <= 100 && monsterChance > 90) {
- gameState = "huntBear";
- sendMessage("bear");
- sendMessage("combatChoose");
- }
- }
- public static void sendMessage(String message) {
- switch (message) {
- case "start":
- Client.textArea.setText("");
- append("Welcome To The Game\n-----------------------\n");
- case "menu":
- appendLine("What do you want to do?\n" + "Hunt | Shop | Sleep "
- + "| Stats | \nLevelUp" + " | Inventory | Save | Exit |\n");
- break;
- case "rat":
- Client.textArea.setText("");
- appendLine("A wild Rat has appeared");
- break;
- case "combatChoose":
- appendLine("What Skill do you want to use?"
- + "\n1.Attack, 2.Heal, 3.Item, 4.Run: ");
- break;
- case "weasel":
- Client.textArea.setText("");
- appendLine("A wild Weasel has appeared");
- break;
- case "bear":
- Client.textArea.setText("");
- appendLine("A wild Bear has appeared be careful!");
- break;
- case "save":
- Client.textArea.setText("");
- appendLine("Your game has been saved!\n");
- default:
- break;
- }
- }
- private static void gameOver(String choice) {
- switch (choice) {
- case "Yes":
- gameState = "started";
- sendMessage("start");
- resetStats();
- break;
- case "No":
- System.exit(0);
- break;
- default:
- break;
- }
- }
- public static void admin() {
- hp = 100;
- level = 1;
- mana = 10;
- expTotal += 2000;
- goldTotal += 3000;
- appendLine("You have admin EXP/LEVEL now!\n");
- }
- public static void resetStats() {
- hp = 100;
- level = 0;
- mana = 10;
- expTotal = 0;
- goldTotal = 0;
- arrow = 0;
- shuriken = 0;
- bomb = 0;
- hpPotion = 0;
- mpPotion = 0;
- potion = 0;
- items = 0;
- running = false;
- }
- private static void sleep() {
- hp = 100;
- mana = 10;
- Client.textArea.setText("");
- appendLine("-You now have full hp and mana!\n");
- sendMessage("menu");
- }
- private static void stats() {
- Client.textArea.setText("");
- appendLine("-You have: " + expTotal + " exp!\n" + "-You have: "
- + goldTotal + " gold!\n" + "-Your level is: " + level + "\n");
- sendMessage("menu");
- }
- private static void inventory() {
- Client.textArea.setText("");
- appendLine("-You have: " + arrow + " arrow(s)\n" + "-You have: "
- + shuriken + " shuriken(s)\n" + "-You have: " + bomb
- + " bomb(s)\n" + "-You have: " + hpPotion
- + " Small Hp-Potion(s)\n" + "-You have: " + mpPotion
- + " Mana-Potion(s)\n" + "-You have: " + potion
- + " Large Hp-Potion(s)\n");
- sendMessage("menu");
- }
- private static void levelUp() {
- Client.textArea.setText("");
- if (expTotal >= 100) {
- level++;
- appendLine("CONGRATS! You have leveled up!" + "\nYour level is: "
- + level);
- expTotal -= 100;
- } else {
- appendLine("You don't have enough exp! Hunt more!\n");
- }
- sendMessage("menu");
- }
- public static void shop() {
- Client.textArea.setText("");
- appendLine("SHOPS:\nNOT IMPLEMENTED YET!\n");
- sendMessage("menu");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement