ported from perforce
This commit is contained in:
27
RobotAndDonkey.Game/Intents/Turn.cs
Normal file
27
RobotAndDonkey.Game/Intents/Turn.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using RobotAndDonkey.Game.Board;
|
||||
using RobotAndDonkey.Game.Execution.Results;
|
||||
using RobotAndDonkey.Game.GameState;
|
||||
using RobotAndDonkey.Game.Pois;
|
||||
|
||||
namespace RobotAndDonkey.Game.Intents;
|
||||
|
||||
public class Turn(Cell cell, int delta) : Intent
|
||||
{
|
||||
public override void Run(Guid requestId, CoreLoop coreLoop, List<Intent> newIntents, List<Result> results)
|
||||
{
|
||||
var avatar = (Avatar)cell.Poi!;
|
||||
var newDirection = ((int)avatar.Direction + Delta) % 6;
|
||||
if (newDirection < 0)
|
||||
newDirection += 6;
|
||||
avatar.Direction = (EDirection)newDirection;
|
||||
results.Add(new PoiResult(requestId, new(coreLoop.Board), avatar, cell.Hex));
|
||||
|
||||
base.Run(requestId, coreLoop, newIntents, results);
|
||||
}
|
||||
|
||||
public override bool IsValid(CoreLoop coreLoop) => base.IsValid(coreLoop) && cell.Poi is Avatar;
|
||||
|
||||
public int Delta { get; set; } = delta;
|
||||
|
||||
public override string ToString() => $"Turn by {Delta}, " + base.ToString();
|
||||
}
|
||||
Reference in New Issue
Block a user