Guest User

Untitled

a guest
Jan 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.24 KB | None | 0 0
  1. package pkg;
  2. import java.io.*;
  3. import java.util.*;
  4. /*
  5.  * load
  6.  * shop
  7.  *
  8.  */
  9. public class Spel_1 {
  10.     public static Scanner input = new Scanner(System.in);
  11.     public static void save(int number, String name, int Item_1_i, int Item_2_i, int Item_3_i, int balance) throws Exception{
  12.         if (number==1){
  13.             FileWriter saveFile1 = new FileWriter("save1.txt");
  14.             saveFile1.write(name + "\n");
  15.             saveFile1.write(Item_1_i + "\n");
  16.             saveFile1.write(Item_2_i + "\n");
  17.             saveFile1.write(Item_3_i + "\n");
  18.             saveFile1.write(balance + "\n");
  19.             saveFile1.close();
  20.         }
  21.         else if (number==2){
  22.             FileWriter saveFile2 = new FileWriter("save2.txt");
  23.             saveFile2.write(name + "\n");
  24.             saveFile2.write(Item_1_i + "\n");
  25.             saveFile2.write(Item_2_i + "\n");
  26.             saveFile2.write(Item_3_i + "\n");
  27.             saveFile2.write(balance + "\n");
  28.             saveFile2.close();
  29.         }
  30.         else if (number==3){
  31.             FileWriter saveFile3 = new FileWriter("save3.txt");
  32.             saveFile3.write(name + "\n");
  33.             saveFile3.write(Item_1_i + "\n");
  34.             saveFile3.write(Item_2_i + "\n");
  35.             saveFile3.write(Item_3_i + "\n");
  36.             saveFile3.write(balance + "\n");
  37.             saveFile3.close();
  38.         }
  39.     }
  40.     public static void load(int number) throws Exception{
  41.         if (number==1){
  42.            
  43.         }
  44.         else if (number==2){
  45.            
  46.         }
  47.         else if (number==3){
  48.            
  49.         }
  50.     }
  51.     public static int battle(int balance)throws Exception{
  52.         int reward=100;
  53.         String[] array_mob = new String[5];
  54.         array_mob[0] = "Rat";
  55.         array_mob[1] = "Wild Dog";
  56.         array_mob[2] = "Bear";
  57.         array_mob[3] = "Gladiator";
  58.         array_mob[4] = "Dragon";
  59.         String mob = array_mob[(int)(Math.random()*5)];
  60.         int multiplier = 1;
  61.         if (mob.equals("Rat")){
  62.             multiplier = 1;
  63.         }
  64.         else if (mob.equals("Wild Dog")){
  65.             multiplier = 3;
  66.         }
  67.         else if (mob.equals("Bear")){
  68.             multiplier = 5;
  69.         }
  70.         else if (mob.equals("Gladiator")){
  71.             multiplier = 8;
  72.         }
  73.         else if (mob.equals("Dragon")){
  74.             multiplier = 10;
  75.         }
  76.         System.out.println("You have encountered a " + mob);
  77.         int loop = 1;
  78.         while (loop==1){
  79.             int win_lose = (int)(Math.random()*100);
  80.             if (win_lose>50){
  81.                 System.out.println("You beat the " + mob + " and recieved " + reward*multiplier + " gold coins.");
  82.                 balance = balance + reward*multiplier;
  83.             }
  84.             else{
  85.                 System.out.println("You lost the battle.");
  86.             }
  87.             loop = 0;
  88.         }
  89.         return balance;
  90.     }
  91.     public static void game(int sword_lvl, int shield_lvl, int armor_lvl, String name, int balance)throws Exception{
  92.         int play = 1;
  93.         while (play==1){
  94.             System.out.println("1. Inventory");
  95.             System.out.println("2. Battle");
  96.             System.out.println("3. Shop");
  97.             System.out.println("4. Save");
  98.             System.out.println("5. Back");
  99.             int choice_game = input.nextInt();
  100.             if (choice_game==1){
  101.                 System.out.println("***************");
  102.                 System.out.println("Sword level: " + sword_lvl);
  103.                 System.out.println("Shield level: " +  shield_lvl);
  104.                 System.out.println("Armor level: " +  armor_lvl);
  105.                 System.out.println("***************");
  106.             }
  107.             else if (choice_game==2){
  108.                 balance = battle(balance);
  109.             }
  110.             else if (choice_game==3){
  111.                
  112.             }
  113.             else if (choice_game==4){
  114.                 System.out.println("Save in slot 1, 2 or 3?");
  115.                 int number = input.nextInt();
  116.                 save(number, name, sword_lvl, shield_lvl, armor_lvl, balance);
  117.             }
  118.             else if (choice_game==5){
  119.                 return;
  120.             }
  121.         }
  122.     }
  123.     public static void welcome_msg(){
  124.         System.out.println("You are trapped in an arena. The only way out is to fight your way out.");
  125.         System.out.println("You have been given a sword, a shield and some protetictive armor which you can upgrade inside the arena.");
  126.         System.out.println("Good luck.");
  127.     }
  128.     public static void main(String[] args)throws Exception{
  129.         int programOn = 1;
  130.         while (programOn==1){
  131.             System.out.println("1. Load");
  132.             System.out.println("2. New game");
  133.             System.out.println("3. Quit");
  134.             int choice_slng = input.nextInt();
  135.             if (choice_slng==1){
  136.                
  137.             }
  138.             else if (choice_slng==2){
  139.                 welcome_msg();
  140.                 int sword_lvl = 1;
  141.                 int shield_lvl = 1;
  142.                 int armor_lvl = 1;
  143.                 int balance = 1000;
  144.                 System.out.println("What is your name?");
  145.                 String name = input.next();
  146.                 game(sword_lvl, shield_lvl, armor_lvl, name, balance);
  147.             }
  148.             else if(choice_slng==3){
  149.                 programOn = 0;
  150.             }
  151.         }
  152.     }
  153. }
Add Comment
Please, Sign In to add comment