Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Digger
- {
- public enum DrawPriority
- {
- Player = 1,
- Terrain = 2,
- Sack = 3,
- Gold = 4
- };
- public class Terrain : ICreature
- {
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand();
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- return true;
- }
- public int GetDrawingPriority()
- {
- return (int)DrawPriority.Terrain;
- }
- public string GetImageFileName()
- {
- return "Terrain.png";
- }
- }
- public class Player : ICreature
- {
- public CreatureCommand Act(int x, int y)
- {
- var deltaX = 0;
- var deltaY = 0;
- if (Game.KeyPressed == Keys.Up)
- deltaY -= 1;
- if (Game.KeyPressed == Keys.Down)
- deltaY += 1;
- if (Game.KeyPressed == Keys.Right)
- deltaX += 1;
- if (Game.KeyPressed == Keys.Left)
- deltaX -= 1;
- var newX = x + deltaX;
- var newY = y + deltaY;
- if (newX >= Game.MapWidth || newX < 0)
- deltaX = 0;
- if (newY >= Game.MapHeight || newY < 0)
- deltaY = 0;
- IsMove(ref deltaX, ref deltaY, newX, newY);
- return new CreatureCommand
- {
- DeltaX = deltaX,
- DeltaY = deltaY
- };
- }
- private static void IsMove(ref int deltaX, ref int deltaY, int newX, int newY)
- {
- if (newX < Game.MapWidth && newX >= 0 &&
- newY < Game.MapHeight && newY >= 0)
- {
- var nextCreature = Game.Map[newX, newY];
- if (nextCreature != null)
- {
- if (nextCreature.GetType() == typeof(Sack))
- deltaX = deltaY = 0;
- }
- }
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- return conflictedObject.GetType() == typeof(Sack);
- }
- public int GetDrawingPriority()
- {
- return (int)DrawPriority.Player;
- }
- public string GetImageFileName()
- {
- return "Digger.png";
- }
- }
- public class Sack : ICreature
- {
- public int CounterFallingDownSack = 0;
- public CreatureCommand Act(int x, int y)
- {
- int deltaY, newY;
- ChangeSackCoordinates(x, y, out deltaY, out newY);
- if (newY >= Game.MapHeight)
- deltaY = 0;
- var transform = this as ICreature;
- CounterFallingDownSack += deltaY;
- if (deltaY == 0)
- {
- if (CounterFallingDownSack >= 2)
- {
- transform = new Gold() as ICreature;
- }
- CounterFallingDownSack = 0;
- }
- return new CreatureCommand
- {
- DeltaX = 0,
- DeltaY = deltaY,
- TransformTo = transform
- };
- }
- private void ChangeSackCoordinates(int x, int y, out int deltaY, out int newY)
- {
- deltaY = 1;
- newY = y + deltaY;
- if (newY < Game.MapHeight)
- {
- var below = Game.Map[x, newY];
- if (below != null)
- {
- if (below.GetType() == typeof(Terrain) || below.GetType() == typeof(Sack) ||
- below.GetType() == typeof(Gold) || (below.GetType() == typeof(Player) &&
- CounterFallingDownSack == 0))
- deltaY = 0;
- }
- }
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- return false;
- }
- public int GetDrawingPriority()
- {
- return (int)DrawPriority.Sack;
- }
- public string GetImageFileName()
- {
- return "Sack.png";
- }
- }
- public class Gold : ICreature
- {
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand();
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- if (conflictedObject.GetType() == typeof(Player))
- {
- Game.Scores += 10;
- return true;
- }
- return false;
- }
- public int GetDrawingPriority()
- {
- return (int)DrawPriority.Gold;
- }
- public string GetImageFileName()
- {
- return "Gold.png";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement