Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding the illusion of age in a text based game

Tags:

c#

so i'm developing a text based game in C#, i've currently got it laid out that a person will spawn as a class in the main body of the code (Person.cs). This person has an age inside the class that is randomly picked in the generator (int between 1 - 500), This will also include random enemies (Enemy.cs : Person) and maybe a partner or two on the way(Person.cs).

I want a way that when certain things happen everyone inside the program will all change age (people, pets). I dont want it based on the PC clock (think a magician that can change time forwards or backwards).

I setup a class for TimeManager.cs which just has an int inside it and i can obviously modify that, I just haven't got a way to push the date/age to all the other classes. I'd rather not hardcode a limit on how many of anything you can have if that makes sense

Have i overlooked something simple ? Cheers

like image 595
Alistair Bendall Avatar asked Mar 02 '23 22:03

Alistair Bendall


1 Answers

First of all, the game seems really interresting!

Every element that can age must implement the interface Ageable or something, forcing them to implement a method that makes them change age.

Once you have this, keep a List<Agable> somewhere in your code, for example in the World class that is closely related to your main class and reachable directly or indirectly by all your Magicians.

Once your want to change the age of all the Ageable, simply tell your World to iterate on the list and call all the methods that make your living creatures older or younger.

like image 108
SteeveDroz Avatar answered Mar 05 '23 19:03

SteeveDroz