CharacterStats.ToString() now returns a formatted string with all of the stats.

StandardGame and it's Child Classes display the name of the game when ToString() is invoked.
Realm and Zone save/load code is completed.
This commit is contained in:
Scionwest_cp 2012-03-11 13:25:32 -07:00
parent ee3cd897f2
commit 706c770dd7
6 changed files with 133 additions and 15 deletions

View file

@ -113,23 +113,35 @@ namespace MudEngine.DAL
public String GetPath(DataTypes objectType)
{
//Exception checking
String path = String.Empty;
switch (objectType)
{
case DataTypes.Root:
return this._InstallRoot;
path = this._InstallRoot;
break;
case DataTypes.Characters:
return this._Characters;
path = this._Characters;
break;
case DataTypes.Environments:
return this._Environments;
path = this._Environments;
break;
case DataTypes.Equipment:
return this._Equipment;
path = this._Equipment;
break;
case DataTypes.Players:
return this._Players;
path = this._Players;
break;
case DataTypes.Scripts:
return this._Scripts;
path = this._Scripts;
break;
}
return String.Empty;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
return path;
}
public String GetFilePath(DataTypes objectType, String filename)

View file

@ -1,4 +1,4 @@
using System;
//using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -17,5 +17,17 @@ namespace MudEngine.Game.Characters
public int Wisdom { get; set; }
public int Charisma { get; set; }
public int Experience { get; set; }
public override string ToString()
{
return
"Strength:" + this.Strength.ToString()
+ ".Dexterity:" + this.Dexterity.ToString()
+ ".Constitution:" + this.Constitution.ToString()
+ ".Intelligence:" + this.Intelligence.ToString()
+ ".Wisdom:" + this.Wisdom.ToString()
+ ".Charisma:" + this.Charisma.ToString()
+ ".Experience:" + this.Experience.ToString();
}
}
}

View file

@ -29,7 +29,7 @@ namespace MudEngine.Game.Environment
public Zone CreateZone(String name, String description)
{
Zone zone = new Zone(this.Game, name, description);
Zone zone = new Zone(this.Game, name, description, this);
this._ZoneCollection.Add(zone);
zone.Realm = this;
return zone;
@ -51,7 +51,6 @@ namespace MudEngine.Game.Environment
foreach (Zone zone in this._ZoneCollection)
{
this.SaveData.AddSaveData("Zone", zone.Name);
zone.Save();
}
@ -60,6 +59,27 @@ namespace MudEngine.Game.Environment
return true;
}
public override void Load(string filename)
{
String path = Path.GetDirectoryName(filename);
if (!Directory.Exists(path))
return;
base.Load(filename);
String[] zones = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(this.Filename), "Zones"), "*.zone");
foreach (String zone in zones)
{
Zone z = new Zone(this.Game, String.Empty, String.Empty, this);
z.Load(zone);
if (z != null)
this._ZoneCollection.Add(z);
}
}
private List<Zone> _ZoneCollection;
}
}

View file

@ -17,7 +17,7 @@ namespace MudEngine.Game.Environment
{
get
{
String path = Path.Combine(this.Game.SavePaths.GetPath(DAL.DataTypes.Environments), this.Realm.Name, "Zones", this.Name + "." + this.GetType().Name);
String path = Path.Combine(Path.GetDirectoryName(this.Realm.Filename), "Zones", this.Name + "." + this.GetType().Name);
return path;
}
}
@ -31,8 +31,9 @@ namespace MudEngine.Game.Environment
public Realm Realm { get; set; }
public Zone(StandardGame game, String name, String description) : base(game, name, description)
public Zone(StandardGame game, String name, String description, Realm realm) : base(game, name, description)
{
this.Realm = realm;
this._RoomCollection = new List<Room>();
}
@ -42,8 +43,59 @@ namespace MudEngine.Game.Environment
return false;
this.SaveData.AddSaveData("Safe", this.Safe.ToString());
this.SaveData.Save(this.Filename);
return true;
this.SaveData.AddSaveData("CharacterStats", this.StatDrain.ToString());
return this.SaveData.Save(this.Filename);
}
public override void Load(string filename)
{
String path = Path.GetDirectoryName(filename);
if (!Directory.Exists(path))
return;
base.Load(filename);
try { this.Safe = Convert.ToBoolean(this.SaveData.GetData("Safe")); }
catch { this.LoadFailedMessage("Safe"); }
try
{
String data = this.SaveData.GetData("CharacterStats");
String[] stats = data.Split('.');
CharacterStats charStats = new CharacterStats();
foreach (String stat in stats)
{
String[] value = stat.Split(':');
switch (value[0])
{
case "Strength":
charStats.Strength = Convert.ToInt32(value[1]);
break;
case "Dexterity":
charStats.Dexterity = Convert.ToInt32(value[1]);
break;
case "Constitution":
charStats.Constitution = Convert.ToInt32(value[1]);
break;
case "Wisdom":
charStats.Wisdom = Convert.ToInt32(value[1]);
break;
case "Charisma":
charStats.Charisma = Convert.ToInt32(value[1]);
break;
case "Experience":
charStats.Experience = Convert.ToInt32(value[1]);
break;
}
}
}
catch
{
this.LoadFailedMessage("CharacterStats");
}
}
public Room CreateRoom(String name, String description)

View file

@ -272,5 +272,10 @@ namespace MudEngine.Game
if (!Directory.Exists(this.SavePaths.GetPath(DataTypes.Scripts)))
Directory.CreateDirectory(this.SavePaths.GetPath(DataTypes.Scripts));
}
public override string ToString()
{
return "Game: " + this.Name + " " + this.Version;
}
}
}

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using MudEngine.Game.Environment;
using MudEngine.Core.Interfaces;
@ -57,7 +58,23 @@ namespace MudEngine.Game
public void Load()
{
Logger.WriteLine("World Loading has not been implemented as of yet!");
if (!Directory.Exists(this.Game.SavePaths.GetPath(DAL.DataTypes.Environments)))
{
return;
}
String[] realmPaths = Directory.GetDirectories(this.Game.SavePaths.GetPath(DAL.DataTypes.Environments));
foreach (String realm in realmPaths)
{
String[] realms = Directory.GetFiles(realm);
foreach (String file in realms)
{
Realm r = new Realm(this.Game, String.Empty, String.Empty);
r.Load(file);
}
}
}
public void Destroy()