0
\$\begingroup\$

I'm trying to create a multidimensional array as a sort of 2D map for a text-based RPG game. I want to create a multidimensional array that's, for example, 5x5. The array would be filled with 0s to represent a space void of an object. Other numbers would represent the player on the map, an enemy, an npc, a skill-object (like an enchantment table, etc.), doors that link to maps, and chests. They would all have different values to represent what object is there. If a player tries walking into a chest, it would instead loot the chest. Then the chest would be reset to 0 to represent the empty space, letting the player walk there and representing that there is no more chest. If the player tries walking over an enemy, it would instead engage combat (handled by a separate class and functions). Walking over a number representing a door would link to another multidimensional array that represents another map.

I want to know what kind of property I need to put inside the player class to handle where he is on the map. A function would then change that value to move him around the map. Would creating a class for a map be a good idea? Would I store the values for the objects there or in the individual classes for those objects? How would I go about this? Thank you for your help. For reference, here's my player class (careful, it's long...):

public class Player
{
    public string   name        { get; set; }        //Name of Player
    public int      level       { get; set; }        //Player's combat level         (average of combat-related skills' levels)
    public int      health      { get; set; }        //Player's health               (player dies when this value reaches 0)
    public int      health_max  { get; set; }        //Player's maximum health
    public int      stamina     { get; set; }        //Player's stamina              (used for power attacks, slowly recharges on own)
    public int      stamina_max { get; set; }        //Player's maxiumum stamina
    public int      fatigue     { get; set; }        //Player's fatigue rate         (player cannot fight or run while fatigue is 100)
    public int      hunger      { get; set; }        //Player's hunger level         (player becomes weaker as hunger increases)
    public int      style       { get; set; }        //Player's fighting style       (refer to styles.txt)
    // tons of skills fields
}
\$\endgroup\$
8
  • 1
    \$\begingroup\$ So much depends on what you have not told us, that it is difficult to know where to begin with what you have. \$\endgroup\$ Commented Jul 23, 2013 at 22:05
  • \$\begingroup\$ I just need to know how to literally create the array and if I should house the variable to tab their position in the object's individual class or a new class for each map. I can create all the functions myself. \$\endgroup\$ Commented Jul 23, 2013 at 22:08
  • 1
    \$\begingroup\$ I'm inclined to remove the code from this question as I don't really see how most of it has to do with the question. EDIT, nevermind :p Thanks Sean. \$\endgroup\$
    – House
    Commented Jul 23, 2013 at 22:22
  • 1
    \$\begingroup\$ @Byte56: Haha, beat ya! \$\endgroup\$ Commented Jul 23, 2013 at 22:23
  • 1
    \$\begingroup\$ @AnthonyHackett: storing special numbers inside your tile map to represent if an object is there is bad. What if you have two base tiles, like normal floor vs water, and also want to note whether an enemy is there? Or want to have a pile of items in the same spot? Let the tilemap store static world information, use a completely different data structure to store and look up the locations of entities (like a simple hash of their <X,Y> locations). \$\endgroup\$ Commented Jul 23, 2013 at 22:24

1 Answer 1

1
\$\begingroup\$

I want to know what kind of property I need to put inside the player class to handle where he is on the map

A point.

 public Point Location;

Or two coordinates:

 public int X,Y;

In other way, for the skills, I would use a Dictionary, is more versatile.

 Dictionary<SkillType, Skill> Skills;

 void InitializeSkills()
 {   
     foreach (var key in Enum.GetValues(typeof(SkillType)).Cast<SkillType>())
     {
         Skills.Add(key, new Skill()));
     }
 } 

This is equivalent to your players class skill definition area... I think that is not your final code, but it you need load skill definitions from xml is easier now to adapt the code, and create them programatically.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .