Class NonogramAPI
- Namespace
- NonoSharp
- Assembly
- NonoSharp.dll
Class for the Nonogram API. Can be initialised with static methods such as CreateRandomPuzzle(int, int, NonogramOptions?) or LoadPuzzle(string, NonogramOptions?).
public class NonogramAPI
- Inheritance
-
NonogramAPI
- Inherited Members
Properties
CanRedo
A boolean indicating whether a redo via Redo() is possible.
public bool CanRedo { get; }
Property Value
CanUndo
A boolean indicating whether an undo via Undo() is possible.
public bool CanUndo { get; }
Property Value
ColumnHints
The hints, i.e. the numbers on the side of a grid, for the columns of the grid. In Nonogram puzzles these are usually shown at the top of the grid.
public Hints[] ColumnHints { get; }
Property Value
- Hints[]
Height
The height of the game grid
public int Height { get; }
Property Value
Options
The NonogramOptions for this instance
public NonogramOptions Options { get; set; }
Property Value
RowHints
The hints, i.e. the numbers on the side of a grid, for the rows of the grid. In Nonogram puzzles these are usually shown at the left side of the grid.
public Hints[] RowHints { get; }
Property Value
- Hints[]
Solution
The solution for the current puzzle, i.e. the cells (and only those cells) that must be filled for the puzzle to be solved.
public HashSet<CellPosition> Solution { get; }
Property Value
Width
The width of the game grid
public int Width { get; }
Property Value
Methods
CreateRandomPuzzle(int, int, NonogramOptions?)
Creates an API instance with a random puzzle. See CreateRandomPuzzleAsync(int, int, NonogramOptions?) for the asynchronous method.
public static NonogramAPI CreateRandomPuzzle(int width, int height, NonogramOptions? options = null)
Parameters
widthintWidth of the grid for the game
heightintHeight of the grid for the game
optionsNonogramOptionsThe NonogramOptions to use. Leave as
nullto use the default options
Returns
- NonogramAPI
NonogramAPI instance as described above
CreateRandomPuzzleAsync(int, int, NonogramOptions?)
Creates an API instance with a random puzzle asynchronously by running CreateRandomPuzzle(int, int, NonogramOptions?) on the ThreadPool as it is computionally expensive.
public static Task<NonogramAPI> CreateRandomPuzzleAsync(int width, int height, NonogramOptions? options = null)
Parameters
widthintWidth of the grid for the game
heightintHeight of the grid for the game
optionsNonogramOptionsThe NonogramOptions to use. Leave as
nullto use the default options
Returns
- Task<NonogramAPI>
NonogramAPI instance as described above
CrossCell(int, int)
Marks the cell at (x, y) as crossed.
public void CrossCell(int x, int y)
Parameters
xintx-coordinate of the cell, zero-indexed from the left.
yinty-coordinate of the cell, zero-indexed from the top.
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryfalls outside the bounds of the grid.
EmptyCell(int, int)
Clears the cell at (x, y), returning it to blank.
public void EmptyCell(int x, int y)
Parameters
xintx-coordinate of the cell, zero-indexed from the left.
yinty-coordinate of the cell, zero-indexed from the top.
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryfalls outside the bounds of the grid.
FillCell(int, int)
Fills the cell at (x, y).
public void FillCell(int x, int y)
Parameters
xintx-coordinate of the cell, zero-indexed from the left.
yinty-coordinate of the cell, zero-indexed from the top.
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryfalls outside the bounds of the grid.
IsCellCrossed(int, int)
Determines whether the cell at (x, y) is crossed.
public bool IsCellCrossed(int x, int y)
Parameters
Returns
- bool
True if the cell is crossed, false otherwise
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryis out of bounds of the grid
IsCellEmpty(int, int)
Determines whether the cell at (x, y) is empty.
public bool IsCellEmpty(int x, int y)
Parameters
Returns
- bool
True if the cell is empty, false otherwise
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryis out of bounds of the grid
IsCellFilled(int, int)
Determines whether the cell at (x, y) is filled.
public bool IsCellFilled(int x, int y)
Parameters
Returns
- bool
True if the cell is filled, false otherwise
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryis out of bounds of the grid
IsPuzzleSolved()
Determines whether the puzzle is solved, i.e. the filled cells match the solution exactly.
public bool IsPuzzleSolved()
Returns
- bool
True if the puzzle is solved, false otherwise
LoadPuzzle(Stream, NonogramOptions?)
Loads the puzzle in stream and returns a new NonogramAPI instance. The stream is automatically closed.
public static NonogramAPI LoadPuzzle(Stream stream, NonogramOptions? options = null)
Parameters
streamStreamStream to read the puzzle from. To avoid false positives on InvalidFileFormatException exceptions, the stream must consist of ONLY one valid puzzle, such as one provided by SavePuzzle(string).
optionsNonogramOptionsThe NonogramOptions to use. Leave as
nullto use the default options
Returns
- NonogramAPI
NonogramAPI instance of the puzzle
Exceptions
- InvalidFileFormatException
Thrown when the given file format is not supported
- NotSupportedException
Thrown when the version of the save system is not supported
- ArgumentNullException
Thrown when
streamisnull
LoadPuzzle(string, NonogramOptions?)
Loads the puzzle at path and returns a new NonogramAPI instance.
public static NonogramAPI LoadPuzzle(string path, NonogramOptions? options = null)
Parameters
pathstringPuzzle to load
optionsNonogramOptionsThe NonogramOptions to use. Leave as
nullto use the default options
Returns
- NonogramAPI
NonogramAPI instance of the puzzle located at the given path
Exceptions
- InvalidFileFormatException
Thrown when the given file format is not supported
- NotSupportedException
Thrown when the version of the save system is not supported
- PuzzleLoadingFailedException
Thrown when loading files fails, e.g. because of an I/O Exception. See the inner exception for more details
- ArgumentNullException
Thrown when
pathisnullor empty
LoadPuzzleAsync(Stream, NonogramOptions?)
Loads the puzzle in stream asynchronously. Contents of stream
are expected to be relatively small. Larger streams might cause noticeable blocking.
The stream is automatically closed.
public static Task<NonogramAPI> LoadPuzzleAsync(Stream stream, NonogramOptions? options = null)
Parameters
streamStreamStream to read the puzzle from. To avoid false positives on InvalidFileFormatException exceptions, the stream must consist of ONLY one valid puzzle, such as one provided by SavePuzzle(string).
optionsNonogramOptionsThe NonogramOptions to use. Leave as
nullto use the default options
Returns
- Task<NonogramAPI>
NonogramAPI instance of the puzzle located at the given path
Exceptions
- InvalidFileFormatException
Thrown when the given file format is not supported
- NotSupportedException
Thrown when the version of the save system is not supported
- ArgumentNullException
Thrown when
streamisnull
LoadPuzzleAsync(string, NonogramOptions?)
Loads the puzzle at path asynchronously and returns a new NonogramAPI instance.
public static Task<NonogramAPI> LoadPuzzleAsync(string path, NonogramOptions? options = null)
Parameters
pathstringPuzzle to load
optionsNonogramOptionsThe NonogramOptions to use. Leave as
nullto use the default options
Returns
- Task<NonogramAPI>
NonogramAPI instance of the puzzle located at the given path
Exceptions
- InvalidFileFormatException
Thrown when the given file format is not supported
- NotSupportedException
Thrown when the version of the save system is not supported
- PuzzleLoadingFailedException
Thrown when loading files fails, e.g. because of an I/O Exception. See the inner exception for more details
- ArgumentNullException
Thrown when
pathisnullor empty
Redo()
Redo the last undone move (if any). Silently returns if there is no command to redo.
public void Redo()
SaveAsFile(string, string?)
Saves a serialized version of the puzzle (that is, the solution and dimensions) to path.
If path already exists, it is overwritten.
public void SaveAsFile(string path, string? title = null)
Parameters
Exceptions
- PuzzleSerializationFailedException
Thrown when serialization failed. For example, when the given title is too long, or an I/O exception occurs. Usually, there is an inner exception giving more details.
- PuzzleSavingFailedException
Thrown when saving files fails, e.g. because of an I/O Exception. See the inner exception for more details
- ArgumentNullException
Thrown when
pathisnullor empty
SaveAsFileAsync(string, string?)
Saves a serialized version of the puzzle (that is, the solution and dimensions) to path.
If path already exists, it is overwritten.
public Task SaveAsFileAsync(string path, string? title = null)
Parameters
Returns
Exceptions
- PuzzleSerializationFailedException
Thrown when serialization failed. For example, when the given title is too long, or an I/O exception occurs. Usually, there is an inner exception giving more details.
- PuzzleSavingFailedException
Thrown when saving files fails, e.g. because of an I/O Exception. See the inner exception for more details
- ArgumentNullException
Thrown when
pathisnullor empty
ToString()
Converts this instance into a nice string representation of the grid. This includes all cells and their respective states and the hints at the sides.
public override string ToString()
Returns
- string
A string showing the current state of the game
Undo()
Undoes the last move (if any). Silently returns if there is no command to undo.
public void Undo()
Events
CellCorrected
Raised when a cell is changed incorrectly and is therefore corrected to the expected state of this cell.
public event EventHandler<CorrectionEventArgs>? CellCorrected
Event Type
CellStateChanged
CellStateChanged is raised when one or more cell change to a new state.
public event EventHandler<CellStateEventArgs>? CellStateChanged
Event Type
PuzzleSolved
Raised when the puzzle has been solved.
public event EventHandler? PuzzleSolved