Field, Player und Gamemanger in vielen Zügen bereits programmiert. Es läuft noch nicht aber der Grundbau ist fast fertig. [Noch ohne Kommentare]

This commit is contained in:
Lars Nießen 2023-08-04 13:22:28 +02:00
parent 8d76c8bcf0
commit 47797fc963
4 changed files with 205 additions and 0 deletions

View File

@ -0,0 +1,39 @@
import java.util.ArrayList;
import Player;
public class Field {
private int dice_number;
private ArrayList<Field> neighbours;
private Player owner;
public Field(int input_dice_number, Player input_owner){
neighbours = new ArrayList<Field>();
dice_number = input_dice_number;
owner = input_owner;
}
public ArrayList<Field> get_neighbours(){
return neighbours;
}
public void add_neighbour(Field input){
neighbours.add(input);
}
public int get_dice_number(){
return dice_number;
}
public void set_dice_number(int number){
dice_number = number;
}
public Player get_owner(){
return owner;
}
public void set_owner(Player input){
owner = input;
}
}

View File

@ -0,0 +1,137 @@
import Player;
import Field;
import java.util.ArrayList;
import java.util.Random;
public class Max{
private int max;
public Max(int num1, int num2){
if(num1 < num2){
max = num1;
}
else{
max = num2;
}
}
public get_max(){
return max;
}
}
public class AttackInformations{
private int attack_field_dice;
private int defense_field_dice;
private boolean attack_success;
private boolean attack_allowed;
public AttackInformations(int input_att_field, int input_def_field,boolean input_attack_allowed){
attack_field_dice = input_att_field;
defense_field_dice = input_def_field;
attack_success = (input_att_field >= input_def_field);
attack_allowed = input_attack_allowed;
}
public int get_attack_field_dice(){
return attack_field_dice;
}
public int get_defense_field_dice(){
return defense_field_dice;
}
public boolean get_attack_success(){
return attack_success;
}
public boolean get_attack_allowed(){
return attack_allowed;
}
}
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){
players.add(Player(input,players.size()));
}
}
public AttackInformations attack_field(Field att_field, Field def_field){
boolean attack_allowed;
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;
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);
}
AttackInformations infor = new AttackInformations(att_field_sum, def_field_sum,true);
if(infor.get_attack_success()){
def_field.set_dice_number(Max(att_field.get_dice_number()-1,1).get_max());
def_field.set_owner(att_field.get_owner());
}
att_field.set_dice_number(1);
}
return AttackInformations(-1,-1,false);
}
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;
}
}
}

View File

@ -0,0 +1,21 @@
public class Player{
private String name;
private int playerid;
public Player(String input_name, int input_id){
name = input_name;
playerid = input_id;
}
public void set_name(String input_name){
name = input_name;
}
public String get_name(){
return name;
}
public int get_playerid(){
return playerid;
}
}

View File

@ -0,0 +1,8 @@
import GameManager.*;
public class Test {
public static void main(String[] args){
Random rand_num = new Random();
System.out.println(Integer.toString(rand_num.nextInt(2)));
}
}