public override void OnInspectorGUI() { Hexagon hexagon = this.target as Hexagon; sideInfo = new bool[6] { (hexagon.blockState & (int)(HexagonEdget.UpperLeft)) != 0, (hexagon.blockState & (int)(HexagonEdget.UpperRight)) != 0, (hexagon.blockState & (int)(HexagonEdget.UpperDown)) != 0, (hexagon.blockState & (int)(HexagonEdget.DownLeft)) != 0, (hexagon.blockState & (int)(HexagonEdget.DownRight)) != 0, (hexagon.blockState & (int)(HexagonEdget.DownUp)) != 0 }; sideInfo[0] = EditorGUILayout.Toggle("TL Side", sideInfo[0]); sideInfo[1] = EditorGUILayout.Toggle("TR Side", sideInfo[1]); sideInfo[2] = EditorGUILayout.Toggle("MD Side", sideInfo[2]); sideInfo[3] = EditorGUILayout.Toggle("BL Side", sideInfo[3]); sideInfo[4] = EditorGUILayout.Toggle("BR Side", sideInfo[4]); sideInfo[5] = EditorGUILayout.Toggle("MU Side", sideInfo[5]); upperState = hexagon.upperState; upperState = (HexagonState)EditorGUILayout.EnumPopup("Upper State", upperState); lowerState = hexagon.lowerState; lowerState = (HexagonState)EditorGUILayout.EnumPopup("Lower State", lowerState); upperPiece = hexagon.upper != null; lowerPiece = hexagon.lower != null; upperPiece = EditorGUILayout.Toggle("Upper Piece", upperPiece); lowerPiece = EditorGUILayout.Toggle("Lower Piece", lowerPiece); UpdateHexagonState(); UpdateEdgetState(); UpdatePiece(); this.serializedObject.ApplyModifiedProperties(); }
public void SetState(bool isUpper, HexagonState state) { if (isUpper) { upperState = state; } else { lowerState = state; } SetupSpecialItem(); if (upperState == HexagonState.Normal) { if (mazeU != null) { mazeU.ShutDown(); } mazeU = null; if (rockU != null) { rockU.ShutDown(); } rockU = null; if (switchU != null) { switchU.ShutDown(); } switchU = null; /* * if (teleportU != null) teleportU.ShutDown(); * teleportU = null;*/ } if (lowerState == HexagonState.Normal) { if (mazeD != null) { mazeD.ShutDown(); } mazeD = null; if (rockD != null) { rockD.ShutDown(); } rockD = null; if (switchD != null) { switchD.ShutDown(); } switchD = null; /* if (teleportD != null) teleportD.ShutDown(); * teleportD = null;*/ } }
public void ParseFromText(ref Board board, ref string text) { board.ResetBoard(); XDocument document = XDocument.Parse(text); XElement level = document.Element("Level"); step = (int)level.Attribute("Step"); objective = (LevelObjective)((int)level.Attribute("Mode")); XElement hexagons = level.Element("Hexagons"); foreach (XElement hexagon in hexagons.Elements("Hexagon")) { HexagonState upperState = (HexagonState)((int)hexagon.Attribute("UpperState")); HexagonState lowerState = (HexagonState)((int)hexagon.Attribute("LowerState")); int blockState = (int)hexagon.Attribute("BlockState"); int x = (int)hexagon.Attribute("X"); int y = (int)hexagon.Attribute("Y"); board.SetHexagonStateAt(x, y, true, upperState); board.SetHexagonStateAt(x, y, false, lowerState); if (blockState > 0) { board.GetHexagonAt(x, y).SetBlock(blockState); } } XElement pieces = level.Element("Pieces"); foreach (XElement piece in pieces.Elements("Piece")) { bool isUpper = ((int)piece.Attribute("Upper")) == 1; bool core = piece.Attribute("Core") == null ? false : (((int)piece.Attribute("Core")) == 1); PieceState state = (PieceState)((int)piece.Attribute("State")); PieceColor color = (PieceColor)((int)piece.Attribute("Type")); Piece p = board.GeneratePieceAt((int)piece.Attribute("X"), (int)piece.Attribute("Y"), isUpper, color, core); p.SetState(state); } XElement walls = level.Element("Walls"); foreach (XElement wall in walls.Elements("Wall")) { int index = (int)wall.Attribute("Index"); board.SetWallState(index, (WallState)((int)wall.Attribute("State"))); if (wall.Attribute("Level") != null) { board.GetWall(index).SetLevel((int)wall.Attribute("Level")); } } XElement groups = level.Element("Groups"); foreach (XElement group in groups.Elements("Group")) { PieceGroup g = PieceGroup.CreateInstance <PieceGroup>(); foreach (XElement piece in group.Elements("Piece")) { bool isUpper = ((int)piece.Attribute("Upper")) == 1; g.AddChild(board.GetPieceAt((int)piece.Attribute("X"), (int)piece.Attribute("Y"), isUpper)); } g.Sort(); g.MakeChain(); } XElement switchers = level.Element("Switchers"); foreach (XElement switcher in switchers.Elements("Switcher")) { int x = (int)switcher.Attribute("X"); int y = (int)switcher.Attribute("Y"); bool isUpper = (int)switcher.Attribute("Upper") == 1; bool isStatic = (int)switcher.Attribute("Static") == 1; PieceColor color = (PieceColor)((int)switcher.Attribute("Color")); //Debug.Log(color); Hexagon hexagon = board.GetHexagonAt(x, y); if (isUpper) { hexagon.switchU.isStatic = isStatic; hexagon.switchU.color = color; hexagon.switchU.UpdateColor(); } else { hexagon.switchD.isStatic = isStatic; hexagon.switchD.color = color; hexagon.switchD.UpdateColor(); } } XElement clocks = level.Element("Clocks"); foreach (XElement clock in clocks.Elements("Clock")) { int x = (int)clock.Attribute("X"); int y = (int)clock.Attribute("Y"); bool isUpper = (int)clock.Attribute("Upper") == 1; HexagonEdget edget = (HexagonEdget)((int)clock.Attribute("Edget")); Piece piece = board.GetPieceAt(x, y, isUpper); piece.clock.triggerEdget = edget; piece.clock.UpdateTrigger(); } XElement twines = level.Element("Twines"); foreach (XElement twine in twines.Elements("Twine")) { int x = (int)twine.Attribute("X"); int y = (int)twine.Attribute("Y"); bool isUpper = (int)twine.Attribute("Upper") == 1; int state = ((int)twine.Attribute("State")); Piece piece = board.GetPieceAt(x, y, isUpper); piece.twine.SetState(state); } XElement ices = level.Element("Ices"); foreach (XElement ice in ices.Elements("Ice")) { int x = (int)ice.Attribute("X"); int y = (int)ice.Attribute("Y"); bool isUpper = (int)ice.Attribute("Upper") == 1; int life = ((int)ice.Attribute("Life")); Piece piece = board.GetPieceAt(x, y, isUpper); piece.ice.SetLife(life); } guides = new List <LevelGuide>(); XElement steps = level.Element("Steps"); foreach (XElement s in steps.Elements("Step")) { int index = (int)s.Attribute("Index"); BoardDirection direction = (BoardDirection)((int)s.Attribute("Direction")); LevelGuide guide = new LevelGuide(); guide.direction = direction; guide.PieceIndex = index; guides.Add(guide); } }
void OnTreeInfectionAtMax() { switch (HexState) { case HexagonState.Empty: case HexagonState.Sapling: case HexagonState.Tree: case HexagonState.InfectedSapling: case HexagonState.InfectedDeadWood: case HexagonState.InfectedTree: case HexagonState.CutTree: case HexagonState.DeadWood: case HexagonState.InfectingSapling: case HexagonState.InfectingDeadWood: case HexagonState.InfectingTree: case HexagonState.KilledInfectedDeadWood: break; //nothing to do case HexagonState.KillingInfectedTree: case HexagonState.KillingInfectedDeadWood: _HexState = HexagonState.KilledInfectedDeadWood; break; } }
private void updateTree() { if (lastTreeUpdate != HexState) { lastTreeUpdate = HexState; switch (HexState) { case HexagonState.InfectingSapling: case HexagonState.InfectedSapling: case HexagonState.Sapling: ReplaceTree(TreeType.Sapling); break; case HexagonState.Tree: case HexagonState.InfectedTree: case HexagonState.InfectingTree: case HexagonState.KillingInfectedTree: ReplaceTree(Type); break; case HexagonState.CutTree: ReplaceTree(TreeType.CutTree); break; case HexagonState.DeadWood: case HexagonState.InfectedDeadWood: case HexagonState.KilledInfectedDeadWood: case HexagonState.InfectingDeadWood: case HexagonState.KillingInfectedDeadWood: ReplaceTree(TreeType.DeadTree); break; } } }
public void TakeCuttedTreeAway() { switch (HexState) { case HexagonState.Empty: case HexagonState.Sapling: case HexagonState.Tree: case HexagonState.InfectedSapling: case HexagonState.InfectedDeadWood: case HexagonState.KilledInfectedDeadWood: case HexagonState.KillingInfectedTree: case HexagonState.KillingInfectedDeadWood: case HexagonState.InfectedTree: case HexagonState.DeadWood: case HexagonState.InfectingSapling: case HexagonState.InfectingDeadWood: case HexagonState.InfectingTree: Debug.Assert(false, "unexpected state"); break; case HexagonState.CutTree: _HexState = HexagonState.Empty; break; } }
public void PlantTree(TreeType type) { Debug.Assert(!HexagonContainsFungus, "Trees can only be planted when no fungus is on it"); Type = type; switch (type) { case TreeType.Sapling: _HexState = HexagonState.Sapling; break; case TreeType.SmallTree: case TreeType.BigTree: _HexState = HexagonState.Tree; break; case TreeType.DeadTree: _HexState = HexagonState.DeadWood; break; case TreeType.CutTree: _HexState = HexagonState.CutTree; break; } }
public void InfectTree() { switch (HexState) { case HexagonState.CutTree: case HexagonState.Empty: case HexagonState.Sapling: case HexagonState.Tree: case HexagonState.InfectedSapling: case HexagonState.DeadWood: case HexagonState.KillingInfectedTree: case HexagonState.KillingInfectedDeadWood: case HexagonState.InfectingSapling: case HexagonState.InfectingDeadWood: case HexagonState.InfectingTree: case HexagonState.KilledInfectedDeadWood: Debug.Assert(false, "unexpected state: " + HexState); break; case HexagonState.InfectedDeadWood: addTreeInfectingFungi(); TileInfection.reset(); GridManager.instance.UserInteraction.updateView(); _HexState = HexagonState.KillingInfectedDeadWood; break; case HexagonState.InfectedTree: addTreeInfectingFungi(); TileInfection.reset(); GridManager.instance.UserInteraction.updateView(); _HexState = HexagonState.KillingInfectedTree; break; } }
/// <summary> /// Set the next state of the tree /// </summary> public void GrowTree() { switch (Type) { case TreeType.CutTree: Debug.Assert(false, "unexpected state"); break; case TreeType.Sapling: switch (HexState) { case HexagonState.CutTree: case HexagonState.Empty: case HexagonState.KillingInfectedDeadWood: case HexagonState.InfectingDeadWood: case HexagonState.DeadWood: case HexagonState.InfectedDeadWood: case HexagonState.KilledInfectedDeadWood: case HexagonState.Tree: case HexagonState.InfectedTree: case HexagonState.InfectingTree: case HexagonState.KillingInfectedTree: Debug.Assert(false, "unexpected state: " + HexState); break; case HexagonState.InfectingSapling: _HexState = HexagonState.InfectingTree; break; case HexagonState.Sapling: _HexState = HexagonState.Tree; break; case HexagonState.InfectedSapling: _HexState = HexagonState.InfectedTree; break; } ReplaceTree(TreeType.SmallTree); break; case TreeType.SmallTree: ReplaceTree(TreeType.BigTree); break; case TreeType.BigTree: switch (HexState) { case HexagonState.CutTree: case HexagonState.Empty: case HexagonState.Sapling: case HexagonState.InfectedSapling: case HexagonState.KillingInfectedDeadWood: case HexagonState.InfectingDeadWood: case HexagonState.InfectingSapling: case HexagonState.DeadWood: case HexagonState.InfectedDeadWood: case HexagonState.KilledInfectedDeadWood: Debug.Assert(false, "unexpected state: " + HexState); break; case HexagonState.Tree: _HexState = HexagonState.DeadWood; break; case HexagonState.InfectedTree: _HexState = HexagonState.InfectedDeadWood; break; case HexagonState.InfectingTree: _HexState = HexagonState.InfectingDeadWood; break; case HexagonState.KillingInfectedTree: _HexState = HexagonState.KillingInfectedDeadWood; break; } ReplaceTree(TreeType.DeadTree); break; case TreeType.DeadTree: switch (HexState) { case HexagonState.CutTree: case HexagonState.Empty: case HexagonState.Sapling: case HexagonState.Tree: case HexagonState.InfectedSapling: case HexagonState.InfectedTree: case HexagonState.InfectingSapling: case HexagonState.InfectingTree: Debug.Assert(false, "unexpected state: " + HexState); break; case HexagonState.DeadWood: case HexagonState.InfectedDeadWood: case HexagonState.KilledInfectedDeadWood: case HexagonState.KillingInfectedTree: case HexagonState.KillingInfectedDeadWood: case HexagonState.InfectingDeadWood: _HexState = HexagonState.Sapling; break; } break; } }
public void addTileInfectingFungi() { TileInfection = CreateFungi(_tileInfectPrefab); switch (HexState) { case HexagonState.CutTree: case HexagonState.Empty: case HexagonState.KillingInfectedTree: case HexagonState.KillingInfectedDeadWood: case HexagonState.InfectedSapling: case HexagonState.InfectedDeadWood: case HexagonState.KilledInfectedDeadWood: case HexagonState.InfectedTree: case HexagonState.InfectingSapling: case HexagonState.InfectingDeadWood: case HexagonState.InfectingTree: Debug.Assert(false, "unexpected state: " + HexState); break; case HexagonState.Sapling: _HexState = HexagonState.InfectingSapling; break; case HexagonState.Tree: _HexState = HexagonState.InfectingTree; break; case HexagonState.DeadWood: _HexState = HexagonState.InfectingDeadWood; break; } }