bool CheckVictory() { // Did the player win? // Go through every tree one at a time and make sure all it's leaves match int treeCheck = 0; Tree workingTree; while ((workingTree = LeafManager.GetTree(treeCheck)) != null) { LeafColor color = LeafColor.None; for (int x = 0; x < workingTree.GetLeafCount(); x++) { // Check each leaf, if it doesn't match then we didn't win if (color == LeafColor.None) { // There wasn't a color already, so just save the first one seen color = workingTree.GetLeafByIndex(x).Color; continue; } // If it doesn't match, then we lost if (workingTree.GetLeafByIndex(x).Color != color) { return(false); } } treeCheck++; } return(true); }
public static Color GetRandomColor(this LeafColor leafColor) { // Set starting color values var v = new Vector3(155, 155, 155); // The chosen color should be given more focus, so up it's color value switch (leafColor) { case LeafColor.Red: v.x += 100; break; case LeafColor.Green: v.y += 100; break; case LeafColor.Blue: v.z += 100; break; } // Modify each color randomly within the given threshold return(new Color( RNG.Next((int)v.x - 50, (int)v.x) / 255f, RNG.Next((int)v.y - 50, (int)v.y) / 255f, RNG.Next((int)v.z - 50, (int)v.z) / 255f));; }
public static Color GetLeafColor(this LeafColor leafColor) { switch (leafColor) { case LeafColor.Red: return(new Color(1, 0, 0)); case LeafColor.Green: return(new Color(0, 1, 0)); case LeafColor.Blue: return(new Color(0, 0, 1)); default: return(new Color(0, 0, 0)); } }
// Find the first empty leaf, starting from an index, and color it the given color public void ColorFirstAvailableLeaf(LeafColor color, int starting) { if (starting >= Leaves.Count) { starting = 0; } if (Leaves[starting].Color == LeafColor.None) { if (Leaves[starting].Color != color) { Leaves[starting].SetColor(color); return; } } ColorFirstAvailableLeaf(color, starting + 1); }
// Color the leaf the specified color public void SetColor(LeafColor color) { Color = color; Sprite.Modulate = color.GetRandomColor(); }