//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynter.Game
{
#region Using Statements
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Net;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.Xml;
#endregion
using DarkWynter.Engine;
using DarkWynter.Engine.Globals;
using DarkWynter.Engine.Menus;
using DarkWynter.Engine.Networking;
using DarkWynter.Engine.Utilities;
using Controllers;
using RuleBook;
using Menus;
using GameObjects;
//using WindowsGame2;
//using CSTextEditor;
using System.Windows.Forms;
using System.Collections;
using DarkWynter.Stream;
///
/// Base class for creating a game using the DarkWynter Engine.
/// DarkWynterEngine extends object modification to the user through XML.
/// DakrWynterEngine extends functionality to the user through overridable objects.
///
public class DarkWynterGame : DarkWynterEngine
{
#region Properties
///
/// Manage scoring, respawn, and gameover
///
private GameLogicController gameRules;
///
/// Game Controller
///
public static List gameControllers;
///
/// Menu Controller
///
public static List menuControllers;
//-- COMPILER
//Panel drawSurface;
//MainForm compilerForm;
//Form gameForm;
/////
///// Simple Network Client
/////
//private Client chatClient;
#endregion
#region Methods
// --------------- Constructor -----------------
///
/// Main Engine Class.
/// Check for Hardware Capabilities.
/// Create GraphicsDeviceManager and ContentManager.
///
public DarkWynterGame():base()
{
this.Dock = DockStyle.Fill;
//-- COMPILER
//drawSurface = new Panel();
//gameForm = Form.FromHandle(this.Window.Handle).FindForm();
//gameForm.IsMdiContainer = true;
//compilerForm = new MainForm();
//compilerForm.MdiParent = gameForm;
//Statics_Stream.RenderSettings.graphics.PreparingDeviceSettings += OnPreparingDeviceSettings;
}
/////
///// Set Form Draw Surface to Window Handle
/////
/////
/////
//private void OnPreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs args)
//{
// args.GraphicsDeviceInformation.PresentationParameters.DeviceWindowHandle = drawSurface.Handle;
//}
// ----------------- Load ----------------------
///
/// Set Up Display Window.
/// Create Logging, XML, GameFlow, Renderer, SpriteBatch,
/// FontWriter, MenuSystem, Audio, ShaderParameters, ChatClient,
/// Frames Per Second Counter, and Screensaver
///
protected override void Initialize()
{
DarkWynter.Game.Globals.Statics_Game.GameSettings.myThoughts = new List();
base.Initialize(new UserDefinedTypes());
// Menu System
menuSystem = new GameMenuSystem();
// Set up the Game Rules
gameRules = new GameLogicController();
// Controller Setup
gameControllers = new List();
menuControllers = new List();
ControllerManager.CheckForControllers(objectLibrary);
#region Old Compiler Code
//-- COMPILER
//drawSurface.Width = Statics_Stream.RenderSettings.clientWidth;
//drawSurface.Height = Statics_Stream.RenderSettings.clientHeight;
//drawSurface.Dock = DockStyle.Top;
//compilerForm.StartPosition = FormStartPosition.Manual;
//compilerForm.Location= new System.Drawing.Point(0, 650);
//compilerForm.Width = Statics_Stream.RenderSettings.clientWidth;
//compilerForm.Height = Statics_Stream.RenderSettings.clientHeight - 650;
//compilerForm.Dock = DockStyle.Bottom;
//compilerForm.MinimizeBox = false;
//compilerForm.MaximizeBox = false;
//compilerForm.TopLevel = false;
//compilerForm.FormBorderStyle = FormBorderStyle.None;
//compilerForm.Show();
//compilerForm.BackColor = System.Drawing.Color.Black;
//compilerForm.TransparencyKey = System.Drawing.Color.Black;
//this.Window.AllowUserResizing = true;
//gameForm.Text = "DarkWynterEngine Demo from www.darkwynter.com";
//gameForm.MinimizeBox = true;
//gameForm.MaximizeBox = true;
//gameForm.FormBorderStyle = FormBorderStyle.Fixed3D;
//gameForm.Controls.Add(drawSurface);
//gameForm.Controls.Add(compilerForm);
this.IsMouseVisible = false;
#endregion
// Get a web page
//string result = Socket_Simple.SocketSendReceive("DarkWynter.com", 80);
// Open a chat connection
//chatClient = new Client();
//chatClient.OpenConnection("amanda", 7777);
}
// --------------- Update ---------------------
///
/// Update MenuSystemGame, Audio, FPS.
/// Check For Level Loading Request.
/// Check For Exit.
///
/// XNA GameTime
protected override void Update(GameTime gameTime)
{
// Game Update current section of Game Pipeline
if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.GAME_MODE)
{
// Update GameRules
gameRules.Update(ref objectLibrary);
if (Statics_Engine.SystemSettings.WINDOW_IN_FOCUS)
{
// Update Controllers
foreach (GameController gameController in gameControllers)
{
// Check that the human is alive and hence active in the game
if (objectLibrary.humans[gameController.playerNumber].IsAlive())
{
gameController.Update(ref objectLibrary, ref menuSystem);
}
}
}
}
// Menu update
else
{
// Update all menu controllers
foreach (MenuController menuController in menuControllers)
{
menuController.Update(ref objectLibrary, ref menuSystem);
}
}
// Check for user exit request
CheckExit();
base.Update(gameTime);
}
// ----------------- Draw ----------------------
///
/// Draw Game or MenuSystem Screen
///
/// XNA GameTime
protected override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
renderer.DisableSpriteBatches();
}
// ---------------- Exit -----------------------
///
/// Reset the Graphics Device Settings after using SpriteBatch.
/// Use this function if you are experiencing weird effects after using SpriteBatch.
///
///
/// Check to see if user has requested to exit the application.
///
protected override void CheckExit()
{
if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.EXIT)
{
DarkWynter.Engine.Controllers.Controller.StopRumble(objectLibrary);
base.CheckExit();
}
}
#endregion
private void InitializeComponent()
{
this.SuspendLayout();
//
// DarkWynterGame
//
this.Name = "DarkWynterGame";
this.Size = new System.Drawing.Size(537, 314);
this.ResumeLayout(false);
}
#region Utilities
#endregion
}
}