Advertisement
Guest User

Untitled

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