muddesigner/Mud Designer/Runtime.cs
Scionwest_cp 79f6d36083 Engine:
- Changed the IGameCommand Interface constructor for the Execute method.
 - Updated all of the game commands to make use of the new Execute Method Constructor requirements set by the updated interface.
 - Look command now returns a description of the players current Room.
 - Walk command now supports moving players from one Room to another. Use 'Walk Direction' where Direction equals the direction you want to travel (Example: 'Walk North")
 - TravelDirections.GetTravelDirectionValue now checks the supplied direction value in a case-insensitive manor.
 - Add a new CommandEngine that handles the commands inputed from the user.
 - Modified CommandResult to return an array of objects rather than a single object.

Runtime:
 - Now scans the supplied collection of objects returned to the runtime after executing a game command, and adjusts the runtime components as needed, including printing information to the console.
 - Now displays various warnings during startup to let the user know if certain content hasn't been set within the ProjectInformation yet.
 - Now executes the 'Look' command on startup to display the users current location.
 - Fully supports the 'Look' and 'Walk' commands.
2010-02-04 17:18:53 -08:00

159 lines
5.7 KiB
C#

//.Net Framework
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//Mud Designer
using MudDesigner.MudEngine.Characters;
using MudDesigner.MudEngine.Characters.Controlled;
using MudDesigner.MudEngine.Characters.NPC;
using MudDesigner.MudEngine.GameCommands;
using MudDesigner.MudEngine.FileSystem;
using MudDesigner.MudEngine.GameManagement;
using MudDesigner.MudEngine.GameObjects;
using MudDesigner.MudEngine.GameObjects.Environment;
using MudDesigner.MudEngine.GameObjects.Items;
namespace MudDesigner
{
public partial class Runtime : Form
{
PlayerBasic _Player;
Room _Room;
ProjectInformation _Project;
public Runtime()
{
InitializeComponent();
_Player = new PlayerBasic();
_Project = new ProjectInformation();
_Room = new Room();
}
public void Print(string message)
{
txtConsole.Text += message + "\n";
txtConsole.Select(txtConsole.Text.Length, 0);
}
private void Runtime_Load(object sender, EventArgs e)
{
Print("Loading project information...");
_Project = (ProjectInformation)_Project.Load(FileManager.GetDataPath(SaveDataTypes.Root));
if (_Project.InitialLocation.Zone == "")
{
Print("No Initial Zone was defined within the Project Information. Please associated a Zone to the Projects Initial Zone setting in order to launch the game.");
Application.Exit();
}
Print("Loading environment...");
string filename = FileManager.GetDataPath(SaveDataTypes.Root);
if (_Project.InitialLocation.Realm != "No Realm Associated.")
{
filename = Path.Combine(filename, "Realms");
filename = Path.Combine(filename, _Project.InitialLocation.Realm);
}
filename = Path.Combine(filename, "Zones");
filename = Path.Combine(filename, _Project.InitialLocation.Zone);
filename = Path.Combine(filename, "Rooms");
filename = Path.Combine(filename, _Project.InitialLocation.Room);
filename += ".room";
_Room = (Room)_Room.Load(filename);
Print("Prepping test player...");
_Player.CurrentRoom = _Room;
_Player.OnTravel(AvailableTravelDirections.North);
Print("Loading Game Commands...");
CommandEngine.LoadAllCommands();
Print("Startup Complete.");
Print(""); //blank line
txtCommand.Select();
if (string.IsNullOrEmpty(_Project.CompanyName))
Print("No company name defined for the project!");
else
Print("Created by " + _Project.CompanyName);
if (string.IsNullOrEmpty(_Project.Website))
Print("No website defined for the project!");
else
Print("Visit us at " + _Project.Website);
if (string.IsNullOrEmpty(_Project.GameTitle))
Print("No Game Title defiend for the project!");
else
Print(_Project.GameTitle);
if (string.IsNullOrEmpty(_Project.Version))
Print("Game Version was not specified.");
else
Print(_Project.Version);
if (string.IsNullOrEmpty(_Project.Story))
Print("The games startup story has not been created yet!");
else
Print(_Project.Story);
Print("");//blank line
CommandResults result = CommandEngine.ExecuteCommand("Look", _Player, _Project, _Room, "Look");
if (result.Result.Length != 0)
Print(result.Result[0].ToString());
}
private void txtCommand_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
string[] words = txtCommand.Text.Split(' ');
string firstWord = "";
if (words.Length == 0)
return;
firstWord = words[0];
List<object> arguments = new List<object>();
foreach (string word in words)
{
if (word == firstWord)
continue;
arguments.Add(word);
}
arguments.Add(_Room);
arguments.Add(_Player);
arguments.Add(_Project);
CommandResults result = CommandEngine.ExecuteCommand(txtCommand.Text, _Player, _Project, _Room, txtCommand.Text);
if (result.Result == null)
return;
foreach (object obj in result.Result)
{
switch (obj.GetType().Name.ToLower())
{
case "string":
Print(obj.ToString());
break;
case "room":
_Room = (Room)obj;
break;
case "projectinformation":
_Project = (ProjectInformation)obj;
break;
case "playerbasic":
_Player = (PlayerBasic)obj;
break;
}
}
txtCommand.Clear();
}
}
}
}