Пример #1
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  = 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;

                    switch (grid [row, col])
                    {
                    case TileView.Ship:
                        draw = false;
                        break;

                    //If small Then fillColor = _SMALL_SHIP Else fillColor = _LARGE_SHIP
                    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);
                }
            }
        }
        /// <summary>
        /// Draws the game during the attack phase.
        /// </summary>s
        public static void DrawDiscovery()
        {
            const int SCORES_LEFT = 172;
            const int SHOTS_TOP   = 157;
            const int HITS_TOP    = 206;
            const int SPLASH_TOP  = 256;
            const int AI_LEFT     = 50;
            const int AI_TOP      = 350;

            if (UtilityFunctions.ShowShipsCheat)
            {
                UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, true);
            }
            else
            {
                UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, false);
            }

            UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer);
            UtilityFunctions.DrawMessage();

            SwinGame.DrawText(GameController.HumanPlayer.Shots.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, SHOTS_TOP);
            SwinGame.DrawText(GameController.HumanPlayer.Hits.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, HITS_TOP);
            SwinGame.DrawText(GameController.HumanPlayer.Missed.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, SPLASH_TOP);
            SwinGame.DrawText(GameController.AiGameSetting(), Color.White, GameResources.GameFont("Menu"), AI_LEFT, AI_TOP);

            //Draws Ships
            foreach (ShipName sn in Enum.GetValues(typeof(ShipName)))
            {
                if (object.ReferenceEquals(GameController.ComputerPlayer.Ship(sn), null))
                {
                }
                else
                {
                    if (GameController.ComputerPlayer.Ship(sn).IsDestroyed)
                    {
                        int i = 0;
                        i = (int)sn - 1;
                        int rowTop  = 122 + (2 + 40) * GameController.ComputerPlayer.Ship(sn).Row + 3;
                        int colLeft = 349 + (2 + 40) * GameController.ComputerPlayer.Ship(sn).Column + 3;
                        if (i >= 0)
                        {
                            string shipName   = null;
                            int    shipHeight = 0;
                            int    shipWidth  = 0;
                            int    cellHeight = 40;
                            int    SHIP_GAP   = 3;
                            int    cellWidth  = 40;
                            int    cellGap    = 2;
                            int    j          = (int)GameController.ComputerPlayer.Ship(sn).CurrentShipColour;
                            if (GameController.ComputerPlayer.Ship(sn).Direction == Direction.LeftRight)
                            {
                                shipName   = "ShipLR" + GameController.ComputerPlayer.Ship(sn).Size + "a" + j;
                                shipHeight = cellHeight - (SHIP_GAP * 2);
                                shipWidth  = (cellWidth + cellGap) * GameController.ComputerPlayer.Ship(sn).Size - (SHIP_GAP * 2) - cellGap;
                            }
                            else
                            {
                                //Up down
                                shipName   = "ShipUD" + GameController.ComputerPlayer.Ship(sn).Size + "a" + j;
                                shipHeight = (cellHeight + cellGap) * GameController.ComputerPlayer.Ship(sn).Size - (SHIP_GAP * 2) - cellGap;
                                shipWidth  = cellWidth - (SHIP_GAP * 2);
                            }
                            //FIX HERE!!!
                            SwinGame.DrawBitmap(GameResources.GameImage(shipName), colLeft, rowTop);

                            //    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)
                        }

                        //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)
                    }
                }
            }
        }