/// <summary>
        /// Draws the player's grid and ships.
        /// </summary>
        /// <param name="grid">the grid to show</param>
        /// <param name="thePlayer">the player to show the ships of</param>
        /// <param name="small">true if the small grid is shown</param>
        /// <param name="showShips">true if ships are to be shown</param>
        /// <param name="left">the left side of the grid</param>
        /// <param name="top">the top of the grid</param>
        /// <param name="width">the width of the grid</param>
        /// <param name="height">the height of the grid</param>
        /// <param name="cellWidth">the width of each cell</param>
        /// <param name="cellHeight">the height of each cell</param>
        /// <param name="cellGap">the gap between the cells</param>
        private static void DrawCustomField(ISeaGrid grid, Player thePlayer, bool small, bool showShips, int left, int top, int width, int height, int cellWidth, int cellHeight, int cellGap)
        {
            //SwinGame.FillRectangle(Color.Blue, left, top, width, height)

            int rowTop  = 0;
            int colLeft = 0;

            //Draw the grid
            for (int row = 0; row <= 9; row++)
            {
                rowTop = top + (cellGap + cellHeight) * row;

                for (int col = 0; col <= 9; col++)
                {
                    colLeft = left + (cellGap + cellWidth) * col;

                    Color fillColor = SMALL_MISS;
                    bool  draw      = true;


                    switch (grid.get_Item(row, col))
                    {
                    case TileView.Miss:
                        if (small)
                        {
                            fillColor = SMALL_MISS;
                        }
                        else
                        {
                            fillColor = LARGE_MISS;
                        }
                        break;

                    case TileView.Hit:
                        if (small)
                        {
                            fillColor = SMALL_HIT;
                        }
                        else
                        {
                            fillColor = LARGE_HIT;
                        }
                        break;

                    case TileView.Sea:
                    case TileView.Ship:
                        if (small)
                        {
                            fillColor = SMALL_SEA;
                        }
                        else
                        {
                            draw = false;
                        }
                        break;
                    }

                    if (draw)
                    {
                        SwinGame.FillRectangle(fillColor, colLeft, rowTop, cellWidth, cellHeight);
                        if (!small)
                        {
                            SwinGame.DrawRectangle(OUTLINE_COLOR, colLeft, rowTop, cellWidth, cellHeight);
                        }
                    }
                }
            }

            if (!showShips)
            {
                return;
            }

            int    shipHeight = 0;
            int    shipWidth  = 0;
            string shipName   = null;

            //Draw the ships
            foreach (Ship s in thePlayer)
            {
                if (s == null || !s.IsDeployed)
                {
                    continue;
                }
                rowTop  = top + (cellGap + cellHeight) * s.Row + SHIP_GAP;
                colLeft = left + (cellGap + cellWidth) * s.Column + SHIP_GAP;

                if (s.Direction == Direction.LeftRight)
                {
                    shipName   = "ShipLR" + s.Size;
                    shipHeight = cellHeight - (SHIP_GAP * 2);
                    shipWidth  = (cellWidth + cellGap) * s.Size - (SHIP_GAP * 2) - cellGap;
                }
                else
                {
                    //Up down
                    shipName   = "ShipUD" + s.Size;
                    shipHeight = (cellHeight + cellGap) * s.Size - (SHIP_GAP * 2) - cellGap;
                    shipWidth  = cellWidth - (SHIP_GAP * 2);
                }

                if (!small)
                {
                    SwinGame.DrawBitmap(GameResources.GameImage(shipName), colLeft, rowTop);
                }
                else
                {
                    SwinGame.FillRectangle(SHIP_FILL_COLOR, colLeft, rowTop, shipWidth, shipHeight);
                    SwinGame.DrawRectangle(SHIP_OUTLINE_COLOR, colLeft, rowTop, shipWidth, shipHeight);
                }
            }
        }
        // Draws the deployment screen showing the field and the ships
        // that the player can deploy.

        public static void DrawDeployment()
        {
            UtilityFunctions.DrawField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer, true);

            // Draw the Left/Right and Up/Down buttons

            if ((_currentDirection == Direction.LeftRight))
            {
                SwinGame.DrawBitmap(GameResources.GameImage("LeftRightButton"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP);

                // CHECK
                // SwinGame.DrawText("U/D", Color.Gray, GameFont("Menu"), UP_DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP)
                // SwinGame.DrawText("L/R", Color.White, GameFont("Menu"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP)
                // CHECK
            }
            else
            {
                SwinGame.DrawBitmap(GameResources.GameImage("UpDownButton"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP);

                // CHECK
                // SwinGame.DrawText("U/D", Color.White, GameFont("Menu"), UP_DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP)
                // SwinGame.DrawText("L/R", Color.Gray, GameFont("Menu"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP)
            }

            // CHECK
            // DrawShips
            foreach (ShipName sn in Enum.GetValues(typeof(ShipName)))
            {
                int i;
                i = ((int)(sn) - 1);
                if ((i >= 0))
                {
                    if ((sn == _selectedShip))
                    {
                        SwinGame.DrawBitmap(GameResources.GameImage("SelectedShip"), SHIPS_LEFT, (SHIPS_TOP
                                                                                                  + (i * SHIPS_HEIGHT)));

                        // CHECK
                        //     SwinGame.FillRectangle(Color.LightBlue, SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT)
                        // Else
                        //     SwinGame.FillRectangle(Color.Gray, SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT)
                    }

                    // CHECK
                    // SwinGame.DrawRectangle(Color.Black, SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT)
                    // SwinGame.DrawText(sn.ToString(), Color.Black, GameFont("Courier"), SHIPS_LEFT + TEXT_OFFSET, SHIPS_TOP + i * SHIPS_HEIGHT)
                    // CHECK
                }
            }

            if (GameController.HumanPlayer.ReadyToDeploy)
            {
                SwinGame.DrawBitmap(GameResources.GameImage("PlayButton"), PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP);

                //CHECK
                // SwinGame.FillRectangle(Color.LightBlue, PLAY_BUTTON_LEFT, PLAY_BUTTON_TOP, PLAY_BUTTON_WIDTH, PLAY_BUTTON_HEIGHT)
                // SwinGame.DrawText("PLAY", Color.Black, GameFont("Courier"), PLAY_BUTTON_LEFT + TEXT_OFFSET, PLAY_BUTTON_TOP)
            }

            SwinGame.DrawBitmap(GameResources.GameImage("RandomButton"), RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP);
            UtilityFunctions.DrawMessage();
        }
Beispiel #3
0
        // '' <summary>
        // '' Draws the player's grid and ships.
        // '' </summary>
        // '' <param name="grid">the grid to show</param>
        // '' <param name="thePlayer">the player to show the ships of</param>
        // '' <param name="small">true if the small grid is shown</param>
        // '' <param name="showShips">true if ships are to be shown</param>
        // '' <param name="left">the left side of the grid</param>
        // '' <param name="top">the top of the grid</param>
        // '' <param name="width">the width of the grid</param>
        // '' <param name="height">the height of the grid</param>
        // '' <param name="cellWidth">the width of each cell</param>
        // '' <param name="cellHeight">the height of each cell</param>
        // '' <param name="cellGap">the gap between the cells</param>
        private static void DrawCustomField(ISeaGrid grid, Player thePlayer, bool small, bool showShips, int left, int top, int width, int height, int cellWidth, int cellHeight, int cellGap)
        {
            // SwinGame.FillRectangle(Color.Blue, left, top, width, height)
            int rowTop;
            int colLeft;

            // Draw the grid
            for (int row = 0; (row <= 9); row++)
            {
                rowTop = (top
                          + ((cellGap + cellHeight)
                             * row));
                for (int col = 0; (col <= 9); col++)
                {
                    colLeft = (left
                               + ((cellGap + cellWidth)
                                  * col));
                    Color fillColor = Color.Gold;
                    bool  draw;
                    draw = true;
                    switch (grid.Item(row, col))
                    {
                    case TileView.Ship:
                        draw = false;
                        break;

                    case TileView.Miss:
                        if (small)
                        {
                            fillColor = SMALL_MISS;
                        }
                        else
                        {
                            fillColor = LARGE_MISS;
                        }

                        break;

                    case TileView.Hit:
                        if (small)
                        {
                            fillColor = SMALL_HIT;
                        }
                        else
                        {
                            fillColor = LARGE_HIT;
                        }
                        break;

                    case TileView.Sea:
                        if (small)
                        {
                            fillColor = SMALL_SEA;
                        }
                        else
                        {
                            draw = false;
                        }
                        break;
                    }
                    if (draw)
                    {
                        SwinGame.FillRectangle(fillColor, colLeft, rowTop, cellWidth, cellHeight);
                        if (!small)
                        {
                            SwinGame.DrawRectangle(OUTLINE_COLOR, colLeft, rowTop, cellWidth, cellHeight);
                        }
                    }
                }
            }

            if (!showShips)
            {
                return;
            }

            int    shipHeight;
            int    shipWidth;
            string shipName;

            // Draw the ships
            foreach (Ship s in thePlayer)
            {
                if (((s == null) ||
                     !s.IsDeployed))
                {
                    // TODO: Continue For... Warning!!! not translated
                }

                rowTop = (top
                          + (((cellGap + cellHeight)
                              * s.Row)
                             + SHIP_GAP));
                colLeft = (left
                           + (((cellGap + cellWidth)
                               * s.Column)
                              + SHIP_GAP));
                if ((s.Direction == Direction.LeftRight))
                {
                    shipName   = ("ShipLR" + s.Size);
                    shipHeight = (cellHeight
                                  - (SHIP_GAP * 2));
                    shipWidth = (((cellWidth + cellGap)
                                  * s.Size)
                                 - ((SHIP_GAP * 2)
                                    - cellGap));
                }
                else
                {
                    // Up down
                    shipName   = ("ShipUD" + s.Size);
                    shipHeight = (((cellHeight + cellGap)
                                   * s.Size)
                                  - ((SHIP_GAP * 2)
                                     - cellGap));
                    shipWidth = (cellWidth
                                 - (SHIP_GAP * 2));
                }

                if (!small)
                {
                    SwinGame.DrawBitmap(GameResources.GameImage(shipName), colLeft, rowTop);
                }
                else
                {
                    SwinGame.FillRectangle(SHIP_FILL_COLOR, colLeft, rowTop, shipWidth, shipHeight);
                    SwinGame.DrawRectangle(SHIP_OUTLINE_COLOR, colLeft, rowTop, shipWidth, shipHeight);
                }
            }
        }
        /// <summary>
        /// Draws the player's grid and ships.
        /// </summary>
        /// <param name="grid">the grid to show</param>
        /// <param name="thePlayer">the player to show the ships of</param>
        /// <param name="small">true if the small grid is shown</param>
        /// <param name="showShips">true if ships are to be shown</param>
        /// <param name="left">the left side of the grid</param>
        /// <param name="top">the top of the grid</param>
        /// <param name="width">the width of the grid</param>
        /// <param name="height">the height of the grid</param>
        /// <param name="cellWidth">the width of each cell</param>
        /// <param name="cellHeight">the height of each cell</param>
        /// <param name="cellGap">the gap between the cells</param>
        private static void DrawCustomField(ISeaGrid grid, Player thePlayer, bool small, bool showShips, int left, int top, int width, int height, int cellWidth, int cellHeight, int cellGap)
        {
            //SwinGame.FillRectangle(Color.Blue, left, top, width, height)

            int rowTop  = 0;
            int colLeft = 0;

            //Draw the grid
            for (int row = 0; row <= 9; row++)
            {
                rowTop = top + (cellGap + cellHeight) * row;

                for (int col = 0; col <= 9; col++)
                {
                    colLeft = left + (cellGap + cellWidth) * col;

                    Color fillColor = default(Color);
                    bool  draw      = false;

                    draw = true;

                    if (grid.Item(row, col) == TileView.Ship)
                    {
                        draw = false;
                        //If small Then fillColor = _SMALL_SHIP Else fillColor = _LARGE_SHIP
                    }
                    else if (grid.Item(row, col) == TileView.Miss)
                    {
                        if (small)
                        {
                            fillColor = SMALL_MISS;
                        }
                        else
                        {
                            fillColor = LARGE_MISS;
                        }
                    }
                    else if (grid.Item(row, col) == TileView.Hit)
                    {
                        if (small)
                        {
                            fillColor = SMALL_HIT;
                        }
                        else
                        {
                            fillColor = LARGE_HIT;
                        }
                    }
                    else if ((grid.Item(row, col) == TileView.Sea) || (grid.Item(row, col) == TileView.Ship))
                    {
                        if (small)
                        {
                            fillColor = SMALL_SEA;
                        }
                        else
                        {
                            draw = false;
                        }
                    }

                    if (draw)
                    {
                        SwinGame.FillRectangle(fillColor, colLeft, rowTop, cellWidth, cellHeight);
                        if (!small)
                        {
                            SwinGame.DrawRectangle(OUTLINE_COLOR, colLeft, rowTop, cellWidth, cellHeight);
                        }
                    }
                }
            }

            if (!showShips)
            {
                return;
            }

            int    shipHeight = 0;
            int    shipWidth  = 0;
            string shipName   = "";

            //Draw the ships
            foreach (Ship s in thePlayer)
            {
                if (ReferenceEquals(s, null) || !s.IsDeployed)
                {
                    continue;
                }
                rowTop  = top + (cellGap + cellHeight) * s.Row + SHIP_GAP;
                colLeft = left + (cellGap + cellWidth) * s.Column + SHIP_GAP;

                if (s.Direction == Direction.LeftRight)
                {
                    shipName   = "ShipLR" + s.Size;
                    shipHeight = cellHeight - (SHIP_GAP * 2);
                    shipWidth  = System.Convert.ToInt32((cellWidth + cellGap) * s.Size - (SHIP_GAP * 2) - cellGap);
                }
                else
                {
                    //Up down
                    shipName   = "ShipUD" + s.Size;
                    shipHeight = System.Convert.ToInt32((cellHeight + cellGap) * s.Size - (SHIP_GAP * 2) - cellGap);
                    shipWidth  = cellWidth - (SHIP_GAP * 2);
                }

                if (!small)
                {
                    SwinGame.DrawBitmap(GameResources.GameImage(shipName), colLeft, rowTop);
                }
                else
                {
                    SwinGame.FillRectangle(SHIP_FILL_COLOR, colLeft, rowTop, shipWidth, shipHeight);
                    SwinGame.DrawRectangle(SHIP_OUTLINE_COLOR, colLeft, rowTop, shipWidth, shipHeight);
                }
            }
        }