app

package
v0.5.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GridLabelSize float32 = 40

	ResetDefaultText          = "🙂"
	ResetGameOverText         = "☠"
	ResetGameWonText          = "😎"
	ResetTextSize     float32 = 40
)
View Source
const (
	GameAlgorithmSafePos = iota
	GameAlgorithmSafeArea
	GameAlgorithmSolvable
)
View Source
const (
	ChunkSize = 10
)
View Source
const DEFAULT_AUTOSOLVE_DELAY = 500 * time.Millisecond
View Source
const DEFAULT_GAME_ALGORITHM = GameAlgorithmSolvable

Variables

View Source
var (
	TileDefaultColor    = color.Gray16{32767}
	TileBackgroundColor = color.Gray16{^uint16(0)}
	TileExplodedColor   = color.RGBA{240, 10, 20, alpha}

	TileSize             = fyne.NewSize(32, 32)
	TileTextSize float32 = 23 // Biggest we can go with TileSize of 32^2
)
View Source
var (
	HelperMarkerSymbols = []string{"", "!", "?"}
	HelperMarkerColors  = []color.Color{
		color.White,
		color.RGBA{180, 15, 15, alpha},
		color.RGBA{15, 180, 15, alpha},
	}
)
View Source
var (
	GridLabelColor = color.RGBA{240, 10, 20, alpha}
)
View Source
var TEXT_COLOR = color.White
View Source
var TileTextColor = []color.Color{
	color.White,
	color.RGBA{20, 15, 220, alpha},
	color.RGBA{5, 110, 20, alpha},
	color.RGBA{240, 10, 20, alpha},
	color.RGBA{5, 5, 100, alpha},
	color.RGBA{90, 38, 42, alpha},
	color.RGBA{25, 230, 230, alpha},
	color.RGBA{10, 10, 10, alpha},
	color.RGBA{64, 64, 64, alpha},
}

Functions

This section is empty.

Types

type App

type App struct {
	Version Version
	// contains filtered or unexported fields
}

Struct representing the current app. There should only ever be a single instance during runtime.

func New

func New() *App

Create a new App

func (*App) NewGrid added in v0.3.0

func (a *App) NewGrid(d minesweeper.Difficulty)

func (*App) Run

func (a *App) Run()

Simply calls app.Run()

type Button

type Button struct {
	widget.BaseWidget

	Label  *canvas.Text
	Action func()
}

Custom implementation for a button that is only portraied by text. The text is fully configurable by exposing the backing label.

func NewButton

func NewButton(text string, color color.Color, action func()) *Button

Create a new button from the given text, color and function

func (*Button) CreateRenderer

func (b *Button) CreateRenderer() fyne.WidgetRenderer

Function to create renderer needed to implement widget

func (*Button) SetText

func (b *Button) SetText(text string)

Set label text to the given string and refresh widget

func (*Button) Tapped

func (b *Button) Tapped(_ *fyne.PointEvent)

Left click action

func (*Button) TappedSecondary

func (b *Button) TappedSecondary(_ *fyne.PointEvent)

Right click action, currently not implemented or exposed

type Counter added in v0.1.1

type Counter struct {
	Label *canvas.Text
	Count int
	// contains filtered or unexported fields
}

Displays a counter that can be increased and decreased

func NewCounter added in v0.1.1

func NewCounter(count int) *Counter

Create new counter

func (*Counter) Dec added in v0.1.1

func (m *Counter) Dec()

Decrease the counter

func (*Counter) Inc added in v0.1.1

func (m *Counter) Inc()

Increase the counter

func (*Counter) SetCount added in v0.1.1

func (m *Counter) SetCount(c int)

Set the count to a specific number

type HelpMarking added in v0.3.0

type HelpMarking int
const (
	HelpMarkingNone HelpMarking = iota
	HelpMarkingMine
	HelpMarkingSafe
)

type MinesweeperGrid

type MinesweeperGrid struct {
	Tiles         [][]*Tile
	Difficulty    minesweeper.Difficulty
	Game          minesweeper.Game
	AssistedMode  bool
	GameAlgorithm int

	Timer       *Timer
	MineCount   *Counter
	ResetButton *Button
	// contains filtered or unexported fields
}

Graphical display for a minesweeper game

func NewMinesweeperGrid

func NewMinesweeperGrid(d minesweeper.Difficulty, assistedMode bool) *MinesweeperGrid

Create a new grid suitable for the give difficulty

func (*MinesweeperGrid) Autosolve added in v0.4.0

func (g *MinesweeperGrid) Autosolve(delay time.Duration) bool

Autosolve the current running game, delay is the time between steps Returns false if it can't run autosolve, otherwise true. If there are no steps to be taken, still

func (*MinesweeperGrid) Col

func (g *MinesweeperGrid) Col() int

Return the number of columns in the grid

func (*MinesweeperGrid) GetCanvasObject

func (g *MinesweeperGrid) GetCanvasObject() fyne.CanvasObject

Get the graphical representation of the grid

func (*MinesweeperGrid) Hint added in v0.3.0

func (g *MinesweeperGrid) Hint() bool

Display a single hint on the grid. Returns false if no hint could be displayed.

func (*MinesweeperGrid) NewGame

func (g *MinesweeperGrid) NewGame()

Start a new game

func (*MinesweeperGrid) OutOfBounds added in v0.2.0

func (g *MinesweeperGrid) OutOfBounds(p minesweeper.Pos) bool

Check if the given position is out of bounds. Calls Game.OutOfBounds(Pos)

func (*MinesweeperGrid) Replay added in v0.2.0

func (g *MinesweeperGrid) Replay()

Replay the current game

func (*MinesweeperGrid) Reset

func (g *MinesweeperGrid) Reset()

Reset Grid

func (*MinesweeperGrid) Row

func (g *MinesweeperGrid) Row() int

Return the number of rows in the grid

func (*MinesweeperGrid) TapNeighbours added in v0.4.1

func (g *MinesweeperGrid) TapNeighbours(pos minesweeper.Pos)

Called by the child tiles to reveal all neighbours when they have been double tapped

func (*MinesweeperGrid) TappedTile

func (g *MinesweeperGrid) TappedTile(pos minesweeper.Pos)

Called by the child tiles to signal they have been tapped. Checks the given tile and then updates the display according to the new state. Starts a new game when no game is currently running.

type Tile

type Tile struct {
	widget.BaseWidget
	// contains filtered or unexported fields
}

A tile extends the base widget and displays the current state of the backing games field

func NewTile

func NewTile(x, y int, grid *MinesweeperGrid) *Tile

Create a new Tile with a reference to it's parent grid, as well as knowledge of it's own position in the Grid

func (*Tile) Checked added in v0.4.1

func (t *Tile) Checked() bool

Returns if the tiles field is checked

func (*Tile) Content added in v0.4.1

func (t *Tile) Content() minesweeper.FieldContent

Returns the field content

func (*Tile) CreateRenderer

func (t *Tile) CreateRenderer() fyne.WidgetRenderer

Function to create renderer needed to implement widget

func (*Tile) DoubleTapped added in v0.2.0

func (t *Tile) DoubleTapped(_ *fyne.PointEvent)

Double click on tile

func (*Tile) Flag added in v0.4.1

func (t *Tile) Flag(v bool)

Flag the tile as a suspected mine

func (*Tile) Flagged

func (t *Tile) Flagged() bool

Returns if the tile is flagged as a suspected mine

func (*Tile) Mark added in v0.4.1

func (t *Tile) Mark(m HelpMarking)

Mark the tile

func (*Tile) Marking added in v0.4.1

func (t *Tile) Marking() HelpMarking

Returns the marking of the tile

func (*Tile) Reset

func (t *Tile) Reset()

Reset tile to default state, used for starting new game

func (*Tile) SetField added in v0.4.1

func (t *Tile) SetField(f minesweeper.Field)

Set the content of the field

func (*Tile) Tapped

func (t *Tile) Tapped(_ *fyne.PointEvent)

Left mouse click on tile

func (*Tile) TappedSecondary

func (t *Tile) TappedSecondary(_ *fyne.PointEvent)

Right mouse click on tile

type Timer

type Timer struct {
	Label   *canvas.Text
	Seconds int
	// contains filtered or unexported fields
}

Timer to display an upwards countdown in a fyne app.

func NewTimer

func NewTimer() *Timer

Create new timer

func (*Timer) Reset

func (t *Timer) Reset()

Reset the timer back to zero

func (*Timer) Running added in v0.2.0

func (t *Timer) Running() bool

Check if the timer is running

func (*Timer) Start

func (t *Timer) Start()

Start the timer, runs concurrently

func (*Timer) Stop

func (t *Timer) Stop()

Stop the timer

type Version

type Version struct {
	Name, Version, Commit, Go string
}

Struct for containing the current version of the app

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL