private void DeselectOtherShipBoxes(ShipBox sb) { for (int i = 0; i < shipsBoxes.Length; i++) { if (shipsBoxes[i] != sb) { shipsBoxes[i].Reset(true); } } }
private void shipPictureBox_Click(object sender, EventArgs e) { MouseEventArgs temp = (MouseEventArgs)e; ShipBox shipBox = (ShipBox)sender; if (temp.Button == MouseButtons.Left && selectedShip != shipBox) { shipBox.BorderStyle = BorderStyle.FixedSingle; DeselectOtherShipBoxes(shipBox); this.selectedShip = shipBox; } else if (temp.Button == MouseButtons.Right && selectedShip != null && selectedShip.Type == shipBox.Type) { shipBox.Rotate(); } }
private void DrawShipButtons() { shipsBoxes = new ShipBox[5]; shipsBoxes[0] = new ShipBox(Ship.Type.AircraftCarrier); shipsBoxes[0].Location = new System.Drawing.Point(32, 619); shipsBoxes[1] = new ShipBox(Ship.Type.Battleship); shipsBoxes[1].Location = new System.Drawing.Point(209, 619); shipsBoxes[2] = new ShipBox(Ship.Type.Cruiser); shipsBoxes[2].Location = new System.Drawing.Point(385, 619); shipsBoxes[3] = new ShipBox(Ship.Type.Destroyer); shipsBoxes[3].Location = new System.Drawing.Point(559, 619); shipsBoxes[4] = new ShipBox(Ship.Type.Submarine); shipsBoxes[4].Location = new System.Drawing.Point(738, 619); for (int i = 0; i < shipsBoxes.Length; i++) { shipsBoxes[i].Click += new System.EventHandler(this.shipPictureBox_Click); this.Controls.Add(shipsBoxes[i]); } }
private void playerBoard_Click(Object sender, EventArgs e) { gs = (GraphicSquare)sender; MouseEventArgs temp = (MouseEventArgs)e; if (!gameStarted && temp.Button == MouseButtons.Right && selectedShip != null) { selectedShip.Rotate(); } else if (!gameStarted && temp.Button == MouseButtons.Left && selectedShip != null) { if (possibleToPlaceShip) { markedSquares = new Square[markedGraphicSquares.Length]; for (int i = 0; i < markedGraphicSquares.Length; i++) { markedSquares[i] = markedGraphicSquares[i].GetSquare(); markedGraphicSquares[i].Image = Properties.Resources.shipMark; } // A clone is needed because Stack pushes a pointer and not a value. placedShips.Push((GraphicSquare[])markedGraphicSquares); placedShipsBoxes.Push(selectedShip); player.AddShip(new Ship(markedSquares, selectedShip.Type)); selectedShip.Lock(); selectedShip = null; } else { MessageBox.Show("You can't place the ship here.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public MainForm() { InitializeComponent(); this.Size = new Size(308, 315); this.BackgroundImageLayout = ImageLayout.Center; backgroundTheme = new SoundPlayer(Properties.Resources.BackgroundTheme); backgroundTheme.PlayLooping(); placedShips = new Stack <GraphicSquare[]>(); placedShipsBoxes = new Stack <ShipBox>(); selectedShip = null; shipHorn = new SoundPlayer(Properties.Resources.ShipHorn); hitWater = new SoundPlayer(Properties.Resources.HitWater); hitShip = new SoundPlayer(Properties.Resources.HitShip); shipExplosion = new SoundPlayer(Properties.Resources.ShipExplosion); win = new SoundPlayer(Properties.Resources.Win); lose = new SoundPlayer(Properties.Resources.Lose); playerTurnsCount = 0; computerTurnsCount = 0; gameStarted = false; possibleToPlaceShip = false; debugMode = false; sound = true; }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { DebugMode(false); selectedShip = null; StartGame(); }