|
| 1 | +# Cookbook |
| 2 | + |
| 3 | +This page contains some short samples of how you can interact with the domain. |
| 4 | + |
| 5 | +## `IGameData` |
| 6 | + |
| 7 | +```C# |
| 8 | +// Creating a dummy `IGameData` object |
| 9 | +var facade = new PiCrossFacade(); |
| 10 | +var gameData = facade.CreateDummyGameData(); |
| 11 | + |
| 12 | +// Reading an `IGameData` object from file, fails if file does not exist |
| 13 | +var facade = new PiCrossFacade(); |
| 14 | +var gameData = facade.LoadGameData(path); |
| 15 | + |
| 16 | +// Reading an `IGameData` object from file, creates new file if no file is present at path |
| 17 | +var facade = new PiCrossFacade(); |
| 18 | +var gameData = facade.LoadGameData( path, createIfNotExistent: true ); |
| 19 | +``` |
| 20 | + |
| 21 | +## Puzzle Library |
| 22 | + |
| 23 | +```C# |
| 24 | +// Creating a Puzzle object from constraints for |
| 25 | +// ..... |
| 26 | +// .x... |
| 27 | +// .xx.. |
| 28 | +// x.xx. |
| 29 | +// ..xxx |
| 30 | +var puzzle = Puzzle.FromConstraints(columnConstraints: "1;2;3;2;1", |
| 31 | + rowConstraints: ";1;2;1 2;3"); |
| 32 | + |
| 33 | +// Creating a Puzzle object from solution |
| 34 | +var puzzle = Puzzle.FromRowStrings( |
| 35 | + ".....", |
| 36 | + ".x...", |
| 37 | + ".xx..", |
| 38 | + "x.xx.", |
| 39 | + "..xxx" |
| 40 | + ); |
| 41 | + |
| 42 | +// Getting a list of puzzle entries in the puzzle library |
| 43 | +var puzzleEntries = gameData.PuzzleLibrary.Entries; |
| 44 | + |
| 45 | +// Adding a new puzzle to the Puzzle Library |
| 46 | +var puzzleEntry = gameData.PuzzleLibrary.Create(puzzle, author); |
| 47 | +``` |
| 48 | + |
| 49 | +## Playing |
| 50 | + |
| 51 | +```C# |
| 52 | +// Creating an IPlayablePuzzle |
| 53 | +var facade = new PiCrossFacade(); |
| 54 | +var puzzle = GetHoldOfAPuzzleSomehow(); |
| 55 | +var playablePuzzle = facade.CreatePlayablePuzzle(puzzle); |
| 56 | + |
| 57 | +// Marking the upper left square as filled |
| 58 | +var position = new Vector(0, 0); |
| 59 | +var square = playablePuzzle.Grid[position]; |
| 60 | +square.Contents.Value = Square.FILLED; // square.Contents is a Cell and therefore observable |
| 61 | +
|
| 62 | +// Checking if puzzle is solved (observable) |
| 63 | +if ( playablePuzzle.IsSolved.Value ) { ... } |
| 64 | + |
| 65 | +// Checking if there are cells marked unknown left (observable) |
| 66 | +if ( playablePuzzle.ContainsUnknowns.Value ) { ... } |
| 67 | + |
| 68 | +// Number of cells marked unknown left (observable) |
| 69 | +var count = playablePuzzle.UnknownCount.Value; |
| 70 | + |
| 71 | +// Checking if upper row constraints are satisfied (observable) |
| 72 | +if ( playablePuzzle.RowConstraints[0].IsSatisfied.Value ) { ... } |
| 73 | + |
| 74 | +// Getting the values in the upper row constraints |
| 75 | +var values = playablePuzzle.RowConstraints[0].Values; |
| 76 | +``` |
| 77 | + |
| 78 | +## Player Database |
| 79 | + |
| 80 | +```C# |
| 81 | +// Get player names |
| 82 | +var facade = new PiCrossFacade(); |
| 83 | +var playerNames = facade.PlayerDatabase.PlayerNames; |
| 84 | + |
| 85 | +// Get player profile |
| 86 | +var playerProfile = facade.PlayerDatabase[playerName]; |
| 87 | + |
| 88 | +// Find out if player has played puzzle before |
| 89 | +var puzzleEntry = facade.PuzzleLibrary.Entries.First(); |
| 90 | +if ( playerProfile[puzzleEntry].BestTime.HasValue ) { ... } |
| 91 | + |
| 92 | +// Get player's best time |
| 93 | +if ( playerProfile[puzzleEntry].BestTime.Value ) { ... } |
| 94 | +``` |
0 commit comments