Skip to content

Commit

Permalink
Add comments to const
Browse files Browse the repository at this point in the history
  • Loading branch information
oklahomer committed Jan 8, 2018
1 parent 62906f7 commit f27c4bd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
22 changes: 20 additions & 2 deletions cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,34 @@ var (
ErrUnflaggingNonFlaggedCell = errors.New("non-flagged cell can not be unflagged")
)

// CellState depicts a state of a cell.
type CellState int

const (
_ CellState = iota

// Closed represents a state of a cell where no operation is currently applied.
//
// A cell with this state may or may not have underlying land mine.
Closed

// Opened represents a state of a cell where the cell is dug and is secure.
//
// This is final and no more operation can be applied to its belonging cell.
Opened

// Flagged represents a state of a cell that is marked by a user to indicate possible underlying mine.
//
// To open this cell, user must unflag the cell first.
Flagged

// Exploded represents a state of a cell where user tried to open, but had an underlying mine.
//
// This is final and no more operation can be applied to its belonging cell.
Exploded
)

type CellState int

// String returns stringified representation of CellState.
func (s CellState) String() string {
switch s {
case Closed:
Expand Down
20 changes: 20 additions & 0 deletions game.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,43 @@ var (
ErrOperatingFinishedGame = errors.New("can not operate on finished game")
)

// GameState depicts state of the game.
//
// When Cleared or Lost is returned from Game.Operate, the game is finished and no further operation is available.
type GameState int

const (
_ GameState = iota

// InProgress represents a state of a game where the game is not finished yet and user operation is available.
InProgress

// Cleared represents a state of a game where all safe cells are opened.
//
// This state is final so any further Game.Operate call results in returning GameState of Cleared and ErrOperatingFinishedGame.
Cleared

// Lost represents a state of a game where non-safe cell was dug and underlying mine has exploded.
Lost
)

// OpType represents a type of operation a user is applying.
type OpType int

const (
_ OpType = iota

// Open represents a kind of operation to open a closed field cell.
Open

// Flag represents a kind of operation to flag a closed suspicious field cell with a possible underlying mine.
Flag

// Unflag represents a kind of operation to unflag a flagged field cell.
Unflag
)

// String returns stringified representation of GameState.
func (s GameState) String() string {
switch s {
case InProgress:
Expand All @@ -49,6 +68,7 @@ func (s GameState) String() string {
}
}

// MarshalJSON returns GameState value that can be part of JSON structure.
func (s GameState) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, s.String())), nil
}
Expand Down

0 comments on commit f27c4bd

Please sign in to comment.