Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.Vector;
- public class test{
- static Scanner scan=new Scanner(System.in);
- static String username="";
- static int leveluser=1;
- static int troopyuser=0;
- static int total=0;
- static int slot=10;
- static int userattack1=100;
- static int usermoney=50000;
- static int userhp;
- static int choose=10;
- static int troopy=0;
- static int levelenemy[] = new int[100];
- static Vector<Integer> pangkat = new Vector<Integer>();
- static int table2=10;
- static int userdefence=0;
- static int userdamage=0;
- static int damageenemy=0;
- static int flag2=0;
- static String test[] = new String[100];
- Vector<Integer> attack = new Vector<Integer>();
- Vector<Integer> hp = new Vector<Integer>();
- static String username1[]=new String[8];
- static int troopyenemy[]=new int[100];
- static int attackenemy[]=new int[100];
- static int defence[]=new int[100];
- static int money[]=new int[10];
- static int xp[]=new int[100];
- void spasi()
- {
- for(int i=0;i<25;i++)
- {
- System.out.println("");
- }
- }
- //---ENEMY
- void enemy(){
- for(int i=0;i<8;i++){
- xp[i]=0;
- }
- username1[0]="Alita";
- levelenemy[0]=10;
- troopyenemy[0]=300;
- attackenemy[0]=1000;
- defence[0]=612;
- money[0]=146000;
- username1[1]="Stevanus";
- levelenemy[1]=20;
- troopyenemy[1]=1500;
- attackenemy[1]=777;
- defence[1]=900;
- money[1]=120000;
- username1[2]="Even";
- levelenemy[2]=22;
- troopyenemy[2]=400;
- attackenemy[2]=1700;
- defence[2]=1200;
- money[2]=175000;
- username1[3]="Rudi";
- levelenemy[3]=5;
- troopyenemy[3]=200;
- attackenemy[3]=900;
- defence[3]=900;
- money[3]=100000;
- username1[4]="Alam";
- levelenemy[4]=15;
- troopyenemy[4]=250;
- attackenemy[4]=1400;
- defence[4]=612;
- money[4]=131000;
- username1[5]="Robin";
- levelenemy[5]=31;
- troopyenemy[5]=1100;
- attackenemy[5]=1200;
- defence[5]=2200;
- money[5]=257200;
- username1[6]="Velinda";
- levelenemy[6]=5;
- troopyenemy[6]=100;
- attackenemy[6]=950;
- defence[6]=301;
- money[6]=40000;
- username1[7]="Andi";
- levelenemy[7]=2;
- troopyenemy[7]=50;
- attackenemy[7]=850;
- defence[7]=150;
- money[7]=20000;
- String pendapat="";
- Random rand= new Random();
- int angka=rand.nextInt((8-1) + 1 ) + 1;
- do{
- System.out.println("Your status");
- System.out.println("============================");
- System.out.println("Level : "+leveluser);
- System.out.println("Tropy : "+troopyuser);
- System.out.println("Attack : "+userattack1);
- System.out.println("HP : "+userhp);
- System.out.println("Money : $"+usermoney);
- System.out.println("============================");
- System.out.println("Enemy status");
- System.out.println("============================");
- System.out.println("Name : "+username1[angka]);
- System.out.println("Level : "+levelenemy[angka]);
- System.out.println("Tropy : "+troopyenemy[angka]);
- System.out.println("Attack : "+attackenemy[angka]);
- System.out.println("Defence : "+defence[angka]);
- System.out.println("Money : $"+money[angka]);
- System.out.println("============================");
- System.out.println("Attack "+username1[angka]+" [Y/N] :");
- pendapat=scan.nextLine();
- if(pendapat.equals("Y")){
- flag2=1;
- }else if(pendapat.equals("N")){
- match();
- }
- scan.nextLine();
- }while(flag2!=1);
- //rumus yang nentuin menang kalahnya user
- int i=angka;
- userattack1+=attack.get(i);
- userdefence=hp.get(i);
- userdamage=userattack1-defence[angka];
- damageenemy=attackenemy[angka]-userdefence;
- //validasi antara menang atau kalah
- if(userdamage>damageenemy)
- {
- userhp+=25;
- usermoney+=money[angka];
- troopyuser+=25;
- xp[angka]+=5;
- troopyenemy[angka]+=5;
- money[angka]-=usermoney;
- System.out.println("you win");
- System.out.println("you got 25 hp");
- System.out.println("you got 25 troopy");
- }
- if(userdamage<damageenemy)
- {
- xp[angka]+=25;
- troopyenemy[angka]+=25;
- userhp+=5;
- troopyuser+=5;
- System.out.println("you lose");
- System.out.println("you got 5 hp");
- System.out.println("you got 5 troopy");
- }
- //levelup
- if(userhp>100)
- {
- leveluser+=1;
- userattack1+=20;
- userhp=0;
- }
- /*if(xp[angka]>100){
- attackenemy[angka]+=20;
- levelenemy[angka]+=1;
- xp[angka]=0;
- }*/
- }
- //--LOGIN
- void login(){
- spasi();
- String email="";
- String password="";
- int pass;
- String alamat="";
- do{
- System.out.println("Input your email [ex: stevanusyohanesvcn@gmail.com] : ");
- email=scan.nextLine();
- }while(email.contains("@gmail.com")==false);
- do{
- System.out.println("Input your username [3..20] :");
- username=scan.nextLine();
- }while(username.length()<3 || username.length()>20);
- do{
- System.out.println("Input your password [ex: stevanus123] :");
- password=scan.nextLine();
- }while(password.contains("0")==false&&password.contains("1")==false &&password.contains("2")==false&&password.contains("3")==false&&password.contains("4")==false&&password.contains("5")==false&&password.contains("6")==false &&password.contains("7")==false &&password.contains("8")==false&&password.contains("9")==false);
- System.out.print("Register success!");
- scan.nextLine();
- spasi();
- menu2();
- }
- //--UPGRADE
- void upgrade(){
- String pilihan2="";
- int flag;
- int index;
- view();
- do{
- System.out.println("Input soldier name for battle :");
- pilihan2=scan.nextLine();
- if(pilihan2.startsWith("Barbarian"))
- {
- flag=1;
- index=0;
- }else if(pilihan2.startsWith("Archer"))
- {
- flag=1;
- index=1;
- pangkat.set(index, pangkat.get(index)+1);
- }else if(pilihan2.startsWith("Giant"))
- {
- flag=1;
- index=2;
- }else{ System.out.println("No soldier for this name "+pilihan2);flag=0;}
- }while(flag!=1);
- }
- //--VOID VIEW
- void view(){
- int number=3;
- int cost []=new int [100];
- test[0]="Barbarian";
- pangkat.add(1);
- attack.add(50);
- hp.add(150);
- cost[0]=2;
- test[1]="Archer ";
- pangkat.add(1);
- attack.add(70);
- hp.add(50);
- cost[1]=1;
- test[2]="Giant ";
- pangkat.add(1);
- attack.add(20);
- hp.add(220);
- cost[2]=51;
- spasi();
- //table soldier
- System.out.println("List Soldier");
- System.out.println("=====================");
- System.out.println("+------------------------------------------------------+");
- System.out.println("|Nama |Level |Attack |Hp |Cost |");
- System.out.println("+------------------------------------------------------+");
- for(int i=0;i<number;i++)
- {
- System.out.println("|"+test[i]+" |"+pangkat.get(i)+ " |"+attack.get(i)+ " |"+hp.get(i)+ " |"+cost[i]+" |");
- System.out.println("+------------------------------------------------------+");
- }
- scan.nextLine();
- }
- void buy()
- {
- String pembelian="";
- System.out.println("List Soldier");
- System.out.println("=====================");
- System.out.println("");
- System.out.println("Level Requitment is 5");
- System.out.println("=====================");
- System.out.println("+------------------------------------------------------+");
- System.out.println("|Nama |Attack |Hp |Cost |Price |");
- System.out.println("+------------------------------------------------------+");
- System.out.println("|Wizard |120 |100 |6 |10000 |");
- System.out.println("|Dragon |220 |200 |7 |30000 |");
- System.out.println("+------------------------------------------------------+");
- System.out.println("Level Requitment is 15");
- System.out.println("=====================");
- System.out.println("+------------------------------------------------------+");
- System.out.println("|Nama |Attack |Hp |Cost |Price |");
- System.out.println("+------------------------------------------------------+");
- System.out.println("|Pekka |500 |300 |10 |50000 |");
- System.out.println("|Minion |200 |100 |3 |80000 |");
- System.out.println("+------------------------------------------------------+");
- System.out.println("");
- System.out.println("Level Requitment is 35");
- System.out.println("=====================");
- System.out.println("+------------------------------------------------------+");
- System.out.println("|Nama |Attack |Hp |Cost |Price |");
- System.out.println("+------------------------------------------------------+");
- System.out.println("|Hog Rider |350 |200 |8 |120000 |");
- System.out.println("|Golem |200 |500 |10 |170000 |");
- System.out.println("+------------------------------------------------------+");
- System.out.println("");
- System.out.println("Level Requitment is 40");
- System.out.println("=====================");
- System.out.println("+------------------------------------------------------+");
- System.out.println("|Nama |Attack |Hp |Cost |Price |");
- System.out.println("+------------------------------------------------------+");
- System.out.println("|Lava Hound|500 |500 |12 |300000 |");
- System.out.println("+------------------------------------------------------+");
- System.out.println("");
- System.out.println("");
- System.out.print("Input soldier name: ");
- pembelian=scan.nextLine();
- scan.nextLine();
- if(leveluser<5)
- {
- System.out.println("sorry your level not enough");
- scan.nextLine();
- }
- }
- void match(){
- String pilihan="";
- int qty=0;
- int kali=0;
- int flag=0;
- do{
- //table soldier
- view();
- do{
- System.out.println("Input soldier name for battle :");
- pilihan=scan.nextLine();
- if(pilihan.startsWith("Barbarian"))
- {
- flag=1;
- kali=2;
- choose=0;
- slot1();
- table2=0;
- }else if(pilihan.startsWith("Archer"))
- {
- flag=1;
- kali=1;
- choose=1;
- slot1();
- table2=1;
- }else if(pilihan.startsWith("Giant"))
- {
- flag=1;
- kali=5;
- choose=2;
- slot1();
- table2=2;
- }else{ System.out.println("No soldier for this name "+pilihan);flag=0;}
- }while(flag!=1);
- total+=total;
- System.out.println("Input quantity soldier [your slot : "+slot+"] :");
- qty=scan.nextInt();
- total=qty*kali;
- if(total>slot){
- System.out.println("you have not enough slot");
- scan.nextLine();
- }
- }while(total!=slot);
- spasi();
- //list soldier yang akan ikut bertempur
- System.out.println("List Soldier");
- System.out.println("=====================");
- System.out.println("+-------------------------------------------+");
- System.out.println("|Nama |Attack |Hp |Quantity |");
- System.out.println("+-------------------------------------------+");
- System.out.println("|"+test[table2]+" |"+attack.get(table2)+" |"+hp.get(table2)+" |"+qty+" |");
- System.out.println("+-------------------------------------------+");
- System.out.println("Press enter to find match...");
- scan.nextLine();
- scan.nextLine();
- userattack1=userattack1+attack.get(table2)*qty;
- userhp=hp.get(table2)*qty;
- for(int i=0;i<10;i++){
- spasi();
- System.out.print("|");
- try{
- Thread.sleep(1000);
- }catch(Exception e)
- {
- }
- spasi();System.out.println("/");
- try{
- Thread.sleep(1000);
- }catch(Exception e)
- {
- }
- spasi();System.out.println("--");
- try{
- Thread.sleep(1000);
- }catch(Exception e)
- {
- }
- spasi();System.out.println("\\");
- try{
- Thread.sleep(1000);
- }catch(Exception e)
- {
- }
- spasi();System.out.println("|");
- try{
- Thread.sleep(500);
- }catch(Exception e)
- {
- }
- spasi();System.out.println("/");
- try{
- Thread.sleep(500);
- }catch(Exception e)
- {
- }
- spasi();System.out.println("--");
- try{
- Thread.sleep(500);
- }catch(Exception e)
- {
- }
- spasi();System.out.println("\\");
- try{
- Thread.sleep(500);
- }catch(Exception e)
- {
- }
- enemy();
- }
- }
- void slot1(){
- if(pangkat.get(choose)<=5){slot=10;}
- else if(pangkat.get(choose)<=15){slot=20;}
- else if(pangkat.get(choose)<=35){slot=30;}
- else if(pangkat.get(choose)<=40){slot=40;}
- else if(pangkat.get(choose)<=50){slot=50;}
- else{slot=0;}
- }
- void soldier(){
- //void pasukan yang di case
- view();
- }
- void rangking(){
- String username1[]=new String[8];
- int level[]=new int[100];
- int troopyenemy[]=new int[100];
- int attackenemy[]=new int[100];
- int defence[]=new int[100];
- int money[]=new int[10];
- int xp[]=new int[100];
- for(int i=0;i<8;i++){
- xp[i]=0;
- }
- username1[0]="Alita ";
- level[0]=10;
- troopyenemy[0]=300;
- attackenemy[0]=1000;
- defence[0]=612;
- money[0]=146000;
- username1[1]="Stevanus";
- level[1]=20;
- troopyenemy[1]=1500;
- attackenemy[1]=777;
- defence[1]=900;
- money[1]=120000;
- username1[2]="Even ";
- level[2]=22;
- troopyenemy[2]=400;
- attackenemy[2]=1700;
- defence[2]=1200;
- money[2]=175000;
- username1[3]="Rudi ";
- level[3]=5;
- troopyenemy[3]=200;
- attackenemy[3]=900;
- defence[3]=900;
- money[3]=100000;
- username1[4]="Alam ";
- level[4]=15;
- troopyenemy[4]=250;
- attackenemy[4]=1400;
- defence[4]=612;
- money[4]=131000;
- username1[5]="Robin ";
- level[5]=31;
- troopyenemy[5]=1100;
- attackenemy[5]=1200;
- defence[5]=2200;
- money[5]=257200;
- username1[6]="Velinda ";
- level[6]=5;
- troopyenemy[6]=100;
- attackenemy[6]=950;
- defence[6]=301;
- money[6]=40000;
- username1[7]="Andi ";
- level[7]=2;
- troopyenemy[7]=50;
- attackenemy[7]=850;
- defence[7]=150;
- money[7]=20000;
- System.out.println("List Ranking");
- System.out.println("==================================");
- System.out.println("+-----------------------------------------------+");
- System.out.println("|Nama |Tropy |Level |");
- System.out.println("+-----------------------------------------------+");
- for(int i=0;i<8;i++)
- {
- System.out.println("+-----------------------------------------------+");
- System.out.println("|"+username1[i]+" |"+troopyenemy[i]+" |"+level[i]+ "|");
- }
- System.out.println("+-----------------------------------------------+");
- System.out.println("|"+username+" |"+troopyuser+ "|"+leveluser+ "|");
- System.out.println("+-----------------------------------------------+");
- }
- void menu2(){
- int menu3;
- int flag=0;
- do{
- System.out.println("Hello,"+username);
- System.out.println("1. Find match");
- System.out.println("2. Soldier");
- System.out.println("3. Buy soldier");
- System.out.println("4. Ranking");
- System.out.println("5. View Status");
- System.out.println("6. Exit");
- System.out.print("Choose :");
- try{
- menu3=scan.nextInt();
- flag=menu3;
- }catch(Exception e)
- {
- System.out.println("sorry you must input Number ");
- scan.nextLine();
- }
- //switch case
- switch(flag)
- {
- case 1:match();break;
- case 2:upgrade();break;
- case 3:buy();break;
- case 4:rangking();break;
- case 5:view();break;
- }
- }while(flag!=6);
- }
- test()
- {
- login();
- }
- public static void main(String[] args){
- System.out.println(" ______ __ _____ ______ __ __ ");
- System.out.println("/ ____/\\ /\\_\\ /\\___/\\ / ____/\\ /\\_\\ /_/\\ ");
- System.out.println(") ) __\\/( ( ( / / _ \\ \\ ) ) __\\/( ( (_) ) ) ");
- System.out.println("\\ \\ \\ \\ \\_\\ \\ \\(_)/ / \\ \\ \\ \\ \\___/ /");
- System.out.println("_\\ \\ \\ / / /__ / / _ \\ \\ _\\ \\ \\ / / _ \\ \\ ");
- System.out.println(")____) )( (_____(( (_( )_) ))____) )( (_( )_) )");
- System.out.println("\\____\\/ \\/_____/ \\/_/ \\_\\/ \\____\\/ \\/_/ \\_\\/");
- System.out.println(" _____ _____");
- System.out.println(" ) ___ ( /\\_____\\ ");
- System.out.println("/ /\\_/\\ \\( ( ___/");
- System.out.println("/ /_/ (_\\ \\ \\ \\_");
- System.out.println("\\ \\ )_/ / // / /_\\ ");
- System.out.println(" \\ \\/_\\/ // /____/");
- System.out.println(")_____( \\/_/");
- System.out.println(" _____ __ _____ __ __ ______");
- System.out.println(" /\\ __/\\ /\\_\\ /\\___/\\ /_/\\ /\\_\\/ ____/\\ ");
- System.out.println(" ) )__\\/ ( ( ( / / _ \\ \\ ) ) \\ ( () ) __\\/");
- System.out.println(" / / / \\ \\_\\ \\ \\(_)/ //_/ \\ \\_\\\\ \\ \\ ");
- System.out.println(" \\ \\ \\_ / / /__ / / _ \\ \\\\ \\ \\ / /_\\ \\ \\ ");
- System.out.println(" ) )__/\\( (_____(( (_( )_) ))_) \\ (_()____) )");
- System.out.println(" \\/___\\/ \\/_____/ \\/_/ \\_\\/ \\_\\/ \\/_/\\____\\/");
- System.out.println("");
- System.out.print("Press enter to continue . . .");
- scan.nextLine();
- new test();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement