public void ClearSelected() { var num_btn = GameObject.Find("NumbersButton").GetComponent <Image>(); num_btn.color = Color.white; foreach (var name in button_names.Values) { var btn = GameObject.Find(name).GetComponent <Image>(); btn.color = Color.white; } selected_tile_type = Enums.TileType.none; // set player interaction mode PlayerInteract player_interact = null; foreach (var obj in GameObject.FindGameObjectsWithTag("Player")) { if (obj.GetComponent <NetworkIdentity>().isLocalPlayer) { player_interact = obj.GetComponent <PlayerInteract>(); break; } } if (player_interact != null) { player_interact.player_interaction_mode = Enums.PlayerInteractionMode.normal; } }
void OnClickTileButton(Enums.TileType tile_type) { this.ClearSelected(); var button_name = button_names[tile_type]; var button = GameObject.Find(button_name).GetComponent <Image>(); button.color = button_highlight_color; selected_tile_type = tile_type; // set player interaction mode PlayerInteract player_interact = null; foreach (var obj in GameObject.FindGameObjectsWithTag("Player")) { if (obj.GetComponent <NetworkIdentity>().isLocalPlayer) { player_interact = obj.GetComponent <PlayerInteract>(); break; } } if (player_interact != null) { player_interact.player_interaction_mode = Enums.PlayerInteractionMode.create_tile; } }
public TileData(Enums.TileType type, int data1, int data2, int data3, string String1, string String2, string String3) { Type = type; Data1 = data1; Data2 = data2; Data3 = data3; this.String1 = String1; this.String2 = String2; this.String3 = String3; }
public TileData(Enums.TileType type, int data1, int data2, int data3, string String1, string String2, string String3) { Type = type; Data1 = data1; Data2 = data2; Data3 = data3; this.String1 = String1; this.String2 = String2; this.String3 = String3; }
public void SetAttribute(int x, int y, Enums.TileType tileType, int data1, int data2, int data3, string string1, string string2, string string3) { Tile[x, y].Data1 = data1; Tile[x, y].Data2 = data2; Tile[x, y].Data3 = data3; Tile[x, y].Type = tileType; Tile[x, y].String1 = string1; Tile[x, y].String2 = string2; Tile[x, y].String3 = string3; }
} // end LoadFromTilemap private void BuildTile(int posX, int posY, GameObject tilePrefab, Enums.TileType type, string rawName) { // find parent container GameObject MT = GameObject.Find("Map Tiles"); // create an instance and add tileType to matrix TileType tile = new TileType(type); // GlobalVariables.tilesMatrix[posX,posY] = (int)type; GlobalVariables.tilesMatrix[posX, posY] = (tile); // spawn prefab, set its name, and add it to parent container GameObject tilePrefabGO = Instantiate(tilePrefab, new Vector3(posX, posY, 0), Quaternion.identity); tilePrefabGO.name = posX + "_" + posY + "_" + rawName + "_tile"; tilePrefabGO.transform.parent = MT.transform; tilePrefabGO.GetComponent <GameTile>().SetTileType(type); }
void CmdCreateTile(Vector3 position, Enums.TileType tileType) { Quaternion rotation = Quaternion.identity * Quaternion.Euler(90, 0, 0); GameObject prefab; if (tileType == Enums.TileType.metal) { prefab = mountainsTilePrefab; } else if (tileType == Enums.TileType.brick) { prefab = brickTilePrefab; } else if (tileType == Enums.TileType.sheep) { prefab = sheepTilePrefab; } else if (tileType == Enums.TileType.wheat) { prefab = wheatTilePrefab; } else if (tileType == Enums.TileType.wood) { prefab = woodTilePrefab; } else if (tileType == Enums.TileType.sea) { prefab = seaTilePrefab; } else { return; } var tile = (GameObject)Instantiate( prefab, position - transform.forward, rotation ); tile.layer = 8; NetworkServer.Spawn(tile); }
public void SetTileType(Enums.TileType tt) { tileType = tt; }
public void Load(int rdungeonNum, int floorNum) { using (XmlReader reader = XmlReader.Create(Paths.DataPath + "RDungeon\\" + rdungeonNum.ToString() + "\\" + floorNum + ".xml")) { while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "Algorithm": { Algorithm = reader.ReadString().ToInt(); LoadAlgorithmSettings(); break; } case "FloorSettings": { XmlReader settingsReader = reader.ReadSubtree(); while (settingsReader.Read()) { if (settingsReader.IsStartElement() && FloorSettings.ContainsKey(settingsReader.Name)) { FloorSettings[settingsReader.Name] = settingsReader.ReadString().ToInt(); } } break; } case "TileLayers": { XmlReader settingsReader = reader.ReadSubtree(); while (settingsReader.Read()) { if (settingsReader.IsStartElement() && FloorSettings.ContainsKey(settingsReader.Name)) { string settingName = settingsReader.Name; if (settingsReader.Read()) { List <Maps.TileAnim> layerList = new List <Maps.TileAnim>(); while (settingsReader.Read()) { int tileNumX = settingsReader.ReadElementString("TextureX").ToInt(); int tileNumY = settingsReader.ReadElementString("TextureY").ToInt(); int tileSheet = settingsReader.ReadElementString("Sheet").ToInt(); layerList.Add(new Maps.TileAnim(new Maps.Loc2D(tileNumX, tileNumY), tileSheet)); } TileLayers[settingName] = layerList; } } } break; } case "TileData": { XmlReader settingsReader = reader.ReadSubtree(); while (settingsReader.Read()) { if (settingsReader.IsStartElement() && FloorSettings.ContainsKey(settingsReader.Name)) { string settingName = settingsReader.Name; if (settingsReader.Read()) { List <Maps.TileData> tileDataList = new List <Maps.TileData>(); while (settingsReader.Read()) { Enums.TileType type = settingsReader.ReadString().ToEnum <Enums.TileType>(); int data1 = settingsReader.ReadElementString("Data1").ToInt(); int data2 = settingsReader.ReadElementString("Data2").ToInt(); int data3 = settingsReader.ReadElementString("Data3").ToInt(); string tileString = settingsReader.ReadElementString("String"); tileDataList.Add(new Maps.TileData(type, data1, data2, data3, tileString, "", "")); } TileData[settingName] = tileDataList; } } } break; } case "Weather": { FloorWeather.Add(reader.ReadString().ToEnum <Enums.Weather>(), reader.ReadString().ToInt()); break; } case "Darkness": { Darkness = reader.ReadString().ToInt(); break; } case "Music": { Music = reader.ReadString(); break; } case "NpcSpawnTime": { NpcSpawnTime = reader.ReadString().ToInt(); break; } case "NpcMin": { NpcMin = reader.ReadString().ToInt(); break; } case "NpcMax": { NpcMax = reader.ReadString().ToInt(); break; } case "Items": { XmlReader settingsReader = reader.ReadSubtree(); while (settingsReader.Read()) { if (settingsReader.IsStartElement()) { string settingName = settingsReader.Name; settingsReader.Read(); if (settingsReader.Read()) { List <Tuple <ItemPreset, int> > itemList = new List <Tuple <ItemPreset, int> >(); while (settingsReader.Read()) { if (settingsReader.IsStartElement() && settingsReader.Name == "Element") { settingsReader.Read(); ItemPreset preset = new ItemPreset(); preset.ItemNum = settingsReader.ReadElementString("ItemNum").ToInt(); preset.MinAmount = settingsReader.ReadElementString("MinAmount").ToInt(); preset.MaxAmount = settingsReader.ReadElementString("MaxAmount").ToInt(); int appearanceRate = settingsReader.ReadElementString("AppearanceRate").ToInt(); preset.StickyRate = settingsReader.ReadElementString("StickyRate").ToInt(); preset.Tag = settingsReader.ReadElementString("Tag"); preset.Hidden = settingsReader.ReadElementString("Hidden").ToBool(); preset.OnGround = settingsReader.ReadElementString("Ground").ToBool(); preset.OnWater = settingsReader.ReadElementString("Water").ToBool(); preset.OnWall = settingsReader.ReadElementString("Wall").ToBool(); itemList.Add(new Tuple <ItemPreset, int>(preset, appearanceRate)); } } Items[settingName] = itemList; } } } break; } case "Npcs": { XmlReader settingsReader = reader.ReadSubtree(); while (settingsReader.Read()) { if (settingsReader.IsStartElement()) { string settingName = settingsReader.Name; settingsReader.Read(); if (settingsReader.Read()) { List <Tuple <NpcPreset, int> > npcList = new List <Tuple <NpcPreset, int> >(); while (settingsReader.Read()) { if (settingsReader.IsStartElement() && settingsReader.Name == "Element") { settingsReader.Read(); NpcPreset preset = new NpcPreset(); preset.NpcNum = settingsReader.ReadElementString("NpcNum").ToInt(); preset.SpawnX = settingsReader.ReadElementString("SpawnX").ToInt(); preset.SpawnY = settingsReader.ReadElementString("SpawnY").ToInt(); preset.MinLevel = settingsReader.ReadElementString("MinLevel").ToInt(); preset.MaxLevel = settingsReader.ReadElementString("MaxLevel").ToInt(); int appearanceRate = settingsReader.ReadElementString("AppearanceRate").ToInt(); npcList.Add(new Tuple <NpcPreset, int>(preset, appearanceRate)); } } Npcs[settingName] = npcList; } } } break; } case "Rooms": { XmlReader settingsReader = reader.ReadSubtree(); while (settingsReader.Read()) { if (settingsReader.IsStartElement()) { string settingName = settingsReader.Name; settingsReader.Read(); if (settingsReader.Read()) { List <Tuple <int, int> > roomList = new List <Tuple <int, int> >(); while (settingsReader.Read()) { if (settingsReader.IsStartElement() && settingsReader.Name == "Element") { settingsReader.Read(); int num = settingsReader.ReadElementString("RoomNum").ToInt(); int appearanceRate = settingsReader.ReadElementString("AppearanceRate").ToInt(); roomList.Add(new Tuple <int, int>(num, appearanceRate)); } } Rooms[settingName] = roomList; } } } break; } } } } } }
/// <summary> /// This function finds all the vertical matches in a column /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns>Returns a list with all tiles matched vertically in a column</returns> private List <Tile> FindVerticalMatches(int x, int y) { //Get the starting tile from which to start matching int startTileCode = m_logicalBoard[x, y]; int matchCount = 1; //Temp list to store all matches found vertically List <Tile> verticalMatches = new List <Tile>(); //Add the starting tile verticalMatches.Add(m_tilesOnBoard[x, y]); //This search alogrithm will find matches by searching 2 neighbouring tiles above the starting tile // and 2 neighbouring tiles below the starting tile making a total of 5 max tiles that can be matched //We continue search if we have matching tile codes in up as well as down direction //We end search if next neighbouring tile has different tile code or we have reached the array boundary // UP (Start searching for 2 mathcing neighbours above starting tile) //TODO: Change the number 2 to a variable so we can set how many max matches we can find // 2 represents 2 above and 2 below so total 5 matches including the start tile for (int i = 1; i < height + width; i++) { //Check if we have 2 neighbours above if (!CheckBounds(x, y + i)) { //If not break and continue searching for 2 neighbours below the starting tile break; } //Get the next tile code int nextTileCode = m_logicalBoard[x, y + i]; //Get next TileType Enums.TileType nextTileType = m_tilesOnBoard[x, y + i].tileData.tileType; //If its a block type do not match if (nextTileType == Enums.TileType.Block) { break; } //If the tile above has same tile code // then a match is found if (startTileCode == nextTileCode) { //Increment match counter to keep track of how many matches matchCount += 1; //Add the tile to the matches list if (!verticalMatches.Contains(m_tilesOnBoard[x, y + i])) { verticalMatches.Add(m_tilesOnBoard[x, y + i]); } //EXTEND: We can add special bonuses for more matches //If we have match of 4 then place a bomb if (matchCount > 3) { //Utils.DebugUtils.Log("Matched Vertically " + matchCount); if (!m_bombPosition.Contains(m_tilesOnBoard[x, y]) && !m_matchedTiles.Contains(m_tilesOnBoard[x, y])) { m_bombPosition.Add(m_tilesOnBoard[x, y]); } } } //If the tile above has different tile code then end the up search else { break; } } // Down search for (int i = 1; i < height + width; i++) { if (!CheckBounds(x, y - i)) { break; } int nextTileCode = m_logicalBoard[x, y - i]; //Get next TileType Enums.TileType nextTileType = m_tilesOnBoard[x, y - i].tileData.tileType; //If its a block type do not match if (nextTileType == Enums.TileType.Block) { break; } if (startTileCode == nextTileCode) { matchCount += 1; if (!verticalMatches.Contains(m_tilesOnBoard[x, y - i])) { verticalMatches.Add(m_tilesOnBoard[x, y - i]); } //If we have a match of 4 vertically then place a bomb if (matchCount > 3) { //Utils.DebugUtils.Log("Matched vertically " + matchCount); if (!m_bombPosition.Contains(m_tilesOnBoard[x, y]) && !m_matchedTiles.Contains(m_tilesOnBoard[x, y])) { m_bombPosition.Add(m_tilesOnBoard[x, y]); } } } else { break; } } //If we have minimum of 3 matches then return those matches if (matchCount >= 3) { return(verticalMatches); } return(null); }
/// <summary> /// This function finds all the horizontal matches in a row /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns>Returns a list with all matches found horizontally in a row</returns> private List <Tile> FindHorizontalMatches(int x, int y) { int startTileCode = m_logicalBoard[x, y]; int matchCount = 1; List <Tile> horizontalMatches = new List <Tile>(); horizontalMatches.Add(m_tilesOnBoard[x, y]); // Right for (int i = 1; i < height + width; i++) { if (!CheckBounds(x + i, y)) { break; } int nextTileCode = m_logicalBoard[x + i, y]; //Get next TileType Enums.TileType nextTileType = m_tilesOnBoard[x + i, y].tileData.tileType; //If its a block type do not match if (nextTileType == Enums.TileType.Block) { break; } if (startTileCode == nextTileCode) { matchCount += 1; if (!horizontalMatches.Contains(m_tilesOnBoard[x + i, y])) { horizontalMatches.Add(m_tilesOnBoard[x + i, y]); } //If we have match of 4 then place a bomb if (matchCount > 3) { // Utils.DebugUtils.Log("Matched Horizontally " + matchCount); if (!m_bombPosition.Contains(m_tilesOnBoard[x, y]) && !m_matchedTiles.Contains(m_tilesOnBoard[x, y])) { m_bombPosition.Add(m_tilesOnBoard[x, y]); } } } else { break; } } // Left for (int i = 1; i < height + width; i++) { if (!CheckBounds(x - i, y)) { break; } int nextTileCode = m_logicalBoard[x - i, y]; //Get next TileType Enums.TileType nextTileType = m_tilesOnBoard[x - i, y].tileData.tileType; //If its a block type do not match if (nextTileType == Enums.TileType.Block) { break; } if (startTileCode == nextTileCode) { matchCount += 1; if (!horizontalMatches.Contains(m_tilesOnBoard[x - i, y])) { horizontalMatches.Add(m_tilesOnBoard[x - i, y]); } //If we have a match of 4 // Place bomb //TODO: match of 5 for a special bomb if (matchCount > 3) { if (!m_bombPosition.Contains(m_tilesOnBoard[x, y]) && !m_matchedTiles.Contains(m_tilesOnBoard[x, y])) { m_bombPosition.Add(m_tilesOnBoard[x, y]); } } } else { break; } } if (matchCount >= 3) { return(horizontalMatches); } return(null); }
public TileType(Enums.TileType type) { tileType = type; switch (type) { case Enums.TileType.Castle: name = "Castle"; movementCost = 1; staminaCost = 1; defenseMod = 30; break; case Enums.TileType.Bridge: name = "Bridge"; movementCost = 1; staminaCost = 1; defenseMod = 0; break; case Enums.TileType.Grass: name = "Grass"; movementCost = 1; staminaCost = 2; defenseMod = 0; break; case Enums.TileType.GrassRough: name = "Rough Grass"; movementCost = 2; staminaCost = 3; defenseMod = 0; break; case Enums.TileType.WaterShallow: name = "Shallow Water"; movementCost = 3; staminaCost = 10; defenseMod = -2; break; case Enums.TileType.WaterDeep: name = "Deep Water"; movementCost = 4; staminaCost = 15; defenseMod = -5; break; case Enums.TileType.Woods: name = "Woods"; movementCost = 2; staminaCost = 4; defenseMod = 5; break; case Enums.TileType.WoodsDense: name = "Dense Woods"; movementCost = 3; staminaCost = 5; defenseMod = 10; break; } }
public Tile(Enums.TileType type, int data1, int data2, int data3, string tileString1, string tileString2, string tileString3) { Data = new TileData(type, data1, data2, data3, tileString1, tileString2, tileString3); }
public Tile(Enums.TileType type, int data1, int data2, int data3) { Data = new TileData(type, data1, data2, data3, "", "", ""); }