Created a turn manager.
This commit is contained in:
@@ -24,11 +24,11 @@ namespace DepthsBelow
|
||||
|
||||
public Lua Lua;
|
||||
|
||||
public EntityManager EntityManager;
|
||||
public EntityManager EntityManager;
|
||||
public TurnManager TurnManager;
|
||||
|
||||
public Camera Camera;
|
||||
|
||||
public bool PlayerTurn = true;
|
||||
public static MouseInput MouseInput;
|
||||
public static KeyboardInput KeyboardInput;
|
||||
public List<Soldier> Squad;
|
||||
@@ -64,18 +64,24 @@ namespace DepthsBelow
|
||||
/// and initialize them as well.
|
||||
/// </summary>
|
||||
protected override void Initialize()
|
||||
{
|
||||
{
|
||||
Lua = new Lua();
|
||||
|
||||
// TODO: Add your initialization logic here
|
||||
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);
|
||||
Squad = new List<Soldier>();
|
||||
Swarm = new List<SmallEnemy>();
|
||||
Volley = new List<Shot>();
|
||||
|
||||
// Run scripts after everything is initialized
|
||||
Lua = new Lua();
|
||||
Lua.LoadScripts();
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
@@ -104,7 +110,10 @@ namespace DepthsBelow
|
||||
TestMonster = new SmallEnemy(EntityManager, ref Swarm);
|
||||
TestMonster.X = 12;
|
||||
TestMonster.Y = 4;
|
||||
Swarm.Add(TestMonster);
|
||||
Swarm.Add(TestMonster);
|
||||
|
||||
// Load Lua scripts after everything is created
|
||||
Lua.LoadScripts();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -159,8 +168,6 @@ namespace DepthsBelow
|
||||
// Draw mouse input visuals
|
||||
MouseInput.Draw(spriteBatch);
|
||||
|
||||
TestMonster.GetComponent<Component.SpriteRenderer>().Draw(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
// Start drawing GUI components
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Camera.cs" />
|
||||
<Compile Include="TurnManager.cs" />
|
||||
<Compile Include="CustomExtensions.cs" />
|
||||
<Compile Include="EntityManager.cs" />
|
||||
<Compile Include="GameServices.cs" />
|
||||
|
||||
@@ -12,41 +12,36 @@ namespace DepthsBelow
|
||||
{
|
||||
public class KeyboardInput
|
||||
{
|
||||
Core core;
|
||||
bool Enter = false;
|
||||
bool turn;
|
||||
Core core;
|
||||
private KeyboardState lastKeyboardState;
|
||||
|
||||
int checkerSpeed = 2;
|
||||
|
||||
public KeyboardInput(Core core)
|
||||
{
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
KeyboardState ks = Keyboard.GetState();
|
||||
|
||||
if (ks.IsKeyUp(Keys.Enter) && Enter == true)
|
||||
{
|
||||
Enter = false;
|
||||
}
|
||||
|
||||
if (ks.IsKeyDown(Keys.Enter) && Enter == false)
|
||||
{
|
||||
Enter = true;
|
||||
if (core.PlayerTurn == false)
|
||||
if (ks.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter))
|
||||
{
|
||||
if (core.TurnManager.CurrentTurn == core.TurnManager["Player"])
|
||||
{
|
||||
core.PlayerTurn = true;
|
||||
foreach (var unit in core.Squad)
|
||||
{
|
||||
unit.step = 0;
|
||||
unit.Fired = false;
|
||||
}
|
||||
}
|
||||
|
||||
core.TurnManager.EndTurn();
|
||||
}
|
||||
else
|
||||
|
||||
if (core.TurnManager.CurrentTurn == core.TurnManager["Computer"])
|
||||
{
|
||||
core.TestMonster.step = 0;
|
||||
core.PlayerTurn = false;
|
||||
Point target = Point.Zero;
|
||||
float distance = 7000;
|
||||
foreach (var unit in core.Squad)
|
||||
@@ -63,7 +58,9 @@ namespace DepthsBelow
|
||||
}
|
||||
}
|
||||
core.TestMonster.GetComponent<Component.PathFinder>().Goal = target;
|
||||
distance = 7000;
|
||||
distance = 7000;
|
||||
|
||||
core.TurnManager.EndTurn();
|
||||
}
|
||||
}
|
||||
if (ks.IsKeyDown(Keys.A))
|
||||
@@ -161,7 +158,9 @@ namespace DepthsBelow
|
||||
hit = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastKeyboardState = ks;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ namespace DepthsBelow
|
||||
}
|
||||
}
|
||||
|
||||
if (core.PlayerTurn == true)
|
||||
if (core.TurnManager.CurrentTurn == core.TurnManager["Player"])
|
||||
{
|
||||
// Selection rectangle
|
||||
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