Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- namespace Tanki
- {
- public class Enemy : ICreature
- {
- public Point View = new Point(1, 0);
- public int Flag = 0;
- CreatureCommand ICreature.Act(int x, int y)
- {
- var monsterCommand = new CreatureCommand();
- for (var xPlayer = 0; xPlayer < Game.MapWidth; xPlayer++)
- {
- for (var yPlayer = 0; yPlayer < Game.MapHeight; yPlayer++)
- {
- if (Game.Map[xPlayer, yPlayer] is Tank)
- {
- if (x != 0 && x.CompareTo(xPlayer) > 0
- && !(Game.Map[x - 1, y] is Brick || Game.Map[x - 1, y] is Enemy))
- {
- monsterCommand.DeltaX--;
- Flag = -1;
- }
- else if (y != Game.MapHeight - 1 && y.CompareTo(yPlayer) < 0
- && !(Game.Map[x, y + 1] is Brick || Game.Map[x, y + 1] is Enemy))
- {
- Flag = 1;
- monsterCommand.DeltaY++;
- }
- else if (y != 0 && y.CompareTo(yPlayer) > 0
- && !(Game.Map[x, y - 1] is Brick || Game.Map[x, y - 1] is Enemy))
- {
- Flag = -2;
- monsterCommand.DeltaY--;
- }
- else if (x != Game.MapWidth - 1 && x.CompareTo(xPlayer) < 0
- && !(Game.Map[x + 1, y] is Brick || Game.Map[x + 1, y] is Enemy))
- {
- monsterCommand.DeltaX++;
- }
- }
- }
- }
- return monsterCommand;
- }
- CreatureCommand Something(int x, int y, int dx, int dy)
- {
- if (Game.Map[x + dx, y + dy] is null)
- {
- View = new Point(dx, dy);
- return DoAct(dx, dy, this);
- }
- return DoAct(0, 0, this);
- }
- CreatureCommand DoAct(int x, int y, ICreature transformTo)
- {
- return new CreatureCommand()
- {
- DeltaX = x,
- DeltaY = y,
- TransformTo = transformTo,
- };
- }
- private int[] FindPlaer()
- {
- for (int x = 0; x < Game.MapWidth; x++)
- for (int y = 0; y < Game.MapHeight; y++)
- if (Game.Map[x, y] != null && Game.Map[x, y].GetImageFileName() == "tank.png")
- return new int[] { x, y };
- return null;
- }
- bool ICreature.DeadInConflict(ICreature conflictedObject)
- {
- return conflictedObject is Bullet;
- }
- int ICreature.GetDrawingPriority()
- {
- return 13;
- }
- string ICreature.GetImageFileName()
- {
- if (Flag == 0)
- return "r_enemy.png";
- else if (Flag == -1)
- return "l_enemy.png";
- else if (Flag == 1)
- return "d_enemy.png";
- return "u_enemy.png";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement