Пример #1
0
        /// <summary>
        /// Draws the menu at the indicated level.
        /// </summary>
        /// <param name="menu">the menu to draw</param>
        /// <param name="level">the level (height) of the menu</param>
        /// <param name="xOffset">the offset of the menu</param>
        /// <remarks>
        /// The menu text comes from the _menuStructure field. The level indicates the height
        /// of the menu, to enable sub menus. The xOffset repositions the menu horizontally
        /// to allow the submenus to be positioned correctly.
        /// </remarks>
        private static void DrawButtons(int menu, int level, int xOffset = 100)
        {
            int btnTop = 0;

            btnTop = MENU_TOP - (MENU_GAP + BUTTON_HEIGHT) * level - 17;
            int i = 0;

            for (i = 0; i <= _menuStructure[menu].Length - 1; i++)
            {
                int btnLeft = 0;
                btnLeft = MENU_LEFT + BUTTON_SEP * (i + xOffset);
                //SwinGame.FillRectangle(Color.White, btnLeft, btnTop, BUTTON_WIDTH, BUTTON_HEIGHT)
                SwinGame.DrawTextLines(_menuStructure[menu][i], MENU_COLOR, Color.Black, GameResources.GameFont("Menu"), FontAlignment.AlignCenter, btnLeft + TEXT_OFFSET, btnTop + TEXT_OFFSET, BUTTON_WIDTH, BUTTON_HEIGHT);

                if (IsMouseOverMenu(i, level, xOffset))
                {
                    SwinGame.DrawRectangle(HIGHLIGHT_COLOR, btnLeft, btnTop - 6, BUTTON_WIDTH, BUTTON_HEIGHT);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Draws the menu at the indicated level.
        /// </summary>
        /// <param name="menu">the menu to draw</param>
        /// <param name="level">the level (height) of the menu</param>
        /// <param name="xOffset">the offset of the menu</param>
        /// <remarks>
        /// The menu text comes from the _menuStructure field. The level indicates the height
        /// of the menu, to enable sub menus. The xOffset repositions the menu horizontally
        /// to allow the submenus to be positioned correctly.
        /// </remarks>
        private static void DrawButtons(int menu, int level, int xOffset)
        {
            int btnTop = 0;

            btnTop = MENU_TOP - (MENU_GAP + BUTTON_HEIGHT) * level;
            int i = 0;

            for (i = 0; i <= _menuStructure[menu].Length - 1; i++)
            {
                int btnLeft = 0;
                btnLeft = MENU_LEFT + BUTTON_SEP * (i + xOffset);
                //SwinGame.FillRectangle(Color.White, btnLeft, btnTop, BUTTON_WIDTH, BUTTON_HEIGHT)

                /* SwinGame.DrawTextLines(_menuStructure[menu][i], MENU_COLOR, Color.Black, GameResources.GameFont("Menu"), FontAlignment.AlignCenter, btnLeft + TEXT_OFFSET, btnTop + TEXT_OFFSET, BUTTON_WIDTH, BUTTON_HEIGHT);
                 *
                 * if (SwinGame.MouseDown(MouseButton.LeftButton) && IsMouseOverMenu(i, level, xOffset))
                 * {
                 *   SwinGame.DrawRectangle(HIGHLIGHT_COLOR, btnLeft, btnTop, BUTTON_WIDTH, BUTTON_HEIGHT);
                 * }*/
                if (_menuStructure[menu][i].Equals("AUDIO"))
                {
                    if (SwinGame.MusicVolume() > 0)
                    {
                        SwinGame.DrawTextLines(_menuStructure[menu][i], MENU_COLOR, Color.Black, GameResources.GameFont("Menu"), FontAlignment.AlignCenter, btnLeft + TEXT_OFFSET, btnTop + TEXT_OFFSET, BUTTON_WIDTH, BUTTON_HEIGHT);
                    }
                    else
                    {
                        SwinGame.DrawTextLines(_menuStructure[menu][i], FADE_COLOR, Color.Black, GameResources.GameFont("Menu"), FontAlignment.AlignCenter, btnLeft + TEXT_OFFSET, btnTop + TEXT_OFFSET, BUTTON_WIDTH, BUTTON_HEIGHT);
                    }
                }
                else
                {
                    SwinGame.DrawTextLines(_menuStructure[menu][i], MENU_COLOR, Color.Black, GameResources.GameFont("Menu"), FontAlignment.AlignCenter, btnLeft + TEXT_OFFSET, btnTop + TEXT_OFFSET, BUTTON_WIDTH, BUTTON_HEIGHT);
                }
            }
        }
        /// <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);
                }
            }
        }
 /// <summary>
 /// Draws the message to the screen
 /// </summary>
 public static void DrawMessage()
 {
     SwinGame.DrawText(Message, MESSAGE_COLOR, GameResources.GameFont("Courier"), FIELD_LEFT, MESSAGE_TOP);
 }
Пример #5
0
        /// <summary>
        /// Draws the high scores to the screen.
        /// </summary>
        public static void DrawHighScores()
        {
            const int SCORES_HEADING = 40;
            const int SCORES_TOP     = 80;
            const int SCORE_GAP      = 30;

            if (_Scores.Count == 0)
            {
                LoadScores();
            }

            SwinGame.DrawText("   High Scores   ", Color.White, GameResources.GameFont("Courier"), SCORES_LEFT, SCORES_HEADING);

            // For all of the scores
            int i      = default(int);
            var loopTo = _Scores.Count - 1;

            for (i = 0; i <= loopTo; i++)
            {
                Score s = default(Score);

                s = _Scores[i];

                // for scores 1 - 9 use 01 - 09
                if (i < 9)
                {
                    SwinGame.DrawText(" " + Convert.ToString((i + 1)) + ":   " + s.Name + "   " + Convert.ToString(s.Value), Color.White, GameResources.GameFont("Courier"), SCORES_LEFT, SCORES_TOP + (i * SCORE_GAP));
                }
                else
                {
                    SwinGame.DrawText(Convert.ToString(i + 1) + ":   " + s.Name + "   " + Convert.ToString(s.Value), Color.White, GameResources.GameFont("Courier"), SCORES_LEFT, SCORES_TOP + (i * SCORE_GAP));
                }
            }
        }
Пример #6
0
        // '' <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 RATIO_TOP   = 303;

            if (((SwinGame.KeyDown(KeyCode.LeftShiftKey) || SwinGame.KeyDown(KeyCode.RightShiftKey)) &&
                 SwinGame.KeyDown(KeyCode.CKey)))
            {
                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("Ingame_Menu"), SCORES_LEFT, SHOTS_TOP);
            SwinGame.DrawText(GameController.HumanPlayer.Hits.ToString(), Color.White, GameResources.GameFont("Ingame_Menu"), SCORES_LEFT, HITS_TOP);
            SwinGame.DrawText(GameController.HumanPlayer.Missed.ToString(), Color.White, GameResources.GameFont("Ingame_Menu"), SCORES_LEFT, SPLASH_TOP);
            if (GameController.HumanPlayer.Shots != 0)
            {
                SwinGame.DrawText((Math.Round(((double)GameController.HumanPlayer.Hits / (double)GameController.HumanPlayer.Shots) * 100, 2)).ToString() + " %", Color.White, GameResources.GameFont("Ingame_Menu"), SCORES_LEFT, RATIO_TOP);
            }
            else
            {
                SwinGame.DrawText("N/A", Color.White, GameResources.GameFont("Ingame_Menu"), SCORES_LEFT, RATIO_TOP);
            }
        }
Пример #7
0
        // 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();
        }
        /// <summary>
        /// Draws the deployment screen showing the field and the ships
        /// that the player can deploy.
        /// </summary>
        public static void DrawDeployment()
        {
            UtilityFunctions.DrawField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer, true);
            SwinGame.DrawBitmap(GameResources.GameImage("LeftButton"), LEFT_BUTTON_LEFT, TOP_BUTTONS_TOP);
            SwinGame.DrawBitmap(GameResources.GameImage("RightButton"), RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP);
            SwinGame.DrawBitmap(GameResources.GameImage("UpButton"), UP_BUTTON_LEFT, TOP_BUTTONS_TOP);
            SwinGame.DrawBitmap(GameResources.GameImage("DownButton"), DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP);
            //Draw the Left/Right and Up/Down buttons
            if (_currentDirection == Direction.Left)
            {
                SwinGame.DrawRectangleOnScreen(Color.Yellow, LEFT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT);
                //SwinGame.DrawBitmap(GameResources.GameImage("LeftButton"), LEFT_BUTTON_LEFT, TOP_BUTTONS_TOP);
            }
            else if (_currentDirection == Direction.Right)
            {
                SwinGame.DrawRectangleOnScreen(Color.Yellow, RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT);
                //SwinGame.DrawBitmap(GameResources.GameImage("RightButton"), LEFT_BUTTON_LEFT, TOP_BUTTONS_TOP);
            }
            else if (_currentDirection == Direction.Up)
            {
                SwinGame.DrawRectangleOnScreen(Color.Yellow, UP_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT);
                // SwinGame.DrawBitmap(GameResources.GameImage("UpButton"), LEFT_BUTTON_LEFT, TOP_BUTTONS_TOP);
            }
            else if (_currentDirection == Direction.Down)
            {
                SwinGame.DrawRectangleOnScreen(Color.Yellow, DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT);

                // SwinGame.DrawBitmap(GameResources.GameImage("DownButton"), LEFT_BUTTON_LEFT, TOP_BUTTONS_TOP);
            }

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

                        //    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, GameResources.GameFont("Courier"), SHIPS_LEFT + TEXT_OFFSET, SHIPS_TOP + i * SHIPS_HEIGHT)
                }
            }

            if (GameController.HumanPlayer.ReadyToDeploy)
            {
                SwinGame.DrawBitmap(GameResources.GameImage("PlayButton"), PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP);
                //SwinGame.FillRectangle(Color.LightBlue, PLAY_BUTTON_LEFT, PLAY_BUTTON_TOP, PLAY_BUTTON_WIDTH, PLAY_BUTTON_HEIGHT)
                //SwinGame.DrawText("PLAY", Color.Black, GameResources.GameFont("Courier"), PLAY_BUTTON_LEFT + TEXT_OFFSET, PLAY_BUTTON_TOP)
            }

            SwinGame.DrawBitmap(GameResources.GameImage("RandomButton"), RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP);
            //SwinGame.DrawBitmap(GameResources.GameImage("MenuButton"), MENU_LEFT, MENU_TOP);

            if (Sound == true)
            {
                //SwinGame.DrawBitmap(GameResources.GameImage("SoundButton"), MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP);
                SwinGame.DrawText("AUDIO", Color.White, MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP);
            }
            else
            {
                SwinGame.DrawText("AUDIO", Color.Grey, MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP);
            }

            UtilityFunctions.DrawMessage();
        }
Пример #9
0
 private static void NewTransparentColourImage(string imageName, string fileName, Color transColor)
 {
     GameResources.NewTransparentColorImage(imageName, fileName, transColor);
 }
Пример #10
0
 private static void LoadMusic()
 {
     GameResources.NewMusic("Background", "bensound-instinct.wav");
 }
Пример #11
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;

                    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);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Draws the high scores to the screen.
        /// </summary>
        public static void DrawHighScores()
        {
            const int SCORES_HEADING = 40;
            const int SCORES_TOP     = 80;
            const int SCORE_GAP      = 30;

            if (_Scores.Count == 0)
            {
                LoadScores();
            }

            SwinGame.DrawText("   High Scores   ", Color.White, GameResources.GameFont("HighScore"), SCORES_LEFT, SCORES_HEADING);

            //For all of the scores
            int i = 0;

            for (i = 0; i <= _Scores.Count - 1; i++)
            {
                Score s = new Score();

                s = _Scores[i];

                //for scores 1 - 10
                if (i < 10)
                {
                    SwinGame.DrawText(" " + System.Convert.ToString(i + 1) + ":   " + s.Name + "   " + System.Convert.ToString(s.Value), Color.White, GameResources.GameFont("HighScore"), SCORES_LEFT, SCORES_TOP + i * SCORE_GAP);
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Read the user's name for their highsSwinGame.
        /// </summary>
        /// <param name="value">the player's sSwinGame.</param>
        /// <remarks>
        /// This verifies if the score is a highsSwinGame.
        /// </remarks>
        public static void ReadHighScore(int value)
        {
            const int ENTRY_TOP = 500;

            if (_Scores.Count == 0)
            {
                LoadScores();
            }

            bool temp = true;

            if (_Scores.Count > 0)
            {
                if (value < _Scores[_Scores.Count - 1].Value)
                {
                    temp = false;
                }
            }

            // is it a high score
            if (temp)
            {
                Score s = new Score();
                s.Value = value;

                GameController.AddNewState(GameState.ViewingHighScores);

                int x;
                x = SCORES_LEFT + SwinGame.TextWidth(GameResources.GameFont("Courier"), "Name: ");

                SwinGame.StartReadingText(Color.White, NAME_WIDTH, GameResources.GameFont("Courier"), x, ENTRY_TOP);

                // Read the text from the user
                while (SwinGame.ReadingText())
                {
                    SwinGame.ProcessEvents();

                    UtilityFunctions.DrawBackground();
                    DrawHighScores();
                    SwinGame.DrawText("Name: ", Color.White, GameResources.GameFont("Courier"), SCORES_LEFT, ENTRY_TOP);
                    SwinGame.RefreshScreen();
                }

                s.Name = SwinGame.TextReadAsASCII();

                if (s.Name.Length < 3)
                {
                    s.Name = s.Name + new string(System.Convert.ToChar(" "), 3 - s.Name.Length);
                }

                if (!temp)
                {
                    _Scores.RemoveAt(_Scores.Count - 1);
                }

                _Scores.Add(s);
                _Scores.Sort();

                GameController.EndCurrentState();
            }
        }
Пример #14
0
        /// <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;

            if ((SwinGame.KeyDown(KeyCode.vk_LSHIFT) || SwinGame.KeyDown(KeyCode.vk_RSHIFT)) && SwinGame.KeyDown(KeyCode.vk_c))
            {
                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);
        }
Пример #15
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);
                }
            }
        }
Пример #16
0
        /// <summary>
        ///     ''' Draw the end of the game screen, shows the win/lose state
        ///     ''' </summary>
        public static void DrawEndOfGame()
        {
            UtilityFunctions.DrawField(GameController.ComputerPlayer.PlayerGrid, GameController.ComputerPlayer, true);
            UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer);

            if (GameController.HumanPlayer.IsDestroyed)
            {
                SwinGame.DrawTextLines("YOU LOSE!", Color.White, Color.Transparent, GameResources.GameFont("ArialLarge"), FontAlignment.AlignCenter, 0, 250, SwinGame.ScreenWidth(), SwinGame.ScreenHeight());
            }
            else
            {
                SwinGame.DrawTextLines("-- WINNER --", Color.White, Color.Transparent, GameResources.GameFont("ArialLarge"), FontAlignment.AlignCenter, 0, 250, SwinGame.ScreenWidth(), SwinGame.ScreenHeight());
            }
        }
Пример #17
0
        /// <summary>
        /// Listens for attacks to be completed.
        /// </summary>
        /// <param name="sender">the game</param>
        /// <param name="result">the result of the attack</param>
        /// <remarks>
        /// Displays a message, plays sound and redraws the screen
        /// </remarks>
        private static void AttackCompleted(object sender, AttackResult result)
        {
            bool isHuman;

            isHuman = _theGame.Player == HumanPlayer;

            if (isHuman)
            {
                UtilityFunctions.Message = "You " + result.ToString();
            }
            else
            {
                UtilityFunctions.Message = "The AI " + result.ToString();
            }

            switch (result.Value)
            {
            case var @case when @case == ResultOfAttack.Destroyed:
            {
                PlayHitSequence(result.Row, result.Column, isHuman);
                Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
                break;
            }

            case var case1 when case1 == ResultOfAttack.GameOver:
            {
                PlayHitSequence(result.Row, result.Column, isHuman);
                Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

                while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
                {
                    SwinGame.Delay(10);
                    SwinGame.RefreshScreen();
                }

                if (HumanPlayer.IsDestroyed)
                {
                    Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
                }
                else
                {
                    Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
                }
                break;
            }

            case var case2 when case2 == ResultOfAttack.Hit:
            {
                PlayHitSequence(result.Row, result.Column, isHuman);
                break;
            }

            case var case3 when case3 == ResultOfAttack.Miss:
            {
                PlayMissSequence(result.Row, result.Column, isHuman);
                break;
            }

            case var case4 when case4 == ResultOfAttack.ShotAlready:
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Error"));
                break;
            }
            }
        }
        /// <summary>
        /// Handles user input for the Deployment phase of the game.
        /// </summary>
        /// <remarks>
        /// Involves selecting the ships, deloying ships, changing the direction
        /// of the ships to add, randomising deployment, end then ending
        /// deployment
        /// </remarks>
        public static void HandleDeploymentInput()
        {
            if (SwinGame.KeyTyped(KeyCode.vk_ESCAPE))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

            else if (SwinGame.MouseClicked(MouseButton.LeftButton) & UtilityFunctions.IsMouseInRectangle(MENU_LEFT, MENU_TOP, MENU_WIDTH, MENU_WIDTH))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

            if (SwinGame.KeyTyped(KeyCode.vk_UP))
            {
                _currentDirection = Direction.Up;
            }
            if (SwinGame.KeyTyped(KeyCode.vk_DOWN))
            {
                _currentDirection = Direction.Down;
            }
            if (SwinGame.KeyTyped(KeyCode.vk_LEFT))
            {
                _currentDirection = Direction.Left;
            }
            if (SwinGame.KeyTyped(KeyCode.vk_RIGHT))
            {
                _currentDirection = Direction.Right;
            }

            if (SwinGame.KeyTyped(KeyCode.vk_r))
            {
                GameController.HumanPlayer.RandomizeDeployment();
            }

            if (SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                ShipName selected = default(ShipName);
                selected = GetShipMouseIsOver();
                if (selected != ShipName.None)
                {
                    _selectedShip = selected;
                }


                if (GameController.HumanPlayer.ReadyToDeploy && UtilityFunctions.IsMouseInRectangle(PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP, PLAY_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    GameController.EndDeployment();
                }
                else if (UtilityFunctions.IsMouseInRectangle(UP_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.Up;
                    DoUpClick();
                }
                else if (UtilityFunctions.IsMouseInRectangle(DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.Down;
                    DoDownClick();
                }
                else if (UtilityFunctions.IsMouseInRectangle(LEFT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.Left;
                    DoLeftClick();
                }
                else if (UtilityFunctions.IsMouseInRectangle(RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.Right;
                    DoRightClick();
                }
                else if (UtilityFunctions.IsMouseInRectangle(RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    GameController.HumanPlayer.RandomizeDeployment();
                }
                else if (UtilityFunctions.IsMouseInRectangle(MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP, MUTE_BUTTON_WIDTH, MUTW_BUTTON_HEIGHT) && (Sound == true))
                {
                    SwinGame.StopMusic();
                    SwinGame.DrawText("AUDIO ON", Color.Grey, MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP);
                    Sound = false;
                }
                else if (UtilityFunctions.IsMouseInRectangle(MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP, MUTE_BUTTON_WIDTH, MUTW_BUTTON_HEIGHT) && (Sound == false))
                {
                    SwinGame.PlayMusic(GameResources.GameMusic("Background"));
                    SwinGame.DrawText("AUDIO OFF", Color.White, MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP);
                    Sound = true;
                }
                else
                {
                    DoDeployClick();
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Draws the menu at the indicated level.
        /// </summary>
        /// <param name="menu">the menu to draw</param>
        /// <param name="level">the level (height) of the menu</param>
        /// <param name="xOffset">the offset of the menu</param>
        /// <remarks>
        /// The menu text comes from the _menuStructure field. The level indicates the height
        /// of the menu, to enable sub menus. The xOffset repositions the menu horizontally
        /// to allow the submenus to be positioned correctly.
        /// </remarks>
        private static void DrawButtons(int menu, int level, int xOffset)
        {
            int       btnTop = 0;
            Rectangle toDraw = new Rectangle();

            btnTop = MENU_TOP - (MENU_GAP + BUTTON_HEIGHT) * level;
            int i = 0;
            //INSTANT C# NOTE: The ending condition of VB 'For' loops is tested only on entry to the loop. Instant C# has created a temporary variable in order to use the initial value of _menuStructure(menu).Length for every iteration:
            int tempVar = _menuStructure[menu].Length;

            for (i = 0; i < tempVar; i++)
            {
                int btnLeft = MENU_LEFT + BUTTON_SEP * (i + xOffset);

                //SwinGame.FillRectangle(Color.White, btnLeft, btnTop, BUTTON_WIDTH, BUTTON_HEIGHT)
                toDraw.X      = btnLeft + TEXT_OFFSET;
                toDraw.Y      = btnTop + TEXT_OFFSET;
                toDraw.Width  = BUTTON_WIDTH;
                toDraw.Height = BUTTON_HEIGHT;
                SwinGame.DrawTextLines(_menuStructure[menu][i], MENU_COLOR, Color.Black, GameResources.GameFont("Menu"), FontAlignment.AlignCenter, toDraw);

                if ((SwinGame.MouseDown(MouseButton.LeftButton) && !IsMouseOverMenu(i, level, xOffset)))
                {
                    SwinGame.DrawRectangle(HIGHLIGHT_COLOR, btnLeft, btnTop, BUTTON_WIDTH, BUTTON_HEIGHT);
                }
            }
        }