Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Digger
- {
- public class Terrain : ICreature
- {
- public CreatureCommand Act(int x, int y) => new CreatureCommand {DeltaX = 0, DeltaY = 0};
- public bool DeadInConflict(ICreature conflictedObject) => true;
- public int GetDrawingPriority() => 2;
- public string GetImageFileName() => "Terrain.png";
- }
- public class Player : ICreature
- {
- public CreatureCommand Act(int x, int y)
- {
- switch (Game.KeyPressed)
- {
- case System.Windows.Forms.Keys.Left:
- if (IsStepPossible(x - 1, y))
- return new CreatureCommand {DeltaX = -1, DeltaY = 0};
- break;
- case System.Windows.Forms.Keys.Up:
- if (IsStepPossible(x, y - 1))
- return new CreatureCommand {DeltaX = 0, DeltaY = -1};
- break;
- case System.Windows.Forms.Keys.Right:
- if (IsStepPossible(x + 1, y))
- return new CreatureCommand {DeltaX = 1, DeltaY = 0};
- break;
- case System.Windows.Forms.Keys.Down:
- if (IsStepPossible(x, y + 1))
- return new CreatureCommand {DeltaX = 0, DeltaY = 1};
- break;
- }
- return new CreatureCommand();
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- if (conflictedObject is Gold)
- {
- Game.Scores += 10;
- return false;
- }
- return conflictedObject is Sack;
- }
- public int GetDrawingPriority() => 1;
- public string GetImageFileName() => "Digger.png";
- private bool IsStepPossible(int x, int y)
- {
- if (!(x >= 0 && x < Game.MapWidth && y >= 0 && y < Game.MapHeight))
- return false;
- return Game.Map[x, y] == null || !(Game.Map[x, y] is Sack);
- }
- }
- public class Sack : ICreature
- {
- private int counter;
- public CreatureCommand Act(int x, int y)
- {
- if (y < Game.MapHeight - 1)
- {
- var map = Game.Map[x, y + 1];
- if (map == null || counter > 0 && map is Player)
- {
- counter++;
- return new CreatureCommand {DeltaX = 0, DeltaY = 1};
- }
- }
- if (counter > 1)
- return new CreatureCommand {DeltaX = 0, DeltaY = 0, TransformTo = new Gold()};
- counter = 0;
- return new CreatureCommand {DeltaX = 0, DeltaY = 0};
- }
- public bool DeadInConflict(ICreature conflictedObject) => false;
- public int GetDrawingPriority() => 5;
- public string GetImageFileName() => "Sack.png";
- }
- public class Gold : ICreature
- {
- public CreatureCommand Act(int x, int y) => new CreatureCommand {DeltaX = 0, DeltaY = 0};
- public bool DeadInConflict(ICreature conflictedObject) => conflictedObject is Player;
- public int GetDrawingPriority() => 3;
- public string GetImageFileName() => "Gold.png";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement