models

package
v0.0.0-...-725ff28 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: GPL-3.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

type Game struct {
	// Percentages is a value from 0 to 1 that represents the current completion of the typing test
	Percentages []float64         `json:"percentages"`
	Progress    []*progress.Model `json:"-"`
	// this player's playerID
	PlayerID int `json:"player_id"`
	// Text is the randomly generated text for the user to type
	Text string `json:"-"`
	// Typed is the text that the user has typed so far
	Typed string `json:"-"`
	// Start and end are the start and end time of the typing test
	Start time.Time `json:"-"`
	// Mistakes is the number of characters that were mistyped by the user
	Mistakes int `json:"-"`
	// Score is the user's score calculated by correct characters typed
	Score float64 `json:"-"`
}

The game model is used for storing the bubbletea application's current state It contains mutliple progress bars, their percentages and is drawn on the screen All clients send their percentages to the central server.

func (Game) Init

func (m Game) Init() tea.Cmd

Init inits the bubbletea model for use

func (Game) Update

func (m Game) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update updates the bubbletea model by handling the progress bar update and adding typed characters to the state if they are valid typing characters

func (Game) View

func (m Game) View() string

View shows the current state of the typing test. It displays a progress bar for the progression of the typing test, the typed characters (with errors displayed in red) and remaining characters to be typed in a faint display

Jump to

Keyboard shortcuts

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