sqlite3

package
v0.0.0-...-4a31f9d Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNextChar

func GetNextChar(character string, maxCharacters uint) byte

return the next alphabet character but stop at maxCharacters

func MatchFound

func MatchFound(coordinates string, stringOfCoords string) bool

Types

type BattleModel

type BattleModel struct {
	DB *sql.DB
}

func (*BattleModel) Accept

func (m *BattleModel) Accept(player2ID, boardID, battleID int) (int, error)

Accept a challenge (battle)

func (*BattleModel) CheckBoardOwner

func (m *BattleModel) CheckBoardOwner(playerID, battleID, boardID int) bool

GetBoardOwner - Ensure the player is the owner of this board and this board is part of this battle

func (*BattleModel) CheckChallenger

func (m *BattleModel) CheckChallenger(player1ID, battleID, player2BoardID int) bool

Check that the person logged in should be updating this battle

func (*BattleModel) CheckTurn

func (m *BattleModel) CheckTurn(battleID, playerID int) (int, string)

Just ask the database whose turn it is - The database will return a secret key representing player1 or player2

func (*BattleModel) Create

func (m *BattleModel) Create(player1ID, player1BoardID, player2ID int, secretTurn string) (int, error)

Create a new Battle - record the challenger (player1) and the challengee (player2)

func (*BattleModel) Get

func (m *BattleModel) Get(playerID, battleID int) (*models.Battle, error)

Get - return a single battle; this is for the battle board

func (*BattleModel) GetChallenger

func (m *BattleModel) GetChallenger(currentPlayerID int) (int, error)

GetChallenger - See if there are any challengers out there

func (*BattleModel) GetChallenges

func (m *BattleModel) GetChallenges(rowid int) ([]*models.Battle, error)

GetAll - Get all active battles or challenges (this could be combined with GetOpen below)

func (*BattleModel) GetOpen

func (m *BattleModel) GetOpen(rowid, battleID int) ([]*models.Battle, error)

GetOpen - Get a list of open challenges

func (*BattleModel) GetTurn

func (m *BattleModel) GetTurn(battleID int) (int, error)

Just ask the database whose turn it is - The database will return a secret key representing player1 or player2

func (*BattleModel) UpdateChallenge

func (m *BattleModel) UpdateChallenge(player1 int, player2 int, player2Accepted bool, battleID int) error

Update challenge - opponent has accepted

func (*BattleModel) UpdateTurn

func (m *BattleModel) UpdateTurn(player1 int, player2 int, nextTurn int, battleID int, secretTurn []byte) error

Update turn - other player's turn

type BoardModel

type BoardModel struct {
	DB *sql.DB
}

func (*BoardModel) ChooseBoard

func (m *BoardModel) ChooseBoard(rowid, boardID int, action string) (int, error)

Choose Board - I can't store the boardID in my session so...

update the database and keep one "selected" board at any given point in time

func (*BoardModel) Create

func (m *BoardModel) Create(rowid int, boardName string) (int, error)

Create a board if one with the same name doesn't already exist (belonging to this user)

func (*BoardModel) GetInfo

func (m *BoardModel) GetInfo(playerID, boardID int) (*models.Board, error)

Get board info - name of board

func (*BoardModel) GetPositions

func (m *BoardModel) GetPositions(rowid int) ([]*models.Position, error)

Get positions on board

func (*BoardModel) Insert

func (m *BoardModel) Insert(playerID int, boardID int, shipName string, arrayOfCoords []string) (int, error)

Insert coordinates for a board

func (*BoardModel) List

func (m *BoardModel) List(rowid int) ([]*models.Board, error)

func (*BoardModel) Update

func (m *BoardModel) Update(rowid int, boardName string, playerID int) (int, error)

type PlayerModel

type PlayerModel struct {
	DB *sql.DB
}

func (*PlayerModel) Authenticate

func (m *PlayerModel) Authenticate(screenName, password string) (int, error)

authenticate player

func (*PlayerModel) Get

func (m *PlayerModel) Get(rowid int) (*models.Player, error)

get player information

func (*PlayerModel) Insert

func (m *PlayerModel) Insert(screenName string, emailAddress string, password string) (int, error)

insert new player

func (*PlayerModel) List

func (m *PlayerModel) List(rowid int, status string) ([]*models.Player, error)

list players

func (*PlayerModel) Update

func (m *PlayerModel) Update(id int, emailAddress string) (int, error)

update player

func (*PlayerModel) UpdateLogin

func (m *PlayerModel) UpdateLogin(id int, loggedIn bool) (int, error)

update login

type PositionModel

type PositionModel struct {
	DB *sql.DB
}

func (*PositionModel) CheckWinner

func (m *PositionModel) CheckWinner(playerID, battleID int) (bool, error)

Check the Battles board to see if one of the players has 5 sunken ships

func (*PositionModel) Get

func (m *PositionModel) Get(id int) (*models.Position, error)

func (*PositionModel) Insert

func (m *PositionModel) Insert(boardID int, battleshipID int, playerID int, coordX int, coordY int, pinColor string) (int, error)

func (*PositionModel) List

func (m *PositionModel) List(boardID, playerID int) ([]*models.Position, error)

func (*PositionModel) Update

func (m *PositionModel) Update(playerID int, playerTakingTheirTurn int, battleID int, boardID int, coordX int, coordY, secretTurn string) (string, string, bool, error)

Update positions pinColor - Query player, battle, board, and coordinates - Return the pinColor and shipType (if sunk) - Update whose turn it is

type ShipModel

type ShipModel struct {
	DB *sql.DB
}

func (*ShipModel) Get

func (m *ShipModel) Get(id int) (*models.Ship, error)

func (*ShipModel) Insert

func (m *ShipModel) Insert(shipType string, shipLength int) (int, error)

func (*ShipModel) List

func (m *ShipModel) List() ([]*models.Ship, error)

Jump to

Keyboard shortcuts

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