Beispiel #1
0
        public SimulatorStatistics getSimulatorStatistics()
        {
            SimulatorStatistics stats = new SimulatorStatistics(DeadHumans.Count, AliveHumans.Count);

            return(stats);
        }
Beispiel #2
0
        // Draw the updated game state each frame
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue); // Clear the screen

            spriteBatch.Begin();                        // Begin drawing

            if (currentGameState == GameStates.idle)
            {
                // Fill the screen with black before the game starts
                spriteBatch.Draw(startGameSplash, new Rectangle(0, 0, (int)screenWidth, (int)screenHeight), Color.White);

                String title      = "Life Simulator";
                String pressSpace = "Press Space to start the simulation";

                // Measure the size of text in the given font
                Vector2 titleSize      = stateFont.MeasureString(title);
                Vector2 pressSpaceSize = stateFont.MeasureString(pressSpace);

                // Draw the text horizontally centered
                spriteBatch.DrawString(stateFont, title, new Vector2(screenWidth / 2 - titleSize.X / 2, screenHeight / 3), Color.ForestGreen);
                spriteBatch.DrawString(stateFont, pressSpace, new Vector2(screenWidth / 2 - pressSpaceSize.X / 2, screenHeight / 2), Color.White);
            }
            if (currentGameState == GameStates.playing || currentGameState == GameStates.paused)
            {
                if (this.year / 50 == 1)
                {
                    // Draw background
                    if (backgroundCount < 12)
                    {
                        bg = background[backgroundCount];
                        backgroundCount++;
                    }
                    else
                    {
                        backgroundCount = 1;
                    }
                }

                spriteBatch.Draw(bg, new Rectangle(0, 0, (int)screenWidth, (int)screenHeight), Color.White);

                // Draw the players with the SpriteClass method
                foreach (var person in players)
                {
                    person.Draw(spriteBatch);
                }

                // draw year
                String  year     = "Current year: " + simulator.getCurrentDate();
                Vector2 yearSize = stateFont.MeasureString(year);
                spriteBatch.DrawString(stateFont, year, new Vector2(screenWidth / 2 - yearSize.X / 2, screenHeight - 800), Color.White);

                // draw stats
                SimulatorStatistics stats = simulator.getSimulatorStatistics();
                String  statistics        = "Alive Humans: " + stats.getAlive().ToString() + " Dead Humans: " + stats.getDead().ToString();
                Vector2 statsSize         = stateFont.MeasureString(statistics);
                spriteBatch.DrawString(stateFont, statistics, new Vector2(screenWidth / 2 - statsSize.X / 2, screenHeight - 900), Color.White);

                // draw simulator message
                int messageY = 0;
                foreach (var message in messages)
                {
                    Vector2 consoleSize = consoleFont.MeasureString(message);
                    spriteBatch.DrawString(consoleFont, message, new Vector2(screenWidth - consoleSize.X, messageY), Color.White);
                    messageY = messageY + 19;
                }
            }

            if (currentGameState == GameStates.paused)
            {
                Person           person       = simulator.GetHumanity()[selectedPersonIndex];
                List <Texture2D> spriteSheets = calculateCorrectSpriteSheet(person);
                Sprite           sprite;

                sprite   = new Sprite(spriteSheets.ElementAt(0), spriteSheets.ElementAt(1), new Vector2(857, 1672), 4, 1, 8, ScaleToHighDPI(1.7f), person);
                sprite.x = screenWidth / 2 + 50;
                sprite.y = screenHeight / 2 - 80;


                checkSelectedIndex();
                int initialY      = 500;
                var screenCenter  = new Vector2(screenWidth / 2, screenHeight / 2);
                var textureCenter = new Vector2(pauseBackGround.Width / 2, pauseBackGround.Height / 2);
                spriteBatch.Draw(pauseBackGround, screenCenter, null, Color.White, 0f, textureCenter, 1f, SpriteEffects.None, 1f);
                List <String> details = getPersonDetailString(simulator.GetHumanity()[selectedPersonIndex]);
                Person        p       = simulator.GetHumanity()[selectedPersonIndex];

                foreach (var item in details)
                {
                    String  detail      = item;
                    Vector2 consoleSize = consoleFont.MeasureString(detail);
                    spriteBatch.DrawString(consoleFont, detail, new Vector2(screenWidth / 2 - consoleSize.X / 2, initialY), Color.White);
                    initialY = initialY + 19;
                }
                sprite.Draw(spriteBatch);
            }
            spriteBatch.End(); // Stop drawing
            base.Draw(gameTime);
        }