Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### ЗЕМЛЯ И ДИГГЕР
- using System;
- using Avalonia.Input;
- using Digger.Architecture;
- namespace Digger;
- public class Terrain : ICreature
- {
- public string GetImageFileName()
- {
- return "Terrain.png";
- }
- public bool DeadInConflict(ICreature conflictObj)
- {
- return true;
- }
- public int GetDrawingPriority()
- {
- return 0;
- }
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand { DeltaX = 0, DeltaY = 0 };
- }
- }
- public class Player : ICreature
- {
- public string GetImageFileName()
- {
- return "Digger.png";
- }
- public bool DeadInConflict(ICreature conflictObj)
- {
- return false;
- }
- public int GetDrawingPriority()
- {
- return 1;
- }
- public CreatureCommand Act(int x, int y)
- {
- var key = Game.KeyPressed;
- var command = new CreatureCommand { DeltaX = 0, DeltaY = 0 };
- switch (key)
- {
- case Key.Down:
- if (y < Game.MapHeight - 1)
- {
- command.DeltaY = 1;
- }
- break;
- case Key.Up:
- if (y > 0)
- {
- command.DeltaY = -1;
- }
- break;
- case Key.Left:
- if (x > 0)
- {
- command.DeltaX = -1;
- }
- break;
- case Key.Right:
- if (x < Game.MapWidth - 1)
- {
- command.DeltaX = 1;
- }
- break;
- }
- return command;
- }
- }
- ## Мешки и золото
- using System;
- using System.Diagnostics.Metrics;
- using System.Threading;
- using Avalonia.Input;
- using Digger.Architecture;
- namespace Digger;
- public class Terrain : ICreature
- {
- public string GetImageFileName()
- {
- return "Terrain.png";
- }
- public bool DeadInConflict(ICreature conflictObj)
- {
- return true;
- }
- public int GetDrawingPriority()
- {
- return 0;
- }
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand { DeltaX = 0, DeltaY = 0 };
- }
- }
- public class Gold : ICreature
- {
- public string GetImageFileName()
- {
- return "Gold.png";
- }
- public int GetDrawingPriority()
- {
- return 4;
- }
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand { DeltaX = 0, DeltaY = 0 } ;
- }
- public bool DeadInConflict(ICreature conflictObj)
- {
- return true;
- }
- }
- public class Sack : ICreature
- {
- private int counter = 0;
- public string GetImageFileName()
- {
- return "Sack.png";
- }
- public int GetDrawingPriority()
- {
- return 3;
- }
- 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.ToString() == "Digger.Player" ||
- map.ToString() == "Digger.Monster")))
- {
- counter++;
- return new CreatureCommand { DeltaX = 0, DeltaY = 1 };
- }
- }
- if (counter > 1)
- {
- counter = 0;
- return new CreatureCommand { DeltaX = 0, DeltaY = 0, TransformTo = new Gold() };
- }
- counter = 0;
- return new CreatureCommand { DeltaX = 0, DeltaY = 0};
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- return false;
- }
- }
- public class Monster : ICreature
- {
- public string GetImageFileName()
- {
- return "Monster.png";
- }
- public int GetDrawingPriority()
- {
- return 2;
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- return conflictedObject is Sack || conflictedObject is Monster;
- }
- public CreatureCommand Act(int x, int y)
- {
- (var playerX, var playerY) = Player.GetCurrentPosition();
- if (playerX == -1)
- return new CreatureCommand { DeltaX = 0, DeltaY = 0 };;
- (var moveX, var moveY) = Player.GetMoveToPlayer(x, y, playerX, playerY);
- if (x + moveX != playerX || y + moveY != playerY - 1)
- return CanMonsterMoveTo(x, y, moveX, moveY)
- ? new CreatureCommand { DeltaX = 0, DeltaY = 0 }
- : new CreatureCommand { DeltaX = moveX, DeltaY = moveY };
- Game.Map[x + moveX, y + moveY] = null;
- return new CreatureCommand { DeltaX = 0, DeltaY = 0};
- }
- private static bool CanMonsterMoveTo(int x, int y, int moveX, int moveY)
- {
- var newX = x + moveX;
- var newY = y + moveY;
- var isOutsideMap = newX < 0 || newY < 0 || newX >= Game.MapWidth || newY >= Game.MapHeight;
- if (isOutsideMap)
- return true;
- var newPosition = Game.Map[newX, newY];
- return newPosition is Sack || newPosition is Monster || newPosition is Terrain;
- }
- }
- public class Player : ICreature
- {
- public string GetImageFileName()
- {
- return "Digger.png";
- }
- public static (int, int) GetMoveToPlayer(int x, int y, int playerX, int playerY)
- {
- var deltaX = 0;
- var deltaY = 0;
- if (x != playerX)
- {
- deltaX = (x < playerX) ? 1 : -1;
- }
- else if (y != playerY)
- {
- deltaY = (y < playerY) ? 1 : -1;
- }
- return (deltaX, deltaY);
- }
- public bool DeadInConflict(ICreature conflictObj)
- {
- if (conflictObj is Gold)
- {
- Game.Scores += 10;
- }
- return conflictObj is Monster || conflictObj is Sack;
- }
- public int GetDrawingPriority()
- {
- return 1;
- }
- public static (int playerX, int playerY) GetCurrentPosition()
- {
- for (var i = 0; i < Game.MapWidth; i++)
- {
- for (var j = 0; j < Game.MapHeight; j++)
- {
- if (Game.Map[i, j] is Player)
- return (i, j);
- }
- }
- return (-1, -1);
- }
- public CreatureCommand Act(int x, int y)
- {
- var key = Game.KeyPressed;
- var command = new CreatureCommand { DeltaX = 0, DeltaY = 0 };
- switch (key)
- {
- case Key.Down:
- if (y < Game.MapHeight - 1)
- {
- command.DeltaY = 1;
- }
- break;
- case Key.Up:
- if (y > 0)
- {
- command.DeltaY = -1;
- }
- break;
- case Key.Left:
- if (x > 0)
- {
- command.DeltaX = -1;
- }
- break;
- case Key.Right:
- if (x < Game.MapWidth - 1)
- {
- command.DeltaX = 1;
- }
- break;
- }
- if (Game.Map[x + command.DeltaX, y + command.DeltaY] is Sack)
- {
- return new CreatureCommand { DeltaX = 0, DeltaY = 0 };
- }
- return command;
- }
- }
- ## Монстры
- using System;
- using System.Diagnostics.Metrics;
- using System.Threading;
- using Avalonia.Input;
- using Digger.Architecture;
- namespace Digger;
- public class Terrain : ICreature
- {
- public string GetImageFileName()
- {
- return "Terrain.png";
- }
- public bool DeadInConflict(ICreature conflictObj)
- {
- return true;
- }
- public int GetDrawingPriority()
- {
- return 0;
- }
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand { DeltaX = 0, DeltaY = 0 };
- }
- }
- public class Gold : ICreature
- {
- public string GetImageFileName()
- {
- return "Gold.png";
- }
- public int GetDrawingPriority()
- {
- return 4;
- }
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand { DeltaX = 0, DeltaY = 0 } ;
- }
- public bool DeadInConflict(ICreature conflictObj)
- {
- return true;
- }
- }
- public class Sack : ICreature
- {
- private int counter = 0;
- public string GetImageFileName()
- {
- return "Sack.png";
- }
- public int GetDrawingPriority()
- {
- return 3;
- }
- 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.ToString() == "Digger.Player" ||
- map.ToString() == "Digger.Monster")))
- {
- counter++;
- return new CreatureCommand() { DeltaX = 0, DeltaY = 1 };
- }
- }
- if (counter > 1)
- {
- counter = 0;
- return new CreatureCommand() { DeltaX = 0, DeltaY = 0, TransformTo = new Gold() };
- }
- counter = 0;
- return new CreatureCommand() { DeltaX = 0, DeltaY = 0};
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- return false;
- }
- }
- public class Monster : ICreature
- {
- public string GetImageFileName()
- {
- return "Monster.png";
- }
- public int GetDrawingPriority()
- {
- return 2;
- }
- public bool DeadInConflict(ICreature conflictedObject)
- {
- return conflictedObject is Sack || conflictedObject is Monster;
- }
- public CreatureCommand Act(int x, int y)
- {
- (var playerX, var playerY) = Player.GetCurrentPosition();
- if (playerX == -1)
- return new CreatureCommand();
- (var moveX, var moveY) = Player.GetMoveToPlayer(x, y, playerX, playerY);
- if (x + moveX != playerX || y + moveY != playerY - 1)
- return CanMonsterMoveTo(x, y, moveX, moveY)
- ? new CreatureCommand { DeltaX = 0, DeltaY = 0 }
- : new CreatureCommand { DeltaX = moveX, DeltaY = moveY };
- Game.Map[x + moveX, y + moveY] = null;
- return new CreatureCommand { DeltaX = 0, DeltaY = 0};
- }
- private static bool CanMonsterMoveTo(int x, int y, int moveX, int moveY)
- {
- var newX = x + moveX;
- var newY = y + moveY;
- var isOutsideMap = newX < 0 || newY < 0 || newX >= Game.MapWidth || newY >= Game.MapHeight;
- if (isOutsideMap)
- return true;
- var newPosition = Game.Map[newX, newY];
- return newPosition is Sack || newPosition is Monster || newPosition is Terrain;
- }
- }
- public class Player : ICreature
- {
- public string GetImageFileName()
- {
- return "Digger.png";
- }
- public static (int, int) GetMoveToPlayer(int x, int y, int playerX, int playerY)
- {
- var deltaX = 0;
- var deltaY = 0;
- if (x != playerX)
- {
- deltaX = (x < playerX) ? 1 : -1;
- }
- else if (y != playerY)
- {
- deltaY = (y < playerY) ? 1 : -1;
- }
- return (deltaX, deltaY);
- }
- public bool DeadInConflict(ICreature conflictObj)
- {
- if (conflictObj is Gold)
- {
- Game.Scores += 10;
- }
- return conflictObj is Monster || conflictObj is Sack;
- }
- public int GetDrawingPriority()
- {
- return 1;
- }
- public static (int playerX, int playerY) GetCurrentPosition()
- {
- for (var i = 0; i < Game.MapWidth; i++)
- {
- for (var j = 0; j < Game.MapHeight; j++)
- {
- if (Game.Map[i, j] is Player)
- return (i, j);
- }
- }
- return (-1, -1);
- }
- public CreatureCommand Act(int x, int y)
- {
- var key = Game.KeyPressed;
- var command = new CreatureCommand { DeltaX = 0, DeltaY = 0 };
- switch (key)
- {
- case Key.Down:
- if (y < Game.MapHeight - 1)
- {
- command.DeltaY = 1;
- }
- break;
- case Key.Up:
- if (y > 0)
- {
- command.DeltaY = -1;
- }
- break;
- case Key.Left:
- if (x > 0)
- {
- command.DeltaX = -1;
- }
- break;
- case Key.Right:
- if (x < Game.MapWidth - 1)
- {
- command.DeltaX = 1;
- }
- break;
- }
- if (Game.Map[x + command.DeltaX, y + command.DeltaY] is Sack)
- {
- return new CreatureCommand { DeltaX = 0, DeltaY = 0 };
- }
- return command;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment