oder auch doch nicht

This commit is contained in:
Johannes Theiner 2018-03-09 09:41:10 +01:00
parent 967abdba8f
commit 8ad3198be3
3 changed files with 1 additions and 102 deletions

1
README.md Normal file
View File

@ -0,0 +1 @@
Als Abschlussaufgabe des Praktikums Java 1 sollte ein spielbares Monopoly entwickelt werden.

View File

@ -1,16 +0,0 @@
package de.joethei.monopoly;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter @AllArgsConstructor
public abstract class Action {
private String name;
public abstract void execute(Player player);
@Override
public String toString() {
return name;
}
}

View File

@ -1,86 +0,0 @@
package de.joethei.monopoly;
import de.joethei.monopoly.colors.BoldColor;
import de.joethei.monopoly.colors.ConsoleColor;
import de.joethei.monopoly.colors.NormalColor;
import de.joethei.monopoly.fields.Field;
import de.joethei.monopoly.fields.Street;
import lombok.Getter;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class Main {
@Getter private static List<Player> players = new LinkedList<>();
@Getter private static CircularLinkedList<Field> fields = new CircularLinkedList<>();
public static void main(String[] args) {
Random random = new Random();
fields.add(new Street("Hausweg", BoldColor.RED));
fields.add(new Street("Torstraße", BoldColor.RED));
fields.add(new Street("Baumstraße", BoldColor.BLUE));
fields.add(new Street("Hotelstraße", BoldColor.BLUE));
fields.add(new Street("Straßenweg", BoldColor.GREEN));
fields.add(new Street("Hauptstraße", BoldColor.GREEN));
fields.add(new Street("Mauerstraße", BoldColor.CYAN));
fields.add(new Street("TesterStraße", BoldColor.CYAN));
Scanner scanner = new Scanner(System.in);
System.out.println("Spieleranzahl eingeben");
int playerNumber = scanner.nextInt();
for (int i = 0; i < playerNumber; i++) {
System.out.println("Name des " + (players.size() + 1) + ". Spielers eingeben");
players.add(new Player(scanner.next(), NormalColor.values()[i]));
}
boolean running = true;
while(running) {
if(players.size() <= 0) {
Player player = players.get(0);
System.out.println(player.getColor().getColorCode() + player.getName() + " hat gewonnen");
running = false;
}
for(Player player : players) {
if(player.getMoney() <= 0) {
System.out.println(player.getColor().getColorCode() + player.getName() + " ist ausgeschieden");
players.remove(player);
}
Field field = fields.get(player.getField() + (random.nextInt(10) + 2));
if(field instanceof Street) {
Street street = (Street) field;
if(street.getOwner() == null) {
System.out.println(player.getColor().getColorCode() +
"Möchtest du das Feld " + street.getColor().getColorCode() + field.getName() +
player.getColor().getColorCode() + " kaufen ?");
if(scanner.next().equalsIgnoreCase("ja")) {
player.buy(street);
}
}else {
if(street.getOwner() == player && street.getHouses() < 5) {
System.out.println(player.getColor().getColorCode() + "Möchtest du auf dem Feld " + street.getColor().getColorCode() +
street.getName() + player.getColor().getColorCode() + " ein Haus bauen ?");
if(scanner.next().equalsIgnoreCase("ja")) field.getOptionalAction().execute(player);
}
field.getRequiredAction().execute(player);
}
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static long getFieldsByColor(ConsoleColor color) {
return fields.stream().filter(field -> field instanceof Street && ((Street) field).getColor().equals(color)).count();
}
}