private void DeckPictureBoxMouseMove(object sender, MouseEventArgs e) { if (currentShip != -1) { if (GraphicContext.GetCoorX(this, deckPictureBox) != -1 && GraphicContext.GetCoorY(this, deckPictureBox) != -1) { if (GraphicContext.GetCell(GraphicContext.GetCoorX(this, deckPictureBox)) != mouseCellX || GraphicContext.GetCell(GraphicContext.GetCoorY(this, deckPictureBox)) != mouseCellY) { mouseCellX = GraphicContext.GetCell(GraphicContext.GetCoorX(this, deckPictureBox)); mouseCellY = GraphicContext.GetCell(GraphicContext.GetCoorY(this, deckPictureBox)); deckPictureBox.Refresh(); if (shipRotation) { for (int i = 0; i < Game.shipLengths[currentShip]; i++) { if (mouseCellX + i <= 9) { GraphicContext.DrawInnerFrameCell(mouseCellX + i, mouseCellY, currentShip, this, deckPictureBox); } else { break; } } } else { for (int i = 0; i < Game.shipLengths[currentShip]; i++) { if (mouseCellY + i <= 9) { GraphicContext.DrawInnerFrameCell(mouseCellX, mouseCellY + i, currentShip, this, deckPictureBox); } else { break; } } } } } else { if (mouseCellX != -1 || mouseCellY != -1) { mouseCellX = -1; mouseCellY = -1; deckPictureBox.Refresh(); } } } }
private void DeckPictureBoxMouseMove(object sender, MouseEventArgs e) { // Is there any ship selected? if (currentShip != -1) { // Are we on the grid of the deck? if (GraphicContext.GetCoorX(this, deckPictureBox) != -1 && GraphicContext.GetCoorY(this, deckPictureBox) != -1) { // Has the mouse selected cell changed? if (GraphicContext.GetCell(GraphicContext.GetCoorX(this, deckPictureBox)) != mouseCellX || GraphicContext.GetCell(GraphicContext.GetCoorY(this, deckPictureBox)) != mouseCellY) { // Rewrite Mouse cell information. mouseCellX = GraphicContext.GetCell(GraphicContext.GetCoorX(this, deckPictureBox)); mouseCellY = GraphicContext.GetCell(GraphicContext.GetCoorY(this, deckPictureBox)); // Reraw the deck. deckPictureBox.Refresh(); // Is the horizontal rotation on? if (shipRotation) { // Deploy current ship with its color into the deck. for (int i = 0; i < Game.shipLengths[currentShip]; i++) { // Do not corss the boundaries. if (mouseCellX + i <= 9) { GraphicContext.DrawInnerFrameCell(mouseCellX + i, mouseCellY, currentShip, this, deckPictureBox); } else { break; } } } else { // Vertical rotation is on. for (int i = 0; i < Game.shipLengths[currentShip]; i++) { if (mouseCellY + i <= 9) { GraphicContext.DrawInnerFrameCell(mouseCellX, mouseCellY + i, currentShip, this, deckPictureBox); } else { break; } } } } } else { // Out of the boundaries of the deck. if (mouseCellX != -1 || mouseCellY != -1) { mouseCellX = -1; mouseCellY = -1; // Reraw the deck. deckPictureBox.Refresh(); } } } }