117 lines
2.8 KiB
Java
117 lines
2.8 KiB
Java
package Manager;
|
|
|
|
import Field.Field;
|
|
import Player.Player;
|
|
import AttackInformations.AttackInformations;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Random;
|
|
|
|
class Max{
|
|
private int max;
|
|
|
|
public Max(int num1, int num2){
|
|
if(num1 < num2){
|
|
max = num1;
|
|
}
|
|
else{
|
|
max = num2;
|
|
}
|
|
}
|
|
|
|
public int get_max(){
|
|
return max;
|
|
}
|
|
}
|
|
|
|
public class GameManager {
|
|
private ArrayList<Field> fields;
|
|
private ArrayList<Player> players;
|
|
private Player current_att_pl;
|
|
private Random rand_num_gen;
|
|
|
|
public GameManager(){
|
|
fields = new ArrayList<Field>();
|
|
players = new ArrayList<Player>();
|
|
rand_num_gen = new Random();
|
|
}
|
|
|
|
public ArrayList<Player> get_players(){
|
|
return players;
|
|
}
|
|
|
|
public void add_player(String input){
|
|
if(players.size() < 8){
|
|
Player pl = new Player(input,players.size());
|
|
players.add(pl);
|
|
}
|
|
}
|
|
|
|
public AttackInformations attack_field(Field att_field, Field def_field){
|
|
boolean attack_allowed= false;
|
|
boolean att_field_allowed = false;
|
|
boolean def_field_allowed = false;
|
|
|
|
for(Field field:fields){
|
|
if(field == att_field){
|
|
att_field_allowed = true;
|
|
}
|
|
if(field == def_field){
|
|
def_field_allowed = true;
|
|
}
|
|
}
|
|
|
|
for(Field neigh:att_field.get_neighbours()){
|
|
if(neigh == def_field){
|
|
attack_allowed = true;
|
|
}
|
|
}
|
|
|
|
attack_allowed = att_field_allowed && def_field_allowed && attack_allowed;
|
|
|
|
AttackInformations infor;
|
|
|
|
if(attack_allowed){
|
|
int att_field_sum = 0;
|
|
int def_field_sum = 0;
|
|
|
|
for(int i = 0; i < att_field.get_dice_number();i++){
|
|
att_field_sum += 1 + rand_num_gen.nextInt(6);
|
|
}
|
|
for(int i = 0; i < def_field.get_dice_number();i++){
|
|
def_field_sum += 1 + rand_num_gen.nextInt(6);
|
|
}
|
|
|
|
infor = new AttackInformations(att_field_sum, def_field_sum,true);
|
|
|
|
if(infor.get_attack_success()){
|
|
Max M = new Max(att_field.get_dice_number()-1,1);
|
|
def_field.set_dice_number(M.get_max());
|
|
|
|
def_field.set_owner(att_field.get_owner());
|
|
}
|
|
att_field.set_dice_number(1);
|
|
}
|
|
else{
|
|
infor = new AttackInformations(-1,-1,false);
|
|
}
|
|
|
|
return infor;
|
|
}
|
|
|
|
public ArrayList<Field> get_fields(){
|
|
return fields;
|
|
}
|
|
|
|
public void new_game(){
|
|
fields.clear();
|
|
|
|
int num_fields = 20 + rand_num_gen.nextInt(10);
|
|
|
|
int[] player_num_fields = new int[players.size()];
|
|
|
|
for(int x: player_num_fields){
|
|
x = 0;
|
|
}
|
|
}
|
|
} |