Exemplo n.º 1
0
    private void CreateTiles()
    {
        Tiles = new GameObject[Width + 1, Height + 1];
        Units = new GameObject[Width + 1, Height + 1];
        Areas = new GameObject[Width + 1, Height + 1];

        for (int x = 1; x <= Width; x++)
        {
            for (int y = 1; y <= Height; y++)
            {
                GameObject tile = Instantiate <GameObject>(TilePrefab, this.transform);
                tile.transform.SetParent(this.transform);

                RectTransform rt = (RectTransform)tile.transform;
                tileWidth  = rt.rect.width;
                tileHeight = rt.rect.height;

                // Show text
                //TextMeshPro text = tile.transform.Find("Text").gameObject.GetComponent<TextMeshPro>();
                //text.SetText(x.ToString() + ";" + y.ToString());

                tile.transform.localPosition = PointerToIcometric(new Point(x, y), tileWidth, tileHeight);

                TileDisplay tileDisplay = tile.GetComponent <TileDisplay>();
                tileDisplay.x = x;
                tileDisplay.y = y;
                tileDisplay.SetText(x + " " + y);

                Tiles[x, y] = tile as GameObject;
            }
        }
    }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the board.
        /// </summary>
        private void InitializeBoard()
        {
            gameBoardTable.SuspendLayout();
            gameBoardTable.Controls.Clear();
            gameBoardTable.RowCount    = Game.NumberOfRows;
            gameBoardTable.ColumnCount = Game.NumberOfColumns;
            foreach (RowStyle rowStyle in gameBoardTable.RowStyles)
            {
                rowStyle.SizeType = SizeType.AutoSize;
            }
            foreach (ColumnStyle colStyle in gameBoardTable.ColumnStyles)
            {
                colStyle.SizeType = SizeType.AutoSize;
            }

            for (int playerIndex = 0; playerIndex < Game.PlayerStates.Count; playerIndex++)
            {
                var playerState = Game.PlayerStates[playerIndex];
                playerState.GameBoardTiles.ForEach(gameBoardTile =>
                {
                    var tileDisplay = new TileDisplay(gameBoardTile, playerState.PlayerName);
                    gameBoardTable.Controls.Add(tileDisplay, gameBoardTile.Column, gameBoardTile.Row + Game.NumberOfRows * playerIndex);
                    tileDisplay.Draw();
                    tileDisplay.Click += TileDisplay_Click;
                });
            }
            gameBoardTable.ResumeLayout();
        }
Exemplo n.º 3
0
    public void InstantiateTile(Tile tile, Vector2 position)
    {
        TileDisplay newTileDisplay = Instantiate(tileDisplay, this.transform);

        // instantiatedTileDisplays.Add(position, newTileDisplay);
        newTileDisplay.SetTile(tile, position);
    }
Exemplo n.º 4
0
 void Start()
 {
     pos = (Vector2)(transform.position);
     //sprite = GetComponent<SpriteRenderer> ();
     //cover = GetComponent<SpriteRenderer> ();
     display = GetComponent <TileDisplay> ();
 }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Board       = new DemoBuilder().Build();
            Writer      = Console.Out;
            TileDisplay = new TileDisplay(new DisplayFactory());

            BoardDisplay = new BoardDisplay(Writer, TileDisplay);

            MenuDisplay = new MenuDisplay(Writer, new List <MenuOption>
            {
                new MenuOption("Build"),
            });

            Player = new TerraMysticaPlayer("Player 1", new Mermaids());
            Player.Resources.Gold.Add(100);
            Player.Resources.Workers.Add(100);

            BoardDisplay.PrintHeader = true;
            PrintLoop();

            Console.WriteLine($"{Player.Name}, Build a damn Dwelling!");
            Console.ReadKey();

            Console.Clear();

            var tile        = Board.TileForLocation(new HexLocation(3, 0));
            var buildAction = new BuildAction(Board, Player, tile.Location);

            buildAction.Execute();

            PrintLoop();
            Console.WriteLine($"Good, good. Now dance for me!");

            Console.ReadKey();
        }
Exemplo n.º 6
0
 private void OnTileMouseExitOnBoard(TileDisplay tile)
 {
     this.hoveredTile = null;
     tile.HighlightOff();
     CursorController.SetDefault();
     this.boardCreator.RemoveAllBlinks();
     this.boardCreator.ShowPathReach(this.selectedUnit);
 }
Exemplo n.º 7
0
        private void SwapTiles(TileDisplay source, Point srcTile, TileDisplay dest, Point destTile)
        {
            byte tileA = source.GetTile(srcTile);
            byte tileB = dest.GetTile(destTile);

            source.SetTile(srcTile, tileB);
            dest.SetTile(destTile, tileA);
        }
Exemplo n.º 8
0
    private Dictionary <Tile, TileDisplay> MakeTilesDictionary(Map tiles)
    {
        Dictionary <Tile, TileDisplay> ret = new Dictionary <Tile, TileDisplay>();

        foreach (Tile tile in tiles)
        {
            TileDisplay display = CreateTileDisplay(tile);
            ret.Add(tile, display);
        }
        return(ret);
    }
Exemplo n.º 9
0
    public bool ShowTile(Vector2 position)
    {
        bool tileDisplayExists = instantiatedTileDisplays.ContainsKey(position);

        if (tileDisplayExists)
        {
            TileDisplay selectedTile = instantiatedTileDisplays[position];
            selectedTile.gameObject.SetActive(true);
        }
        return(tileDisplayExists);
    }
Exemplo n.º 10
0
    public UnitDisplay GetUnitByTile(TileDisplay tileDisplay)
    {
        Point tilePosition = GetTilePosition(tileDisplay);
        var   unit         = Units[tilePosition.x, tilePosition.y];

        if (unit)
        {
            return(unit.GetComponent <UnitDisplay>());
        }

        return(null);
    }
Exemplo n.º 11
0
 //Should this change the tile being displayed to a river?
 //Yes for clarity in other places
 public void AddSegment(TileDisplay newSeg)
 {
     Segments.Add(newSeg);
     newSeg.setRiver();
     if (newSeg.GetHeight() < lowestHeight)
     {
         lowestHeight = newSeg.GetHeight();
         foreach (TileDisplay t in Segments)
         {
             t.setHeight(lowestHeight);
         }
     }
 }
 private void OnTileMouseEnterOnBoard(TileDisplay tile)
 {
     this.hoveredTile = tile;
     if (this.boardCreator.CheckTileInPoints(tile, points))
     {
         CursorController.SetPointer();
         tile.HighlightOn();
     }
     else
     {
         CursorController.SetPointerForbidden();
     }
 }
Exemplo n.º 13
0
    private void RunResetLevelCommand()
    {
        GameObject LevelMap = GameObject.Find("Level Map");

        if (LevelMap != null)
        {
            DestroyImmediate(LevelMap);
        }

        // Create Level Map
        LevelMap = new GameObject("Level Map");
        LevelMap.AddComponent <PlatformCollisionBoxes>();
        LevelMap.transform.position = new Vector3(-10.0f, 0.0f);

        // Create TileMap
        for (int x = LevelGrid.TileHorzBeginID; x < (LevelGrid.TileCountHorz); ++x)
        {
            GameObject NewRow = new GameObject("Row " + (x + 1).ToString());
            NewRow.transform.parent   = LevelMap.transform;
            NewRow.transform.position = new Vector3(-10.0f, 0.0f);

            for (int y = LevelGrid.TileVertzBeginID; y < (LevelGrid.TileCountVertz); ++y)
            {
                GameObject NewCol = new GameObject("Col " + (y + 1).ToString());
                NewCol.tag = "Stage_Tile";
                NewCol.transform.parent = NewRow.transform;
                float XPos = (Target.m_v2StartPos.x + (x * LevelGrid.GetTileSize().x)) + (LevelGrid.GetTileSize().x * 0.5f);
                float YPos = (Target.m_v2StartPos.y + (y * LevelGrid.GetTileSize().y)) + (LevelGrid.GetTileSize().y * 0.5f);
                NewCol.transform.position = new Vector3(XPos, YPos);
                TileDisplay pTileDisplay = NewCol.AddComponent <TileDisplay>();
#if UNITY_EDITOR
                // Assign Identities
                pTileDisplay.COL = x + 1;
                pTileDisplay.ROW = y;
#endif

                if ((x < 0) || (y >= Target.m_iTileCountVertz) || (x >= Target.m_iTileCountHorz))
                {
                    pTileDisplay.SetAsOffscreenTile();
                }
            }
        }

        // Add LevelMap to Object Manager
        GameObject ObjectManager = GameObject.Find("Level Manager");
        if (ObjectManager != null)
        {
            ObjectManager.GetComponent <ImportantObjectsManager>().m_goLevelMapObject = LevelMap;
        }
    }
Exemplo n.º 14
0
 // Update is called once per frame
 void Update()
 {
     if (targetLocation != null)
     {
         if (currentLocation != targetLocation)
         {
             transform.position = Vector3.MoveTowards(rb.position, targetLocation.gameObject.transform.position, speed);
             if (Vector3.Distance(transform.position, targetLocation.gameObject.transform.position) < 0.001f)
             {
                 currentLocation = targetLocation;
                 moving          = false;
             }
         }
     }
 }
Exemplo n.º 15
0
    public Point GetTilePosition(TileDisplay tileDispay)
    {
        for (int x = 1; x <= Width; x++)
        {
            for (int y = 1; y <= Height; y++)
            {
                if (Tiles[x, y] == tileDispay.gameObject)
                {
                    return(new Point(x, y));
                }
            }
        }

        return(null);
    }
Exemplo n.º 16
0
    //hills currently look too spikey, so moving their neighbours to be a similar height
    void hillSmooth(TileDisplay hill)
    {
        List <TileDisplay> neighbours = new List <TileDisplay>(hill.GetNeightbours());

        foreach (TileDisplay t in neighbours)
        {
            if (t != null)
            {
                if (t.GetHeight() < hill.GetHeight())
                {
                    t.setHeight(hill.GetHeight() - 1);
                }
            }
        }
    }
Exemplo n.º 17
0
        private void TileClick(TileDisplay ctrl, Point tile)
        {
            if (tileMarked)
            {
                SwapTiles(markedControl, markedControl.InvertedTile, ctrl, tile);

                tileMarked = false;
                markedControl.InvertedTile = new Point(-1, -1);
            }
            else
            {
                markedControl     = ctrl;
                ctrl.InvertedTile = tile;
                tileMarked        = true;
            }
        }
Exemplo n.º 18
0
    public IEnumerator FlashWinningTiles(LineDefinition winningLine, PostFlashRoutine postFlashRoutine)
    {
        for (int flashCount = 0; flashCount < 6; ++flashCount)
        {
            yield return(new WaitForSeconds(0.15f));

            bool flashOn = flashCount % 2 == 0;

            for (int tileCount = 0; tileCount < 3; ++tileCount)
            {
                Move        tilePosition = winningLine.GetMove(tileCount);
                TileDisplay tileDisplay  = GetTileDisplay(tilePosition);
                tileDisplay.SetWinningFlashMaterial(flashOn);
            }
        }
        postFlashRoutine();
    }
Exemplo n.º 19
0
        public frmRearrageTiles()
        {
            InitializeComponent();

            tdArrangement        = new TileDisplay();
            tdArrangement.Zoom   = true;
            tdArrangement.Bounds = new Rectangle(8, 8, 256, 256);
            tdArrangement.SetInitialArrangement();
            tdArrangement.MouseDown += new MouseEventHandler(tdArrangement_MouseDown);
            Controls.Add(tdArrangement);

            tdUnplaced        = new TileDisplay();
            tdUnplaced.Zoom   = true;
            tdUnplaced.Bounds = new Rectangle(272, 8, 256, 256);
            tdUnplaced.SetEmptyArrangement();
            tdUnplaced.MouseDown += new MouseEventHandler(tdUnplaced_MouseDown);
            Controls.Add(tdUnplaced);
        }
    void FindPlatforms()
    {
        m_PlatformsOnGrid = new PlatformSetup[LevelGrid.TileCountHorz, LevelGrid.TileCountVertz];
        for (int y = 0; y < LevelGrid.TileCountVertz; ++y)
        {
            for (int x = 0; x < LevelGrid.TileCountHorz; ++x)
            {
                if (m_PlatformsOnGrid[x, y] != null)
                {
                    continue;
                }

                TileDisplay pTileDisplay = transform.GetChild(x).GetChild(y).GetComponent <TileDisplay>();
                if (pTileDisplay.TileType == TileDisplay.eTileType.PLATFORM || pTileDisplay.TileType == TileDisplay.eTileType.SHORT_PLATFORM)
                {
                    m_PlatformsOnGrid[x, y] = new PlatformSetup();
                    PlatformSetup pPlatformSetup = m_PlatformsOnGrid[x, y];
                    pPlatformSetup.PlatformObject = transform.GetChild(x).GetChild(y).gameObject;
                    pPlatformSetup.IsPlatform     = true;


                    List <PlatformProperties> lConnectedPlatforms = new List <PlatformProperties>();
                    lConnectedPlatforms.Add(new PlatformProperties(x, y, pTileDisplay.TileType == TileDisplay.eTileType.SHORT_PLATFORM));
                    while (x < (LevelGrid.TileCountHorz - 1))
                    {
                        x += 1;
                        if (transform.GetChild(x).GetChild(y).GetComponent <TileDisplay>().IsPlatform)
                        {
                            m_PlatformsOnGrid[x, y]       = new PlatformSetup();
                            pPlatformSetup                = m_PlatformsOnGrid[x, y];
                            pPlatformSetup.PlatformObject = transform.GetChild(x).GetChild(y).gameObject;
                            pPlatformSetup.IsPlatform     = true;
                            lConnectedPlatforms.Add(new PlatformProperties(x, y, pTileDisplay.TileType == TileDisplay.eTileType.SHORT_PLATFORM));
                        }
                        else
                        {
                            break;
                        }
                    }
                    m_lPlatformConnections.Add(lConnectedPlatforms);
                }
            }
        }
    }
Exemplo n.º 21
0
        private void TileDisplay_Click(object sender, System.EventArgs e)
        {
            EditingTileDisplay = (TileDisplay)sender;
            switch (EditingTileDisplay.TileState.HitState)
            {
            case TileHitState.Unknown:
                rdoUnknown.Checked = true;
                break;

            case TileHitState.Hit:
                rdoHit.Checked = true;
                break;

            case TileHitState.Miss:
                rdoMiss.Checked = true;
                break;
            }
            lblHitPercentage.Text = @"Possible Hits: " + EditingTileDisplay.TileState.PossibleHits + @" (" + EditingTileDisplay.TileState.PossibleHitPercentage.ToString("P") + @")";
        }
Exemplo n.º 22
0
    void OnTileMouseExit(Point position)
    {
        GameObject unit = Units[position.x, position.y];

        if (unit)
        {
            UnitDisplay unitDisplay = unit.GetComponent <UnitDisplay>();

            this.hoveredUnit = null;

            Unibus.Dispatch <UnitDisplay>(UNIT_MOUSE_EXIT_ON_BOARD, unitDisplay);
        }
        else
        {
            TileDisplay tileDisplay = this.Tiles[position.x, position.y].GetComponent <TileDisplay>();

            this.hoveredTile = null;

            Unibus.Dispatch <TileDisplay>(TILE_WITHOUT_UNIT_MOUSE_EXIT_ON_BOARD, tileDisplay);
        }
    }
Exemplo n.º 23
0
        public void Show(TileDisplay toShow)
        {
            switch (toShow)
            {
            case TileDisplay.Normal:
                ShowMainResourceType(_normalResourceType);
                _actingResourceType = _normalResourceType;
                _rectPermResourceType.Visibility = Visibility.Collapsed;
                break;

            case TileDisplay.Gold:
                _rectPermResourceType.Visibility = Visibility.Visible;
                _actingResourceType = ResourceType.GoldMine;
                ShowMainResourceType(ResourceType.GoldMine);
                ShowSmallResourceType(_normalResourceType);
                break;

            default:
                break;
            }
        }
Exemplo n.º 24
0
    private void OnTileMouseEnterOnBoard(TileDisplay tile)
    {
        this.hoveredTile = tile;
        this.boardCreator.RemoveAllBlinks();

        Point fromPosition = this.boardCreator.GetTilePosition(tile);

        this.ShowRangeAttackReach(this.selectedUnit, fromPosition);

        var points       = this.boardCreator.ShowPathReach(this.selectedUnit);
        var tilePosition = this.boardCreator.GetTilePosition(tile);

        if (this.boardCreator.CheckTileInPoints(tile, points))
        {
            tile.HighlightOn();
            CursorController.SetPointer();
        }
        else
        {
            CursorController.SetPointerForbidden();
        }
    }
Exemplo n.º 25
0
    public void CreateTiles(GridData gridData)
    {
        _width  = gridData.GetWidth();
        _height = gridData.GetHeight();
        for (int column = 0; column < _width; ++column)
        {
            for (int row = 0; row < _height; ++row)
            {
                Vector3     tilePosition = new Vector3(CalculateTilePosition(column, _height), CalculateTilePosition(row, _width), 0.5f);
                GameObject  tile         = Instantiate(_tilePrefab, tilePosition, Quaternion.Euler(-90, 0, 0)) as GameObject;
                TileDisplay tileDisplay  = tile.GetComponent <TileDisplay>();
                tileDisplay.SetCoordinates(column, row);

                // Don't display grid lines for the last column/row, so
                // that we get that traditional noughts and crosses grid.
                tileDisplay.EnableRightLine(column < _width - 1);
                tileDisplay.EnableTopLine(row < _height - 1);
                eState state = gridData.GetTileState(new Move(column, row));
                tileDisplay.UpdateDisplay(state);
                tile.name = CreateTileName(column, row);
            }
        }
    }
Exemplo n.º 26
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Clone Tile
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#if UNITY_EDITOR
    private void CloneTo(int X, int Y)
    {
        if (LevelGrid.ValidTile(X, Y))
        {
            TileDisplay pTile = GameObject.Find("Level Map").transform.GetChild(X).GetChild(Y).GetComponent <TileDisplay>();
            pTile.ChangeTileType(m_eTileType);

            if (gameObject.GetComponent <SpriteRenderer>() != null)
            {
                pTile.GetComponent <SpriteRenderer>().sprite = gameObject.GetComponent <SpriteRenderer>().sprite;
            }
            if (gameObject.GetComponent <PlatformInformation>() != null)
            {
                pTile.GetComponent <PlatformInformation>().m_eDirectionType = gameObject.GetComponent <PlatformInformation>().m_eDirectionType;
                pTile.GetComponent <PlatformInformation>().m_bBreakable     = gameObject.GetComponent <PlatformInformation>().m_bBreakable;
                pTile.GetComponent <PlatformInformation>().m_bCanDash       = gameObject.GetComponent <PlatformInformation>().m_bCanDash;
            }
            if (Child != null)
            {
                pTile.AddChild();
                pTile.Child.GetComponent <SpriteRenderer>().sprite = Child.GetComponent <SpriteRenderer>().sprite;
            }
        }
    }
 private void OnTileMouseExitOnBoard(TileDisplay tile)
 {
     CursorController.SetPointer();
     this.hoveredTile = null;
     tile.HighlightOff();
 }
 public void OnTileClicked(TileDisplay tile)
 {
     Move move = new Move(tile._column, tile._row);
     MakeMove(move);
 }
Exemplo n.º 29
0
    // Use this for initialization
    void Start()
    {
        GameObject tile_holder = new GameObject();

        tile_holder.name = "Tiles";

        for (int x = 0; x < CreateGridWidth; x++)
        {
            for (int y = 0; y < CreateGridHeight; y++)
            {
                GameObject tile_go = new GameObject();
                tile_go.transform.SetParent(tile_holder.transform);
                tile_go.name = "Tile_" + x + "_" + y;
                tile_go.transform.position = new Vector2(x, y);
                SpriteRenderer sr = tile_go.AddComponent <SpriteRenderer>();
                sr.color            = Color.gray;
                sr.sortingLayerName = "Floor";
                TileDisplay td = tile_go.AddComponent <TileDisplay>();
                //TODO Replace this with a sprite manager of some sort.
                td.floor_sprite     = floor_sprite;
                td.wall_sprite      = wall_sprite;
                td.OffsetFromOrigin = new Vector2(x, y);
            }
        }


        CharacterData cd = new CharacterData(new Vector2(0, 16));

        GameObject tile_holder = new GameObject();

        tile_holder.name = "Tiles";
        MapLoaderImage mli = tile_holder.AddComponent <MapLoaderImage>();

        mli.floor_sprite = floor_sprite;
        mli.wall_sprite  = wall_sprite;
        mli.mapImage     = mapImage;


        CharacterData cd = new CharacterData(new Vector2(15, 16));

        GameObject player_go = new GameObject();

        player_go.name = "Player";
        //player_go.transform.position = new Vector2 (0, 0);
        //player_go.AddComponent<PCMovement> ();
        AI_Player pc = player_go.AddComponent <AI_Player>();

        pc.Character = cd;
        GameData.SetActiveCharacter(cd); // TODO This isn't the way to do this...
        SpriteRenderer player_sr = player_go.AddComponent <SpriteRenderer>();

        player_sr.color            = Color.white;
        player_sr.sprite           = player_sprite;
        player_sr.sortingLayerName = "Units";
        UpdateCharacterSpriteLocation scr = player_go.AddComponent <UpdateCharacterSpriteLocation>();

        scr.cd = cd;
        LightSource l = player_go.AddComponent <LightSource>();

        l.UpdateIntensity(16.0f);

        GameData.MapCharacterToObject(cd, player_go);



        /*    CharacterData nuper_data = new CharacterData(new Vector2(5, 5));
         *
         * GameObject nuper_go = new GameObject();
         * nuper_go.name = "Test Nuper";
         * //nuper_go.transform.position = new Vector2 (5, 5);
         * AI_Critter ai = nuper_go.AddComponent<AI_Critter>();
         * ai.Character = nuper_data;
         * SpriteRenderer nuper_sr = nuper_go.AddComponent<SpriteRenderer>();
         * nuper_sr.color = Color.magenta;
         * nuper_sr.sprite = nuper_sprite;
         * UpdateCharacterSpriteLocation nscr = nuper_go.AddComponent<UpdateCharacterSpriteLocation>();
         * nscr.cd = nuper_data;
         *
         * GameData.MapCharacterToObject(nuper_data, nuper_go);
         */


        MapLoaderImage mli = tile_holder.AddComponent <MapLoaderImage>();

        mli.floor_sprite = floor_sprite;
        mli.wall_sprite  = wall_sprite;
        mli.mapImage     = mapImage;
    }
Exemplo n.º 30
0
    //will currently stop if it meets another river
    void placeRiver(TileDisplay hill)
    {
        River              newRiver;
        TileDisplay        next          = hill;
        TileDisplay        currentLowest = null;
        List <TileDisplay> inRoute       = new List <TileDisplay>();

        TileDisplay[] toCheck;
        int           loops = 0;
        bool          done  = false;

        //this check is being done to reduce the number of rivers
        toCheck = next.GetNeightbours();
        for (int i = 0; i < 5; i++)
        {
            if (toCheck[i] != null)
            {
                if (toCheck[i].name == "Water")
                {
                    done = true;
                }
            }
        }

        while (!done)
        {
            loops += 1;
            if (loops > 999)
            {
                Debug.Log("Infinite looped");
                break;
            }
            if (next.getNextLowestNeighbour(inRoute) != null)
            {
                currentLowest = next.getNextLowestNeighbour(inRoute);
                if (currentLowest.name == "Water")
                {
                    done = true;
                }
                if (currentLowest.GetNumNeighbours() < 5)
                {
                    done = true;
                }
            }
            else //if stuck, backtrack
            {
                currentLowest = inRoute[inRoute.Count - 1];
            }
            if (currentLowest != null)
            {
                inRoute.Add(currentLowest);
                next = currentLowest;
            }
        }
        if (inRoute.Count != 0)
        {
            newRiver = new River(inRoute);
            //Debug.Log("River Finished");
            rivers.Add(newRiver);
        }
    }
Exemplo n.º 31
0
 public TileReference(byte tileSet, short tile, TileDisplay display = TileDisplay.Visible)
 {
     Display = display;
     TileSet = tileSet;
     Tile    = tile;
 }