Skip to content

Commit

Permalink
ver 1.1.0-nightly
Browse files Browse the repository at this point in the history
resource management overhaul (resources are now saved in a game entity)
capability to save maps
respawning wildlife and ore
workers build houses
game starts with one worker instead of house
  • Loading branch information
Kerbaltec-Solutions authored Jan 9, 2024
2 parents 8e1acb0 + 4523eb4 commit d8ffe42
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 154 deletions.
57 changes: 20 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,26 @@ In "This is MOD(D)ABLE" the player controls their own tribe, helps it defend its
## Useage:

- Download the version, you would like to use.
- open the console
- Navigate inside the folder "this_is_MOD-D-ABLE"
- ensure, you have .NET 6.0 installed
- on first run, first use "dotnet add Package Accord" to install neccesarry Libraries
- start the program by typing "dotnet run"
- press ENTER to switch in and out of the command input mode.
- in the input mode, type sys:help() to view a list of available commands. (not yet implemented)

## Zielsetzung

- Das Ziel ist das erstellen eines Management/Survival-Spiels ähnlich AoE in C# unter berücksichtigung der Modifizierbarkeit durch Dritte in der Zukunft.
- Die Software soll als Sourcecode verteilt werden und erst bei Ausführung lokal compiliert werden.
- Mittels System.Reflexion soll das Programm selbstständig die Funktionen der Entitäten des Spiels aufrufen können.
- Die Steuerung des Spiels erfolgt hauptsächlich über pseudo-funktionsaufrufe, die der Spieler in die Konsole eingibt.
- Um die Konsole zu öffnen und, um den gezeigten Kartenausschnitt zu ändern soll ein asyncroner Input handler mittels System.Threading geschrieben werden.
- Das Spiel soll in Takten die Eigenschaften sämmtlicher Entitäten bearbeiten und zwar über eine Funktion der Entität, die angibt, was geschehen soll.
- Die Karte, mit Ressourcen, Hindernissen und Farben soll mittels Perlin noise aus der Bibliothek Accord zufällig erzeugt werden.
- Entitäten, die auf der Karte gezeigt werden, sollen über einen einzelnen Charakter repräsentiert werden.
- Die Karte soll mittels variation der Hintergrundfarbe in der Konsole gezeichnet werden.
- normal installation mode (only available for Linux):
- ensure, you have .NET 6.X installed
- open the "this_is_MOD-D-ABLE" folder in your file explorer
- for first installation:
- right click on "setup.sh"
- navigate to "properties/Permissions"
- check "Allow executing file as program"
- close the Properties menu and right click on setup.sh again
- click "Run as a Program"
-starting the game after installation:
- right click on "start.sh"
- click "Run as a Program"
- manual installation and running
- open the console
- Navigate inside the folder "this_is_MOD-D-ABLE"
- ensure, you have .NET 6.0 installed
- on first run, first use "dotnet add Package Accord" to install neccesarry Libraries
- start the program by typing "dotnet run"
- press ENTER to switch in and out of the command input mode.
- in the input mode, type sys:help() to view a list of available commands.

## Vorläufiges Dateizusammenhangsdiagramm
<!--
Expand Down Expand Up @@ -82,21 +83,3 @@ style="width: 90%; max-width: 860px; display: block; margin-left: auto; margin-r
+------------------------------------+
````

## Einschränkung im Rahmen der Abschlussarbeit

Es soll nur das Grundgerüst des Spiels sowie folgende Entitäten und Resourcen erstellt werden.

Entitäten:

- Fighter: Kann andere Entitäten umbringen, Kostet Nahrung und Geld
- Worker: Kann Gestein & Ore abbauen, Kostet Nahrung
- Wildlife (friendly): Kann von Fighter getötet werden, enthält Nahrung
- Wildlife (aggresive): Kann andere Entitäten umbringen, Kann von Fighter getötet werden
- Ore: Kann von Worker abgebaut werden, Enthält Geld
- House: Kann Worker und Fighter ausbilden, Kostet Geld

Resourcen:

- Geld: produziert aus Ore von Worker
- Nahrung: produziert aus Wildlife von Fighter
13 changes: 13 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

echo "for setup, please enter your sudo passwort:"
sudo -s
echo "making startfile executable"
sudo chmod u+r start.sh
echo "adding Accord library"
sudo dotnet add package Accord
echo "install xterm for terminal resizing"
sudo apt-get install xterm
echo "cleaning up"
sudo apt autoremove
./start.sh
35 changes: 5 additions & 30 deletions src/EntityManagement/Entities/AbstractCreature.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
using RoutePlanning;
public abstract class Creature{

protected TIM.main game = null!; // reference go game
public abstract class Creature:Entity{
public bool draw{get;} = true; //if the entity should be drawn on the map
public bool iterate{get;} = true; //if the entity has actions to perform every frame
public abstract bool createByPlayer{get;} //can the entity be created by the player directly

public abstract bool controlledByPlayer{get;} // can the player controll the entity
public abstract char mapChar{get;} //character which will represent the entity on the map
public abstract int mapColor{get;} //color in which the entity will be drawn on the map
protected abstract float speed{get;} //movement speed of the entity in fields per second

protected bool isDead{get;set;} = false;

protected abstract int maxHealthPoints {get;}
protected abstract int healthPoints{get;set;}


public Position position{get;set;} = null!; //current position of the entity
protected Position? target = null; //target position
protected Route? route = null; // currently assigned route
protected functionProperties? tgtEntity = null; // target entity
protected bool trackEntity = false; // is currently following entity
protected float timeSinceLastMove = TIM.main.STEPTIME; // in seconds


//setup function, set position ect.
public virtual void setup(string input, TIM.main game){
this.game = game;
this.position= new Position(Math.Min(int.Parse(input.Split(",")[0]),game.mapsize.X),Math.Min(int.Parse(input.Split(",")[1]),game.mapsize.Y));
this.route = null;
}

// setup for spawning entities at start of game
public virtual void autoSetup(Position pos, TIM.main game){
this.game = game;
this.position = pos;
}

//frame actions
public virtual void step(TIM.main game){
if(isDead){
Expand Down Expand Up @@ -106,16 +84,12 @@ public void getHit(int damage){
healthPoints -= damage;
if(healthPoints <= 0){
isDead = true;

}
}

// functions for player

// prints coordinates of position
public void printPosition(TIM.main game){
Console.WriteLine("{0}",position);
}

// prints current route
public void printRoute(TIM.main game){
if(route != null){
Expand All @@ -128,6 +102,7 @@ public void printRoute(TIM.main game){
// print health points and maximal health points
public void printHP(TIM.main game){
Console.WriteLine("HP: {0} | maxHp: {1}",healthPoints, maxHealthPoints);
Console.WriteLine("Is dead? {0}",isDead);
}

//set a target
Expand All @@ -143,10 +118,10 @@ public void GoTo(string input, TIM.main game){
}

// set new targetEntity
public void GoToEntity(string input, TIM.main game){
public void GoToE(string input, TIM.main game){
// try to find entity
try{
if(controlledByPlayer){
if(controlledByPlayer){
functionProperties entity = game.entities[input];
var boolVar= entity.fType.GetProperty("draw");
if(boolVar!=null){
Expand Down
28 changes: 28 additions & 0 deletions src/EntityManagement/Entities/AbstractEntities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public abstract class Entity{
protected TIM.main game = null!;

public abstract bool createByPlayer{get;} //can the entity be created by the player directly

public abstract bool controlledByPlayer{get;} // can the player controll the entity
public abstract char mapChar{get;} //character which will represent the entity on the map
public abstract int mapColor{get;} //color in which the entity will be drawn on the map

public Position position{get;set;} = null!;

//setup function, set position ect.
public virtual void setup(string input, TIM.main game){
this.game = game;
this.position= new Position(Math.Min(int.Parse(input.Split(",")[0]),game.mapsize.X),Math.Min(int.Parse(input.Split(",")[1]),game.mapsize.Y));
}

// setup for spawning entities at start of game
public virtual void autoSetup(Position pos, TIM.main game){
this.game = game;
this.position = pos;
}

// prints coordinates of position
public void printPosition(TIM.main game){
Console.WriteLine("{0}",position);
}
}
2 changes: 1 addition & 1 deletion src/EntityManagement/Entities/Fighters/AbstractFighter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
public abstract class Fighter :Creature{
public bool isTarget{get;} = true; // creature is target for enemies
protected abstract int damage{get;} // damage the fighter deals per hit
protected abstract int hitRange{get;} // maximal distance to target in which fighter can deal damage

Expand Down Expand Up @@ -71,7 +72,6 @@ public void targetNearestWildlife(TIM.main game){
Console.WriteLine("No Wildlife in range.");
}
}

public void hunt(TIM.main game){
targetNearestWildlife(game);
}
Expand Down
74 changes: 33 additions & 41 deletions src/EntityManagement/Entities/House.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// entity that can be build by player, that is able to spawn entities that are controlled by the player
public class House{
private TIM.main game = null!;
public bool createByPlayer{get;} = true;
using System;
using System.Reflection;
public class House:Entity{

public override bool createByPlayer{get;} = false;
public bool isHouse{get;} = true;
public bool draw{get;} = true;
public char mapChar{get;} = 'H';
public int mapColor{get;} = 4;
public Position position{get;set;} = null!;
public override char mapChar{get;} = 'H';
public override int mapColor{get;} = 4;
public override bool controlledByPlayer{get;} = true; // can the player controll the entity

public void setup(string input, TIM.main g){
game=g;
this.position= new Position(Math.Min(int.Parse(input.Split(",")[0]),game.mapsize.X),Math.Min(int.Parse(input.Split(",")[1]),game.mapsize.Y));
public override void setup(string input, TIM.main g){
base.setup(input, g);
if(!game.gameMap.mapArray[position.X,position.Y].resource.IsWalkable){
throw new NotSupportedException("Position not valid");
}
Expand All @@ -22,45 +23,36 @@ public void setup(string input, TIM.main g){
private int checkMaterials(string entityClass){
switch(entityClass){
case "Worker":{
if(game.materials.Food >= 2){
return 1;
}else{return 0;}
try{
int[] mat ={-2,0};
methods.callMethod("mat_std","IncMaterialsSave",mat,game);
}catch(System.Reflection.TargetInvocationException){
return 0;
}
return 1;
}
case "SwordFighter":{
if(game.materials.Food >= 2 && game.materials.Money >= 2){
return 1;
}else{return 0;}
try{
int[] mat ={-2,-2};
methods.callMethod("mat_std","IncMaterialsSave",mat,game);
}catch(System.Reflection.TargetInvocationException){
return 0;
}
return 1;
}
case "BowFighter":{
if(game.materials.Food >= 2 && game.materials.Money >= 4){
return 1;
}else{return 0;}
try{
int[] mat ={-2,-4};
methods.callMethod("mat_std","IncMaterialsSave",mat,game);
}catch(System.Reflection.TargetInvocationException){
return 0;
}
return 1;
}
default: return -1;
}
}

private void subtractMaterials(string entityClass){
switch(entityClass){
case "Worker":{
game.materials.Food-= 2;
break;
}
case "SwordFighter":{
game.materials.Food -= 2;
game.materials.Money -= 2;
break;
}
case "BowFighter":{
game.materials.Food-= 2;
game.materials.Money -= 4;
break;
}
default: return;
}
}


// function that spawns an entity, can be called by player
public void spawnEntity(string input,TIM.main game){
string[] inp = input.Split(",");
Expand All @@ -82,7 +74,7 @@ public void spawnEntity(string input,TIM.main game){
functionProperties entity=new functionProperties(entityClass);
switch(checkMaterials(entityClass)){
case 0:{
Console.WriteLine("Not enough resources");
Console.WriteLine("Could not create entity.");
return;
}case -1:{
Console.WriteLine("{0} can not be created here.", entityClass);
Expand All @@ -93,7 +85,7 @@ public void spawnEntity(string input,TIM.main game){
if(entity.fType.GetMethod("autoSetup") is not null){
entity.fType.GetMethod("autoSetup")!.Invoke(entity.fObject, new object[]{this.position,game});
game.entities.Add(name,entity);
subtractMaterials(entityClass);
game.sys.displayMap(game);
}
}catch (ArgumentException){
Console.WriteLine("INF: Entity '{0}' already exists.",name);
Expand Down
6 changes: 3 additions & 3 deletions src/EntityManagement/Entities/Ore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ public class Ore{
public int mapColor{get;} = 15;
public bool isDestroyed = false;
public Position position{get;set;} = null!;
public int money{get;} = 2;
public int[] mat ={0,2};

public int durability{get;set;} = 3; // number of hits until destroyed

public void getHit(int damage){
durability -= damage;
if(durability<=0){
isDestroyed = true;
isDestroyed = true;
}
}

public void step(TIM.main game){
if(isDestroyed){
game.materials.Money += money;
methods.callMethod("mat_std","IncMaterials",mat,game);
throw new NotSupportedException("Ore was destroyed");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/EntityManagement/Entities/Wildlife/AbstractWildlife.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public abstract class Wildlife: Creature{
protected Position Spawnpoint = null!;
protected abstract int territoryRange{get;} // radius of territory (around spawnpoint)

public abstract int food {get;}
public abstract int[] mat {get;}

public override void autoSetup(Position pos, TIM.main game){
this.game = game;
Expand All @@ -19,7 +19,7 @@ public override void step(TIM.main game)
initIdleMovement(game);
}
if(isDead){
game.materials.Food += food;
methods.callMethod("mat_std","IncMaterials",mat,game);
}
base.step(game);
}
Expand Down
4 changes: 2 additions & 2 deletions src/EntityManagement/Entities/Wildlife/Bear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Bear: Wildlife{
protected override float speed{get;} = 7; // in fields per second
protected override int territoryRange{get;} = 10;

public override int food{get;} = 4;
public override int[] mat{get;} = {4,0};

protected int maxDistanceToSpawn {get{return 3* territoryRange;}} // maximal distance the entity can have to spawn

Expand Down Expand Up @@ -40,7 +40,7 @@ protected override void updateMovement(mapPixel[,] maparr)

// check territory for player-controlled entities to attack
private void checkTerritory(TIM.main game){
entityProperties? tgtCandidate = game.gameMap.findNearestP(this.position.X,this.position.Y,territoryRange + 1,"controlledByPlayer");
entityProperties? tgtCandidate = game.gameMap.findNearestP(this.position.X,this.position.Y,territoryRange + 1,"isTarget");
if(tgtCandidate!=null){
tgtEntity = tgtCandidate.entity;
trackEntity = true;}
Expand Down
2 changes: 1 addition & 1 deletion src/EntityManagement/Entities/Wildlife/Deer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class Deer: Wildlife{
protected override float speed{get;} = 7; // in fields per second
protected override int territoryRange{get;} = 10;

public override int food{get;} = 2;
public override int[] mat{get;} = {2,0};

}
Loading

0 comments on commit d8ffe42

Please sign in to comment.