app

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GridLabelSize float32 = 40

	ResetDefaultText          = "🙂"
	ResetGameOverText         = "☠"
	ResetGameWonText          = "😎"
	ResetTextSize     float32 = 40
)

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 (
	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) 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
}

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 MinesweeperGrid

type MinesweeperGrid struct {
	Tiles      [][]*Tile
	Difficulty minesweeper.Difficulty
	Game       minesweeper.Game

	Timer       *Timer
	MineCount   *Counter
	ResetButton *Button
}

Graphical display for a minesweeper game

func NewMinesweeperGrid

func NewMinesweeperGrid(d minesweeper.Difficulty) *MinesweeperGrid

Create a new grid suitable for the give difficulty

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) 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) 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

	Pos   minesweeper.Pos
	Field *minesweeper.Field

	Flagged bool
	// 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) 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) Reset

func (t *Tile) Reset()

Reset tile to default state, used for starting new game

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

func (*Tile) UpdateContent

func (t *Tile) UpdateContent()

Update the tile render depending on the current state of it's backing Field

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

Jump to

Keyboard shortcuts

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