Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

enum is actually a good idea here, but what you want is for the enum to be:

enum MapTileBuilding { defaultTile, homeBase, farm1, farm2 /*...and so on...*/ };

and a class

class MapTile
{
   MapTileBuilding building;
   ... //other members e.g.
   //structuralStrength
   //isOnFire
   //troopCount
   //incomeGenerated
   //etc.
}

...which gives you the ability to support your initial building type property, as well as other properties you may wish to add to each tile later.

Finally, your array:

MapTile[,] map = new MapTiles[4, 4];

Do not inherit when composition will doDo not inherit when composition will do (i.e. what you are already doing), otherwise you end up restricting yourself into narrowly-defined class hierarchies as you continue to try to extend the system. You want your tiles to be composable and inheritance is at odds with that idea. You'll begin adding new components as other concepts come into play (see examples above), and you don't want inheritance chains in your way at that point.

Re array dimensionality, the only time you will ever use a 1D array for a 2D concept is when you want precise control over memory access in low-level code (say in C or ASM), that is, in your case and in C# in general, just use the conceptually simpler 2D array.

P.S. Sorry if syntax is slightly off, C# isn't my first language these days.

enum is actually a good idea here, but what you want is for the enum to be:

enum MapTileBuilding { defaultTile, homeBase, farm1, farm2 /*...and so on...*/ };

and a class

class MapTile
{
   MapTileBuilding building;
   ... //other members e.g.
   //structuralStrength
   //isOnFire
   //troopCount
   //incomeGenerated
   //etc.
}

...which gives you the ability to support your initial building type property, as well as other properties you may wish to add to each tile later.

Finally, your array:

MapTile[,] map = new MapTiles[4, 4];

Do not inherit when composition will do (i.e. what you are already doing), otherwise you end up restricting yourself into narrowly-defined class hierarchies as you continue to try to extend the system. You want your tiles to be composable and inheritance is at odds with that idea. You'll begin adding new components as other concepts come into play (see examples above), and you don't want inheritance chains in your way at that point.

Re array dimensionality, the only time you will ever use a 1D array for a 2D concept is when you want precise control over memory access in low-level code (say in C or ASM), that is, in your case and in C# in general, just use the conceptually simpler 2D array.

P.S. Sorry if syntax is slightly off, C# isn't my first language these days.

enum is actually a good idea here, but what you want is for the enum to be:

enum MapTileBuilding { defaultTile, homeBase, farm1, farm2 /*...and so on...*/ };

and a class

class MapTile
{
   MapTileBuilding building;
   ... //other members e.g.
   //structuralStrength
   //isOnFire
   //troopCount
   //incomeGenerated
   //etc.
}

...which gives you the ability to support your initial building type property, as well as other properties you may wish to add to each tile later.

Finally, your array:

MapTile[,] map = new MapTiles[4, 4];

Do not inherit when composition will do (i.e. what you are already doing), otherwise you end up restricting yourself into narrowly-defined class hierarchies as you continue to try to extend the system. You want your tiles to be composable and inheritance is at odds with that idea. You'll begin adding new components as other concepts come into play (see examples above), and you don't want inheritance chains in your way at that point.

Re array dimensionality, the only time you will ever use a 1D array for a 2D concept is when you want precise control over memory access in low-level code (say in C or ASM), that is, in your case and in C# in general, just use the conceptually simpler 2D array.

P.S. Sorry if syntax is slightly off, C# isn't my first language these days.

deleted 32 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124

enum is actually a good idea here, but what you want is for the enum to be:

enum MapTileBuilding { defaultTile, homeBase, farm1, farm2 /*...and so on...*/ };

and a class

class MapTile
{
   MapTileBuilding building;
   ... //other members e.g.
   //structuralStrength
   //isOnFire
   //troopCount
   //incomeGenerated
   //etc.
}

...which gives you the ability to support your initial building type property, as well as other properties you may wish to add to each tile later.

Finally, your array:

MapTile[,] map = new MapTiles[4, 4];

Do not inherit when composition will do (i.e. what you are already doing), otherwise you end up restricting yourself into narrowly-defined class hierarchies as you continue to try to extend the system. You want your tiles to be composable and inheritance is at odds with that idea. You'll begin adding new components as other concepts come into play (e.g. percentile structural integrity per MapTilesee examples above), and you don't want inheritance chains in your way at that point.

Re array dimensionality, the only time you will ever use a 1D array for a 2D concept is when you want precise control over memory access in low-level code (say in C or ASM), that is, in your case and in C# in general, just use the conceptually simpler 2D array.

P.S. Sorry if syntax is slightly off, C# isn't my first language these days.

enum is actually a good idea here, but what you want is for the enum to be:

enum MapTileBuilding { defaultTile, homeBase, farm1, farm2 /*...and so on...*/ };

and a class

class MapTile
{
   MapTileBuilding building;
   ... //other members e.g.
   //structuralStrength
   //isOnFire
   //troopCount
   //incomeGenerated
   //etc.
}

...which gives you the ability to support your initial building type property, as well as other properties you may wish to add to each tile later.

Finally, your array:

MapTile[,] map = new MapTiles[4, 4];

Do not inherit when composition will do (i.e. what you are already doing), otherwise you end up restricting yourself into narrowly-defined class hierarchies as you continue to try to extend the system. You want your tiles to be composable and inheritance is at odds with that idea. You'll begin adding new components as other concepts come into play (e.g. percentile structural integrity per MapTile), and you don't want inheritance chains in your way.

Re array dimensionality, the only time you will ever use a 1D array for a 2D concept is when you want precise control over memory access in low-level code (say in C or ASM), that is, in your case and in C# in general, just use the conceptually simpler 2D array.

P.S. Sorry if syntax is slightly off, C# isn't my first language these days.

enum is actually a good idea here, but what you want is for the enum to be:

enum MapTileBuilding { defaultTile, homeBase, farm1, farm2 /*...and so on...*/ };

and a class

class MapTile
{
   MapTileBuilding building;
   ... //other members e.g.
   //structuralStrength
   //isOnFire
   //troopCount
   //incomeGenerated
   //etc.
}

...which gives you the ability to support your initial building type property, as well as other properties you may wish to add to each tile later.

Finally, your array:

MapTile[,] map = new MapTiles[4, 4];

Do not inherit when composition will do (i.e. what you are already doing), otherwise you end up restricting yourself into narrowly-defined class hierarchies as you continue to try to extend the system. You want your tiles to be composable and inheritance is at odds with that idea. You'll begin adding new components as other concepts come into play (see examples above), and you don't want inheritance chains in your way at that point.

Re array dimensionality, the only time you will ever use a 1D array for a 2D concept is when you want precise control over memory access in low-level code (say in C or ASM), that is, in your case and in C# in general, just use the conceptually simpler 2D array.

P.S. Sorry if syntax is slightly off, C# isn't my first language these days.

deleted 5 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124

enum is actually a good idea here, but what you want is for the enum to be:

enum MapTileBuilding { defaultTile, homeBase, farm1, farm2 /*...and so on...*/ };

and a class

class MapTile
{
   enum MapTileBuilding building;
   ... //other propertiesmembers suche.g.
 as structural strength,//structuralStrength
 troop count, income//isOnFire
 level,  //troopCount
   //incomeGenerated
   //etc.
}

and...which gives you the ability to support your initial building type property, as well as other properties you may wish to add to each tile later.

Finally, your array:

MapTile[,] map = new MapTiles[4, 4];

Do not inherit when composition will do (i.e. what you are already doing), otherwise you find you restrictend up restricting yourself into narrowly-defined class hierarchies as you continue to try to extend the system. You want your tiles to be composable and inheritance is at odds with that idea. You'll begin adding new components as other concepts come into play (e.g. percentile structural integrity per MapTile), and you don't want inheritance chains in your way.

So you have this exactly right except for the lack of a 2DRe array. In most cases dimensionality, the only time you will ever use a 1D array for a 2D concept is when you want precise control over memory access in low-level code (say in C or ASM), that is, in your case and in C# in general, just use the conceptually simpler 2D array.

P.S. Sorry if syntax is slightly off, C# isn't my first language these days.

enum is actually a good idea here, but what you want is for the enum to be:

enum MapTileBuilding { defaultTile, homeBase, farm1, farm2 /*...and so on...*/ };

and a class

class MapTile
{
   enum MapTileBuilding building;
   ... //other properties such as structural strength, troop count, income level, etc.
}

and array

MapTile[,] map = new MapTiles[4, 4];

Do not inherit when composition will do (i.e. what you are already doing), otherwise you find you restrict yourself into narrowly-defined class hierarchies as you continue to try to extend the system. You want your tiles to be composable and inheritance is at odds with that idea. You'll begin adding new components as other concepts come into play (e.g. percentile structural integrity per MapTile), and you don't want inheritance chains in your way.

So you have this exactly right except for the lack of a 2D array. In most cases the only time you will ever use a 1D array for a 2D concept is when you want precise control over memory access in low-level code, that is, in your case, just use the conceptually simpler 2D array.

P.S. Sorry if syntax is slightly off, C# isn't my first language these days.

enum is actually a good idea here, but what you want is for the enum to be:

enum MapTileBuilding { defaultTile, homeBase, farm1, farm2 /*...and so on...*/ };

and a class

class MapTile
{
   MapTileBuilding building;
   ... //other members e.g.
   //structuralStrength
   //isOnFire
   //troopCount
   //incomeGenerated
   //etc.
}

...which gives you the ability to support your initial building type property, as well as other properties you may wish to add to each tile later.

Finally, your array:

MapTile[,] map = new MapTiles[4, 4];

Do not inherit when composition will do (i.e. what you are already doing), otherwise you end up restricting yourself into narrowly-defined class hierarchies as you continue to try to extend the system. You want your tiles to be composable and inheritance is at odds with that idea. You'll begin adding new components as other concepts come into play (e.g. percentile structural integrity per MapTile), and you don't want inheritance chains in your way.

Re array dimensionality, the only time you will ever use a 1D array for a 2D concept is when you want precise control over memory access in low-level code (say in C or ASM), that is, in your case and in C# in general, just use the conceptually simpler 2D array.

P.S. Sorry if syntax is slightly off, C# isn't my first language these days.

Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124
Loading