Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pkg;
- import java.io.*;
- import java.util.*;
- /*
- * load
- * shop
- *
- */
- public class Spel_1 {
- public static Scanner input = new Scanner(System.in);
- public static void save(int number, String name, int Item_1_i, int Item_2_i, int Item_3_i, int balance) throws Exception{
- if (number==1){
- FileWriter saveFile1 = new FileWriter("save1.txt");
- saveFile1.write(name + "\n");
- saveFile1.write(Item_1_i + "\n");
- saveFile1.write(Item_2_i + "\n");
- saveFile1.write(Item_3_i + "\n");
- saveFile1.write(balance + "\n");
- saveFile1.close();
- }
- else if (number==2){
- FileWriter saveFile2 = new FileWriter("save2.txt");
- saveFile2.write(name + "\n");
- saveFile2.write(Item_1_i + "\n");
- saveFile2.write(Item_2_i + "\n");
- saveFile2.write(Item_3_i + "\n");
- saveFile2.write(balance + "\n");
- saveFile2.close();
- }
- else if (number==3){
- FileWriter saveFile3 = new FileWriter("save3.txt");
- saveFile3.write(name + "\n");
- saveFile3.write(Item_1_i + "\n");
- saveFile3.write(Item_2_i + "\n");
- saveFile3.write(Item_3_i + "\n");
- saveFile3.write(balance + "\n");
- saveFile3.close();
- }
- }
- public static void load(int number) throws Exception{
- if (number==1){
- }
- else if (number==2){
- }
- else if (number==3){
- }
- }
- public static int battle(int balance)throws Exception{
- int reward=100;
- String[] array_mob = new String[5];
- array_mob[0] = "Rat";
- array_mob[1] = "Wild Dog";
- array_mob[2] = "Bear";
- array_mob[3] = "Gladiator";
- array_mob[4] = "Dragon";
- String mob = array_mob[(int)(Math.random()*5)];
- int multiplier = 1;
- if (mob.equals("Rat")){
- multiplier = 1;
- }
- else if (mob.equals("Wild Dog")){
- multiplier = 3;
- }
- else if (mob.equals("Bear")){
- multiplier = 5;
- }
- else if (mob.equals("Gladiator")){
- multiplier = 8;
- }
- else if (mob.equals("Dragon")){
- multiplier = 10;
- }
- System.out.println("You have encountered a " + mob);
- int loop = 1;
- while (loop==1){
- int win_lose = (int)(Math.random()*100);
- if (win_lose>50){
- System.out.println("You beat the " + mob + " and recieved " + reward*multiplier + " gold coins.");
- balance = balance + reward*multiplier;
- }
- else{
- System.out.println("You lost the battle.");
- }
- loop = 0;
- }
- return balance;
- }
- public static void game(int sword_lvl, int shield_lvl, int armor_lvl, String name, int balance)throws Exception{
- int play = 1;
- while (play==1){
- System.out.println("1. Inventory");
- System.out.println("2. Battle");
- System.out.println("3. Shop");
- System.out.println("4. Save");
- System.out.println("5. Back");
- int choice_game = input.nextInt();
- if (choice_game==1){
- System.out.println("***************");
- System.out.println("Sword level: " + sword_lvl);
- System.out.println("Shield level: " + shield_lvl);
- System.out.println("Armor level: " + armor_lvl);
- System.out.println("***************");
- }
- else if (choice_game==2){
- balance = battle(balance);
- }
- else if (choice_game==3){
- }
- else if (choice_game==4){
- System.out.println("Save in slot 1, 2 or 3?");
- int number = input.nextInt();
- save(number, name, sword_lvl, shield_lvl, armor_lvl, balance);
- }
- else if (choice_game==5){
- return;
- }
- }
- }
- public static void welcome_msg(){
- System.out.println("You are trapped in an arena. The only way out is to fight your way out.");
- System.out.println("You have been given a sword, a shield and some protetictive armor which you can upgrade inside the arena.");
- System.out.println("Good luck.");
- }
- public static void main(String[] args)throws Exception{
- int programOn = 1;
- while (programOn==1){
- System.out.println("1. Load");
- System.out.println("2. New game");
- System.out.println("3. Quit");
- int choice_slng = input.nextInt();
- if (choice_slng==1){
- }
- else if (choice_slng==2){
- welcome_msg();
- int sword_lvl = 1;
- int shield_lvl = 1;
- int armor_lvl = 1;
- int balance = 1000;
- System.out.println("What is your name?");
- String name = input.next();
- game(sword_lvl, shield_lvl, armor_lvl, name, balance);
- }
- else if(choice_slng==3){
- programOn = 0;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment