AiTest/Sprite.cs
Download
aitest.zip
(11.27 KB | 19 June 2010 )
Sample project for implementing the AI of the Butterfly and Firefly sprites of the Boulderdash arcade game.
Donate
If this site or its services have saved you time, please consider a donation to help with running costs and timely updates.
Contents of aitest.zip/AiTest/Sprite.cs
using System;
using System.Drawing;
namespace AiTest
{
abstract class Sprite
{
#region Public Abstract Methods
public abstract void Move();
#endregion Public Abstract Methods
#region Public Methods
public Tile GetAdjacentTile(Direction direction)
{
Tile result;
switch (direction)
{
case Direction.Up:
result = this.Map.Tiles[this.Location.X, this.Location.Y - 1];
break;
case Direction.Left:
result = this.Map.Tiles[this.Location.X + 1, this.Location.Y];
break;
case Direction.Down:
result = this.Map.Tiles[this.Location.X, this.Location.Y + 1];
break;
case Direction.Right:
result = this.Map.Tiles[this.Location.X - 1, this.Location.Y];
break;
default:
throw new ArgumentException();
}
return result;
}
public Direction GetNewDirection(Direction turnDirection)
{
Direction result;
switch (turnDirection)
{
case Direction.Left:
result = this.Direction - 1;
if (result < Direction.Up)
result = Direction.Right;
break;
case Direction.Right:
result = this.Direction + 1;
if (result > Direction.Right)
result = Direction.Up;
break;
default:
throw new ArgumentException();
}
return result;
}
#endregion Public Methods
#region Public Properties
public abstract Color Color { get; }
public Direction Direction { get; set; }
public Point Location { get; set; }
public Map Map { get; set; }
#endregion Public Properties
}
}
