public void FillEnemyMap(ShipsLogic sl, Map map) { bool successful = false; while (successful == false) { int shipCount = 0; Ship[] ships = new Ship[4]; for (int i = 0; i < ships.Length; i++) { ships[i] = new Ship(i + 1); } for (int i = 0; i < 4; i++) { for (int j = 0; j < 50; j++) { int[] pos = new int[] { rand2.Next(0, 10), rand2.Next(0, 10) }; while (true) { if (map.state[pos[0], pos[1]] == 0) { break; } else { pos = new int[] { rand2.Next(0, 10), rand2.Next(0, 10) }; } } pos = new int[] { pos[0] * 50 + 50, pos[1] * 50 + 50 }; List <string> arrDir = new List <string> { "Up", "Down", "Left", "Right" }; for (int i2 = 0; i2 < 4; i2++) { string strDir = arrDir[rand2.Next(0, arrDir.Count)]; if (sl.SetShips(pos, ref ships[i], strDir)) { break; } arrDir.Remove(strDir); } } } for (int i = 0; i < 4; i++) { shipCount += ships[i].count; } //MessageBox.Show(shipCount.ToString()); if (shipCount == 0) { successful = true; } else { RemoveShips(map); } } }
public void Config(object slender, EventArgs e) { if (!isGameStart) { Button pressedButton = slender as Button; sl.SetShips(new int[] { pressedButton.Location.X, pressedButton.Location.Y }, ref currShip, currDirection); } }