Programming technique for a Tycoon game?

Started by
1 comment, last by Nicholas Kong 10 years, 3 months ago

I've heard a lot about entity component systems for MMO and data-intensive games, but i haven't heard anything about a specific system for tycoon or simulation games. Do you guys know any pattern or technique that's helpful on building a tycoon game, which is heavily based on time scales and ticks?

Advertisement

No one? Do you guys think that an ECS variant would suffice? With each component being a data type for looping ticks?

It really depends on the situation and something you need to plan ahead of time. It is also a skill you will develop overtime. I provided code examples down below.

Example 1: Suppose you were tasked to program a Wizard to be a NPC.

You can do this below in the programming sense in Scenario 1 but you will see Wizard inherits from two classes NPC and Sprite which means it is of type NPC and Sprite together. While it will work in the English-speaking sense, coding style wise, it will just create a bunch of class extension for an object. Scenario 1 can cause a ripple effect on your Wizard class when you decide to change the code for NPC that you don't want your Wizard to inherit from.

Scenario 1: <---Bad Design for NPC design


public class Wizard extends NPC
{
 
}
 
public class NPC extends Sprite
{
 
}

Why do the above: when you can code like Scenario 2 down below. Here if you perform code design on the NPC class, it has no effect on you Wizard class because Wizard does not inherit from NPC. Here Wizard is a Sprite but NPC has a Sprite. Inheritance uses "is a" relationship but Composition uses "has a" relationship.

Scenario 2: <---Better Choice for NPC design


public class NPC implements Talkable
 
{
 
  private Sprite sprite;
 
   public NPC(Sprite sprite)
   {
 
   }
}
 
public class Wizard extends Sprite
{
       public Wizard(double x, double y)
       {
                     super(x,y);
       }
 
}
 
public class Game()
{
       NPC npc = new NPC(new Wizard (0,0));
}

There are appropriate cases where a class can have a mixed of both inheritance and composition in the works at the same time. There are also some classes that use only inheritance. Some class that use inheritance but will be later treated as a component.

You generally use composition of you want the class(for example: Sora class which is the class for the main character) to be made up of other classes you already written(like the animated functionality to move in 4 directions). However, the animation functionality can be using inheritance. Sora can also be using inheritance to inherit the position properties of the Sprite class. So in that sense, Sora uses both inheritance and composition at the same time.

Code from my game:

This code uses inheritance and composition at the same time.


public class Sora extends Sprite
{
 
// soraRunRight use inheritance internally but is treated as a component. 
private Animation soraRunRight;
private Animation soraRunLeft;
 
        public Sora(double x, double y)
       {
                  super(x,y);
       }
 
}
 
This code only use inheritance because my animation will need to inheritance the same loading assets and interval assigment and drawing algorithm.  
 
public class soraRunRight extends Animation
{
       
         
}
 
public class soraRunLeft extends Animation
{
 
}
 

To answer your question, in terms of ticks, you should just pass the tick as a parameter of a method like this:

public void update(long milliseconds)

{

}

You don't want a tick variable hanging around for every object.

The question you pose is still vague. What technique or pattern for building a tycoon game? You should name a specific feature from the tycoon game you need help designing. This statement would be much more clear.

This topic is closed to new replies.

Advertisement