protected void SetWindowRectangleUsingWindowXAndWindowSize(WindowVerticalAlignment alignment, int windowX, int windowWidth, int windowHeight, Padding padding)
        {
            Rectangle windowDestinationRectangle = Constants.GameWindow.DestinationRectangle;
            Point     windowCenterPoint          = windowDestinationRectangle.Center;
            Rectangle windowRectangle;

            switch (alignment)
            {
            case WindowVerticalAlignment.Top:
                windowRectangle = new Rectangle(windowX, 0, windowWidth, windowHeight);
                break;

            case WindowVerticalAlignment.Center:
                windowRectangle = new Rectangle(windowX, windowCenterPoint.Y - (windowHeight / 2), windowWidth, windowHeight);
                break;

            case WindowVerticalAlignment.Bottom:
                windowRectangle = new Rectangle(windowX, windowDestinationRectangle.Bottom - windowHeight, windowWidth, windowHeight);
                break;

            default:
                throw new ArgumentOutOfRangeException("alignment");
            }

            Window = new BorderedWindow(windowRectangle, padding);
        }
        private void RenderAnswers(
            RendererParameters parameters,
            WindowTexture selectedAnswerWindowTexture,
            SpriteFont font,
            Matrix transformMatrix,
            IEnumerable <MessageTextAnswer> answers,
            Color shadowColor,
            Vector2 position)
        {
            answers = answers.ToArray();

            int   answerCount        = answers.Count();
            int   totalAnswerPadding = ((answerCount - 1) * TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalPadding);
            float lineWidth          = answers.Sum(arg => arg.Size.X + (selectedAnswerWindowTexture.SpriteWidth * 2) + (TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalTextPadding * 2)) + totalAnswerPadding;
            float lineHeight         = answers.Max(arg => arg.Size.Y);

            position.X += (Window.AbsoluteClientRectangle.Width - lineWidth) / 2;

            foreach (MessageTextAnswer answer in answers)
            {
                var window = new BorderedWindow(
                    new Rectangle(
                        position.X.Round(),
                        position.Y.Round(),
                        (answer.Size.X + (selectedAnswerWindowTexture.SpriteWidth * 2) + (TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalTextPadding * 2)).Round(),
                        (lineHeight + (selectedAnswerWindowTexture.SpriteHeight * 2)).Round()),
                    selectedAnswerWindowTexture.Padding);

                if (answer.Answer == _answerSelectionManager.SelectedAnswer)
                {
                    _messageAnswerRenderer.Update(
                        window.WindowRectangle,
                        selectedAnswerWindowTexture.Padding,
                        answer.SelectedAnswerBackgroundColor.ToXnaColor(),
                        Alpha,
                        Window.AbsoluteClientRectangle,
                        transformMatrix);
                    _messageAnswerRenderer.Render(parameters);
                }

                var textPosition = new Vector2(
                    window.AbsoluteClientRectangle.X + ((window.AbsoluteClientRectangle.Width - answer.Size.X) / 2),
                    window.AbsoluteClientRectangle.Y + ((window.AbsoluteClientRectangle.Height - lineHeight) / 2));
                Color textColor = answer.Answer == _answerSelectionManager.SelectedAnswer ? answer.SelectedAnswerForegroundColor.ToXnaColor() : answer.UnselectedAnswerForegroundColor.ToXnaColor();

                parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, new ScissoringRasterizerState(), null, transformMatrix);

                parameters.SpriteBatch.DrawStringWithShadow(
                    font,
                    answer.Text,
                    textPosition.Round(),
                    textColor * Alpha,
                    shadowColor,
                    Vector2.One);

                parameters.SpriteBatch.End();

                position.X += window.WindowRectangle.Width + TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalPadding;
            }
        }
        protected void SetWindowRectangleUsingWindowYAndWindowSize(WindowHorizontalAlignment alignment, int windowY, int windowWidth, int windowHeight, Padding padding)
        {
            Rectangle windowDestinationRectangle = Constants.GameWindow.DestinationRectangle;
            Point     windowCenterPoint          = windowDestinationRectangle.Center;
            Rectangle windowRectangle;

            switch (alignment)
            {
            case WindowHorizontalAlignment.Left:
                windowRectangle = new Rectangle(0, windowY, windowWidth, windowHeight);
                break;

            case WindowHorizontalAlignment.Center:
                windowRectangle = new Rectangle(windowCenterPoint.X - (windowWidth / 2), windowY, windowWidth, windowHeight);
                break;

            case WindowHorizontalAlignment.Right:
                windowRectangle = new Rectangle(windowDestinationRectangle.Right - windowWidth, windowY, windowWidth, windowHeight);
                break;

            default:
                throw new ArgumentOutOfRangeException("alignment");
            }

            Window = new BorderedWindow(windowRectangle, padding);
        }
        protected void SetWindowRectangle(WindowAlignment alignment, int windowWidth, int windowHeight, Padding padding)
        {
            Rectangle windowDestinationRectangle = Constants.GameWindow.DestinationRectangle;
            Point     windowCenterPoint          = windowDestinationRectangle.Center;
            Rectangle rectangle;

            switch (alignment)
            {
            case WindowAlignment.TopLeft:
                rectangle = new Rectangle(0, 0, windowWidth, windowHeight);
                break;

            case WindowAlignment.TopCenter:
                rectangle = new Rectangle(windowCenterPoint.X - (windowWidth / 2), 0, windowWidth, windowHeight);
                break;

            case WindowAlignment.TopRight:
                rectangle = new Rectangle(windowDestinationRectangle.Right - windowWidth, 0, windowWidth, windowHeight);
                break;

            case WindowAlignment.RightCenter:
                rectangle = new Rectangle(windowDestinationRectangle.Right - windowWidth, windowCenterPoint.Y - (windowHeight / 2), windowWidth, windowHeight);
                break;

            case WindowAlignment.BottomRight:
                rectangle = new Rectangle(windowDestinationRectangle.Right - windowWidth, windowDestinationRectangle.Bottom - windowHeight, windowWidth, windowHeight);
                break;

            case WindowAlignment.BottomCenter:
                rectangle = new Rectangle(windowCenterPoint.X - (windowWidth / 2), windowDestinationRectangle.Bottom - windowHeight, windowWidth, windowHeight);
                break;

            case WindowAlignment.BottomLeft:
                rectangle = new Rectangle(0, windowDestinationRectangle.Bottom - windowHeight, windowWidth, windowHeight);
                break;

            case WindowAlignment.LeftCenter:
                rectangle = new Rectangle(0, windowCenterPoint.Y - (windowHeight / 2), windowWidth, windowHeight);
                break;

            case WindowAlignment.Center:
                rectangle = new Rectangle(windowCenterPoint.X - (windowWidth / 2), windowCenterPoint.Y - (windowHeight / 2), windowWidth, windowHeight);
                break;

            default:
                throw new ArgumentOutOfRangeException("alignment");
            }

            Window = new BorderedWindow(rectangle, padding);
        }
예제 #5
0
        public void Start()
        {
            Register.Populate();
            //Run Menu/startup logic for starting a game/creating character

            Map = new ParseMapFromText().GetLevel;

            var gameplayWindow =
                new BorderedWindow("Gameplay", 5, 0, GameplayWindowWidth, GameplayWindowHeight, false, 1);

            var hpWindow          = new StatsWindow(0, 0, GameplayWindowWidth, 4, Player, 1);
            var atrWindow         = new AttrubitesWindow("Attributes", 0, GameplayWindowWidth, 24, 5, new Symbol(' '), true, Player);
            var combatStats       = new CombatStats("Combat Stats", 6, GameplayWindowWidth + 1, 23, 12, new Symbol(' '), true, Player);
            var borderUnderAtrWin = new TextLineWindow(5, GameplayWindowWidth, 24, Color4.White, Color4.Green, 5);

            borderUnderAtrWin.Update(new Symbol[] { });
            var turnCountWin = new TextLineWindow(ConsoleHeight - 1, 1, 15, Color4.White, Color4.Green, 2);

            turnCountWin.SetTextLine(Symbol.ParseString($"Turn: {TurnCounter}"), 0);

            var logWindow = new LogWindow("Log", 8, GameplayWindowWidth, 24, 20, 55);

            //LogWindow currently is not supported

            //Logger = logWindow;

            windowsManager.AddWindow(gameplayWindow);
            windowsManager.AddWindow(hpWindow);
            windowsManager.AddWindow(atrWindow);
            windowsManager.AddWindow(combatStats);
            windowsManager.AddWindow(borderUnderAtrWin);

            windowsManager.AddWindow(turnCountWin);
            windowsManager.AddWindow(inventoryWindow);
            windowsManager.AddWindow(EnemyInfoWindow);
            // WindowsManager.AddWindow(logWindow);
            visualization.UpdateGameplayWindow(gameplayWindow);
            hpWindow.Update();
            atrWindow.Update();

            visualization.PrintToConsole(windowsManager, console);
            var debugWindow1 = new Window("debug1", 0, 0, 70, 4, 10);
            var debugWindow2 = new Window("combatDebug", 5, GameplayWindowWidth, 23, 20, 10);

            if (Debug)
            {
                windowsManager.AddWindow(debugWindow1);
                windowsManager.AddWindow(debugWindow2);
            }


            // Finally, update the window until a key is pressed or the window is closed:
            while (console.WindowUpdate() && Run)
            {
                if (console.KeyPressed)
                {
                    //Handle player input

                    keyHandler.Handle(console.GetKey());

                    //Wake up enemies and setsup path
                    foreach (var enemy in Map.Enemies)
                    {
                        if (enemy.CanSee(Player.Location, math))
                        {
                            //Wake up enemies
                            if (!Map.AwakenedEnemies.Contains(enemy))
                            {
                                Map.AwakenedEnemies.Add(enemy);
                            }

                            enemy.UpdatePath(Player.Location, math);
                        }
                    }
                    //Enemy Activity
                    foreach (var enemy in Map.AwakenedEnemies)
                    {
                        //Checks if enemy can atack else it moves
                        if (enemy.Map.Neighbours(enemy.Location).Any(neighbour => neighbour.CordY == Player.Location.CordY && neighbour.CordX == Player.Location.CordX))
                        {
                            var successfulHit = combatManager.HandleAttack(enemy, Player);
                            if (successfulHit && !combatManager.OnePunchMode)
                            {
                                if (Player.Dead)
                                {
                                    Run = false;
                                }
                            }
                        }
                        else
                        {
                            //Simulates diffrent running speeds so the player can try and run from enemies
                            bool skipMovingTowardsPlayer = true;
                            int  movementScore           = enemy.Attributes.Agility + 1;

                            if (movementScore <= 0)
                            {
                                movementScore = 1;
                            }
                            else if (movementScore >= 10)
                            {
                                skipMovingTowardsPlayer = false;
                            }
                            else
                            {
                                skipMovingTowardsPlayer = movementScore < randomProvider.Next(10);
                            }

                            if (!skipMovingTowardsPlayer && enemy.MovementQueue.Count != 0 && movement.CanBeMovedTo(enemy.MovementQueue.Peek()))
                            {
                                movement.Move(enemy, enemy.MovementQueue.Dequeue());
                            }
                            else
                            {
                                movement.MoveRandom(enemy);
                            }
                            //else do nothing
                        }
                    }

                    TurnCounter++;
                    combatManager.MassRegenerate(Map.AwakenedEnemies, Engine.Player);

                    hpWindow.Update();
                    atrWindow.Update();

                    //logWindow.Update();
                    turnCountWin.SetTextLine(Symbol.ParseString($"Turn: {TurnCounter}"), 0);
                    visualization.UpdateGameplayWindow(gameplayWindow);

                    visualization.PrintToConsole(windowsManager, console);
                }
            }
        }
 public BorderedWindowRenderer()
 {
     BorderColor = Color.Transparent;
     Window      = new BorderedWindow(Rectangle.Empty, Padding.None);
 }
 protected void SetWindowRectangleUsingClientLocationAndClientSize(int clientX, int clientY, int clientWidth, int clientHeight, Padding padding)
 {
     Window = new BorderedWindow(new Rectangle(clientX - padding.Left, clientY - padding.Top, clientWidth + padding.X, clientHeight + padding.Y), padding);
 }
 protected void SetWindowRectangleUsingWindowLocationAndClientSize(int windowX, int windowY, int clientWidth, int clientHeight, Padding padding)
 {
     Window = new BorderedWindow(new Rectangle(windowX, windowY, clientWidth + padding.X, clientHeight + padding.Y), padding);
 }
 protected void SetWindowRectangle(int x, int y, int width, int height, Padding padding)
 {
     Window = new BorderedWindow(new Rectangle(x, y, width, height), padding);
 }
 protected void SetWindowRectangle(Rectangle windowRectangle, Padding padding)
 {
     Window = new BorderedWindow(windowRectangle, padding);
 }