From 19e3ec0936b980a8aebfc93e9842b23aa6be47b0 Mon Sep 17 00:00:00 2001 From: Scionwest_cp Date: Sun, 25 Jul 2010 17:31:50 -0700 Subject: [PATCH] MudGame: - Display Game Information at game startup now. - Checks to make sure the returned Object from Player.ExecuteCommand() is not null before attempting to iterate through the array. The Exit command no loner causes an error due to this fix. --- MUDGame/Program.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/MUDGame/Program.cs b/MUDGame/Program.cs index 6dfd5eb..31e7c06 100644 --- a/MUDGame/Program.cs +++ b/MUDGame/Program.cs @@ -60,6 +60,13 @@ namespace MUDGame game.IsRunning = true; game.PlayerCollection.Add(player); + + //Send game info to player + Console.WriteLine(game.GameTitle); + Console.WriteLine(game.Version); + Console.WriteLine(game.Website); + Console.WriteLine(game.Story); + Console.WriteLine(); while (game.IsRunning) { @@ -68,13 +75,16 @@ namespace MUDGame //TODO: Does the CommandResult really need to return an array of Objects? //All object management should be dealt with by the Game and Player so this should just be an array of strings. - object[] result = player.ExecuteCommand(command).Result; - - //Search through each object in the array returned to us from the command execution and print the strings. - foreach (object o in result) + Object[] result = player.ExecuteCommand(command).Result; + + if (result != null) { - if (o is string) - Console.WriteLine(o.ToString()); + //Search through each object in the array returned to us from the command execution and print the strings. + foreach (object o in result) + { + if (o is string) + Console.WriteLine(o.ToString()); + } } }