| | 1 | | namespace Minesweeper; |
| | 2 | |
|
| | 3 | | public record Cell |
| | 4 | | { |
| 263 | 5 | | public record Covered(Cell Inner) : Cell; |
| | 6 | | public record Bomb : Cell; |
| 229 | 7 | | public record Number(int Value) : Cell; |
| | 8 | | public record Empty : Cell; |
| | 9 | |
|
| 28 | 10 | | public Cell ClickTo() => this switch |
| 28 | 11 | | { |
| 0 | 12 | | Empty x => x, |
| 14 | 13 | | Covered x => x.Inner.ClickTo(), |
| 14 | 14 | | var x => x |
| 28 | 15 | | }; |
| | 16 | |
|
| 9 | 17 | | public Cell BombTo() => this switch |
| 9 | 18 | | { |
| 0 | 19 | | Empty x => x, |
| 9 | 20 | | Covered x => x with |
| 9 | 21 | | { |
| 9 | 22 | | Inner = new Bomb() |
| 9 | 23 | | }, |
| 0 | 24 | | _ => new Bomb() |
| 9 | 25 | | }; |
| | 26 | |
|
| 49 | 27 | | public bool IsBomb() => this switch |
| 49 | 28 | | { |
| 7 | 29 | | Bomb => true, |
| 20 | 30 | | Covered x => x.Inner.IsBomb(), |
| 22 | 31 | | _ => false |
| 49 | 32 | | }; |
| | 33 | |
|
| 22 | 34 | | public char ToChar() => this switch |
| 22 | 35 | | { |
| 6 | 36 | | Covered => '.', |
| 3 | 37 | | Bomb => '*', |
| 13 | 38 | | Number x => Convert.ToChar(48 + x.Value), |
| 0 | 39 | | _ => throw new NotImplementedException(), |
| 22 | 40 | | }; |
| | 41 | |
|
| 54 | 42 | | public static Cell New() => new Covered(new Number(0)); |
| | 43 | |
|
| 9 | 44 | | public char ToInnerChar() => this switch |
| 9 | 45 | | { |
| 9 | 46 | | Covered x => x.Inner.ToChar(), |
| 0 | 47 | | var x => x.ToChar() |
| 9 | 48 | | }; |
| | 49 | |
|
| 71 | 50 | | public Cell AddNumberTo() => this switch |
| 71 | 51 | | { |
| 33 | 52 | | Covered x => new Covered(x.Inner.AddNumberTo()), |
| 30 | 53 | | Number x => new Number(x.Value + 1), |
| 8 | 54 | | var x => x |
| 71 | 55 | | }; |
| | 56 | | } |