Created a turn manager.
This commit is contained in:
@@ -25,10 +25,10 @@ namespace DepthsBelow
|
|||||||
public Lua Lua;
|
public Lua Lua;
|
||||||
|
|
||||||
public EntityManager EntityManager;
|
public EntityManager EntityManager;
|
||||||
|
public TurnManager TurnManager;
|
||||||
|
|
||||||
public Camera Camera;
|
public Camera Camera;
|
||||||
|
|
||||||
public bool PlayerTurn = true;
|
|
||||||
public static MouseInput MouseInput;
|
public static MouseInput MouseInput;
|
||||||
public static KeyboardInput KeyboardInput;
|
public static KeyboardInput KeyboardInput;
|
||||||
public List<Soldier> Squad;
|
public List<Soldier> Squad;
|
||||||
@@ -65,17 +65,23 @@ namespace DepthsBelow
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void Initialize()
|
protected override void Initialize()
|
||||||
{
|
{
|
||||||
|
Lua = new Lua();
|
||||||
|
|
||||||
// TODO: Add your initialization logic here
|
// TODO: Add your initialization logic here
|
||||||
EntityManager = new EntityManager();
|
EntityManager = new EntityManager();
|
||||||
|
|
||||||
|
TurnManager = new TurnManager(new string[] { "Player", "Computer" });
|
||||||
|
Console.WriteLine("Current turn: " + TurnManager.CurrentTurn.Name);
|
||||||
|
TurnManager.EndTurn();
|
||||||
|
Console.WriteLine("Current turn: " + TurnManager.CurrentTurn.Name);
|
||||||
|
TurnManager.EndTurn();
|
||||||
|
Console.WriteLine("Current turn: " + TurnManager.CurrentTurn.Name);
|
||||||
|
|
||||||
Camera = new Camera(this);
|
Camera = new Camera(this);
|
||||||
Squad = new List<Soldier>();
|
Squad = new List<Soldier>();
|
||||||
Swarm = new List<SmallEnemy>();
|
Swarm = new List<SmallEnemy>();
|
||||||
Volley = new List<Shot>();
|
Volley = new List<Shot>();
|
||||||
|
|
||||||
// Run scripts after everything is initialized
|
|
||||||
Lua = new Lua();
|
|
||||||
Lua.LoadScripts();
|
|
||||||
|
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +111,9 @@ namespace DepthsBelow
|
|||||||
TestMonster.X = 12;
|
TestMonster.X = 12;
|
||||||
TestMonster.Y = 4;
|
TestMonster.Y = 4;
|
||||||
Swarm.Add(TestMonster);
|
Swarm.Add(TestMonster);
|
||||||
|
|
||||||
|
// Load Lua scripts after everything is created
|
||||||
|
Lua.LoadScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -159,8 +168,6 @@ namespace DepthsBelow
|
|||||||
// Draw mouse input visuals
|
// Draw mouse input visuals
|
||||||
MouseInput.Draw(spriteBatch);
|
MouseInput.Draw(spriteBatch);
|
||||||
|
|
||||||
TestMonster.GetComponent<Component.SpriteRenderer>().Draw(spriteBatch);
|
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
// Start drawing GUI components
|
// Start drawing GUI components
|
||||||
|
|||||||
@@ -121,6 +121,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Camera.cs" />
|
<Compile Include="Camera.cs" />
|
||||||
|
<Compile Include="TurnManager.cs" />
|
||||||
<Compile Include="CustomExtensions.cs" />
|
<Compile Include="CustomExtensions.cs" />
|
||||||
<Compile Include="EntityManager.cs" />
|
<Compile Include="EntityManager.cs" />
|
||||||
<Compile Include="GameServices.cs" />
|
<Compile Include="GameServices.cs" />
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ namespace DepthsBelow
|
|||||||
public class KeyboardInput
|
public class KeyboardInput
|
||||||
{
|
{
|
||||||
Core core;
|
Core core;
|
||||||
bool Enter = false;
|
private KeyboardState lastKeyboardState;
|
||||||
bool turn;
|
|
||||||
int checkerSpeed = 2;
|
int checkerSpeed = 2;
|
||||||
|
|
||||||
public KeyboardInput(Core core)
|
public KeyboardInput(Core core)
|
||||||
@@ -26,27 +26,22 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
KeyboardState ks = Keyboard.GetState();
|
KeyboardState ks = Keyboard.GetState();
|
||||||
|
|
||||||
if (ks.IsKeyUp(Keys.Enter) && Enter == true)
|
if (ks.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter))
|
||||||
{
|
{
|
||||||
Enter = false;
|
if (core.TurnManager.CurrentTurn == core.TurnManager["Player"])
|
||||||
}
|
|
||||||
|
|
||||||
if (ks.IsKeyDown(Keys.Enter) && Enter == false)
|
|
||||||
{
|
|
||||||
Enter = true;
|
|
||||||
if (core.PlayerTurn == false)
|
|
||||||
{
|
{
|
||||||
core.PlayerTurn = true;
|
|
||||||
foreach (var unit in core.Squad)
|
foreach (var unit in core.Squad)
|
||||||
{
|
{
|
||||||
unit.step = 0;
|
unit.step = 0;
|
||||||
unit.Fired = false;
|
unit.Fired = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.TurnManager.EndTurn();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (core.TurnManager.CurrentTurn == core.TurnManager["Computer"])
|
||||||
{
|
{
|
||||||
core.TestMonster.step = 0;
|
core.TestMonster.step = 0;
|
||||||
core.PlayerTurn = false;
|
|
||||||
Point target = Point.Zero;
|
Point target = Point.Zero;
|
||||||
float distance = 7000;
|
float distance = 7000;
|
||||||
foreach (var unit in core.Squad)
|
foreach (var unit in core.Squad)
|
||||||
@@ -64,6 +59,8 @@ namespace DepthsBelow
|
|||||||
}
|
}
|
||||||
core.TestMonster.GetComponent<Component.PathFinder>().Goal = target;
|
core.TestMonster.GetComponent<Component.PathFinder>().Goal = target;
|
||||||
distance = 7000;
|
distance = 7000;
|
||||||
|
|
||||||
|
core.TurnManager.EndTurn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ks.IsKeyDown(Keys.A))
|
if (ks.IsKeyDown(Keys.A))
|
||||||
@@ -162,6 +159,8 @@ namespace DepthsBelow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastKeyboardState = ks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ namespace DepthsBelow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core.PlayerTurn == true)
|
if (core.TurnManager.CurrentTurn == core.TurnManager["Player"])
|
||||||
{
|
{
|
||||||
// Selection rectangle
|
// Selection rectangle
|
||||||
if (ms.LeftButton == ButtonState.Pressed)
|
if (ms.LeftButton == ButtonState.Pressed)
|
||||||
|
|||||||
Executable
+116
@@ -0,0 +1,116 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DepthsBelow
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Keeps track of whose turn it is.
|
||||||
|
/// </summary>
|
||||||
|
public class TurnManager
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A player turn token.
|
||||||
|
/// </summary>
|
||||||
|
public class Token
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Unique identifying name of the token.
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; private set; }
|
||||||
|
private TurnManager turnManager;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Token" /> class.
|
||||||
|
/// Preferably use <see cref="TurnManager.CreateToken" /> instead.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="turnManager">The turn manager the token belongs to.</param>
|
||||||
|
/// <param name="name">Unique identifying name of the token.</param>
|
||||||
|
public Token(TurnManager turnManager, string name)
|
||||||
|
{
|
||||||
|
this.turnManager = turnManager;
|
||||||
|
this.Name = name;
|
||||||
|
turnManager.AddToken(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dictionary of turn tokens.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, Token> Tokens;
|
||||||
|
private int currentTokenIndex;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The turn token belonging to a player.
|
||||||
|
/// </summary>
|
||||||
|
public Token CurrentTurn
|
||||||
|
{
|
||||||
|
get { return Tokens.ElementAt(currentTokenIndex).Value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the turn token by the specified name.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The identifying name of the player.</param>
|
||||||
|
/// <returns>Returns a player turn token.</returns>
|
||||||
|
public Token this[string name]
|
||||||
|
{
|
||||||
|
get { return this.Tokens[name]; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a turn manager.
|
||||||
|
/// </summary>
|
||||||
|
public TurnManager()
|
||||||
|
{
|
||||||
|
Tokens = new Dictionary<string, Token>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a turn manager.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tokenNames">Tokens of players.</param>
|
||||||
|
public TurnManager(string[] tokenNames)
|
||||||
|
: this()
|
||||||
|
{
|
||||||
|
foreach (var tokenName in tokenNames)
|
||||||
|
CreateToken(tokenName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a turn token.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Name of the token.</param>
|
||||||
|
/// <returns>Returns a player turn token.</returns>
|
||||||
|
public Token CreateToken(string name)
|
||||||
|
{
|
||||||
|
return Tokens.ContainsKey(name) ? Tokens[name] : new Token(this, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a turn token to
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
public void AddToken(Token token)
|
||||||
|
{
|
||||||
|
if (!Tokens.ContainsKey(token.Name))
|
||||||
|
Tokens.Add(token.Name, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// End the current turn, skipping to the next token in the dictionary.
|
||||||
|
/// </summary>
|
||||||
|
public void EndTurn()
|
||||||
|
{
|
||||||
|
var prevTurn = CurrentTurn;
|
||||||
|
|
||||||
|
if (++currentTokenIndex > Tokens.Count - 1)
|
||||||
|
currentTokenIndex = 0;
|
||||||
|
|
||||||
|
Debug.WriteLine(prevTurn.Name + " turn ended. Current turn: " + CurrentTurn.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user