Datastructures for turn based strategy game.....
I am sorta new to development and .net and currently working on creating a turn based strategy game using Silverlight and C# as a hobby project.
So far I have a a hex map up and running, internally its an array of Hex objects, which render to the canvas as individual polygons. I have now started thinking about implementing players and units into the game and I am having some trouble figuring out what data structures to use for this.
Each game will have a hex map composed of individual hexagons (polygon object in silverlight) that serve as the game tiles. Each game will have 2 or more players that align themselves with one of the two races in game, and then have 1 or more units when they start. During the game they can capture bases and earn credits, which in turn allows them to produce more / different units.
My thinking is that I need to maintain an in memory list of all players and all the units that belong to them as well as the location of that unit (in terms of grid location so I can easily look it up in the array of hex's).
Should i maintain one master list of it all? Or just have a player object which has a list of units and the units themselves have information on their grid location? That would seem to be the logical way, but then when the player clicks a hexagon (to select his unit) I would need to some how relate that hex with the player and the particular unit on it....
I am taking this slow right now. My first step is to get some basic functionality prototyping done on the client side using silverlight before I dive into the server end of things and the multiplayer coding.
Sorry if this sounds a bit noobish, I am new to all this so go easy on me :)
I've never used Silverlight so I'm not sure how that affects what I'm about to say, but typically I'd go for an approach like you suggested, where player classes have a list of units in them (actually I'd be a little more abstract, and have a "Civilization" class with the list of units, and Player classes seperate, so you can replace human players with AI players, but if you're only beginning, keeping it simple is sensible).
For each unit store the grid position that it is currently in rather than the world position, you could also try storing a reference to the units from the hex tile that they are located at. The trick is really to try things out, and see what works best and which option is easiest.
Silverlight shouldnt affect much, since the underlying datastructures are gonna be similar regardlness of language/technology.
I ended up going with a 'Hex' structure which is basically the tile..it stores reference to unit on it, as well as reference to a polygon object (which is what renders to screen).
The Unit structure stores reference to the hex it is on as well as the player it belongs to.
I did not think of 'civilization' or races but thanks for suggesting that. I will need to factor that into my design as well somehow but the thought eluded me until now.
I guess experimentation is the key :)
|All times are GMT -8. The time now is 08:36 PM.|
Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.