-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
114 lines (99 loc) · 3.58 KB
/
Game.java
File metadata and controls
114 lines (99 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import java.io.IOException;
import java.util.Random;
import util.ArrayTools;
public class Game{
static Fighter player1;
static Fighter player2;
static Fighter currentFighter;
static Fighter winner;
public static int turns = 0;
public static int rounds = 0;
static Random random = new Random();
static boolean firstPlayer;
public static void main(String[] args) throws IOException, InterruptedException {
player1 = new Fighter("Player");
player2 = new Fighter("Bot 2", "random");
player1.generateCards(6);
player2.generateCards(6);
player1.setTarget(player2);
player2.setTarget(player1);
firstPlayer = random.nextBoolean();
while(!GameOver()){
clearScreen();
display();
getCurrentFighter().play();
turns++;
}
display();
System.out.println("Battle took " + turns + " moves with " + rounds + " turns");
System.out.println(winner.getName() + " has won");
}
public static void display(){
String spacing1 = " ";
String spacing2 = " ";
String spacing3 = " ";
String spacing4 = " ";
String spacing5 = " ";
String spacing6 = " ";
System.out.println(
player1.getName() + spacing1 + player2.getName()
);
System.out.println(
"Health " + player1.getHealth() + spacing2 + player2.getHealth()
);
System.out.println(
"Stanima: " + player1.getStanima() + spacing3 + player2.getStanima()
);
System.out.println(
"Mana: " + player1.getMana() + spacing4 + player2.getMana()
);
System.out.println(
"Cards: " + ArrayTools.toStringHL(player1.getHand(player1.DECKSIZE)) + spacing5 + ArrayTools.toStringHL(player2.getHand(player2.DECKSIZE))
);
System.out.println();
if(turns > 0){
System.out.println(
spacing6 + currentFighter.getName() + " uses " + currentFighter.getCurrentCard().getName()
);
}
System.out.println();
}
public static boolean GameOver(){
if(player1.defeated()){
winner = player2;
}else if(player2.defeated()){
winner = player1;
}
return player1.defeated() || player2.defeated();
}
public static Fighter getCurrentFighter(){
if(currentFighter == null){
if(firstPlayer){
currentFighter = player1;
return player1;
}else{
currentFighter = player2;
return player2;
}
}
if(turns >= currentFighter.getEndTurn()){
currentFighter.endMultiTurn();
rounds++;
if(currentFighter == player1){
currentFighter = player2;
return player2;
}else if(currentFighter == player2){
currentFighter = player1;
return player1;
}else{
currentFighter = player1;
return player1;
}
}else{
return currentFighter;
}
}
public static void clearScreen()throws IOException, InterruptedException {
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
}
}