//GETTING NUMBERS AND PREPARING WINDOW public BattleshipPlacement(int[] shipNumbers) { InitializeComponent(); DoubleBuffered = true; Hide(); SetUp(); foreach (int n in shipNumbers) { goal += n; } //COUNTING SHIPS placeBoard = new BattleshipBoard(shipsPlaced); placementPanel.Controls.Add(placeBoard); placeBoard.ImgClick += PlaceShip; }
public BattleshipGuessForm(BattleshipPlayer player) { InitializeComponent(); DoubleBuffered = true; bot = new BattleshipBot("BOT", player.shipNumbers); leftNameLabel.Text = bot.name; rightNameLabel.Text = player.name; leftBoard = player.myBoard; leftBoard.DrawGuessBoard(bot.guesses); rightBoard = new BattleshipBoard(player.sunk); rightBoard.DrawGuessBoard(player.guesses); gamePanel.Controls.Add(leftBoard, 0, 0); gamePanel.Controls.Add(rightBoard, 0, 0); player1 = player; rightBoard.ImgClick += Guess1; }
public BattleshipBot(string n, int[] shipNum) : base("BOT", new int[] { }) { name = n; Random rand = new Random(); for (int i = 0; i < 100; i++) { all.Add(i); } /* * for (int i = 0; i < 50; i++) * { * odd.Add(i * 2); * even.Add((i * 2) + 1); * } */ int id = 1; BattleshipPlacement x = new BattleshipPlacement(shipNum); for (int i = 0; i < 5; i++) { for (int j = 0; j < shipNum[i]; j++) { BattleshipShip ship; int xCoord, yCoord; do { ship = new BattleshipShip(i, id); ship.dir(rand.Next(-4, 4) * 90); xCoord = rand.Next(1, 12); yCoord = rand.Next(1, 12); }while (!x.Placeable(ship, myShips, new int[] { xCoord, yCoord })); x.placeBoard.UpdateShips(ship); id++; myShips.Add(ship); } } botBoard = x.placeBoard; x.Close(); }
public void Hit(int[] c, BattleshipBoard board) { board.cells[c[0], c[1]].Image = Resources.Hit; }
public void Miss(int[] c, BattleshipBoard board) { board.cells[c[0], c[1]].Image = Resources.Miss; }