private List <Index2D> PolluteAround(int row, int col)
        {
            var     list = new List <Index2D>();
            MapNode node = opsBoard.map[row, col];

            foreach (Index2D neighbor in node.Neighbors(opsBoard.Rows, opsBoard.Columns, PollutionNeighborDegree))
            {
                TileType?newTile = null;

                switch (opsBoard.map[neighbor.row, neighbor.col].TileValue)
                {
                case TileType.Water:
                    newTile = TileType.PollutedWater;
                    break;

                case TileType.Trees:
                case TileType.Dirt:
                    newTile = TileType.Depleted;
                    break;

                default:
                    break;
                }

                if (newTile != null && UnityEngine.Random.value < pollutionChance)
                {
                    opsBoard.map[neighbor.row, neighbor.col].TileValue = newTile.Value;
                    list.Add(neighbor);
                }
            }

            return(list);
        }
 public override void ProcessEvent(TentativeFarmGridOffEvent e)
 {
     // this order of enabling is important
     this.farm.Enabled         = true;
     this.Enabled              = false;
     this.currSelectedTileType = null;
 }
Example #3
0
        public void PlayAudio(PlayerMode playerMode, BuildOption?buildOption, TileType?tileType = null)
        {
            AudioEvent audioEvent;

            switch (playerMode)
            {
            case PlayerMode.Building:
                if (!buildOption.HasValue)
                {
                    throw new System.ArgumentNullException("buildOption");
                }

                switch (buildOption)
                {
                case BuildOption.City:
                case BuildOption.PowerPlant:
                    audioEvent = AudioEvent.Construction;
                    break;

                default:
                    audioEvent = AudioEvent.PlantingTrees;
                    break;
                }
                break;

            case PlayerMode.Mining:
                if (!tileType.HasValue)
                {
                    throw new System.ArgumentNullException("tileType");
                }

                switch (tileType)
                {
                case TileType.Trees:
                    audioEvent = AudioEvent.MiningTrees;
                    break;

                case TileType.Mountain:
                    audioEvent = AudioEvent.MiningMountain;
                    break;

                case TileType.City:
                case TileType.PowerPlant:
                    audioEvent = AudioEvent.Construction;
                    break;

                default:
                    throw new System.ArgumentException("Unexpected tile type");
                }
                break;

            default:
                audioEvent = AudioEvent.ButtonClick;                         // acknowledge click regardless
                break;
            }

            PlayAudio(audioEvent);
        }
Example #4
0
    public ProcessMatchedSystem(Contexts contexts) : base(contexts.input)
    {
        _contexts = contexts;

        sameTypeEntities  = new List <GameEntity>();
        entitiesToDestroy = new List <GameEntity>();

        previousType = null;
    }
 /// <summary>
 /// Returns the TileBase that has that TILE_TYPE from the TilesArray array
 /// </summary>
 /// <param name="tileType">The TILE_TYPE of the TileBase we want to find</param>
 /// <returns></returns>
 public static TileBase GetTileByType(TileType?tileType)
 {
     foreach (var tile in TilesArray)
     {
         if (tile.TileType == tileType)
         {
             return(tile.Tilebase);
         }
     }
     return(null);
 }
Example #6
0
    //If tile isnt find in any grid, returns EMPTY
    public TileType?GetTileTypeInGrid(Vector3 tileCenter)
    {
        TileType?type = null;

        foreach (GridEntity grid in this.gridsList.Values)
        {
            if (grid.IsTileInGrid(tileCenter))
            {
                type = grid.GetTileTypeAtPosition(tileCenter);
            }
        }

        return(type);
    }
Example #7
0
    public TileType?GetTileTypeAtPosition(Vector3 tileCenter)
    {
        TileType?type = null;

        //Check all tiles to see if tileCenter is found
        foreach (Tile tile in this.tiles.Values)
        {
            if (tile.CenterPosition == tileCenter)
            {
                type = tile.Type;
                break;
            }
        }

        return(type);
    }
    private void TileHasChanged(GameObject obj)
    {
        //-----------------TODO--------------------------
        //Play sounds

        //Move obj selected
        this.shopManager.MoveSelectedObj(this.tileSelected);

        //Check if obj is placeable on tile type
        bool objIsPlaceableOnTileType = false;
        bool isTileTaken = false;

        if (this.shopManager.towerPiece != null)
        {
            TileType?tileType = this.gridManager.GetTileTypeInGrid(this.tileSelected);
            if (tileType != null)
            {
                objIsPlaceableOnTileType = IsObjectPlaceableOnTileType((TileType)tileType, this.shopManager.towerPiece.currentType);
            }
        }
        else if (this.shopManager.trapPiece != null)
        {
            TileType?tileType = this.gridManager.GetTileTypeInGrid(this.tileSelected);
            if (tileType != null)
            {
                objIsPlaceableOnTileType = IsObjectPlaceableOnTileType((TileType)tileType, this.shopManager.trapPiece.currentType);
            }
        }

        //Check if tile is already taken
        if (objIsPlaceableOnTileType)
        {
            isTileTaken = !IsObjectPlaceableThere();
        }

        //If tile isnt available -> change tower color + tile sides to red
        if (isTileTaken || !objIsPlaceableOnTileType)
        {
            //-----------------TODO--------------------------
            //Make obj red
            //-----------------TODO--------------------------
            //Change color to unavailable
            Debug.Log("Cant place the obj there...");
        }
        SetTileSidesColor(isTileTaken);
    }
Example #9
0
    void Action(int x, int y)
    {
        GameEntity entity;

        entity = _contexts.game.GetTileWithPosition(new IntVector2D(x, y));
        if (entity != null)
        {
            if (previousType != entity.gameTileType.value)
            {
                AddEntitiesToDestroy();
                sameTypeEntities.Add(entity);
                previousType = entity.gameTileType.value;
            }
            else
            {
                sameTypeEntities.Add(entity);
            }
        }
    }
Example #10
0
    protected override void Execute(List <InputEntity> entities)
    {
        _somethingDestroyed = false;

        entitiesToDestroy.Clear();
        var globalSettings = _contexts.gameState.globalSettings.value;

        for (int column = globalSettings.startPositionX; column < globalSettings.endPositionX; column++)
        {
            for (int row = globalSettings.startPositionY; row < globalSettings.endPositionY; row++)
            {
                Action(column, row);
            }
            previousType = null;
        }

        for (int row = globalSettings.startPositionY; row < globalSettings.endPositionY; row++)
        {
            for (int column = globalSettings.startPositionX; column < globalSettings.endPositionX; column++)
            {
                Action(column, row);
            }
            previousType = null;
        }

        AddEntitiesToDestroy();

        foreach (var entityToDestroy in entitiesToDestroy)
        {
            _somethingDestroyed         = true;
            entityToDestroy.isDestroyed = true;
        }
        entitiesToDestroy.Clear();

        if (_somethingDestroyed)
        {
            var nextStepEntity = _contexts.input.CreateEntity();
            nextStepEntity.isNextStepEvent = true;
        }
    }
Example #11
0
        private static TileGroup getGroup(TileType?type)
        {
            switch (type)
            {
            case TileType.PlatformCorner:
            case TileType.PlatformMiddle:
            case TileType.PlatformMiddleRotated:
            case TileType.Miniblock:
                return(TileGroup.Solid);

            case TileType.SmallSpikeBottom:
            case TileType.SmallSpikeLeft:
            case TileType.SmallSpikeRight:
            case TileType.SmallSpikeTop:
            case TileType.SpikeBottom:
            case TileType.SpikeLeft:
            case TileType.SpikeRight:
            case TileType.SpikeTop:
                return(TileGroup.Spike);
            }

            return(TileGroup.Ungrouped);
        }
Example #12
0
 public List <Coordinate> GetCoordinatesNear(Coordinate coord, int maxDistance, TileType?filter = null)
 {
     return(GetCoordinatesNear(coord.x, coord.z, maxDistance, filter));
 }
		public Tile(Tile t,int r,int c){
			ttype = t.ttype;
			name = t.name;
			a_name = t.a_name;
			the_name = t.the_name;
			symbol = t.symbol;
			color = t.color;
			passable = t.passable;
			opaque = t.opaque;
			seen = false;
			solid_rock = false;
			light_value = 0;
			toggles_into = t.toggles_into;
			inv = null;
			row = r;
			col = c;
			light_radius = t.light_radius;
		}
Example #14
0
 public PutAttributeEntry(string name, string value, TileType?type)
 {
     _name  = name;
     _value = value;
     _type  = type;
 }
Example #15
0
 public void TransformTo(TileType type_)
 {
     name=Prototype(type_).name;
     a_name=Prototype(type_).a_name;
     the_name=Prototype(type_).the_name;
     symbol=Prototype(type_).symbol;
     color=Prototype(type_).color;
     type=Prototype(type_).type;
     passable=Prototype(type_).passable;
     opaque=Prototype(type_).opaque;
     toggles_into=Prototype(type_).toggles_into;
     if(opaque){
         light_value = 0;
     }
     if(light_radius != Prototype(type_).light_radius){
         UpdateRadius(light_radius,Prototype(type_).light_radius);
     }
     light_radius = Prototype(type_).light_radius;
     if(name == "floor"){ //this could be handled better, by tracking which types are never 'revealed'
         revealed_by_light = false;
     }
     else{
         if(Prototype(type_).revealed_by_light){
             revealed_by_light = true;
         }
     }
     sprite_offset = Prototype(type_).sprite_offset;
 }
Example #16
0
 public Tile(TileType type_,string name_,char symbol_,Color color_,bool passable_,bool opaque_,TileType? toggles_into_)
 {
     type = type_;
     name = name_;
     the_name = "the " + name;
     switch(name[0]){
     case 'a':
     case 'e':
     case 'i':
     case 'o':
     case 'u':
     case 'A':
     case 'E':
     case 'I':
     case 'O':
     case 'U':
         a_name = "an " + name;
         break;
     default:
         a_name = "a " + name;
         break;
     }
     symbol = symbol_;
     color = color_;
     passable = passable_;
     opaque = opaque_;
     seen = false;
     solid_rock = false;
     revealed_by_light = false;
     if(Is(TileType.STAIRS,TileType.CHEST,TileType.FIREPIT,TileType.POOL_OF_RESTORATION)){
         revealed_by_light = true;
     }
     light_value = 0;
     toggles_into = toggles_into_;
     inv = null;
     light_radius = 0;
     direction_exited = 0;
     if(type >= TileType.COMBAT_SHRINE && type <= TileType.STEALTH_SHRINE){
         int diff = type - TileType.COMBAT_SHRINE;
         sprite_offset = new pos(11,diff);
     }
     else{
         if(type >= TileType.FIRE_TRAP && type <= TileType.STONE_RAIN_TRAP){
             int diff = type - TileType.FIRE_TRAP;
             sprite_offset = new pos(14 + diff/16,diff%16);
         }
         else{
             if(passable){
                 sprite_offset = new pos(8,0);
             }
             else{
                 sprite_offset = new pos(0,0);
             }
             switch(type){
             case TileType.BARREL:
                 sprite_offset = new pos(12,14);
                 break;
             case TileType.BLAST_FUNGUS:
                 sprite_offset = new pos(12,5);
                 break;
             case TileType.BREACHED_WALL:
                 sprite_offset = new pos(9,0);
                 break;
             case TileType.BRUSH:
                 sprite_offset = new pos(12,0);
                 break;
             case TileType.CHASM:
                 sprite_offset = new pos(11,14);
                 break;
             case TileType.CHEST:
                 sprite_offset = new pos(10,4);
                 break;
             case TileType.CRACKED_WALL:
                 sprite_offset = new pos(0,1);
                 break;
             case TileType.DEMONIC_IDOL:
                 sprite_offset = new pos(13,1);
                 break;
             case TileType.DOOR_C:
                 sprite_offset = new pos(10,0);
                 break;
             case TileType.DOOR_O:
                 sprite_offset = new pos(10,2);
                 break;
             case TileType.FIRE_GEYSER:
                 sprite_offset = new pos(11,8);
                 break;
             case TileType.FIREPIT:
                 sprite_offset = new pos(10,12);
                 break;
             case TileType.FLOOR:
                 sprite_offset = new pos(8,0);
                 break;
             case TileType.FOG_VENT:
                 sprite_offset = new pos(11,9);
                 break;
             case TileType.GLOWING_FUNGUS:
                 sprite_offset = new pos(12,10);
                 break;
             case TileType.GRAVE_DIRT:
                 sprite_offset = new pos(12,13);
                 break;
             case TileType.GRAVEL:
                 sprite_offset = new pos(10,15);
                 break;
             case TileType.ICE:
                 sprite_offset = new pos(11,11);
                 break;
             case TileType.JUNGLE:
                 sprite_offset = new pos(0,0); //unused
                 break;
             case TileType.POISON_BULB:
                 sprite_offset = new pos(13,0);
                 break;
             case TileType.POISON_GAS_VENT:
                 sprite_offset = new pos(11,10);
                 break;
             case TileType.POOL_OF_RESTORATION:
                 sprite_offset = new pos(13,5);
                 break;
             case TileType.POPPY_FIELD:
                 sprite_offset = new pos(12,4);
                 break;
             case TileType.RUBBLE:
                 sprite_offset = new pos(10,14);
                 break;
             case TileType.STAIRS:
                 sprite_offset = new pos(13,6);
                 break;
             case TileType.STALAGMITE:
                 sprite_offset = new pos(10,13);
                 break;
             case TileType.STANDING_TORCH:
                 sprite_offset = new pos(12,15);
                 break;
             case TileType.STATUE:
                 sprite_offset = new pos(10,8);
                 break;
             case TileType.STONE_SLAB:
                 sprite_offset = new pos(11,12);
                 break;
             case TileType.TOMBSTONE:
                 sprite_offset = new pos(12,12);
                 break;
             case TileType.VINE:
                 sprite_offset = new pos(0,8);
                 break;
             case TileType.WALL:
             case TileType.HIDDEN_DOOR:
                 sprite_offset = new pos(0,0);
                 break;
             case TileType.WATER:
                 sprite_offset = new pos(0,4);
                 break;
             case TileType.WAX_WALL:
                 sprite_offset = new pos(0,12);
                 break;
             }
         }
     }
 }
Example #17
0
 public Tile(Tile t,int r,int c)
 {
     type = t.type;
     name = t.name;
     a_name = t.a_name;
     the_name = t.the_name;
     symbol = t.symbol;
     color = t.color;
     if(t.type == TileType.BRUSH){
         if(R.CoinFlip()){
             color = Color.Yellow;
         }
         if(R.OneIn(20)){
             color = Color.Green;
         }
     }
     passable = t.passable;
     opaque = t.opaque;
     seen = false;
     revealed_by_light = t.revealed_by_light;
     solid_rock = false;
     light_value = 0;
     toggles_into = t.toggles_into;
     inv = null;
     row = r;
     col = c;
     light_radius = t.light_radius;
     direction_exited = 0;
     sprite_offset = t.sprite_offset;
 }
Example #18
0
 void SetPreview(TileType?type)
 {
     pointPreview = type == null ? 0 : TileTypeData.Get(type.Value).cost;
 }
		public Tile(TileType type_,string name_,char symbol_,Color color_,bool passable_,bool opaque_,TileType? toggles_into_){
			ttype = type_;
			name = name_;
			the_name = "the " + name;
			switch(name[0]){
			case 'a':
			case 'e':
			case 'i':
			case 'o':
			case 'u':
			case 'A':
			case 'E':
			case 'I':
			case 'O':
			case 'U':
				a_name = "an " + name;
				break;
			default:
				a_name = "a " + name;
				break;
			}
			symbol = string.FromCharCode(symbol_);
			color = color_;
			passable = passable_;
			opaque = opaque_;
			seen = false;
			solid_rock = false;
			light_value = 0;
			toggles_into = toggles_into_;
			inv = null;
			light_radius = 0;
		}
		public void TransformTo(TileType type_){
			name=Prototype(type_).name;
			a_name=Prototype(type_).a_name;
			the_name=Prototype(type_).the_name;
			symbol=Prototype(type_).symbol;
			color=Prototype(type_).color;
			ttype=Prototype(type_).ttype;
			passable=Prototype(type_).passable;
			opaque=Prototype(type_).opaque;
			toggles_into=Prototype(type_).toggles_into;
			if(opaque){
				light_value = 0;
			}
			if(light_radius != Prototype(type_).light_radius){
				UpdateRadius(light_radius,Prototype(type_).light_radius);
			}
			light_radius = Prototype(type_).light_radius;
		}
        public static bool IsTenpai(IHandAnalysis hand, IReadOnlyList <Tile> concealedTiles, int meldCount)
        {
            if (hand.Shanten <= 0)
            {
                return(true);
            }

            if (meldCount == 0)
            {
                return(false);
            }

            var usedTileTypeIds = new bool[34];
            var initialTiles    = new Stack <TileType>();

            foreach (var tile in concealedTiles)
            {
                usedTileTypeIds[tile.TileType.TileTypeId] = true;
                initialTiles.Push(tile.TileType);
            }

            TileType?draw = null;

            if (initialTiles.Count % 3 == 2)
            {
                draw = initialTiles.Pop();
            }

            var remainingMelds = meldCount;
            var toPon          = new List <TileType>();

            for (var i = 27; i < 34 && remainingMelds > 0; i++)
            {
                if (usedTileTypeIds[i])
                {
                    continue;
                }

                remainingMelds -= 1;
                var tileType = TileType.FromTileTypeId(i);
                initialTiles.Push(tileType);
                initialTiles.Push(tileType);
                initialTiles.Push(tileType);
                toPon.Add(tileType);
            }

            if (remainingMelds > 0)
            {
                return(false);
            }

            var tempHand = new HandCalculator();

            tempHand.Init(initialTiles);
            foreach (var tileType in toPon)
            {
                tempHand.Pon(tileType);
                tempHand.Discard(tileType);
            }

            if (draw != null)
            {
                tempHand.Draw(draw);
            }

            return(tempHand.Shanten <= 0);
        }
Example #22
0
 public static TileType ParseTextureType(IXmlLineInfo lineInfo, string?t, TileType?defaultValue = null)
 {
     return(t.ParseEnumStrict(lineInfo, defaultValue) ?? throw new XmlParseException("Attribute value missing", lineInfo));
 }
        void ProcessInput()
        {
            // TODO rectangle selecting multiple tiles

            // need to check if mouse click collides with any UI
            if (InputManager.Instance.CanAcceptInput(TentativeFarmGrid.inputPriority))
            {
                this.tileHighlighter.HighlightTileAtMouse = true;
                if (Input.LeftMouseButtonDown)
                {
                    var pos = this.playerCamera.MouseToTilePosition();
                    if (!this.currChanges.Positions.ContainsKey(pos))
                    {
                        var x = (int)pos.X;
                        var y = (int)pos.Y;
                        var originalTileType = this.TileGrid[x, y] != null ? this.TileGrid[x, y].Tile.TileType : FarmDefaultTiler.DefaultTileType;
                        if (this.currSelectedTileType.Value == TileType.Destruct)
                        {
                            if (this.RemoveTile(x, y))
                            {
                                this.AddChange(x, y, originalTileType);
                            }
                        }
                        else if (this.currSelectedTileType.Value == TileType.Upgrade)
                        {
                            if (this.UpgradeTile(x, y))
                            {
                                this.AddChange(x, y, originalTileType);
                            }
                        }
                        else if (this.currSelectedTileType.Value == TileType.Reset)
                        {
                            if (this.ResetTile(x, y))
                            {
                                this.AddChange(x, y, originalTileType);
                            }
                        }
                        // else selected an actual (non utility) tile
                        // add new tile only if no existing tile or new tile is of different type
                        // and tile is placeable
                        // TODO better way to determine if existing tentative tile should be directly replaceable
                        else
                        {
                            var tmpTile = Tile.CreateTile(this.currSelectedTileType.Value, x, y, this);
                            if ((this.farm.GetTile(x, y) == null ||
                                 !Tile.AreSameBaseTileType(Tile.GetFutureTileType(this.farm.GetTile(x, y)), this.currSelectedTileType.Value))
                                &&
                                (this.TileGrid[x, y] == null ||
                                 !Tile.AreSameBaseTileType(this.TileGrid[x, y].Tile.TileType, this.currSelectedTileType.Value))
                                &&
                                tmpTile.IsPlaceable()
                                &&
                                this.playerState.Money >= tmpTile.Cost)
                            {
                                this.AddTile(new WeakTile(this.currSelectedTileType.Value, x, y, this));
                                this.AddChange(x, y, originalTileType);
                            }
                        }
                    }
                }
            }
            else
            {
                this.tileHighlighter.HighlightTileAtMouse = false;
            }

            // add change to log when left click released, wherever it occurs
            if (Input.LeftMouseButtonReleased && !this.currChanges.IsEmpty())
            {
                // remove all nodes after this
                while (this.currChangesNode.Next != null)
                {
                    this.changeLog.Remove(this.currChangesNode.Next);
                }
                this.currChangesNode = this.changeLog.AddLast(this.currChanges);
                this.currChanges     = new MouseDownChanges(this.currSelectedTileType.Value);
            }

            // clear selected tile regardless of where right click occurs
            if (Input.RightMouseButtonPressed)
            {
                this.currSelectedTileType = null;
                this.tileHighlighter.HighlightTileAtMouse = false;
            }
        }
Example #24
0
        public static void RefreshContents(this System.Windows.Forms.ListView listView, Tileset tileSet, TileType?type = null)
        {
            listView.Items.Clear();

            for (int j = 0; j < tileSet.Images.Images.Count; ++j)
            {
                switch (type)
                {
                case null:
                    listView.Items.Add("", j);
                    break;

                case TileType.Animated:
                case TileType.Graphic:
                    if (!(tileSet.Tiles[j] is SpecialTile))
                    {
                        listView.Items.Add("", j);
                    }
                    break;

                case TileType.Special:
                    if (tileSet.Tiles[j] is SpecialTile)
                    {
                        listView.Items.Add("", j);
                    }
                    break;
                }
            }

            listView.LargeImageList = tileSet.Images;

            if (listView.Items.Count > 0)
            {
                listView.SelectedIndices.Clear();
                listView.SelectedIndices.Add(0);
            }
        }
 public override void ProcessEvent(TileSelectionEvent e)
 {
     this.currSelectedTileType = e.TileType;
     this.currChanges          = new MouseDownChanges(this.currSelectedTileType.Value);
 }
Example #26
0
    public List <Coordinate> GetCoordinatesNear(int nearX, int nearZ, int maxDistance, TileType?filter = null)
    {
        int minX = Math.Max(0, nearX - maxDistance);
        int maxX = Math.Min(width - 1, nearX + maxDistance);
        int minZ = Math.Max(0, nearZ - maxDistance);
        int maxZ = Math.Min(height - 1, nearZ + maxDistance);

        List <Coordinate> openCoords = new List <Coordinate>();

        for (int x = minX; x <= maxX; x++)
        {
            for (int z = minZ; z <= maxZ; z++)
            {
                if (filter == null || tiles[x, z] == filter)
                {
                    openCoords.Add(new Coordinate(x, z));
                }
            }
        }

        return(openCoords);
    }
Example #27
0
 public PutAttributeEntry(string name, string value, TileType? type)
 {
     _name = name;
     _value = value;
     _type = type;
 }