muddesigner/MUDGame/Program.cs
Scionwest_cp 70533582a6 MudEngine:
- Player movement command now fully implemented. 
 - Game.GetRealm() added to retrieve a Realm within the games RealmCollection property
 - Game.End() added to perform game ending duties and shut down the Server
 - Server now loses opened threads.
 - Player.Move() added to move the player from Room to Room.
 - Room.DoorwayExist() tweaked to work with the new way Environments are managed.

MudGame:
 - Now executes the Look command on startup so the player can see where they are located at.
 - Implements the new Game.End() method and fixes the game hanging upon exit.
2010-07-25 18:33:21 -07:00

108 lines
4.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using MUDGame.Environments;
namespace MUDGame
{
class Program
{
//Setup our Fields
static MudEngine.GameManagement.Game game;
static MudEngine.GameManagement.CommandEngine commands;
static MudEngine.GameObjects.Characters.BaseCharacter player;
static List<MudEngine.GameObjects.Environment.Realm> realmCollection;
static void Main(string[] args)
{
//Initialize them
game = new MudEngine.GameManagement.Game();
commands = new MudEngine.GameManagement.CommandEngine();
realmCollection = new List<MudEngine.GameObjects.Environment.Realm>();
//Setup the game
game.AutoSave = true;
game.BaseCurrencyName = "Copper";
game.BaseCurrencyAmount = 1;
game.CompanyName = "Mud Designer";
game.DayLength = 60 * 8;
game.GameTitle = "Test Mud Project";
game.HideRoomNames = false;
game.PreCacheObjects = true;
game.ProjectPath = MudEngine.FileSystem.FileManager.GetDataPath(MudEngine.FileSystem.SaveDataTypes.Root);
game.TimeOfDay = MudEngine.GameManagement.Game.TimeOfDayOptions.Transition;
game.TimeOfDayTransition = 30;
game.Version = "0.1";
game.Website = "http://MudDesigner.Codeplex.com";
game.ServerType = ProtocolType.Tcp;
game.ServerPort = 555;
game.MaximumPlayers = 1000;
//Create the world
BuildRealms();
//Load all of the available commands from the engine
MudEngine.GameManagement.CommandEngine.LoadAllCommands();
//Player must be instanced AFTER BuildRealms as it needs Game.InitialRealm.InitialZone.InitialRoom
//property so that it can set it's starting room correctly.
player = new MudEngine.GameObjects.Characters.BaseCharacter(game);
// Start the game & server
if (!game.Start())
Console.WriteLine("Error starting game!\nReview Log file for details.");
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();
//Simple Help info
Console.WriteLine("Available Commands are\n Look\n Exit\n Walk 'direction' where direction = north/south/east/west/up/down\n");
//Invoke the Look command so the player knows whats around him/her
Console.WriteLine(player.ExecuteCommand("Look").Result[0]);
while (game.IsRunning)
{
Console.Write("Command: ");
string command = Console.ReadLine();
//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;
if (result != null)
{
//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());
}
}
}
game.End();
Console.WriteLine("Press Enter to exit.");
Console.ReadKey();
}
static private void BuildRealms()
{
Zeroth zeroth = new Zeroth(game);
zeroth.BuildZeroth();
}
}
}