//Gets a well-formed randomly built MatchReplaceRule public static MatchReplaceRule GetRandom() { //If match color/shape is specific, replace color/shape (resp) cannot be wild //Match color/shape cannot both be wild //Replace color/shape cannot both be wild //Replace color/shape cannot both be the same as Match color/shape MatchReplaceRule rule = new MatchReplaceRule(); bool wildMatchShape = Random.value < 0.7f; bool wildMatchColor = Random.value < 0.7f; if(wildMatchShape && wildMatchColor) { if(Random.value < 0.5f) { wildMatchShape = false; } else { wildMatchColor = false; } } rule.MatchFeature = new CrateFeature( wildMatchColor ? CrateFeature.ColorWildcard : Random.Range (0, CrateFeature.NumNormalColors), wildMatchShape ? CrateFeature.ShapeWildcard : Random.Range (0, CrateFeature.NumNormalShapes) ); bool wildReplaceShape = wildMatchShape && Random.value < 0.7f; bool wildReplaceColor = wildMatchColor && Random.value < 0.7f; //Enforce both replace cannot be wild: if(wildReplaceShape && wildReplaceColor) { if(Random.value < 0.5f) { wildReplaceShape = false; } else { wildReplaceColor = false; } } do{ rule.ReplaceFeature = new CrateFeature( wildReplaceColor ? CrateFeature.ColorWildcard : Random.Range (0, CrateFeature.NumNormalColors), wildReplaceShape ? CrateFeature.ShapeWildcard : Random.Range (0, CrateFeature.NumNormalShapes) ); } while(rule.MatchFeature == rule.ReplaceFeature); //reroll until not the same return rule; }
public bool SameEffect(MatchReplaceRule other) { return this.MatchFeature == other.MatchFeature && this.ReplaceFeature == other.ReplaceFeature; }
public void Display(MatchReplaceRule rule) { matchRenderer.sprite = rule.MatchFeature.GetSprite(); replaceRenderer.sprite = rule.ReplaceFeature.GetSprite (); }