Ejemplo n.º 1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.DarkBlue);

            spriteBatch.Begin();
            Vector2 textSize, textPos = Vector2.Zero;
            string  text;
            float   textScale;

            if (currState == State.Start)
            {
                text      = "Sanka skepp";
                textSize  = font.MeasureString(text);
                textPos.X = (Window.ClientBounds.Width - textSize.X) / 2;
                textPos.Y = 10;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.White,
                    0f,
                    Vector2.Zero,
                    Vector2.One,
                    SpriteEffects.None,
                    0f
                    );

                textScale = 1.5f;

                text       = "Grid Size " + grid.NumVertical + "x" + grid.NumHorizontal;
                textSize   = font.MeasureString(text) / textScale;
                textPos.X  = (Window.ClientBounds.Width - textSize.X) / 2;
                textPos.Y += 140;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.White,
                    0f,
                    Vector2.Zero,
                    Vector2.One / textScale,
                    SpriteEffects.None,
                    0f
                    );

                text       = "Game mode: " + (playerBoats.LimitOn ? "Standard" : "Lego");
                textSize   = font.MeasureString(text) / textScale;
                textPos.X  = (Window.ClientBounds.Width - textSize.X) / 2;
                textPos.Y += 30;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.White,
                    0f,
                    Vector2.Zero,
                    Vector2.One / textScale,
                    SpriteEffects.None,
                    0f
                    );

                textScale = 2f;

                text       = (playerBoats.LimitOn ? "Each player has 2 ships of size 2 and one each of size 3-5" : "Each player has 16 ship pieces to freely construct ships");
                textSize   = font.MeasureString(text) / textScale;
                textPos.X  = (Window.ClientBounds.Width - textSize.X) / 2;
                textPos.Y += 40;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.White,
                    0f,
                    Vector2.Zero,
                    Vector2.One / textScale,
                    SpriteEffects.None,
                    0f
                    );

                textScale = 1.5f;

                text       = "Use up & down keys to edit grid size";
                textSize   = font.MeasureString(text) / textScale;
                textPos.X  = (Window.ClientBounds.Width - textSize.X) / 2;
                textPos.Y += 60;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.White,
                    0f,
                    Vector2.Zero,
                    Vector2.One / textScale,
                    SpriteEffects.None,
                    0f
                    );

                text       = "Use tab to toggle game mode";
                textSize   = font.MeasureString(text) / textScale;
                textPos.X  = (Window.ClientBounds.Width - textSize.X) / 2;
                textPos.Y += 30;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.White,
                    0f,
                    Vector2.Zero,
                    Vector2.One / textScale,
                    SpriteEffects.None,
                    0f
                    );

                text       = "Press space to continue";
                textSize   = font.MeasureString(text) / textScale;
                textPos.X  = (Window.ClientBounds.Width - textSize.X) / 2;
                textPos.Y += 30;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.White,
                    0f,
                    Vector2.Zero,
                    Vector2.One / textScale,
                    SpriteEffects.None,
                    0f
                    );
            }
            else if (currState == State.Place)
            {
                grid.Draw(spriteBatch);
                playerBoats.DrawShips(spriteBatch);
                if (boatPlace.Count == 1)
                {
                    playerBoats.DrawTemp(spriteBatch);
                }

                if (playerBoats.Sum < 16)
                {
                    textScale = 2f;

                    text      = "Please place your boats";
                    textSize  = font.MeasureString(text) / textScale;
                    textPos.X = grid.Screen.Width + (((Window.ClientBounds.Width - grid.Screen.Width) - textSize.X) / 2);
                    textPos.Y = 180;

                    spriteBatch.DrawString(
                        font,
                        text,
                        textPos,
                        Color.White,
                        0f,
                        Vector2.Zero,
                        Vector2.One / textScale,
                        SpriteEffects.None,
                        0f
                        );

                    text       = "by clicking on the grid";
                    textSize   = font.MeasureString(text) / textScale;
                    textPos.X  = grid.Screen.Width + (((Window.ClientBounds.Width - grid.Screen.Width) - textSize.X) / 2);
                    textPos.Y += 15;

                    spriteBatch.DrawString(
                        font,
                        text,
                        textPos,
                        Color.White,
                        0f,
                        Vector2.Zero,
                        Vector2.One / textScale,
                        SpriteEffects.None,
                        0f
                        );
                }
                else
                {
                    textScale = 2f;

                    text      = "Can't place more boats";
                    textSize  = font.MeasureString(text) / textScale;
                    textPos.X = grid.Screen.Width + (((Window.ClientBounds.Width - grid.Screen.Width) - textSize.X) / 2);
                    textPos.Y = 180;

                    spriteBatch.DrawString(
                        font,
                        text,
                        textPos,
                        Color.Red,
                        0f,
                        Vector2.Zero,
                        Vector2.One / textScale,
                        SpriteEffects.None,
                        0f
                        );

                    text       = "continue by pressing space";
                    textSize   = font.MeasureString(text) / textScale;
                    textPos.X  = grid.Screen.Width + (((Window.ClientBounds.Width - grid.Screen.Width) - textSize.X) / 2);
                    textPos.Y += 15;

                    spriteBatch.DrawString(
                        font,
                        text,
                        textPos,
                        Color.Red,
                        0f,
                        Vector2.Zero,
                        Vector2.One / textScale,
                        SpriteEffects.None,
                        0f
                        );
                }
            }
            else if (currState == State.Player)
            {
                grid.Draw(spriteBatch);
                computerBoats.DrawHits(spriteBatch);

                if (playerBoats.HasFired)
                {
                    text      = "continue by pressing space";
                    textScale = 2f;
                    textSize  = font.MeasureString(text) / textScale;
                    textPos.X = grid.Screen.Width + (((Window.ClientBounds.Width - grid.Screen.Width) - textSize.X) / 2);
                    textPos.Y = 180;

                    spriteBatch.DrawString(
                        font,
                        text,
                        textPos,
                        Color.Red,
                        0f,
                        Vector2.Zero,
                        Vector2.One / textScale,
                        SpriteEffects.None,
                        0f
                        );
                }
                else
                {
                    text      = "Click To fire";
                    textScale = 2f;
                    textSize  = font.MeasureString(text) / textScale;
                    textPos.X = grid.Screen.Width + (((Window.ClientBounds.Width - grid.Screen.Width) - textSize.X) / 2);
                    textPos.Y = 180;

                    spriteBatch.DrawString(
                        font,
                        text,
                        textPos,
                        Color.White,
                        0f,
                        Vector2.Zero,
                        Vector2.One / textScale,
                        SpriteEffects.None,
                        0f
                        );
                }
            }
            else if (currState == State.Computer)
            {
                grid.Draw(spriteBatch);
                playerBoats.DrawHits(spriteBatch);

                textScale = 2f;

                text      = "The computer has played";
                textSize  = font.MeasureString(text) / textScale;
                textPos.X = grid.Screen.Width + (((Window.ClientBounds.Width - grid.Screen.Width) - textSize.X) / 2);
                textPos.Y = 180;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.White,
                    0f,
                    Vector2.Zero,
                    Vector2.One / textScale,
                    SpriteEffects.None,
                    0f
                    );

                text       = "continue by pressing space";
                textSize   = font.MeasureString(text) / textScale;
                textPos.X  = grid.Screen.Width + (((Window.ClientBounds.Width - grid.Screen.Width) - textSize.X) / 2);
                textPos.Y += 15;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.Red,
                    0f,
                    Vector2.Zero,
                    Vector2.One / textScale,
                    SpriteEffects.None,
                    0f
                    );
            }
            else if (currState == State.End)
            {
                text      = "Sanka skepp";
                textSize  = font.MeasureString(text);
                textPos.X = (Window.ClientBounds.Width - textSize.X) / 2;
                textPos.Y = 10;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.White,
                    0f,
                    Vector2.Zero,
                    Vector2.One,
                    SpriteEffects.None,
                    0f
                    );

                textScale = 1.5f;

                text       = playerBoats.Alive ? "You Win!!!" : "You Lost...";
                textSize   = font.MeasureString(text) / textScale;
                textPos.X  = (Window.ClientBounds.Width - textSize.X) / 2;
                textPos.Y += 140;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    playerBoats.Alive ? Color.Green : Color.Red,
                    0f,
                    Vector2.Zero,
                    Vector2.One / textScale,
                    SpriteEffects.None,
                    0f
                    );

                text       = "Press space to restart";
                textSize   = font.MeasureString(text) / textScale;
                textPos.X  = (Window.ClientBounds.Width - textSize.X) / 2;
                textPos.Y += 30;

                spriteBatch.DrawString(
                    font,
                    text,
                    textPos,
                    Color.White,
                    0f,
                    Vector2.Zero,
                    Vector2.One / textScale,
                    SpriteEffects.None,
                    0f
                    );
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }