예제 #1
0
        private void MoveTop(PawnModel pawn)
        {
            var obstacle = false;
            var x        = pawn.X;
            var y        = pawn.Y;

            while (!obstacle && x > 0)
            {
                if (listTopObstacle.Contains(Grid.Grid[x, y]) || PawnIsPresent(x - 1, y))
                {
                    obstacle = true;
                }
                else if (x != 0)
                {
                    x -= 1;
                }
            }

            pawn.X = x;
            pawn.Y = y;
        }
예제 #2
0
        private void MoveRight(PawnModel pawn)
        {
            var obstacle = false;
            var x        = pawn.X;
            var y        = pawn.Y;

            while (!obstacle && y < Grid.YLastIndex)
            {
                if (listRightObstacle.Contains(Grid.Grid[x, y]) || PawnIsPresent(x, y + 1))
                {
                    obstacle = true;
                }
                else if (y != Grid.YLastIndex)
                {
                    y += 1;
                }
            }

            pawn.X = x;
            pawn.Y = y;
        }
예제 #3
0
        private void MoveLeft(PawnModel pawn)
        {
            var obstacle = false;
            var x        = pawn.X;
            var y        = pawn.Y;

            while (!obstacle && y > 0)
            {
                if (listBottomObstacle.Contains(Grid.Grid[x, y]) || PawnIsPresent(x, y - 1))
                {
                    obstacle = true;
                }
                else if (y != 0)
                {
                    y -= 1;
                }
            }

            pawn.X = x;
            pawn.Y = y;
        }
예제 #4
0
        private void MoveBottom(PawnModel pawn)
        {
            var obstacle = false;
            var x        = pawn.X;
            var y        = pawn.Y;

            while (!obstacle && x < Grid.XLastIndex)
            {
                if (listBottomObstacle.Contains(Grid.Grid[x, y]) || PawnIsPresent(x + 1, y))
                {
                    obstacle = true;
                }
                else if (x != Grid.XLastIndex)
                {
                    x += 1;
                }
            }

            pawn.X = x;
            pawn.Y = y;
        }
예제 #5
0
 public void MovePawn(Direction direction, PawnModel pawn)
 {
     //Vers le haut
     if (direction == Direction.Top)
     {
         MoveTop(pawn);
     }
     //Vers la droite
     else if (direction == Direction.Right)
     {
         MoveRight(pawn);
     }
     //Vers le bas
     else if (direction == Direction.Bottom)
     {
         MoveBottom(pawn);
     }
     //Vers la gauche
     else if (direction == Direction.Left)
     {
         MoveLeft(pawn);
     }
 }
예제 #6
0
 public TargetModel(int x, int y, PawnModel pawn)
 {
     X    = x;
     Y    = y;
     Pawn = pawn;
 }