fam100

package module
v0.5.24 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2016 License: MIT Imports: 14 Imported by: 0

README

Fam100

Famm100 is a text game library to play "Family Fued"

Current supported platform:

  • CLI
  • Telegram

Future platform additions:

  • Slack

Contributors

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RoundDuration = 90 * time.Second

	DelayBetweenRound    = 5 * time.Second
	TickAfterWrongAnswer = false
	RoundPerGame         = 3
	DefaultQuestionLimit = 600
)
View Source
var (
	// DB question database
	DefaultQuestionDB QuestionDB
	QuestionBucket    = []byte("questions")

	// Add to the existing seed
	ExtraQuestionSeed = int64(0)
)
View Source
var DefaultDB db

Functions

func AddQuestion

func AddQuestion(q Question) error

func InitQuestion

func InitQuestion(dbPath string) (numQuestion int, err error)

func SetLogger

func SetLogger(l zap.Logger)

func SetRedisPrefix

func SetRedisPrefix(prefix string)

func T

func T(s string) string

T return text based on the language TODO:

Types

type Answer added in v0.4.1

type Answer struct {
	ID    int
	Text  []string
	Score int
}

func (Answer) String added in v0.4.1

func (a Answer) String() string

type Game

type Game struct {
	ID               int64
	ChanID           string
	ChanName         string
	State            State
	TotalRoundPlayed int

	In  chan Message
	Out chan Message
	// contains filtered or unexported fields
}

Game can consists of multiple round each round user will be asked question and gain points

func NewGame

func NewGame(chanID, chanName string, in, out chan Message) (r *Game, err error)

NewGame create a new round

func (*Game) CurrentQuestion

func (g *Game) CurrentQuestion() Question

func (*Game) Start

func (g *Game) Start()

Start the game

type MemoryDB

type MemoryDB struct {
	Seed int64
	// contains filtered or unexported fields
}

MemoryDb stores data in non persistence way

func (*MemoryDB) ChannelConfig added in v0.4.1

func (m *MemoryDB) ChannelConfig(chanID, key, defaultValue string) (string, error)

func (*MemoryDB) ChannelCount added in v0.4.1

func (m *MemoryDB) ChannelCount() (total int, err error)

func (*MemoryDB) ChannelRanking

func (m *MemoryDB) ChannelRanking(chanID string, limit int) (ranking Rank, err error)

func (*MemoryDB) Channels added in v0.4.1

func (m *MemoryDB) Channels() (channels map[string]string, err error)

func (*MemoryDB) GlobalConfig added in v0.4.1

func (m *MemoryDB) GlobalConfig(key, defaultValue string) (string, error)

func (*MemoryDB) Init

func (m *MemoryDB) Init() (err error)

func (*MemoryDB) PlayerChannelScore added in v0.4.2

func (m *MemoryDB) PlayerChannelScore(chanID string, playerID PlayerID) (PlayerScore, error)

func (*MemoryDB) PlayerCount added in v0.4.1

func (m *MemoryDB) PlayerCount() (total int, err error)

func (*MemoryDB) Reset

func (m *MemoryDB) Reset() error

type Message

type Message interface{}

Message to communicate between player and the game

type Player

type Player struct {
	ID   PlayerID
	Name string
}

Player of the game

type PlayerID

type PlayerID string

PlayerID is the player ID type

type PlayerScore added in v0.4.2

type PlayerScore struct {
	PlayerID PlayerID `json:"playerID"`
	Name     string   `json:"name"`
	Score    int      `json:"score"`
	Position int      `json:"position"`
}

type QNAMessage

type QNAMessage struct {
	ChanID         string
	Round          int
	QuestionText   string
	QuestionID     int
	Answers        []roundAnswers
	ShowUnanswered bool // reveal un-answered question (end of round)
	TimeLeft       time.Duration
}

QNAMessage represents question and answer for a round

type Question

type Question struct {
	ID      int
	Text    string
	Answers []Answer
	// contains filtered or unexported fields
}

Question for a round

func GetQuestion

func GetQuestion(id string) (q Question, err error)

func NextQuestion

func NextQuestion(seed int64, played int, questionLimit int) (q Question, err error)

NextQuestion generates next question randomly by taking into account numbers of game played for particular seed key

type QuestionDB

type QuestionDB struct {
	DB *bolt.DB
	// contains filtered or unexported fields
}

func (*QuestionDB) AddQuestion added in v0.4.1

func (d *QuestionDB) AddQuestion(q Question) error

func (*QuestionDB) Close added in v0.4.1

func (d *QuestionDB) Close() error

func (*QuestionDB) GetQuestion added in v0.4.1

func (d *QuestionDB) GetQuestion(id string) (q Question, err error)

func (*QuestionDB) Initialize added in v0.4.1

func (d *QuestionDB) Initialize(dbPath string) error

type Rank

type Rank []PlayerScore

func (Rank) Add added in v0.4.9

func (r Rank) Add(source Rank) Rank

func (Rank) Len

func (r Rank) Len() int

func (Rank) Less

func (r Rank) Less(i, j int) bool

func (Rank) Subtract added in v0.4.9

func (r Rank) Subtract(source Rank) Rank

func (Rank) Swap

func (r Rank) Swap(i, j int)

type RankMessage

type RankMessage struct {
	ChanID string
	Round  int
	Rank   Rank
	Final  bool
}

type RedisDB

type RedisDB struct {
	// contains filtered or unexported fields
}

func (*RedisDB) ChannelConfig added in v0.4.1

func (r *RedisDB) ChannelConfig(chanID, key, defaultValue string) (config string, err error)

func (*RedisDB) ChannelCount added in v0.3.3

func (r *RedisDB) ChannelCount() (total int, err error)

func (RedisDB) ChannelRanking

func (r RedisDB) ChannelRanking(chanID string, limit int) (ranking Rank, err error)

func (*RedisDB) Channels added in v0.4.1

func (r *RedisDB) Channels() (channels map[string]string, err error)

func (*RedisDB) GlobalConfig added in v0.4.1

func (r *RedisDB) GlobalConfig(key, defaultValue string) (config string, err error)

func (*RedisDB) Init

func (r *RedisDB) Init() (err error)

func (RedisDB) PlayerChannelScore added in v0.4.2

func (r RedisDB) PlayerChannelScore(chanID string, playerID PlayerID) (PlayerScore, error)

func (*RedisDB) PlayerCount added in v0.3.3

func (r *RedisDB) PlayerCount() (total int, err error)

func (*RedisDB) Reset

func (r *RedisDB) Reset() error

type State

type State string

State represents state of the round

const (
	Created       State = "created"
	Started       State = "started"
	Finished      State = "finished"
	RoundStarted  State = "roundStarted"
	RoundTimeout  State = "RoundTimeout"
	RoundFinished State = "roundFinished"
)

Available state

type StateMessage

type StateMessage struct {
	GameID    int64
	ChanID    string
	Round     int
	State     State
	RoundText QNAMessage //question and answer
}

StateMessage represents state change in the game

type TextMessage

type TextMessage struct {
	ChanID     string
	Player     Player
	Text       string
	ReceivedAt time.Time
}

TextMessage represents a chat message

type TickMessage

type TickMessage struct {
	ChanID   string
	TimeLeft time.Duration
}

TickMessage represents time left notification

type WrongAnswerMessage

type WrongAnswerMessage TickMessage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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