View difference between Paste ID: uCEuS3BZ and 9L6j8Z32
SHOW: | | - or go back to the newest paste.
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> level = new Vector<Integer>();
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
static String test[] = new String[100];
25
Vector<Integer> attack = new Vector<Integer>();
26
Vector<Integer> hp = new Vector<Integer>();
27
static String username1[]=new String[8];
28
static int troopyenemy[]=new int[100];
29
static int attackenemy[]=new int[100];
30
static int defence[]=new int[100];
31
static int money[]=new int[10];
32
static int xp[]=new int[100];
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[i]=0;
48
	}
49
	username1[0]="Alita";
50
	levelenemy[0]=10;
51
	troopyenemy[0]=300;
52
	attackenemy[0]=1000;
53
	defence[0]=612;
54
	money[0]=146000;
55
	username1[1]="Stevanus";
56
	levelenemy[1]=20;
57
	troopyenemy[1]=1500;
58
	attackenemy[1]=777;
59
	defence[1]=900;
60
	money[1]=120000;
61
	username1[2]="Even";
62
	levelenemy[2]=22;
63
	troopyenemy[2]=400;
64
	attackenemy[2]=1700;
65
	defence[2]=1200;
66
	money[2]=175000;
67
	username1[3]="Rudi";
68
	levelenemy[3]=5;
69
	troopyenemy[3]=200;
70
	attackenemy[3]=900;
71
	defence[3]=900;
72
	money[3]=100000;
73
	username1[4]="Alam";
74
	levelenemy[4]=15;
75
	troopyenemy[4]=250;
76
	attackenemy[4]=1400;
77
	defence[4]=612;
78
	money[4]=131000;
79
	username1[5]="Robin";
80
	levelenemy[5]=31;
81
	troopyenemy[5]=1100;
82
	attackenemy[5]=1200;
83
	defence[5]=2200;
84
	money[5]=257200;
85
	username1[6]="Velinda";
86
	levelenemy[6]=5;
87
	troopyenemy[6]=100;
88
	attackenemy[6]=950;
89
	defence[6]=301;
90
	money[6]=40000;
91
	username1[7]="Andi";
92
	levelenemy[7]=2;
93
	troopyenemy[7]=50;
94
	attackenemy[7]=850;
95
	defence[7]=150;
96
	money[7]=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[angka]);
116
	System.out.println("Attack  : "+attackenemy[angka]);
117
	System.out.println("Defence : "+defence[angka]);
118
	System.out.println("Money   : $"+money[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
    int i=angka;
132
	userattack1+=attack.get(i);
133
	userdefence=hp.get(i);
134
	userdamage=userattack1-defence[angka];
135
	damageenemy=attackenemy[angka]-userdefence;
136
137
    //validasi antara menang atau kalah
138
	if(userdamage>damageenemy)
139
	{
140
		userhp+=25;
141
		usermoney+=money[angka];
142
		troopyuser+=25;
143
		xp[angka]+=5;
144
		troopyenemy[angka]+=5;
145
		money[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[angka]+=25;
153
		troopyenemy[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
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 level=1;
211+
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
224
		}else if(pilihan2.startsWith("Archer"))
225
		{
226
			flag=1;
227
			index=1;
228
            pangkat.set(index, pangkat.get(index)+1);
229-
            level.set(index, level.get(index)+1);
229+
230
		}else if(pilihan2.startsWith("Giant"))
231
		{
232
			flag=1;
233
			index=2;
234
235
		}else{ System.out.println("No soldier for this name "+pilihan2);flag=0;}
236
237
238
239
240
       }while(flag!=1);
241
242
243
}
244
//--VOID VIEW
245
void view(){
246
247
    int number=3;
248
249
	int cost []=new int [100];
250
	test[0]="Barbarian";
251
	pangkat.add(1);
252-
	level.add(1);
252+
253
	hp.add(150);
254
	cost[0]=2;
255
	test[1]="Archer   ";
256
	pangkat.add(1);
257-
	level.add(1);
257+
258
	hp.add(50);
259
	cost[1]=1;
260
	test[2]="Giant    ";
261
	pangkat.add(1);
262-
	level.add(1);
262+
263
	hp.add(220);
264
	cost[2]=51;
265
266
     spasi();
267
268
           //table soldier
269
	        System.out.println("List Soldier");
270
			System.out.println("=====================");
271
	        System.out.println("+------------------------------------------------------+");
272
		    System.out.println("|Nama            |Level   |Attack    |Hp        |Cost      |");
273
		    System.out.println("+------------------------------------------------------+");
274
			for(int i=0;i<number;i++)
275
			    {
276
					System.out.println("|"+test[i]+"       |"+pangkat.get(i)+         "       |"+attack.get(i)+        "        |"+hp.get(i)+       "       |"+cost[i]+"      |");
277-
					System.out.println("|"+test[i]+"       |"+level.get(i)+         "       |"+attack.get(i)+        "        |"+hp.get(i)+       "       |"+cost[i]+"      |");
277+
278
                }
279
280
scan.nextLine();
281
282
}
283
void buy()
284
{
285
	String pembelian="";
286
	System.out.println("List Soldier");
287
	System.out.println("=====================");
288
	System.out.println("");
289
	System.out.println("Level Requitment is 5");
290
	System.out.println("=====================");
291
	System.out.println("+------------------------------------------------------+");
292
	System.out.println("|Nama      |Attack    |Hp        |Cost      |Price     |");
293
	System.out.println("+------------------------------------------------------+");
294
	System.out.println("|Wizard    |120       |100       |6         |10000     |");
295
	System.out.println("|Dragon    |220       |200       |7         |30000     |");
296
	System.out.println("+------------------------------------------------------+");
297
298
	System.out.println("Level Requitment is 15");
299
	System.out.println("=====================");
300
	System.out.println("+------------------------------------------------------+");
301
	System.out.println("|Nama      |Attack    |Hp        |Cost      |Price     |");
302
	System.out.println("+------------------------------------------------------+");
303
	System.out.println("|Pekka     |500       |300       |10        |50000     |");
304
	System.out.println("|Minion    |200       |100       |3         |80000     |");
305
	System.out.println("+------------------------------------------------------+");
306
	System.out.println("");
307
308
	System.out.println("Level Requitment is 35");
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("|Hog Rider |350       |200       |8         |120000    |");
314
	System.out.println("|Golem     |200       |500       |10        |170000    |");
315
	System.out.println("+------------------------------------------------------+");
316
	System.out.println("");
317
318
	System.out.println("Level Requitment is 40");
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("|Lava Hound|500       |500       |12        |300000    |");
324
	System.out.println("+------------------------------------------------------+");
325
	System.out.println("");
326
	System.out.println("");
327
328
    System.out.print("Input soldier name: ");
329
    pembelian=scan.nextLine();
330
    scan.nextLine();
331
    if(leveluser<5)
332
    {
333
		System.out.println("sorry your level not enough");
334
		scan.nextLine();
335
	}
336
337
338
}
339
void match(){
340
	String pilihan="";
341
    int qty=0;
342
	int kali=0;
343
    int flag=0;
344
345
	do{
346
		//table soldier
347
         view();
348
349
    do{
350
    System.out.println("Input soldier name for battle  :");
351
352
    pilihan=scan.nextLine();
353
354
    if(pilihan.startsWith("Barbarian"))
355
    {
356
		flag=1;
357
	    kali=2;
358
	    choose=0;
359
	    slot1();
360
	    table2=0;
361
362
363
	}else if(pilihan.startsWith("Archer"))
364
	{
365
		flag=1;
366
		kali=1;
367
		choose=1;
368
		slot1();
369
		table2=1;
370
	}else if(pilihan.startsWith("Giant"))
371
	{
372
		flag=1;
373
		kali=5;
374
		choose=2;
375
		slot1();
376
		table2=2;
377
	}else{ System.out.println("No soldier for this name "+pilihan);flag=0;}
378
379
380
381
382
       }while(flag!=1);
383
384
       total+=total;
385
       System.out.println("Input quantity soldier [your slot : "+slot+"] :");
386
       qty=scan.nextInt();
387
       total=qty*kali;
388
       if(total>slot){
389
		   System.out.println("you have not enough slot");
390
		   scan.nextLine();
391
	   }
392
393
394
}while(total!=slot);
395
spasi();
396
//list soldier yang akan ikut bertempur
397
System.out.println("List Soldier");
398
System.out.println("=====================");
399
System.out.println("+-------------------------------------------+");
400
System.out.println("|Nama           |Attack    |Hp        |Quantity  |");
401
System.out.println("+-------------------------------------------+");
402
System.out.println("|"+test[table2]+"      |"+attack.get(table2)+"        |"+hp.get(table2)+"       |"+qty+"         |");
403
System.out.println("+-------------------------------------------+");
404
System.out.println("Press enter to find match...");
405
scan.nextLine();
406
scan.nextLine();
407
userattack1=userattack1+attack.get(table2)*qty;
408
userhp=hp.get(table2)*qty;
409
410
for(int i=0;i<10;i++){
411
spasi();
412
System.out.print("|");
413
414
try{
415
		Thread.sleep(1000);
416
	}catch(Exception e)
417
{
418
419
}
420
spasi();System.out.println("/");
421
try{
422
		Thread.sleep(1000);
423
	}catch(Exception e)
424
{
425
426
}
427
spasi();System.out.println("--");
428
try{
429
	Thread.sleep(1000);
430
	}catch(Exception e)
431
{
432
433
}
434
435
spasi();System.out.println("\\");
436
try{
437
		Thread.sleep(1000);
438
	}catch(Exception e)
439
{
440
441
}
442
spasi();System.out.println("|");
443
try{
444
		Thread.sleep(500);
445
	}catch(Exception e)
446
{
447
448
}
449
spasi();System.out.println("/");
450
try{
451
		Thread.sleep(500);
452
	}catch(Exception e)
453
{
454
455
}
456
spasi();System.out.println("--");
457
try{
458
		Thread.sleep(500);
459
	}catch(Exception e)
460
{
461
462
}
463
spasi();System.out.println("\\");
464
try{
465
		Thread.sleep(500);
466
	}catch(Exception e)
467
{
468
469
}
470
enemy();
471
}
472
473
}
474
void slot1(){
475
476
	     if(pangkat.get(choose)<=5){slot=10;}
477-
	     if(level.get(choose)<=5){slot=10;}
477+
	else if(pangkat.get(choose)<=15){slot=20;}
478-
	else if(level.get(choose)<=15){slot=20;}
478+
	else if(pangkat.get(choose)<=35){slot=30;}
479-
	else if(level.get(choose)<=35){slot=30;}
479+
	else if(pangkat.get(choose)<=40){slot=40;}
480-
	else if(level.get(choose)<=40){slot=40;}
480+
	else if(pangkat.get(choose)<=50){slot=50;}
481-
	else if(level.get(choose)<=50){slot=50;}
481+
482
483
}
484
void soldier(){
485
//void pasukan yang di case
486
	view();
487
488
489
}
490
void rangking(){
491
492
	    String username1[]=new String[8];
493
		int level[]=new int[100];
494
		int troopyenemy[]=new int[100];
495
		int attackenemy[]=new int[100];
496
		int defence[]=new int[100];
497
		int money[]=new int[10];
498
		int xp[]=new int[100];
499
		for(int i=0;i<8;i++){
500
			xp[i]=0;
501
		}
502
		username1[0]="Alita   ";
503
		level[0]=10;
504
		troopyenemy[0]=300;
505
		attackenemy[0]=1000;
506
		defence[0]=612;
507
		money[0]=146000;
508
		username1[1]="Stevanus";
509
		level[1]=20;
510
		troopyenemy[1]=1500;
511
		attackenemy[1]=777;
512
		defence[1]=900;
513
		money[1]=120000;
514
		username1[2]="Even    ";
515
		level[2]=22;
516
		troopyenemy[2]=400;
517
		attackenemy[2]=1700;
518
		defence[2]=1200;
519
		money[2]=175000;
520
		username1[3]="Rudi    ";
521
		level[3]=5;
522
		troopyenemy[3]=200;
523
		attackenemy[3]=900;
524
		defence[3]=900;
525
		money[3]=100000;
526
		username1[4]="Alam    ";
527
		level[4]=15;
528
		troopyenemy[4]=250;
529
		attackenemy[4]=1400;
530
		defence[4]=612;
531
		money[4]=131000;
532
		username1[5]="Robin   ";
533
		level[5]=31;
534
		troopyenemy[5]=1100;
535
		attackenemy[5]=1200;
536
		defence[5]=2200;
537
		money[5]=257200;
538
		username1[6]="Velinda ";
539
		level[6]=5;
540
		troopyenemy[6]=100;
541
		attackenemy[6]=950;
542
		defence[6]=301;
543
		money[6]=40000;
544
		username1[7]="Andi    ";
545
		level[7]=2;
546
		troopyenemy[7]=50;
547
		attackenemy[7]=850;
548
		defence[7]=150;
549
	    money[7]=20000;
550
551
	System.out.println("List Ranking");
552
	System.out.println("==================================");
553
	System.out.println("+-----------------------------------------------+");
554
	System.out.println("|Nama                     |Tropy     |Level     |");
555
	System.out.println("+-----------------------------------------------+");
556
	for(int i=0;i<8;i++)
557
	{
558
    	System.out.println("+-----------------------------------------------+");
559
		System.out.println("|"+username1[i]+"                 |"+troopyenemy[i]+"      |"+level[i]+        "|");
560
    }
561
     System.out.println("+-----------------------------------------------+");
562
     System.out.println("|"+username+"                   |"+troopyuser+          "|"+leveluser+       "|");
563
     System.out.println("+-----------------------------------------------+");
564
565
566
567
}
568
void menu2(){
569
	int menu3;
570
	int flag=0;
571
do{
572
	System.out.println("Hello,"+username);
573
	System.out.println("1. Find match");
574
	System.out.println("2. Soldier");
575
	System.out.println("3. Buy soldier");
576
	System.out.println("4. Ranking");
577
	System.out.println("5. View Status");
578
	System.out.println("6. Exit");
579
      System.out.print("Choose :");
580
      try{
581
          menu3=scan.nextInt();
582
          flag=menu3;
583
         }catch(Exception e)
584
         {
585
			System.out.println("sorry you must input Number ");
586
			scan.nextLine();
587
		 }
588
589
		 //switch case
590
		 switch(flag)
591
		 {
592
			 case 1:match();break;
593
			 case 2:upgrade();break;
594
			 case 3:buy();break;
595
			 case 4:rangking();break;
596
			 case 5:view();break;
597
598
		 }
599
600
	}while(flag!=6);
601
602
}
603
604
605
test()
606
{
607
login();
608
}
609
610
			public static void main(String[] args){
611
612
		System.out.println(" ______   __        _____    ______   __   __ ");
613
		System.out.println("/ ____/\\ /\\_\\      /\\___/\\  / ____/\\ /\\_\\ /_/\\ ");
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.print("Press enter to continue . . .");
635
636
         scan.nextLine();
637
638
         new test();
639
640
641
}
642
}