Hello,
As a project me and some friends have decided to build a MUD (Multi User Dungeon) like game, but we have encountered a little issue regarding the way we will have the coordinates set.
What would be the easiest way to define the coordinates of the player at any time - and allow him to move to different directions (up,down,left and right).
Keep in mind - this is a text based game without any graphical support.
Thank you in advance,
Sleepingcap
Loading
Jason MeyerPosted Oct 1, 2009, 1:29 PM
static class Player
{
private static int posX; //position in X
private static int posY; //position in y
// public properties
public static int PosX
{
get { return posX; }
set { posX = value; }
}
public static int PosY
{
get { return posY; }
set { posY = value; }
}
// When you move call this method
public static void Move(string direction)
{
Room room = Player.GetCurrentRoom(); //gets current room your in
// checks to see if you can move in that direction
if (!room.CanExit(direction))
{
TextBuffer.Add("Invalid direction");
return;
}
// depending on with way your going adjust pos x/y
switch (direction)
{
case Direction.NORTH:
posY--;
break;
case Direction.SOUTH:
posY++;
break;
case Direction.EAST:
posX++;
break;
case Direction.WEST:
posX--;
break;
}
// get room and call the room method to describe new room
Player.GetCurrentRoom().Describe();
}
// get current room... from you rooms array
public static Room GetCurrentRoom()
{
return Level.Rooms[posX, posY];
}
Hope this helps alittle, just make sure you make classes for everything...
"Level" for building the level, will have a array of rooms
"item" for your items
"room" for your rooms, every room has a list for exits and items btw
a struct of directions
a gameManager for starting, ending, rules, ect...
player will have list of items for what he carrying, weight, stats, ect..
This was from one of my first single player tests