commit 56d08a6a6c1dbbb82de5d5763a02f89ef09f7405 Author: Michael Rodin Date: Fri Jun 6 19:22:24 2025 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3052af9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/** + +!/.gitignore +!/README.md +!/Makefile +!/manifest.txt +!/src** diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b309bc4 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ + +build: $(shell find src -type f) #src/de/sus/*/*.java src/de/sus/Main.java + mkdir build 2>/dev/null || (rm -r build && mkdir build) + cd src && javac -d ../build de/sus/Main.java + +package: build + cd build && jar cfm ../Staedte-und-Strassen.jar ../manifest.txt * \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9812eb7 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Städte und Straßen +Städte und Straßen ist ein Siedler von Catan-Klon. + + +## Funktionen +* TBA + +## Kompilieren +Im Wurzelverzeichnis: +```sh +make build +``` + +Für eine jar-Datei: +```sh +make package +``` diff --git a/manifest.txt b/manifest.txt new file mode 100644 index 0000000..8411c84 --- /dev/null +++ b/manifest.txt @@ -0,0 +1,2 @@ +Built-By: people +Main-Class: de.sus.Main diff --git a/src/de/sus/Main.java b/src/de/sus/Main.java new file mode 100644 index 0000000..8ae76dd --- /dev/null +++ b/src/de/sus/Main.java @@ -0,0 +1,22 @@ +package de.sus; + +import de.sus.world.*; +import de.sus.Tests; // Remove in production + +/** + * Main class, initialises and runs the game + * @author Michael Rodin + * @version 2025-06-10 + */ +class Main { + /** + * Main function, initialises the game + * @author Michael Rodin + * @param args command parameters (unused) + */ + public static void main(String[] args) { + System.out.println("Hello, world!"); + Tests.tests(null); // Remove in production + } + +} \ No newline at end of file diff --git a/src/de/sus/Tests.java b/src/de/sus/Tests.java new file mode 100644 index 0000000..3348814 --- /dev/null +++ b/src/de/sus/Tests.java @@ -0,0 +1,36 @@ +package de.sus; + +import de.sus.world.*; + + +/** + * Class for storing and executing tests + * @author Michael Rodin + * @version 2025-06-10 + */ +class Tests { + /** + * Tests for various parts + * @author Michael Rodin + * @param test a selector for the test to run, will execute everything if null + */ + public static void tests(String test) { + switch (test) { + case null: + case "resource_values": // Prints out all values from Resource enum + for (Resource i: Resource.values()) { + System.out.println(i); + } + + case "boardfields_count": + Board board = new Board(5); + for (Field[] i: board.getFields()) { + System.out.println(i.length); + } + + default: + break; + } + } + +} \ No newline at end of file diff --git a/src/de/sus/world/Board.java b/src/de/sus/world/Board.java new file mode 100644 index 0000000..8d50147 --- /dev/null +++ b/src/de/sus/world/Board.java @@ -0,0 +1,44 @@ +package de.sus.world; + +import java.util.Random; + +public class Board { + /** Container for the fields on the board */ + private Field[][] boardfields; + + /** + * Constructor + * @author Michael Rodin + * @param size the radius of the boards aka. field count of the horizontal + */ + public Board(int size) { + if (size < 1) throw new IllegalArgumentException("The size must be 1 or higher!"); + + this.boardfields = new Field[size][]; + + int i = size/2-1; + int count = 0; + + if (size % 2 == 1) { + this.boardfields[size/2] = new Field[size]; + count = 1; + } + + for (; i >= 0; i--, count++) { + this.boardfields[i] = new Field[size-count]; + this.boardfields[size-1-i] = new Field[size-count]; + } + + Random random = new Random(); + for (Field[] k: this.boardfields) { + for (Field j: k) { + j = new Field(Resource.getRandom(), random.nextInt(12)+1); + System.out.println(j); + } + } + } + + public Field[][] getFields() { + return this.boardfields; + } +} \ No newline at end of file diff --git a/src/de/sus/world/Field.java b/src/de/sus/world/Field.java new file mode 100644 index 0000000..d077410 --- /dev/null +++ b/src/de/sus/world/Field.java @@ -0,0 +1,29 @@ +package de.sus.world; + +/** + * Implements the map's fields + * @author Michael Rodin + * @version 2025-06-10 + */ +public class Field { + /** The type of resource this field provides */ + private Resource type; + /** The rolled number the field activates on */ + private int rollnumber; + + /** + * Constructor + * @author Michael Rodin + * @param type the field's type + * @param number the number that needs to be rolled to be activated + */ + public Field(Resource type, int number) { + this.type = type; + this.rollnumber = number; + } + + @Override + public String toString() { + return this.type + " " + this.rollnumber; + } +} \ No newline at end of file diff --git a/src/de/sus/world/Resource.java b/src/de/sus/world/Resource.java new file mode 100644 index 0000000..366ed98 --- /dev/null +++ b/src/de/sus/world/Resource.java @@ -0,0 +1,50 @@ +package de.sus.world; + +import java.util.Random; + +/** + * Defines all possible field resources + * @author Michael Rodin + * @version 2025-06-10 + */ +public enum Resource { + WOOD("Wood"), + STONE("Stone"), + SHEEP("Sheep"), + CLAY("Clay"), + WHEAT("Wheat"); + + /** The representing string for the resource's type */ + private final String name; + + /** + * Constructor + * @author Michael Rodin + */ + Resource(String name) { + this.name = name; + } + + /** + * Getter for the resource's name + * @author Michael Rodin + * @return the string representation of the resource + */ + public String getName() { + return this.name; + } + + @Override + public String toString() { + return this.name; + } + + /** + * Returns a random Resource + * @author Michael Rodin + * @return random Resource enum type + */ + public static Resource getRandom() { + return Resource.values()[new Random().nextInt(Resource.values().length)]; + } +} \ No newline at end of file