示例#1
0
 public void insert(Boat vessel, int x, int y)
 {
     List<int[]> points = this.getPoints(vessel, x, y);
     foreach (int[] point in points)
     {
         grid[point[0], point[1]] = vessel.id;
     }
 }
示例#2
0
 public Boolean testColision(Boat vessel, int x, int y)
 {
     Boolean colision = false;
     List<int[]> points = this.getPoints(vessel, x, y);
     foreach (int[] point in points)
     {
         colision = testPosition(point[0], point[1]);
         if (colision) break;
     }
     return colision;
 }
示例#3
0
        private List<int[]> getPoints(Boat vessel, int x, int y)
        {
            List<int[]> lista = new List<int[]>();
            if ((int)vessel.type == 1)
            {
                lista.Add(new int[] { x, y });

            }
            else if ((int)vessel.type == 2)
            {
                lista.Add(new int[] { x, y });
                if (vessel.orientation == 2)
                {
                    lista.Add(new int[] { x, y + 1 });
                }
                else
                {
                    lista.Add(new int[] { x + 1, y });
                }
            }
            else if ((int)vessel.type == 3)
            {
                lista.Add(new int[] { x, y });
                if (vessel.orientation == 2)
                {
                    lista.Add(new int[] { x, y + 1 });
                    lista.Add(new int[] { x, y + 2 });
                }
                else
                {
                    lista.Add(new int[] { x + 1, y });
                    lista.Add(new int[] { x + 2, y });
                }

            }
            else if ((int)vessel.type == 4)
            {
                lista.Add(new int[] { x, y });
                if (vessel.orientation == 2)
                {
                    lista.Add(new int[] { x, y + 1 });
                    lista.Add(new int[] { x, y + 2 });
                    lista.Add(new int[] { x, y + 3 });
                }
                else
                {
                    lista.Add(new int[] { x + 1, y });
                    lista.Add(new int[] { x + 2, y });
                    lista.Add(new int[] { x + 3, y });
                }
            }
            else if ((int)vessel.type == 5)
            {
                lista.Add(new int[] { x, y });
                if (vessel.orientation == 2)
                {
                    lista.Add(new int[] { x, y - 1 });
                    lista.Add(new int[] { x, y + 1 });
                    lista.Add(new int[] { x - 1, y });
                    lista.Add(new int[] { x - 2, y });
                }
                else
                {
                    lista.Add(new int[] { x + 1, y });
                    lista.Add(new int[] { x - 1, y });
                    lista.Add(new int[] { x, y + 1 });
                    lista.Add(new int[] { x, y + 2 });
                }
            }
            return lista;
        }