Skip to content

Commit

Permalink
Added proper moving, fixed bug with always displaying 1st visit descr…
Browse files Browse the repository at this point in the history
…iption
  • Loading branch information
Zegis committed Oct 2, 2020
1 parent 7b1c39f commit 245142b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
21 changes: 15 additions & 6 deletions Kaeshi/Entity/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@ namespace Keshi.Entity
{
public class Location : IVisible
{
private bool visited = true;
public bool visited;

private string primaryDescription = "1st visit! :O";
private string primaryDescription;

private string secondaryDescription = "So much changed since last visit!";
private string secondaryDescription;

private Dictionary<Direction, Location> linkedLoctions = new Dictionary<Direction, Location>();

public Location(string firstDescription, string secondDescription)
{
primaryDescription = firstDescription;
secondaryDescription = secondDescription;
visited = false;
}

public string Observe()
{
if (visited)
return primaryDescription;
else
return secondaryDescription;
else
return primaryDescription;

}

public void SetLink(Direction direction, Location locationToLink)
Expand All @@ -30,7 +38,8 @@ public void SetLink(Direction direction, Location locationToLink)

public Location GetLink(Direction direction)
{
return linkedLoctions[direction];
linkedLoctions.TryGetValue(direction, out var retVal);
return retVal;
}
}
}
9 changes: 7 additions & 2 deletions Kaeshi/Entity/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public Map()
private Dictionary<string, Location> LoadLocations()
{
var locations = new Dictionary<string, Location>();
locations.Add("root", new Location());
locations.Add("north1", new Location());
locations.Add("root", new Location("You see a root.","Root is still there..."));
locations.Add("north1", new Location("This is north location","Is still on north"));

current = locations["root"];
current.SetLink(Direction.North, locations["north1"]);

locations["north1"].SetLink(Direction.South, locations["root"]);

return locations;
}

Expand All @@ -35,7 +37,10 @@ public void Go(Direction direction)
{
var newLocation = current.GetLink(direction);
if (newLocation != null)
{
current.visited = true;
current = newLocation;
}
}
}
}
1 change: 1 addition & 0 deletions Kaeshi/Kaeshi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static void Main(string[] args)

var entityManager = new EntityManager();
entityManager.AddVisibleObject("yourself", hero);
entityManager.SetMap(map);

var commandParser = new CommandParser(entityManager);

Expand Down
7 changes: 6 additions & 1 deletion Kaeshi/Modules/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public IVisible GetVisibleObject(string key)
{
if("around".Equals(key))
{
level.GetCurrentLocation();
return level.GetCurrentLocation();
}
if (visibleObjects.TryGetValue(key, out var retVal))
return retVal;
Expand All @@ -32,5 +32,10 @@ public Map GetMap()
{
return level;
}

public void SetMap(Map map)
{
level = map;
}
}
}

0 comments on commit 245142b

Please sign in to comment.