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.

Revisions

  1. dmitryzenevich created this gist Dec 4, 2020.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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));
    }