Exemplo n.º 1
0
        private void deck1PictureBoxMouseMove(object sender, MouseEventArgs e)
        {
            // Are we on the grid of the first deck?
            if (GraphicContext.GetCoorX(this, deck1PictureBox) != -1 && GraphicContext.GetCoorY(this, deck1PictureBox) != -1)
            {
                // Have the cell selected by mouse changed?
                if (GraphicContext.GetCell(GraphicContext.GetCoorX(this, deck1PictureBox)) != mouseCellX || GraphicContext.GetCell(GraphicContext.GetCoorY(this, deck1PictureBox)) != mouseCellY)
                {
                    // Update the cell selected by mouse.
                    mouseCellX = GraphicContext.GetCell(GraphicContext.GetCoorX(this, deck1PictureBox));
                    mouseCellY = GraphicContext.GetCell(GraphicContext.GetCoorY(this, deck1PictureBox));

                    // Repaint the first deck.
                    deck1PictureBox.Refresh();

                    // Draw the outer frame of the selected cell.
                    GraphicContext.DrawOuterFrameCell(mouseCellX, mouseCellY, 5, this, deck1PictureBox);
                }
            }
            else
            {
                // Unselect the cell in the first deck.
                mouseCellX = -1;
                mouseCellY = -1;

                // Repaint the first deck.
                deck1PictureBox.Refresh();
            }
        }
Exemplo n.º 2
0
        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();
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void deck1PictureBoxMouseMove(object sender, MouseEventArgs e)
 {
     if (GraphicContext.GetCoorX(this, deck1PictureBox) != -1 && GraphicContext.GetCoorY(this, deck1PictureBox) != -1)
     {
         if (GraphicContext.GetCell(GraphicContext.GetCoorX(this, deck1PictureBox)) != mouseCellX || GraphicContext.GetCell(GraphicContext.GetCoorY(this, deck1PictureBox)) != mouseCellY)
         {
             mouseCellX = GraphicContext.GetCell(GraphicContext.GetCoorX(this, deck1PictureBox));
             mouseCellY = GraphicContext.GetCell(GraphicContext.GetCoorY(this, deck1PictureBox));
             deck1PictureBox.Refresh();
             GraphicContext.DrawOuterFrameCell(mouseCellX, mouseCellY, 5, this, deck1PictureBox);
         }
     }
     else
     {
         mouseCellX = -1;
         mouseCellY = -1;
         deck1PictureBox.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();
                    }
                }
            }
        }