Go Back   ZuneBoards > Zune Discussions > Zune Games > Development Discussions > Development Help

Development Help For help from coding to error finding to that one thing you just can't get right

Reply
 
LinkBack Thread Tools
Old 05-22-2009, 02:39 AM   #1 (permalink)
Zuner
 
badmoodguy88's Avatar
 
Join Date: Jun 2008
Posts: 73
badmoodguy88 is on a distinguished road
Default Keeping track of endless new Troops

I am trying some thing that is a little beyond me. I have been mulling over it for a wile now but I have not been struck with an eureka moment yet (or even and "ah ha!" moment).

Basically my problem is that I want to be able to have troops that can gain experience and be selected to have other variables change like unit type and items. This is easy but it is complicated by the fact that I want to be able to kill of units and add new ones, purity much endlessly. I could live with an upper limit of a hundred - two hundred troops at one time. I would have something like each troop being a subsequent number but I have some vague notion that reassignment of the number for old dead troops out of order would make things more difficult. I think I want a Dynamic array, but that is just my guess. I have been reading more about this kind of array and making new objects but I am still not entirely there. I know this is some thing that must be in countless games.

The attempt I have been fumbling with is to have this array, where the sting of numbers are different stats.

Code:
       
        public int[] Cleric = { 0, 4, -2, 1, 0, 2, 8, 0, 1, 1, 1, 1 };
        public int[] Fighter = { 0, 6, -4, 2, 0, 0, 10, 1, 0, 1, 3, 1 };
        public int[] Thief = { 0, 4, 4, 3, 0, 0, 6, 0, 0, 2, 2, 2 };
        public int[] Wizard = { 2, 2, -2, 0, 0, 0, 4, 0, 0, 1, 1, 1 };
int[]
it is multiplied by the levels in each troop type
Code:
int[] Unitlevels = { 0, 0, 0, 0 };
so Unitlevels[2] is Thief levels.

this increases to some point and then bumps up the level and resets to zero
Code:
Unitexp = { 0, 0, 0, 0 };
all the numbers from the different troop type get added to the base troop Unit stats.
Code:
 int[] Unit = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Witch at some latter point would get added together with other modifiers for equipment and so on.

in this way I would just be keeping track of a few short variables like.
int[] Unitlevels = { 0, 0, 0, 0 };
int[] Unitexp = { 0, 0, 0, 0 };
int Curenthp;
int Equipment;
and a few other manageable variables
but it still gets me nowhere to actually solving my problem.

Last edited by badmoodguy88; 05-22-2009 at 02:41 AM.



badmoodguy88 is offline   Reply With Quote

Advertisement [Remove Advertisement]
Old 05-22-2009, 05:23 AM   #2 (permalink)
Zuner
 
Join Date: Nov 2008
Posts: 56
gbabey will become famous soon enough
Send a message via ICQ to gbabey Send a message via AIM to gbabey
Default

Instead of storing all this data as arrays, you should really look at classes. You mentioned "all the numbers from the different troop type get added to the base troop Unit stats." That just screams for inheritance to me.

You can set up a base class "Troop" and instead of having that array of ints for stats you could define each stat inside the class. Then you can inherit from Troop for your Cleric type, and set the base stats for a Cleric in the constructor. This is just example code, you'll probably want to store the level for each Troop type as well.

Code:
public class Cleric : Troop  // The Cleric class that inherits from Troop
{
     public Cleric()  // The constructor
     {
          // These would be defined as ints in your Troop class
          this.str += 2;
          this.wis += 10;
          this.int += 10;
          this.con += 5;
     }
}
Then for your collection of troops you can create like:
Code:
List<Troop> myTroops = new List<Troop>(); // Your collection of troops

Cleric myCleric = new Cleric();
myCleric.level = 2;
myTroops.add(myCleric);
Then you'll be able to add and delete new troops from your collection all willy-nilly.

Just a suggestion, with programming there is no single right way. Hope that helps, let me know if you need further clarification.





gbabey is offline   Reply With Quote
Old 05-25-2009, 04:18 AM   #3 (permalink)
Zuner
 
badmoodguy88's Avatar
 
Join Date: Jun 2008
Posts: 73
badmoodguy88 is on a distinguished road
Default

Thanks for your help. I really do appreciate it.
I put off responding until I tried to do something with what you suggested. I read up a little (like hardly at all) on lists. But this would be my first time using them. Now I know what to try to wrap my head around at least. Everything turns out to be so complicated.


Let me try to reason this out.
Ok so I have int PlayerGold and int PlayerPopulation.
If on the buy screen I select to buy a thief, that game does some thing like.

Code:
                    if (PlayerGold >= 500 && PlayerPopulation >= 1)
                    {
                        PlayerGold -= 500;
                        PlayerPopulation -= 1;

                        // I would somewhere else in the code have already put in,
                        //List<Troop> myTroops = new List<Troop>(); // This is all objects that were created with or inherited from  the Troop class.
                        //Random random = new Random(); //already in public class


                        Thief myThief = new Thief(); //this make a new thief with default values. 
                        myThief.location = curentlocation //from what town the buy screen was in.
			Numbermade ++;
			myThief.Troopnumber = Numbermade; // this is to keep track of what toops, oldest to newest.
                        myThief.Divinefavor = (random.Next(0, 6) -3); //Divinefavor is a number from -3 and 3 that is assigned to a troop and then never changes. 
                        myTroops.add(myThief);
                    }
I would need to make a troop class that has all kinds of values. As I am trying to work in a game mechanic for being able to change Troop class type (Class, like in D&D or job changing in Final Fantasy Tactics) I would want to have all the stats for Theif, Cleric, Fighter, and Wizard in the main Troop category. The class Theif would just determine what their first level is in or I could dissidence with even that but I have a feeling there will be some reason to keep it around.

I know I am going to need to be able to show them in a list. I guess I would add a counter next to where I made a new troop that would go up by one and assigned it to one of the variables for the troops as I make them.

I would use this with the methods attached to Lists to make well a list. It would be using the sort method to come up with a bunch of objects that fit some criteria to be drawn on the screen. I added that Troopnumber variable so that I can at least sort from newest to oldest. But what would the actual code be like?


In this incomplete mock up of for the screen for displaying troops the five dark blue boxes would need to display the troops in some order. How would I establish that order so I can fill in those little boxes with with variables from the objects that came up from sorting the list. Baring in mind that the list of troops on the screen would 'scroll' up and down and the troop selected changes. Or do I have it the wrong why round. Would I want to have code for drawing a specific object and somehow use the list to come up with if it should be drawn on the screen and where? I know I really don't get object oriented programing very well, yet. oh well, its all a learning process or something like that...

Last edited by badmoodguy88; 05-25-2009 at 04:29 AM.



badmoodguy88 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools