Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.18 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.Vector;
  3.  
  4. public class test{
  5.  
  6. static Scanner scan=new Scanner(System.in);
  7. static String username="";
  8. static int leveluser=1;
  9. static int troopyuser=0;
  10. static int total=0;
  11. static int slot=10;
  12. static int userattack1=100;
  13. static int usermoney=50000;
  14. static int userhp;
  15. static int choose=10;
  16. static int troopy=0;
  17. static int levelenemy[] = new int[100];
  18. static Vector<Integer> pangkat = new Vector<Integer>();
  19. static int table2=10;
  20. static int userdefence=0;
  21. static int userdamage=0;
  22. static int damageenemy=0;
  23. static int flag2=0;
  24. Vector<String> soldier = new Vector<String>();
  25. Vector<Integer> attack = new Vector<Integer>();
  26. Vector<Integer> hp = new Vector<Integer>();
  27. static String username1[]=new String[8];
  28. Vector<Integer> troopyenemy=new Vector<Integer>();
  29. Vector<Integer> attackenemy=new Vector<Integer>();
  30. Vector<Integer> defence=new Vector<Integer>();
  31. Vector<Integer> money=new Vector<Integer>();
  32. Vector<Integer> xp =new Vector<Integer> ();
  33.  
  34.  
  35. void spasi()
  36. {
  37. for(int i=0;i<25;i++)
  38. {
  39. System.out.println("");
  40. }
  41. }
  42.  
  43. //---ENEMY
  44. void enemy(){
  45.  
  46. for(int i=0;i<8;i++){
  47. xp.add(0);
  48. }
  49. username1[0]="Alita";
  50. levelenemy[0]=10;
  51. troopyenemy.add(300);
  52. attackenemy.add(1000);
  53. defence.add(612);
  54. money.add(146000);
  55. username1[1]="Stevanus";
  56. levelenemy[1]=20;
  57. troopyenemy.get(1500);
  58. attackenemy.add(777);
  59. defence.add(900);
  60. money.add(120000);
  61. username1[2]="Even";
  62. levelenemy[2]=22;
  63. troopyenemy.add(400);
  64. attackenemy.add(1700);
  65. defence.add(1200);
  66. money.add(175000);
  67. username1[3]="Rudi";
  68. levelenemy[3]=5;
  69. troopyenemy.add(200);
  70. attackenemy.add(900);
  71. defence.add(900);
  72. money.add(100000);
  73. username1[4]="Alam";
  74. levelenemy[4]=15;
  75. troopyenemy.add(250);
  76. attackenemy.add(1400);
  77. defence.add(612) ;
  78. money.add(131000);
  79. username1[5]="Robin";
  80. levelenemy[5]=31;
  81. troopyenemy.add(1100);
  82. attackenemy.add(1200);
  83. defence.add(2200);
  84. money.get(257200);
  85. username1[6]="Velinda";
  86. levelenemy[6]=5;
  87. troopyenemy.add(100);
  88. attackenemy.add(950);
  89. defence.add(301);
  90. money.add(40000);
  91. username1[7]="Andi";
  92. levelenemy[7]=2;
  93. troopyenemy.add(50);
  94. attackenemy.add(850);
  95. defence.add(150);
  96. money.add(20000);
  97.  
  98.  
  99. String pendapat="";
  100. Random rand= new Random();
  101. int angka=rand.nextInt((8-1) + 1 ) + 1;
  102. do{
  103. System.out.println("Your status");
  104. System.out.println("============================");
  105. System.out.println("Level : "+leveluser);
  106. System.out.println("Tropy : "+troopyuser);
  107. System.out.println("Attack : "+userattack1);
  108. System.out.println("HP : "+userhp);
  109. System.out.println("Money : $"+usermoney);
  110. System.out.println("============================");
  111. System.out.println("Enemy status");
  112. System.out.println("============================");
  113. System.out.println("Name : "+username1[angka]);
  114. System.out.println("Level : "+levelenemy[angka]);
  115. System.out.println("Tropy : "+troopyenemy.add(angka));
  116. System.out.println("Attack : "+attackenemy.get(angka));
  117. System.out.println("Defence : "+defence.get(angka));
  118. System.out.println("Money : $"+money.get(angka));
  119. System.out.println("============================");
  120. System.out.println("Attack "+username1[angka]+" [Y/N] :");
  121. pendapat=scan.nextLine();
  122. if(pendapat.equals("Y")){
  123. flag2=1;
  124. }else if(pendapat.equals("N")){
  125. match();
  126. }
  127. scan.nextLine();
  128. }while(flag2!=1);
  129.  
  130. //rumus yang nentuin menang kalahnya user
  131.  
  132. userattack1+=attack.get(angka);
  133. userdefence=hp.get(angka);
  134. userdamage=userattack1-defence.get(angka);
  135. damageenemy=attackenemy.get(angka)-userdefence;
  136.  
  137. //validasi antara menang atau kalah
  138. if(userdamage>damageenemy)
  139. {
  140. userhp+=25;
  141. usermoney+=money.get(angka);
  142. troopyuser+=25;
  143. xp.set(angka, xp.get(angka)+5);
  144. troopyenemy.set(angka, troopyenemy.get(angka)+5);
  145. money.set(angka, money.get(angka-usermoney));
  146. System.out.println("you win");
  147. System.out.println("you got 25 hp");
  148. System.out.println("you got 25 troopy");
  149. }
  150. if(userdamage<damageenemy)
  151. {
  152. xp.set(angka, xp.get(angka)+25);
  153. troopyenemy.set(angka, troopyenemy.get(angka)+25);
  154. userhp+=5;
  155. troopyuser+=5;
  156. System.out.println("you lose");
  157. System.out.println("you got 5 hp");
  158. System.out.println("you got 5 troopy");
  159. }
  160. //levelup
  161. if(userhp>100)
  162. {
  163. leveluser+=1;
  164. userattack1+=20;
  165. userhp=0;
  166. }
  167.  
  168. /*if(xp[angka]>100){
  169.  
  170. attackenemy[angka]+=20;
  171. levelenemy[angka]+=1;
  172. xp[angka]=0;
  173. }*/
  174.  
  175.  
  176. }
  177. //--LOGIN
  178. void login(){
  179. spasi();
  180. //enemy();
  181. String email="";
  182. String password="";
  183. int pass;
  184. String alamat="";
  185.  
  186. do{
  187. System.out.println("Input your email [ex: stevanusyohanesvcn@gmail.com] : ");
  188. email=scan.nextLine();
  189. }while(email.contains("@gmail.com")==false);
  190.  
  191. do{
  192. System.out.println("Input your username [3..20] :");
  193. username=scan.nextLine();
  194. }while(username.length()<3 || username.length()>20);
  195.  
  196. do{
  197. System.out.println("Input your password [ex: stevanus123] :");
  198. password=scan.nextLine();
  199. }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);
  200.  
  201. System.out.print("Register success!");
  202. scan.nextLine();
  203. spasi();
  204. menu2();
  205.  
  206. }
  207. //--UPGRADE
  208. void upgrade(){
  209. String pilihan2="";
  210. int flag;
  211. int index;
  212. view();
  213.  
  214. do{
  215. System.out.println("Input soldier name for battle :");
  216.  
  217. pilihan2=scan.nextLine();
  218.  
  219. if(pilihan2.startsWith("Barbarian"))
  220. {
  221. flag=1;
  222. index=0;
  223. pangkat.set(index, pangkat.get(index)+1);
  224.  
  225. }else if(pilihan2.startsWith("Archer"))
  226. {
  227. flag=1;
  228. index=1;
  229. pangkat.set(index, pangkat.get(index)+1);
  230.  
  231. }else if(pilihan2.startsWith("Giant"))
  232. {
  233. flag=1;
  234. index=2;
  235. pangkat.set(index, pangkat.get(index)+1);
  236.  
  237. }else{ System.out.println("No soldier for this name "+pilihan2);flag=0;}
  238.  
  239.  
  240.  
  241.  
  242. }while(flag!=1);
  243.  
  244.  
  245. }
  246. //--VOID VIEW
  247. void view(){
  248.  
  249. int number=3;
  250.  
  251. Vector<Integer> cost=new Vector<Integer>();
  252. soldier.add("Barbarian");
  253. pangkat.add(1);
  254. attack.add(50);
  255. hp.add(150);
  256. cost.add(2);
  257. soldier.add("Archer ");
  258. pangkat.add(1);
  259. attack.add(70);
  260. hp.add(50);
  261. cost.add(1);
  262. soldier.add("Giant ");
  263. pangkat.add(1);
  264. attack.add(20);
  265. hp.add(220);
  266. cost.add(51);
  267.  
  268. spasi();
  269.  
  270. //table soldier
  271. System.out.println("List Soldier");
  272. System.out.println("=====================");
  273. System.out.println("+------------------------------------------------------+");
  274. System.out.println("|Nama |Level |Attack |Hp |Cost |");
  275. System.out.println("+------------------------------------------------------+");
  276. for(int i=0;i<number;i++)
  277. {
  278. System.out.println("|"+soldier.get(i)+" |"+pangkat.get(i)+ " |"+attack.get(i)+ " |"+hp.get(i)+ " |"+cost.get(i)+" |");
  279. System.out.println("+------------------------------------------------------+");
  280. }
  281.  
  282. scan.nextLine();
  283.  
  284. }
  285. void buy()
  286. {
  287. String pembelian="";
  288. System.out.println("List Soldier");
  289. System.out.println("=====================");
  290. System.out.println("");
  291. System.out.println("Level Requitment is 5");
  292. System.out.println("=====================");
  293. System.out.println("+------------------------------------------------------+");
  294. System.out.println("|Nama |Attack |Hp |Cost |Price |");
  295. System.out.println("+------------------------------------------------------+");
  296. System.out.println("|Wizard |120 |100 |6 |10000 |");
  297. System.out.println("|Dragon |220 |200 |7 |30000 |");
  298. System.out.println("+------------------------------------------------------+");
  299.  
  300. System.out.println("Level Requitment is 15");
  301. System.out.println("=====================");
  302. System.out.println("+------------------------------------------------------+");
  303. System.out.println("|Nama |Attack |Hp |Cost |Price |");
  304. System.out.println("+------------------------------------------------------+");
  305. System.out.println("|Pekka |500 |300 |10 |50000 |");
  306. System.out.println("|Minion |200 |100 |3 |80000 |");
  307. System.out.println("+------------------------------------------------------+");
  308. System.out.println("");
  309.  
  310. System.out.println("Level Requitment is 35");
  311. System.out.println("=====================");
  312. System.out.println("+------------------------------------------------------+");
  313. System.out.println("|Nama |Attack |Hp |Cost |Price |");
  314. System.out.println("+------------------------------------------------------+");
  315. System.out.println("|Hog Rider |350 |200 |8 |120000 |");
  316. System.out.println("|Golem |200 |500 |10 |170000 |");
  317. System.out.println("+------------------------------------------------------+");
  318. System.out.println("");
  319.  
  320. System.out.println("Level Requitment is 40");
  321. System.out.println("=====================");
  322. System.out.println("+------------------------------------------------------+");
  323. System.out.println("|Nama |Attack |Hp |Cost |Price |");
  324. System.out.println("+------------------------------------------------------+");
  325. System.out.println("|Lava Hound|500 |500 |12 |300000 |");
  326. System.out.println("+------------------------------------------------------+");
  327. System.out.println("");
  328. System.out.println("");
  329.  
  330. System.out.print("Input soldier name: ");
  331. pembelian=scan.nextLine();
  332. scan.nextLine();
  333. if(leveluser<5)
  334. {
  335. System.out.println("sorry your level not enough");
  336. scan.nextLine();
  337. }
  338.  
  339.  
  340. }
  341. void match(){
  342. String pilihan="";
  343. int qty=0;
  344. int kali=0;
  345. int flag=0;
  346.  
  347. do{
  348. //table soldier
  349. view();
  350.  
  351. do{
  352. System.out.println("Input soldier name for battle :");
  353.  
  354. pilihan=scan.nextLine();
  355.  
  356. if(pilihan.startsWith("Barbarian"))
  357. {
  358. flag=1;
  359. kali=2;
  360. choose=0;
  361. slot1();
  362. table2=0;
  363.  
  364.  
  365. }else if(pilihan.startsWith("Archer"))
  366. {
  367. flag=1;
  368. kali=1;
  369. choose=1;
  370. slot1();
  371. table2=1;
  372. }else if(pilihan.startsWith("Giant"))
  373. {
  374. flag=1;
  375. kali=5;
  376. choose=2;
  377. slot1();
  378. table2=2;
  379. }else{ System.out.println("No soldier for this name "+pilihan);flag=0;}
  380.  
  381.  
  382.  
  383.  
  384. }while(flag!=1);
  385.  
  386. total+=total;
  387. System.out.println("Input quantity soldier [your slot : "+slot+"] :");
  388. qty=scan.nextInt();
  389. total=qty*kali;
  390. if(total>slot){
  391. System.out.println("you have not enough slot");
  392. scan.nextLine();
  393. }
  394.  
  395.  
  396. }while(total!=slot);
  397. spasi();
  398. //list soldier yang akan ikut bertempur
  399. System.out.println("List Soldier");
  400. System.out.println("=====================");
  401. System.out.println("+-------------------------------------------+");
  402. System.out.println("|Nama |Attack |Hp |Quantity |");
  403. System.out.println("+-------------------------------------------+");
  404. System.out.println("|"+soldier.get(table2)+" |"+attack.get(table2)+" |"+hp.get(table2)+" |"+qty+" |");
  405. System.out.println("+-------------------------------------------+");
  406. System.out.println("Press enter to find match...");
  407. scan.nextLine();
  408. scan.nextLine();
  409. userattack1=userattack1+attack.get(table2)*qty;
  410. userhp=hp.get(table2)*qty;
  411.  
  412. for(int i=0;i<10;i++){
  413. spasi();
  414. System.out.print("|");
  415.  
  416. try{
  417. Thread.sleep(1000);
  418. }catch(Exception e)
  419. {
  420.  
  421. }
  422. spasi();System.out.println("/");
  423. try{
  424. Thread.sleep(1000);
  425. }catch(Exception e)
  426. {
  427.  
  428. }
  429. spasi();System.out.println("--");
  430. try{
  431. Thread.sleep(1000);
  432. }catch(Exception e)
  433. {
  434.  
  435. }
  436.  
  437. spasi();System.out.println("\\");
  438. try{
  439. Thread.sleep(1000);
  440. }catch(Exception e)
  441. {
  442.  
  443. }
  444. spasi();System.out.println("|");
  445. try{
  446. Thread.sleep(500);
  447. }catch(Exception e)
  448. {
  449.  
  450. }
  451. spasi();System.out.println("/");
  452. try{
  453. Thread.sleep(500);
  454. }catch(Exception e)
  455. {
  456.  
  457. }
  458. spasi();System.out.println("--");
  459. try{
  460. Thread.sleep(500);
  461. }catch(Exception e)
  462. {
  463.  
  464. }
  465. spasi();System.out.println("\\");
  466. try{
  467. Thread.sleep(500);
  468. }catch(Exception e)
  469. {
  470.  
  471. }
  472. enemy();
  473. }
  474.  
  475. }
  476. void slot1(){
  477.  
  478. if(pangkat.get(choose)<=5){slot=10;}
  479. else if(pangkat.get(choose)<=15){slot=20;}
  480. else if(pangkat.get(choose)<=35){slot=30;}
  481. else if(pangkat.get(choose)<=40){slot=40;}
  482. else if(pangkat.get(choose)<=50){slot=50;}
  483. else{slot=0;}
  484.  
  485. }
  486. void soldier(){
  487. //void pasukan yang di case
  488. view();
  489.  
  490.  
  491. }
  492. void rangking(){
  493.  
  494. String username1[]=new String[8];
  495. int level[]=new int[100];
  496. int troopyenemy[]=new int[100];
  497. int attackenemy[]=new int[100];
  498. int defence[]=new int[100];
  499. int money[]=new int[10];
  500. int xp[]=new int[100];
  501. for(int i=0;i<8;i++){
  502. xp[i]=0;
  503. }
  504. username1[0]="Alita ";
  505. level[0]=10;
  506. troopyenemy[0]=300;
  507. attackenemy[0]=1000;
  508. defence[0]=612;
  509. money[0]=146000;
  510. username1[1]="Stevanus";
  511. level[1]=20;
  512. troopyenemy[1]=1500;
  513. attackenemy[1]=777;
  514. defence[1]=900;
  515. money[1]=120000;
  516. username1[2]="Even ";
  517. level[2]=22;
  518. troopyenemy[2]=400;
  519. attackenemy[2]=1700;
  520. defence[2]=1200;
  521. money[2]=175000;
  522. username1[3]="Rudi ";
  523. level[3]=5;
  524. troopyenemy[3]=200;
  525. attackenemy[3]=900;
  526. defence[3]=900;
  527. money[3]=100000;
  528. username1[4]="Alam ";
  529. level[4]=15;
  530. troopyenemy[4]=250;
  531. attackenemy[4]=1400;
  532. defence[4]=612;
  533. money[4]=131000;
  534. username1[5]="Robin ";
  535. level[5]=31;
  536. troopyenemy[5]=1100;
  537. attackenemy[5]=1200;
  538. defence[5]=2200;
  539. money[5]=257200;
  540. username1[6]="Velinda ";
  541. level[6]=5;
  542. troopyenemy[6]=100;
  543. attackenemy[6]=950;
  544. defence[6]=301;
  545. money[6]=40000;
  546. username1[7]="Andi ";
  547. level[7]=2;
  548. troopyenemy[7]=50;
  549. attackenemy[7]=850;
  550. defence[7]=150;
  551. money[7]=20000;
  552.  
  553. System.out.println("List Ranking");
  554. System.out.println("==================================");
  555. System.out.println("+-----------------------------------------------+");
  556. System.out.println("|Nama |Tropy |Level |");
  557. System.out.println("+-----------------------------------------------+");
  558. for(int i=0;i<8;i++)
  559. {
  560. System.out.println("+-----------------------------------------------+");
  561. System.out.println("|"+username1[i]+" |"+troopyenemy[i]+" |"+level[i]+ "|");
  562. }
  563. System.out.println("+-----------------------------------------------+");
  564. System.out.println("|"+username+" |"+troopyuser+ "|"+leveluser+ "|");
  565. System.out.println("+-----------------------------------------------+");
  566.  
  567.  
  568.  
  569. }
  570. void menu2(){
  571. int menu3;
  572. int flag=0;
  573. do{
  574. System.out.println("Hello,"+username);
  575. System.out.println("1. Find match");
  576. System.out.println("2. Soldier");
  577. System.out.println("3. Buy soldier");
  578. System.out.println("4. Ranking");
  579. System.out.println("5. View Status");
  580. System.out.println("6. Exit");
  581. System.out.print("Choose :");
  582. try{
  583. menu3=scan.nextInt();
  584. flag=menu3;
  585. }catch(Exception e)
  586. {
  587. System.out.println("sorry you must input Number ");
  588. scan.nextLine();
  589. }
  590.  
  591. //switch case
  592. switch(flag)
  593. {
  594. case 1:match();break;
  595. case 2:upgrade();break;
  596. case 3:buy();break;
  597. case 4:rangking();break;
  598. case 5:view();break;
  599.  
  600. }
  601.  
  602. }while(flag!=6);
  603.  
  604. }
  605.  
  606.  
  607. test()
  608. {
  609. login();
  610. }
  611.  
  612. public static void main(String[] args){
  613.  
  614. System.out.println(" ______ __ _____ ______ __ __ ");
  615. System.out.println("/ ____/\\ /\\_\\ /\\___/\\ / ____/\\ /\\_\\ /_/\\ ");
  616. System.out.println(") ) __\\/( ( ( / / _ \\ \\ ) ) __\\/( ( (_) ) ) ");
  617. System.out.println("\\ \\ \\ \\ \\_\\ \\ \\(_)/ / \\ \\ \\ \\ \\___/ /");
  618. System.out.println("_\\ \\ \\ / / /__ / / _ \\ \\ _\\ \\ \\ / / _ \\ \\ ");
  619. System.out.println(")____) )( (_____(( (_( )_) ))____) )( (_( )_) )");
  620. System.out.println("\\____\\/ \\/_____/ \\/_/ \\_\\/ \\____\\/ \\/_/ \\_\\/");
  621. System.out.println(" _____ _____");
  622. System.out.println(" ) ___ ( /\\_____\\ ");
  623. System.out.println("/ /\\_/\\ \\( ( ___/");
  624. System.out.println("/ /_/ (_\\ \\ \\ \\_");
  625. System.out.println("\\ \\ )_/ / // / /_\\ ");
  626. System.out.println(" \\ \\/_\\/ // /____/");
  627. System.out.println(")_____( \\/_/");
  628. System.out.println(" _____ __ _____ __ __ ______");
  629. System.out.println(" /\\ __/\\ /\\_\\ /\\___/\\ /_/\\ /\\_\\/ ____/\\ ");
  630. System.out.println(" ) )__\\/ ( ( ( / / _ \\ \\ ) ) \\ ( () ) __\\/");
  631. System.out.println(" / / / \\ \\_\\ \\ \\(_)/ //_/ \\ \\_\\\\ \\ \\ ");
  632. System.out.println(" \\ \\ \\_ / / /__ / / _ \\ \\\\ \\ \\ / /_\\ \\ \\ ");
  633. System.out.println(" ) )__/\\( (_____(( (_( )_) ))_) \\ (_()____) )");
  634. System.out.println(" \\/___\\/ \\/_____/ \\/_/ \\_\\/ \\_\\/ \\/_/\\____\\/");
  635. System.out.println("");
  636. System.out.print("Press enter to continue . . .");
  637.  
  638. scan.nextLine();
  639.  
  640. new test();
  641.  
  642.  
  643. }
  644. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement