Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Решается задача:
- * https://ulearn.me/Course/BasicProgramming/Praktika_Zemlya_i_Digger__b4fba55d-b35d-4366-b3e3-e1d7f53268b1
- * Автор решения: Шарафеев Равиль, 11-808
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Digger {
- public class Player : ICreature {
- public string GetImageFileName() {
- return "Digger.png";
- }
- public int GetDrawingPriority() {
- return 0;
- }
- private bool isCreatureOfType(int x, int y, Type type) {
- return Game.Map[x, y] != null && Game.Map[x, y].GetType() == type;
- }
- public CreatureCommand Act(int x, int y) {
- Keys keys = Game.KeyPressed;
- //Если нажата кнопка перемещения и перемещение возможно, то передает изменение нужной координаты
- //Плюс ограничение перемещения игрока в позицию мешка
- if (keys == Keys.Left || keys == Keys.A) {
- if (x > 0 && !isCreatureOfType(x - 1, y, typeof(Sack))) {
- return new CreatureCommand() { DeltaX = -1 };
- }
- }
- if (keys == Keys.Up || keys == Keys.W) {
- if (y > 0 && !isCreatureOfType(x, y - 1, typeof(Sack))) {
- return new CreatureCommand() { DeltaY = -1 };
- }
- }
- if (keys == Keys.Right || keys == Keys.D) {
- if (x < Game.MapWidth - 1 && !isCreatureOfType(x + 1, y, typeof(Sack))) {
- return new CreatureCommand() { DeltaX = 1 };
- }
- }
- if (keys == Keys.Down || keys == Keys.S) {
- if (y < Game.MapHeight - 1 && !isCreatureOfType(x, y + 1, typeof(Sack))) {
- return new CreatureCommand() { DeltaY = 1 };
- }
- }
- return new CreatureCommand();
- }
- //игрок умирает, если сталкивается с мешком
- public bool DeadInConflict(ICreature conflictedObject) {
- return conflictedObject.GetType() == typeof(Sack);
- }
- }
- public class Terrain : ICreature {
- public string GetImageFileName() {
- return "Terrain.png";
- }
- public int GetDrawingPriority() {
- return 2;
- }
- public CreatureCommand Act(int x, int y) {
- return new CreatureCommand();
- }
- //земля исчезает если сталкивается с игроком
- public bool DeadInConflict(ICreature conflictedObject) {
- return
- conflictedObject.GetType() == typeof(Player);
- }
- }
- public class Gold : ICreature {
- public string GetImageFileName() {
- return "Gold.png";
- }
- public int GetDrawingPriority() {
- return 1;
- }
- 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 class Sack : ICreature {
- private int fallsCount;
- public Sack() {
- fallsCount = 0;
- }
- public string GetImageFileName() {
- return "Sack.png";
- }
- public int GetDrawingPriority() {
- return 1;
- }
- //Метод проверкии того, должен ли мешок падать
- private bool CheckFalling(int x, int y) {
- //если пустое место или (игрок или монстр при условии того, что мешок уже начал падать), то true
- //иначе false
- return
- y+1<Game.MapHeight &&
- (
- Game.Map[x, y+1] == null ||
- fallsCount != 0 &&
- Game.Map[x, y+1].GetType() == typeof(Player)
- )
- ;
- }
- public CreatureCommand Act(int x, int y) {
- ICreature newCreature = null;
- int deltaY = 0;
- //Если мешок должен упасть
- if (CheckFalling(x, y)) {
- fallsCount++;
- deltaY = 1;
- newCreature = this;
- }
- //Если мешок не должен упасть, и он не падал, или падал только 1 блок
- else if (fallsCount <= 1) {
- fallsCount = 0;
- newCreature = this;
- }
- //Если мешок не должен упасть, но он падал не менее 2 блоков
- else {
- newCreature = new Gold();
- }
- return new CreatureCommand() { DeltaY = deltaY, TransformTo = newCreature };
- }
- public bool DeadInConflict(ICreature conflictedObject) {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement