示例#1
0
    internal GameBoardComponent[] GetNeighboringObjects(GameBoardComponent root)
    {
        int distanceInterval = 1; //Default Selection Length

        return
            (GetHorizontalObjects(root, distanceInterval));
    }
 public Entity AddGameBoard(int newColumns, int newRows)
 {
     var component = new GameBoardComponent();
     component.columns = newColumns;
     component.rows = newRows;
     return AddGameBoard(component);
 }
示例#3
0
 internal void SetBoardFocus(GameBoardComponent c)
 {
     if (c != null)
     {
         m_CurrentFocusComponent = c;
     }
 }
示例#4
0
        public void Init()
        {
            Console.Title         = "HearthstoneCORE";
            Console.CursorVisible = false;

            //Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
            //Console.SetBufferSize(Console.LargestWindowWidth, Console.LargestWindowHeight);

            RenderComponents = new List <RenderComponent>();


            List <HSCard> cards = HSCard.GetAllCards();

            HSDeck deck = new HSDeck();

            deck.AddCards(cards);

            player1 = new HSPlayer(deck);

            Logo = new ASCIIComponent("logo", new RenderLocation(Console.WindowWidth - 5, 10));

            GameBoard = new GameBoardComponent(new RenderLocation(1, 1));

            RenderComponents.Add(GameBoard);

            //int i = 1;
            //foreach(var card in deck.Cards)
            //{
            //    card.RenderComponent = new CardComponent(card, new RenderLocation(i * 5, 6));
            //    RenderComponents.Add(card.RenderComponent);
            //    i++;
            //}

            RenderComponents.Add(Logo);
        }
示例#5
0
 private void AddObjectToBoard(Vector2 v, GameBoardComponent component)
 {
     if (!m_CurrentBoardObjects.ContainsKey(v))
     {
         m_CurrentBoardObjects.Add(v, component);
     }
 }
示例#6
0
        public void OnActivate()
        {
            if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Editor)
            {
                return;
            }

            this.gameBoardComponent = GameObj.Scene.FindComponent <GameBoardComponent>();
            this.transform          = GameObj.GetComponent <Transform>();

            //Preload the game assets
            this.playerOneMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "alienPink").FirstOrDefault();
            this.playerOneMat.EnsureLoaded();
            this.playerTwoMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "alienGreen").FirstOrDefault();
            this.playerTwoMat.EnsureLoaded();
            this.playerThreeMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "alienBeige").FirstOrDefault();
            this.playerThreeMat.EnsureLoaded();
            this.playerFourMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "alienYellow").FirstOrDefault();
            this.playerFourMat.EnsureLoaded();

            playerList = new List <GameObject>();

            //Create the players off screen
            for (int playerNumber = 1; playerNumber <= 4; playerNumber++)
            {
                GameObject player          = new GameObject("Player" + playerNumber);
                Transform  playerTransform = new Transform();
                playerTransform.Pos = new Vector3(-2000, -2000, 0); //Create the coin way off screen

                player.AddComponent(playerTransform);

                SpriteRenderer tempCoinSpriteRenderer = new SpriteRenderer();
                tempCoinSpriteRenderer.DepthOffset = -10;

                switch (playerNumber)
                {
                case 1:
                    tempCoinSpriteRenderer.SharedMaterial = playerOneMat;
                    break;

                case 2:
                    tempCoinSpriteRenderer.SharedMaterial = playerTwoMat;
                    break;

                case 3:
                    tempCoinSpriteRenderer.SharedMaterial = playerThreeMat;
                    break;

                case 4:
                    tempCoinSpriteRenderer.SharedMaterial = playerFourMat;
                    break;
                }

                tempCoinSpriteRenderer.Rect = new Rect(0, 0, 66, 92);

                player.AddComponent(tempCoinSpriteRenderer);
                playerList.Add(player);
                GameObj.Scene.AddObject(player);
            }
        }
示例#7
0
        public void OnActivate()
        {
            if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Editor)
            {
                return;
            }

            //Preload the game assets
            this.tileMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "tile").FirstOrDefault();
            this.tileMat.EnsureLoaded();

            this.coinMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "coinGold").FirstOrDefault();
            this.coinMat.EnsureLoaded();

            this.transform          = GameObj.GetComponent <Transform>();
            this.gameBoardComponent = GameObj.Scene.FindComponent <GameBoardComponent>();

            //Setup the game board
            for (int widthIndex = 0; widthIndex < this.gameBoardComponent.GameBoard.Width(); widthIndex++)
            {
                for (int heightIndex = 0; heightIndex < this.gameBoardComponent.GameBoard.Height(); heightIndex++)
                {
                    GameObject tempTileGameObject = new GameObject("Tile_" + widthIndex + "_" + heightIndex);
                    Transform  tempTileTransform  = new Transform();
                    //TODO: make this more flexible/configurable?
                    tempTileTransform.Pos = new Vector3(-225 + 150 * widthIndex, -225 + 150 * heightIndex, 0);

                    tempTileGameObject.AddComponent(tempTileTransform);

                    SpriteRenderer tempTileSpriteRenderer = new SpriteRenderer();
                    tempTileSpriteRenderer.DepthOffset    = 0;
                    tempTileSpriteRenderer.SharedMaterial = tileMat;
                    tempTileSpriteRenderer.Rect           = new Rect(0, 0, 128, 128);

                    tempTileGameObject.AddComponent(tempTileSpriteRenderer);
                    GameObj.Scene.AddObject(tempTileGameObject);
                    boardTileList.Add(tempTileGameObject);

                    //Create the coin pool - only have 5 non-player tiles currently.  Maybe make this more generic down the road.
                    for (int coinIndex = 0; coinIndex < this.gameBoardComponent.GameBoard.MaxCoinsPerTile(); coinIndex++)
                    {
                        GameObject tempCoinGameObject = new GameObject("Coin" + "_" + widthIndex + "_" + heightIndex + "_" + coinIndex);
                        Transform  tempCoinTransform  = new Transform();
                        tempCoinTransform.Pos = new Vector3(-2000, -2000, 0); //Create the coin way off screen

                        tempCoinGameObject.AddComponent(tempCoinTransform);

                        SpriteRenderer tempCoinSpriteRenderer = new SpriteRenderer();
                        tempCoinSpriteRenderer.DepthOffset    = -10;
                        tempCoinSpriteRenderer.SharedMaterial = coinMat;
                        tempCoinSpriteRenderer.Rect           = new Rect(0, 0, 64, 64);

                        tempCoinGameObject.AddComponent(tempCoinSpriteRenderer);
                        GameObj.Scene.AddObject(tempCoinGameObject);
                        coinPoolList.Add(tempCoinGameObject);
                    }
                }
            }
        }
示例#8
0
    public static GameBoardComponent DetermineNextNode
        (GameBoardComponent current, Vector2 destination)
    {
        int currentLowestDistance  = Int32.MaxValue;
        int currentLowestHeuristic = Int32.MaxValue;

        GameBoardComponent closestComponent = null;
        Vector2            origin           = current.Vector;

        GameBoardComponent[] components = current.GetNeighbors();

        for (int i = 0; i < components.Length; i++)
        {
            if (!components[i].IsPassable)
            {
                break;
            }

            int h = ParseVectorDistance(components[i].Vector, destination);
            int g = ParseVectorDistance(components[i].Vector, origin);
            int d = h + g;

            if (d < currentLowestDistance)
            {
                closestComponent       = components[i];
                currentLowestDistance  = d;
                currentLowestHeuristic = h;
            }

            else if (d == currentLowestDistance)
            {
                if (h < currentLowestHeuristic)
                {
                    closestComponent       = components[i];
                    currentLowestDistance  = d;
                    currentLowestHeuristic = h;
                }

                else if (h == currentLowestHeuristic)
                {
                    if (Utility.RandomBoolean())
                    {
                        closestComponent       = components[i];
                        currentLowestDistance  = d;
                        currentLowestHeuristic = h;
                    }
                }
            }
        }

        if (closestComponent != null)
        {
            return(closestComponent);
        }
        else
        {
            return(null);
        }
    }
示例#9
0
        public Entity AddGameBoard(int newColumns, int newRows)
        {
            var component = new GameBoardComponent();

            component.columns = newColumns;
            component.rows    = newRows;
            return(AddGameBoard(component));
        }
示例#10
0
 internal static void DebugBoardComponent(GameBoardComponent component, int count)
 {
     m_StringBuilder.AppendLine
         (string.Format("Virtual Board Object [{0}]", component.ParentIdentifier));
     m_StringBuilder.AppendLine
         (string.Format("Vector [{0}]", component.Vector));
     m_StringBuilder.AppendLine
         (string.Format("GameObject [{0}]", component.ObjectRelative.name));
 }
    void CreateGameBoardCache(GameBoardComponent gameBoard)
    {
        var grid = new Entity[gameBoard.columns, gameBoard.rows];

        foreach (var entity in _pool.GetEntities(CoreMatcher.Interactive))
        {
            grid[entity.position.x, entity.position.y] = entity;
        }
        _pool.ReplaceGameBoardCache(grid);
    }
示例#12
0
    internal void AddGameBoardComponent(GameBoardComponent component)
    {
        if (m_CurrentBoardObjects == null)
        {
            m_CurrentBoardObjects
                = new Dictionary <Vector2, GameBoardComponent>();
        }

        AddObjectToBoard(component.Vector, component);
    }
示例#13
0
        public void Apply(IEntity entity)
        {
            var gameBoardComponent = new GameBoardComponent
            {
                Width  = _width,
                Height = _height
            };

            entity.AddComponents(gameBoardComponent, new ViewComponent());
        }
 void CreateNewGameBoardCache(GameBoardComponent gameBoard)
 {
     var grid = new ICollection<Entity>[gameBoard.columns, gameBoard.rows];
     var entities = pool.GetEntities(Matcher.AllOf(Matcher.GameBoardElement, Matcher.Position));
     foreach (var e in entities)
     {
         var pos = e.position;
         grid.Add(pos.x, pos.y, e);
     }
     pool.ReplaceGameBoardCache(grid);
 }
示例#15
0
    internal GameBoardComponent GetBoardObjectByVector(Vector2 v)
    {
        GameBoardComponent root = null;

        if (m_CurrentBoardObjects.ContainsKey(v))
        {
            root = m_CurrentBoardObjects[v];
        }

        return(root);
    }
示例#16
0
        public Entity SetGameBoard(GameBoardComponent component)
        {
            if (hasGameBoard)
            {
                throw new SingleEntityException(Matcher.GameBoard);
            }
            var entity = CreateEntity();

            entity.AddGameBoard(component);
            return(entity);
        }
    void createNewGameBoardCache(GameBoardComponent gameBoard)
    {
        Debug.Log("Create GameBoard Cache");

        var grid = new Entity[gameBoard.columns, gameBoard.rows];
        foreach (var e in _pool.GetEntities(Matcher.AllOf(Matcher.GameBoardElement, Matcher.Position))) {
            var pos = e.position;
            grid[pos.x, pos.y] = e;
        }
        _pool.ReplaceGameBoardCache(grid);
    }
    void createNewGameBoardCache(GameBoardComponent gameBoard)
    {
        var grid     = new ICollection <Entity> [gameBoard.columns, gameBoard.rows];
        var entities = pool.GetEntities(Matcher.AllOf(Matcher.GameBoardElement, Matcher.Position));

        foreach (var e in entities)
        {
            var pos = e.position;
            grid.Add(pos.x, pos.y, e);
        }
        pool.ReplaceGameBoardCache(grid);
    }
示例#19
0
    void createNewGameBoardCache(GameBoardComponent gameBoard)
    {
        Debug.Log("Create GameBoard Cache");

        var grid = new Entity[gameBoard.columns, gameBoard.rows];

        foreach (var e in _pool.GetEntities(Matcher.AllOf(Matcher.GameBoardElement, Matcher.Position)))
        {
            var pos = e.position;
            grid[pos.x, pos.y] = e;
        }
        _pool.ReplaceGameBoardCache(grid);
    }
 public Entity ReplaceGameBoard(int newColumns, int newRows)
 {
     GameBoardComponent component;
     if (hasGameBoard) {
         WillRemoveComponent(ComponentIds.GameBoard);
         component = gameBoard;
     } else {
         component = new GameBoardComponent();
     }
     component.columns = newColumns;
     component.rows = newRows;
     return ReplaceComponent(ComponentIds.GameBoard, component);
 }
示例#21
0
    internal void AttachBoardObject(GameObject o, Vector2 v)
    {
        try
        {
            var component = new GameBoardComponent(v, m_BoardIdentifier, o);
            AddGameBoardComponent(component);
        }

        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
    }
示例#22
0
 //创建背景地图
 void BoardSetup(GameBoardComponent gameBoard)
 {
     for (int x = -1; x <= gameBoard.columns; x++)
     {
         for (int y = -1; y <= gameBoard.rows; y++)
         {
             bool   edge   = x == -1 || x == Res.columns || y == -1 || y == Res.rows;
             string prefab = edge ? Res.outerWalls.Random() : Res.floors.Random();
             _pools.board.CreateEntity()
             .AddPosition(x, y)
             .AddAsset(prefab);
         }
     }
 }
示例#23
0
    internal void RemoveActiveGameComponent(GameBoardComponent component)
    {
        try
        {
            if (m_ActiveBoardObjects.ContainsKey(component.Vector))
            {
                m_ActiveBoardObjects.Remove(component.Vector);
            }
        }

        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
    }
示例#24
0
    void ResetGridPositions(GameBoardComponent gameBoard)
    {
        var gridPositions = pool.gridPositions.value;

        gridPositions.Clear();

        // start at 1 to avoid placing items along the edges
        for (int x = 1; x < gameBoard.columns - 1; x++)
        {
            for (int y = 1; y < gameBoard.rows - 1; y++)
            {
                gridPositions.Add(new Vector2(x, y));
            }
        }
    }
示例#25
0
        public Entity ReplaceGameBoard(int newColumns, int newRows)
        {
            GameBoardComponent component;

            if (hasGameBoard)
            {
                WillRemoveComponent(ComponentIds.GameBoard);
                component = gameBoard;
            }
            else
            {
                component = new GameBoardComponent();
            }
            component.columns = newColumns;
            component.rows    = newRows;
            return(ReplaceComponent(ComponentIds.GameBoard, component));
        }
示例#26
0
 void BoardSetup(GameBoardComponent gameBoard)
 {
     // start at negative 1 to place outer edges
     for (int x = -1; x <= gameBoard.columns; x++)
     {
         for (int y = -1; y <= gameBoard.rows; y++)
         {
             bool edge = x == -1 || x == gameBoard.columns ||
                         y == -1 || y == gameBoard.rows;
             Prefab prefab = edge ? OUTERWALLS.Random() : FLOORS.Random();
             pool.CreateEntity().AddPosition(x, y)
             .AddResource(prefab)
             .IsDeleteOnExit(true)
             .AddNestedView("Board");
         }
     }
 }
示例#27
0
    internal void AddActiveGameComponent(GameBoardComponent component)
    {
        try
        {
            if (m_ActiveBoardObjects == null)
            {
                m_ActiveBoardObjects = new Dictionary <Vector2, GameBoardComponent>();
            }

            if (!m_ActiveBoardObjects.ContainsKey(component.Vector))
            {
                m_ActiveBoardObjects.Add(component.Vector, component);
            }
        }

        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
    }
示例#28
0
    internal GameBoardComponent[] DeterminePath(Vector2 origin, Vector2 destination)
    {
        List <GameBoardComponent>
        nodes = new List <GameBoardComponent>();

        GameBoardComponent endNode     = GetBoardObjectByVector(destination);
        GameBoardComponent currentNode = GetBoardObjectByVector(origin);

        while (currentNode != endNode)
        {
            currentNode = QueryNextStep(currentNode.Vector, destination);

            if (!nodes.Contains(currentNode))
            {
                nodes.Add(currentNode);
            }
        }

        nodes.Add(endNode); return(nodes.ToArray());
    }
示例#29
0
    internal GameBoardComponent[] GetHorizontalObjects(GameBoardComponent root, int distance)
    {
        Vector2 rootVector = root.Vector; int distanceInterval = distance;
        List <GameBoardComponent> horizontalObjects = new List <GameBoardComponent>();

        var vbo = GetBoardObjectByVector
                      (new Vector2(rootVector.x, rootVector.y + distanceInterval));

        if (vbo != null)
        {
            horizontalObjects.Add(vbo);
            vbo = null;
        }

        vbo = GetBoardObjectByVector
                  (new Vector2(rootVector.x, rootVector.y - distanceInterval));
        if (vbo != null)
        {
            horizontalObjects.Add(vbo);
            vbo = null;
        }

        vbo = GetBoardObjectByVector
                  (new Vector2(rootVector.x - distanceInterval, rootVector.y));
        if (vbo != null)
        {
            horizontalObjects.Add(vbo);
            vbo = null;
        }

        vbo = GetBoardObjectByVector
                  (new Vector2(rootVector.x + distanceInterval, rootVector.y));
        if (vbo != null)
        {
            horizontalObjects.Add(vbo);
            vbo = null;
        }

        return(horizontalObjects.ToArray());
    }
 public Entity SetGameBoard(GameBoardComponent component)
 {
     if (hasGameBoard) {
         throw new SingleEntityException(Matcher.GameBoard);
     }
     var entity = CreateEntity();
     entity.AddGameBoard(component);
     return entity;
 }
 public Entity AddGameBoard(GameBoardComponent component)
 {
     return AddComponent(ComponentIds.GameBoard, component);
 }
    void ResetGridPositions(GameBoardComponent gameBoard)
    {
        var gridPositions = pool.gridPositions.value;
        gridPositions.Clear();

        // start at 1 to avoid placing items along the edges
        for (int x = 1; x < gameBoard.columns - 1; x++)
        {
            for (int y = 1; y < gameBoard.rows - 1; y++)
            {
                gridPositions.Add(new Vector2(x, y));
            }
        }
    }
 void BoardSetup(GameBoardComponent gameBoard)
 {
     // start at negative 1 to place outer edges
     for (int x = -1; x <= gameBoard.columns; x++)
     {
         for (int y = -1; y <= gameBoard.rows; y++)
         {
             bool edge = x == -1 || x == gameBoard.columns ||
                         y == -1 || y == gameBoard.rows;
             Prefab prefab = edge ? OUTERWALLS.Random() : FLOORS.Random();
             pool.CreateEntity().AddPosition(x, y)
                                .AddResource(prefab)
                                .IsDeleteOnExit(true)
                                .AddNestedView("Board");
         }
     }
 }
 internal void SetComponent(GameBoardComponent component)
 {
     m_ComponentRelative = component;
 }
示例#35
0
 public Entity AddGameBoard(GameBoardComponent component)
 {
     return(AddComponent(ComponentIds.GameBoard, component));
 }
示例#36
0
    internal GameBoardComponent[] GetAllObjectsInRange(GameBoardComponent root, int r)
    {
        int range = r;
        List <GameBoardComponent>
        componentsInRange = new List <GameBoardComponent>();

        GameBoardComponent component = null;

        int x = (int)root.Vector.x;
        int y = (int)root.Vector.y;

        m_CurrentFocusComponent = component = root;

        if (component != null)
        {
            componentsInRange.Add(component);
            component = null;
        }

        for (int i = 1; i <= range; i++)
        {
            component = GetBoardObjectByVector(new Vector2(x, y + i));
            if (component != null)
            {
                componentsInRange.Add(component);
                component = null;
            }

            component = GetBoardObjectByVector(new Vector2(x, y - i));
            if (component != null)
            {
                componentsInRange.Add(component);
                component = null;
            }

            component = GetBoardObjectByVector(new Vector2(x + i, y));
            if (component != null)
            {
                componentsInRange.Add(component);
                component = null;
            }

            component = GetBoardObjectByVector(new Vector2(x - i, y));
            if (component != null)
            {
                componentsInRange.Add(component);
                component = null;
            }
        }

        int rangeMod = range - 3;

        for (int h = 1; h <= range + rangeMod; h++)
        {
            range--;
            for (int j = 1; j <= range; j++)
            {
                component = GetBoardObjectByVector(new Vector2(x + h, y + j));
                if (component != null)
                {
                    componentsInRange.Add(component);
                    component = null;
                }

                component = GetBoardObjectByVector(new Vector2(x - h, y - j));
                if (component != null)
                {
                    componentsInRange.Add(component);
                    component = null;
                }

                component = GetBoardObjectByVector(new Vector2(x - h, y + j));
                if (component != null)
                {
                    componentsInRange.Add(component);
                    component = null;
                }

                component = GetBoardObjectByVector(new Vector2(x + h, y - j));
                if (component != null)
                {
                    componentsInRange.Add(component);
                    component = null;
                }
            }
        }
        return(componentsInRange.ToArray());
    }