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); } } }
private void Form1_Load(object sender, EventArgs e) { myMap = new Map(); myMap.GetMapGUI(50, 50); myMap.GetMapState(); SetMapGUI(myMap, false); enemyMap = new Map(); enemyMap.GetMapGUI(myMap.buttonSize * 10 + 100, 50); enemyMap.GetMapState(); SetMapGUI(enemyMap, true); myMapForEnemy = new Map(); myMapForEnemy.GetMapState(); sl = new ShipsLogic(myMap); sl2 = new ShipsLogic(enemyMap); eAI = new EnemyAI(myMapForEnemy, myMap, enemyMap, ref myHealth); // ntrcn currShip = sl.ships[0]; currDirection = "Down"; }