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; } }
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; }
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; }