Advertisement
Graf_Rav

Untitled

Dec 17th, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. /*
  2.  * Решается задача:
  3.  * https://ulearn.me/Course/BasicProgramming/Praktika_Zemlya_i_Digger__b4fba55d-b35d-4366-b3e3-e1d7f53268b1
  4.  * Автор решения: Шарафеев Равиль, 11-808
  5.  */
  6.  
  7.  
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14.  
  15. namespace Digger {
  16.     public class Player : ICreature {
  17.         public string GetImageFileName() {
  18.             return "Digger.png";
  19.         }
  20.  
  21.         public int GetDrawingPriority() {
  22.             return 1;
  23.         }
  24.        
  25.         public CreatureCommand Act(int x, int y) {
  26.             Keys keys = Game.KeyPressed;
  27.             //Если нажата кнопка перемещения и перемещение возможно, то передает изменение нужной координаты
  28.             if (keys == Keys.Left || keys == Keys.A) {
  29.                 if (x > 0) {
  30.                     return new CreatureCommand() { DeltaX = -1 };
  31.                 }
  32.             }
  33.             if (keys == Keys.Up || keys == Keys.W) {
  34.                 if (y > 0) {
  35.                     return new CreatureCommand() { DeltaY = -1 };
  36.                 }
  37.             }
  38.             if (keys == Keys.Right || keys == Keys.D) {
  39.                 if (x < Game.MapWidth - 1) {
  40.                     return new CreatureCommand() { DeltaX = 1 };
  41.                 }
  42.             }
  43.             if (keys == Keys.Down || keys == Keys.S) {
  44.                 if (y < Game.MapHeight - 1) {
  45.                     return new CreatureCommand() { DeltaY = 1 };
  46.                 }
  47.             }
  48.             return new CreatureCommand();
  49.         }
  50.  
  51.         public bool DeadInConflict(ICreature conflictedObject) {
  52.             return false;
  53.         }
  54.     }
  55.  
  56.     public class Terrain : ICreature {
  57.         public string GetImageFileName() {
  58.             return "Terrain.png";
  59.         }
  60.  
  61.         public int GetDrawingPriority() {
  62.             return 0;
  63.         }
  64.  
  65.         public CreatureCommand Act(int x, int y) {
  66.             return new CreatureCommand();
  67.         }
  68.         //возвращает false, если сталкивается с игроком
  69.         public bool DeadInConflict(ICreature conflictedObject) {
  70.             return
  71.                 conflictedObject.GetType() == typeof(Player);
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement