Example #1
0
        /// <summary>
        /// Helper functions for converting a board in a test state
        /// to a board in the game state
        /// </summary>
        /// <param name="state"></param>
        /// <param name="testState"></param>
        private void ConvertBoard(GameState state, TestGameState testState)
        {
            var board = new IO.Models.Board();

            board.Height = testState.Board.Height;
            board.Width  = testState.Board.Width;

            foreach (var tile in testState.Board.Grid)
            {
                var ptile = new Tile()
                {
                    TileType     = tile.TileType,
                    GroundSprite = tile.GroundSprite,
                    AboveSprite  = tile.AboveSprite,
                };

                if (tile.HasItems)
                {
                    ptile.Items.Add(new Item());
                }

                board.Grid.Add(ptile);
            }

            state.BoardNames.Add(testState.Board.Name, board);
        }
Example #2
0
        /// <summary>
        /// Translate from test state to state
        /// </summary>
        /// <param name="testState"></param>
        /// <returns></returns>
        private GameState GetState(TestGameState testState)
        {
            GameState state = new GameState();

            this.ConvertBoard(state, testState);
            this.ConvertCharacter(state, testState);

            return(state);
        }
Example #3
0
        /// <summary>
        /// Helper function for converting players in a test state
        /// to players in the game state
        /// </summary>
        /// <param name="state"></param>
        /// <param name="testState"></param>
        private void ConvertCharacter(GameState state, TestGameState testState)
        {
            foreach (var testCharacter in testState.Characters)
            {
                switch (testCharacter.CharacterType)
                {
                case CharacterType.Player:
                    var player = new PPlayer()
                    {
                        Character = new PCharacter()
                        {
                            Name     = testCharacter.Name,
                            Position = new PPosition()
                            {
                                BoardId = testCharacter.Board,
                                X       = testCharacter.X,
                                Y       = testCharacter.Y
                            },
                            Sprite = testCharacter.SpritePath
                        }
                    };

                    state.PlayerNames.Add(testCharacter.Name, player);
                    break;

                case CharacterType.Monster:
                    var monster = new PMonster()
                    {
                        Character = new PCharacter()
                        {
                            Name     = testCharacter.Name,
                            Position = new PPosition()
                            {
                                BoardId = testCharacter.Board,
                                X       = testCharacter.X,
                                Y       = testCharacter.Y
                            },
                            Sprite = testCharacter.SpritePath
                        }
                    };

                    state.MonsterNames.Add(testCharacter.Name, monster);
                    break;
                }
            }
        }