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;
- using System.Windows.Input;
- namespace Digger
- {
- class Terrain : ICreature
- {
- public CreatureCommand Act(int x, int y)
- {
- var nothing = new CreatureCommand();
- return nothing;
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- return true;
- }
- public int GetDrawingPriority()
- {
- return 0;
- }
- public string GetImageFileName()
- {
- return "Terrain.png";
- }
- }
- class Player : ICreature
- {
- public CreatureCommand Act(int x, int y)
- {
- var command = new CreatureCommand();
- switch (Game.KeyPressed)
- {
- case Keys.Up: command.DeltaY--; break;
- case Keys.Down: command.DeltaY++; break;
- case Keys.Left: command.DeltaX--; break;
- case Keys.Right: command.DeltaX++; break;
- }
- var newX = x + command.DeltaX;
- var newY = y + command.DeltaY;
- if (newX < 0 || newX >= Game.MapWidth || newY < 0 || newY >= Game.MapHeight
- || Game.Map[newX, newY] is Sack)
- return new CreatureCommand();
- return command;
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- if (conflictedObject is Sack)
- {
- Sack sack = (Sack)conflictedObject;
- return sack.AmountBlocks > 0;
- }
- if (conflictedObject is Monster)
- return true;
- else
- return false;
- }
- public int GetDrawingPriority()
- {
- return 0;
- }
- public string GetImageFileName()
- {
- return "Digger.png";
- }
- }
- class Monster : ICreature
- {
- public int[] SearchPlayer()
- {
- for (int x = 0; x < Game.MapHeight; x++)
- for (int y = 0; y < Game.MapWidth; y++)
- if (Game.Map[x, y] is Player)
- return new int[2] { x, y };
- return null;
- }
- public CreatureCommand Act(int x, int y)
- {
- var PlayerLocation = SearchPlayer();
- var monster = new CreatureCommand();
- if (PlayerLocation == null)
- return new CreatureCommand();
- var command = new CreatureCommand();
- var deltaX = PlayerLocation[0] == x ? 0 : (PlayerLocation[0] - x) / Math.Abs(PlayerLocation[0] - x);
- var deltaY = PlayerLocation[1] == y ? 0 : (PlayerLocation[1] - y) / Math.Abs(PlayerLocation[1] - y);
- var newX = x + deltaX;
- var newY = y + deltaY;
- if (Game.Map[newX, y] is null || Game.Map[newX, y] is Player || Game.Map[newX, y] is Gold)
- command.DeltaX += deltaX;
- else if (Game.Map[x, newY] is null || Game.Map[x, newY] is Player || Game.Map[x, newY] is Gold)
- command.DeltaY += deltaY;
- return command;
- }
- public bool DeadInConflict(ICreature conflictedObject)
- => conflictedObject is Sack || conflictedObject is Monster;
- public int GetDrawingPriority()
- {
- return 0;
- }
- public string GetImageFileName()
- {
- return "Monster.png";
- }
- }
- class Sack : ICreature
- {
- public int AmountBlocks = 0;
- public CreatureCommand Act(int x, int y)
- {
- var command = new CreatureCommand();
- if (y++ < Game.MapHeight - 1 && (Game.Map[x, y] is null || AmountBlocks > 0
- && (Game.Map[x, y] is Monster || Game.Map[x, y] is Player)))
- {
- AmountBlocks++;
- command.DeltaY++;
- }
- else
- {
- if (AmountBlocks > 1)
- command.TransformTo = new Gold();
- AmountBlocks = 0;
- }
- return command;
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- if (conflictedObject is Player)
- if (AmountBlocks > 0)
- conflictedObject.DeadInConflict(this);
- return false;
- }
- public int GetDrawingPriority()
- {
- return 1;
- }
- public string GetImageFileName()
- {
- return "Sack.png";
- }
- }
- class Gold : ICreature
- {
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand();
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- if (conflictedObject is Player)
- {
- Game.Scores += 10;
- return true;
- }
- if (conflictedObject is Monster)
- return true;
- else
- return false;
- }
- public int GetDrawingPriority()
- {
- return 0;
- }
- public string GetImageFileName()
- {
- return "Gold.png";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement