Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data type confussion

Status
Not open for further replies.

ppat60

Programmer
Oct 20, 2007
13
0
0
US
I am not sure what data type to use. I have three structures that are made 27, 18 and 17 elements. In PHP I have them as Arrays. But I am not sure that is the Best way in C#.I am new to C# and not sure about using Array, ArrayList, Enums.

I need to set my three sets of elements then access them randomly. So I may set setOne[4] then need to come back to it and increment the index or MoveNext three elements and save it again. And I some point I will need to reset the a set to element[0] again.

Can someone help point me in the right direction for ease of use for this situation?

Cheers,
Pat
 
If you are simply doing position (give me the 4th object in the list) then the List<> class is the way to go.

Dictionary is good if you have an ID (give me the object that has the id of 212)

 
let me see if I can explain better...

I wrote a game in php, now i want to learn how to convert it to C#.

I have 3 routes named Land, Water, and Air. These routes are currently Arrays in php. Every user starts on the Land Route at position[0]. then the user rolls the die(1D6). And they get a 4.

Then next move is to look up what Route: Land, What position are they currently at in this case position[0] increment/move 4 indexes. so now they are on index[4] and then I want to display the information which is a Color.

I am not sure what data type would be the best one to use. I want something that is easy to look up (color, index) and easy to access and save it info to variables. I am new to C# sharp so I am not sure of all my opions and what would be better of those opions.

Does that help at all?

pat
 
It is a Board Game, and my board game has squares that are colored {Black, Yellow, Green, Blue, Purple, and Red}. So every user/player is assigned one of those colors.

everyone starts on the Land route at the start position, then rolls the die and should move that many spaces. if and only if the player how is red lands on a red square do they advance to a new Route which is to the water route.

All this information needs to be saved. What route, what color did they start on, where did they land...

All of this I did in php with arrays. I am looking for a better way to take better advantage of OO programming.
 
Each player should be in a class with a color assigned. By color I mean an enumeration of the color.

Each square should be assigned a color also which is stored in an array.

When someone lands on the color, check to see if the square color matches the player class color. If they match then you would set the type of Route the player is on in the player class.

When you want to save your game, all you will need to do is dump each player class and their positions to an xml file or DB and reload them when they resume the game later.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top