import java.io.*;
import java.util.*;
public class consoleGame{
public BufferedReader reader;
public String name;
public int gold;
public int dmg1;
public int dmg2;
public int win1;
public int win2;
public String again;
public String shop;
public String decision;
public int dmg;
public String weapon0;
public Random random;
public int axe;
public int mace;
public int axeObj;
public int maceObj;
public int decision0;
public void game()throws IOException{
reader = new BufferedReader(new InputStreamReader(System.in));
random = new Random();
System.out.print("Enter your name: ");
name = reader.readLine();
do{
/**//**//**//**//**//**//**//**//**//**//**//**/
/**//**//**//**//**//**//**//**//**//**//**//**/
/**/ if(axe != 1 && mace != 1){ /**/
/**/ weapon0 = "Sword";} /**/
/**/ /**/
/**/ else if(axe == 1){ /**/
/**/ weapon0 = "Axe";} /**/
/**/ /**/
/**/ else if(mace ==1){ /**/
/**/ weapon0 = "Mace";} /**/
/**/ /**/
/**//**//**//**//**//**//**//**//**//**//**//**/
/**//**//**//**//**//**//**//**//**//**//**//**/
for(int i=0; i<=10; i++) System.out.println();
System.out.println("--------------------");
System.out.println(" --OVERVIEW--");
System.out.println("Your name is: " + name);
System.out.println("Your weapon: " + weapon0);
System.out.println("Your health: 1/1");
System.out.println("Your gold: " + gold);
System.out.println("--------------------");
System.out.print('\n' + "Press any key to start fight or [shop] to enter the shop:");
shop = reader.readLine();
/**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/
/**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/
/**/ if(shop.equals("shop")){ /**/
/**/ for (int i=0; i<=3; i++) System.out.println(); /**/
/**/ System.out.println("+---------------SHOP-------------------+"); /**/
/**/ System.out.println("| FOR SALE |"); /**/
/**/ System.out.println("| Axe-300g. |"); /**/
/**/ System.out.println("| Mace-500g. |"); /**/
/**/ System.out.println("| |"); /**/
/**/ System.out.print("|" + "Press [1] to buy axe, [2] to buy mace." + "|"); /**/
/**/ /**/
/**/ decision = reader.readLine(); /**/
/**/ decision0 = Integer.parseInt(decision); /**/
/**/ /**/
/**/ if(decision0 == 1 && gold >= 300){ /**/
/**/ axe = 1; /**/
/**/ mace = 0; /**/
/**/ System.out.println("You bought an axe!"); /**/
/**/ System.out.println('\n' + "Press enter to leave shop..."); /**/
/**/ String leave = reader.readLine(); /**/
/**/ } /**/
/**/ else if (decision0 == 2 && gold >=500){ /**/
/**/ mace = 1; /**/
/**/ axe = 0; /**/
/**/ System.out.println("You bought a mace!"); /**/
/**/ System.out.println('\n' + "Press enter to leave shop..."); /**/
/**/ String leave = reader.readLine(); /**/
/**/ } /**/
/**/ else if ((decision0 == 1 && (gold != 300 || gold < 300))){ /**/
/**/ System.out.println("Not enough gold."); /**/
/**/ axe = 0; /**/
/**/ mace = 0; /**/
/**/ } /**/
/**/ else if ((decision0 == 2 && (gold != 500 || gold < 500))){ /**/
/**/ System.out.println("Not enough gold."); /**/
/**/ axe = 0; /**/
/**/ mace = 0; /**/
/**/ } /**/
/**/ } /**/
/**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/
/**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/
if(axe !=1 && mace !=1){
dmg = 20;}
if(axe == 1){
dmg = 50;
axe = 1;}
if(mace == 1){
dmg = 80;
mace = 1;}
//////////////////////////////////////////////START OF FIGHT////////////////////////////////////////////////
dmg1 = random.nextInt(dmg);
dmg2 = random.nextInt(20);
for(int i=0; i<=2; i++) System.out.println();
System.out.println("Round one: ");
System.out.println(name + " " + dmg1 + " VS" + " " + dmg2 + " " + "CPU");
if(dmg1 > dmg2){
System.out.println('\n' + name + " wins!");
gold = gold + 50;
win1 = 1;
win2 = 0;
}
else if(dmg1 < dmg2){
System.out.println('\n' + "CPU wins!");
gold = gold + 0;
win1 = 0;
win2 = 0;
}
else if (dmg1 == dmg2){
System.out.println('\n' + "Tie!");
gold = gold + 0;
win1 = 0;
win2 = 0;
}
System.out.println("Press enter to proceed...");
again = reader.readLine();
}
while(!again.equals("n"));
}
///////////////////////////////////////CALLING PROGRAM/////////////////////////////////////////////////////
public static void main(String args[])throws IOException{
consoleGame x = new consoleGame();
x.game();
}
}
Comments