Advertisement
Guest User

Untitled

a guest
May 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3.  
  4. namespace Tanki
  5. {
  6. public class Enemy : ICreature
  7. {
  8. public Point View = new Point(1, 0);
  9. public int Flag = 0;
  10.  
  11. CreatureCommand ICreature.Act(int x, int y)
  12. {
  13. var monsterCommand = new CreatureCommand();
  14. for (var xPlayer = 0; xPlayer < Game.MapWidth; xPlayer++)
  15. {
  16. for (var yPlayer = 0; yPlayer < Game.MapHeight; yPlayer++)
  17. {
  18. if (Game.Map[xPlayer, yPlayer] is Tank)
  19. {
  20. if (x != 0 && x.CompareTo(xPlayer) > 0
  21. && !(Game.Map[x - 1, y] is Brick || Game.Map[x - 1, y] is Enemy))
  22. {
  23. monsterCommand.DeltaX--;
  24. Flag = -1;
  25. }
  26. else if (y != Game.MapHeight - 1 && y.CompareTo(yPlayer) < 0
  27. && !(Game.Map[x, y + 1] is Brick || Game.Map[x, y + 1] is Enemy))
  28. {
  29. Flag = 1;
  30. monsterCommand.DeltaY++;
  31. }
  32. else if (y != 0 && y.CompareTo(yPlayer) > 0
  33. && !(Game.Map[x, y - 1] is Brick || Game.Map[x, y - 1] is Enemy))
  34. {
  35. Flag = -2;
  36. monsterCommand.DeltaY--;
  37. }
  38. else if (x != Game.MapWidth - 1 && x.CompareTo(xPlayer) < 0
  39. && !(Game.Map[x + 1, y] is Brick || Game.Map[x + 1, y] is Enemy))
  40. {
  41. monsterCommand.DeltaX++;
  42. }
  43. }
  44. }
  45. }
  46. return monsterCommand;
  47. }
  48.  
  49. CreatureCommand Something(int x, int y, int dx, int dy)
  50. {
  51. if (Game.Map[x + dx, y + dy] is null)
  52. {
  53. View = new Point(dx, dy);
  54. return DoAct(dx, dy, this);
  55. }
  56. return DoAct(0, 0, this);
  57. }
  58.  
  59. CreatureCommand DoAct(int x, int y, ICreature transformTo)
  60. {
  61. return new CreatureCommand()
  62. {
  63. DeltaX = x,
  64. DeltaY = y,
  65. TransformTo = transformTo,
  66. };
  67. }
  68.  
  69. private int[] FindPlaer()
  70. {
  71. for (int x = 0; x < Game.MapWidth; x++)
  72. for (int y = 0; y < Game.MapHeight; y++)
  73. if (Game.Map[x, y] != null && Game.Map[x, y].GetImageFileName() == "tank.png")
  74. return new int[] { x, y };
  75. return null;
  76. }
  77.  
  78. bool ICreature.DeadInConflict(ICreature conflictedObject)
  79. {
  80. return conflictedObject is Bullet;
  81. }
  82.  
  83. int ICreature.GetDrawingPriority()
  84. {
  85. return 13;
  86. }
  87.  
  88. string ICreature.GetImageFileName()
  89. {
  90. if (Flag == 0)
  91. return "r_enemy.png";
  92. else if (Flag == -1)
  93. return "l_enemy.png";
  94. else if (Flag == 1)
  95. return "d_enemy.png";
  96. return "u_enemy.png";
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement