Skip to content

Instantly share code, notes, and snippets.

@dmitryzenevich
Created December 4, 2020 13:58
Show Gist options
  • Save dmitryzenevich/c08a16526ce3698f0389874b0a21db1e to your computer and use it in GitHub Desktop.
Save dmitryzenevich/c08a16526ce3698f0389874b0a21db1e to your computer and use it in GitHub Desktop.
unitytips: Tuple Patterns
using UnityEngine;
public enum Shape
{
Rock,
Paper,
Scissors
}
public class TuplePatterns : MonoBehaviour
{
public Shape First;
public Shape Second;
public static string GetWinnerMessage(Shape first, Shape second)
=> (first, second) switch
{
(Shape.Rock, Shape.Paper) => "rock is covered by paper. Paper wins.",
(Shape.Rock, Shape.Scissors) => "rock breaks scissors. Rock wins.",
(Shape.Paper, Shape.Rock) => "paper covers rock. Paper wins.",
(Shape.Paper, Shape.Scissors) => "paper is cut by scissors. Scissors wins.",
(Shape.Scissors, Shape.Rock) => "scissors is broken by rock. Rock wins.",
(Shape.Scissors, Shape.Paper) => "scissors cuts paper. Scissors wins.",
(_, _) => "tie"
};
void OnValidate() => Debug.Log(GetWinnerMessage(First, Second));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment