Esempio n. 1
0
 public void FilledRectangle(Brush brush, GridSquare currentGridsquare, int yOffset, int xOffset)
 {
     g.FillRectangle(brush, (currentGridsquare.min.X + (xGridSquareSize*xOffset)+ 1), (currentGridsquare.min.Y + (yGridSquareSize * yOffset) + 1), xGridSquareSize - 1, yGridSquareSize - 1);
 }
Esempio n. 2
0
 public void FilledEllipse(Brush brush, GridSquare currentGridsquare, int yOffset, int xOffset)
 {
     g.FillEllipse(brush, (currentGridsquare.min.X + (xGridSquareSize * xOffset) + 1), (currentGridsquare.min.Y + (yGridSquareSize * yOffset) + 1), xGridSquareSize - 2, yGridSquareSize - 2);
 }
Esempio n. 3
0
 public void Ellipse(Pen pen, GridSquare currentGridsquare, int yOffset, int xOffset)
 {
     g.DrawEllipse(pen, (currentGridsquare.min.X + (xGridSquareSize * xOffset) + 1), (currentGridsquare.min.Y + (yGridSquareSize * yOffset) + 1), xGridSquareSize - 2, yGridSquareSize - 2);
 }
Esempio n. 4
0
        private void DrawGrid(Drawer draw, GridSquare[,] GridSquares)
        {         
            for (int i = 1; i < 10; i++)
            {
                //vertical lines
                draw.VerticalLine(draw.with.blackPen, panelSize, i);
                //horizontal lines
                draw.HorizontalLine(draw.with.blackPen, panelSize, i);
            }

            // filling a 2D array with blank gridSquares
            // these will store information about that square
            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y < 10; y++)
                {
                    GridSquares[x, y] = new GridSquare(new Point(x * xGridSquareSize, y * yGridSquareSize), new Point((x * xGridSquareSize) + xGridSquareSize, (y * yGridSquareSize) + yGridSquareSize));
                }
            }
            
        }
Esempio n. 5
0
 private void startButton_Click(object sender, EventArgs e)
 {
     if(!gameRunning)
     {
         //Enable the player panel so the game can begin (also needs to be enabled to draw)
         playerPanel.Enabled = true;
         enemyPanel.Enabled = true;
         DrawGrid(playerDraw, playerGridSquares); // draw a grid on the player's panel
         DrawGrid(enemyDraw, enemyGridSquares); // draw a grid on the enemy's panel
         currentPlayerGridsquare = null; 
         startButton.Text = "Connect to Opponent";
         startButton.Enabled = false;
         startButton.Visible = false;
     }
     if(gameRunning)
     {
         startButton.Enabled = false;
         startButton.Visible = false;
         listBox.Enabled = false;
         listBox.Visible = false;
         attackOpponentLabel.Visible = true;
         placeShipsLabel.Visible = false;
         try
         {
             log.Text += "Waiting for opponent ... ";
             log.ScrollToCaret(); // LOG!
             // (these 3 lines start the game)
             socket = new TcpClient("52.23.160.4", 2000);
             Thread sockets = new Thread(() => TCPRead(socket));
             sockets.Start();
         }
         catch
         {
             Console.WriteLine("server at " + "52.23.160.4" + " down");
             log.Text += "\n\nThe server at 52.23.160.4 is down."; // LOG!
             log.ScrollToCaret();
         }
     }
 }
Esempio n. 6
0
        private void DrawShip(int size)
        {
            currentShipCode = size;
            // clear
            if (currentPlayerGridsquare != null)
            {
                for (int i = 0; i < currentPlayerGridsquare.size; i++)
                {

                    if(rotatePrevious==false)
                    {
                        //got an out of bounds exception on the next if. This should prevent that (and it did)
                        if (((int)((currentPlayerGridsquare.min.Y / yGridSquareSize) + i)) <= 9)
                        {
                            //currently only accounting for y going down starting from head
                            if (playerGridSquares[(int)(currentPlayerGridsquare.min.X / xGridSquareSize), (int)((currentPlayerGridsquare.min.Y / yGridSquareSize) + i)].set != true)
                            {
                                playerDraw.FilledRectangle(playerDraw.with.whiteBrush, currentPlayerGridsquare, i,0);
                            }
                        }
                    }
                    if (rotatePrevious == true)
                    {
                        //got an out of bounds exception on the next if. This should prevent that (and it did)
                        if (((int)((currentPlayerGridsquare.min.X / xGridSquareSize) + i)) <= 9)
                        {
                            //currently only accounting for y going down starting from head
                            if (playerGridSquares[(int)((currentPlayerGridsquare.min.X / xGridSquareSize) + i), (int)(currentPlayerGridsquare.min.Y / yGridSquareSize)].set != true)
                            {
                                playerDraw.FilledRectangle(playerDraw.with.whiteBrush, currentPlayerGridsquare, 0,i);
                            }
                        }
                    }
                }
            }

            // On some machines the player grid squares are drawn a bit too big so cut the indexs to avoid out of range errors
            // This can't break the game because if the mouse was that far away for the origin they wanted the last square anyways
            int xGridSquareIndex = (int)(mousePosition.X / xGridSquareSize);
            if (xGridSquareIndex > 9)
                xGridSquareIndex = 9;
            int yGridSquareIndex = (int)(mousePosition.Y / yGridSquareSize);
            if (yGridSquareIndex > 9)
                yGridSquareIndex = 9;

            // set new current
            currentPlayerGridsquare = playerGridSquares[xGridSquareIndex, yGridSquareIndex];
            //the amount after the head
            if (size == 31 || size == 32)
                size = 3;
            currentPlayerGridsquare.size = size;

            if(rotateNext==false)//draw vertical
            {
                // draw new
                if (yGridSquareIndex + (size - 1) <= 9 && checkForSetSquares(rotateNext))
                {
                    for (int i = 0; i < size; i++)
                    {
                        playerDraw.Ellipse(playerDraw.with.greenPen, currentPlayerGridsquare, i,0);
                    }
                    currentPlayerGridsquare.ok = true; // ready to be set / placed
                }
                else
                {
                    //this if prevents drawing a no go marker over an existing (currently set) grid square
                    if (currentPlayerGridsquare.set != true)
                    {
                        playerDraw.Ellipse(playerDraw.with.redPen, currentPlayerGridsquare, 0,0);
                        currentPlayerGridsquare.ok = false; // not ready to be set / placed
                    }
                }
            }
            if (rotateNext == true)//draw horizontal
            {
                // draw new
                if (xGridSquareIndex + (size - 1) <= 9 && checkForSetSquares(rotateNext))
                {
                    for (int i = 0; i < size; i++)
                    {
                        playerDraw.Ellipse(playerDraw.with.greenPen, currentPlayerGridsquare,0, i);
                    }
                    currentPlayerGridsquare.ok = true; // ready to be set / placed
                }
                else
                {
                    //this if prevents drawing a no go marker over an existing (currently set) grid square
                    if (currentPlayerGridsquare.set != true)
                    {
                        playerDraw.Ellipse(playerDraw.with.redPen, currentPlayerGridsquare, 0,0);
                        currentPlayerGridsquare.ok = false; // not ready to be set / placed
                    }
                }
            }
            rotatePrevious = rotateNext;
        }