first commit

This commit is contained in:
Michael Rodin 2025-06-06 19:22:24 +02:00
commit 56d08a6a6c
9 changed files with 214 additions and 0 deletions

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
/**
!/.gitignore
!/README.md
!/Makefile
!/manifest.txt
!/src**

7
Makefile Normal file
View file

@ -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 *

17
README.md Normal file
View file

@ -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
```

2
manifest.txt Normal file
View file

@ -0,0 +1,2 @@
Built-By: people
Main-Class: de.sus.Main

22
src/de/sus/Main.java Normal file
View file

@ -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
}
}

36
src/de/sus/Tests.java Normal file
View file

@ -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;
}
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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)];
}
}