Example #1
0
func TestIncrementHintsTakenForClueTeam(t *T) {
	beforeTeamProgressTest()

	err := table.IncrementHintsTakenForClueTeam(1, 1)
	rdtest.Assert(t, err == nil, err)
	currentClue, err := table.FindClueWithProgressForTeam(1)
	rdtest.Assert(t, err == nil)
	rdtest.Assert(t, currentClue.HintCnt == 1)
}
Example #2
0
func TestAnswerCorrectVariation(t *testing.T) {
	beforeAnswerTest()

	err := clues.Answer(1, 1, "   1ba   ")
	rdtest.Assert(t, err == nil, err)

	p, err := table.FindClueWithProgressForTeam(1)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, p.Clue.ClueId == 2)
}
Example #3
0
func TestFindWithCurrentClueForTeam(t *T) {
	beforeTeamProgressTest()

	currentClue, err := table.FindClueWithProgressForTeam(20)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, currentClue.Clue.ClueId == 3, "ClueId: %d", currentClue.Clue.ClueId)
	rdtest.Assert(t, currentClue.TeamId == 20, "TeamId: %d", currentClue.TeamId)
	rdtest.Assert(t, currentClue.HintCnt == 1, "Hint Count: %d", currentClue.HintCnt)
	rdtest.Assert(t, currentClue.HintCnt == 1, "Hint Count: %d", currentClue.HintCnt)
	rdtest.Assert(t, currentClue.Clue.HintOne == "hint 3")
	rdtest.Assert(t, currentClue.Clue.HintTwo == "hint b3")
}
Example #4
0
func TestCreateTeamProgress(t *T) {
	beforeTeamProgressTest()

	p, err := table.CreateTeamProgress(2, 1)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, p.TeamId == 2)
	rdtest.Assert(t, p.ClueId == 1)

	currentClue, err := table.FindClueWithProgressForTeam(2)
	rdtest.Assert(t, err == nil)
	rdtest.Assert(t, currentClue.Clue.ClueId == 1)
	rdtest.Assert(t, currentClue.TeamId == 2)
}
Example #5
0
//CurrentClueForTeam gets the current clue for the team
//It should start the team if they are not on a track
//It should advance the team if the clue is disabled
//It should advance the team if the clue has been answered
func CurrentForTeam(teamId, expectedClueId int64) (*Current, error) {

	p, err := table.FindClueWithProgressForTeam(teamId)

	if err == table.NoProgress {
		if err = tracks.Begin(teamId); err != nil {
			return nil, err
		}
		//RECURSION
		return CurrentForTeam(teamId, NoExpectedId)
	} else if err != nil {
		return nil, err
	}

	if !p.Clue.IsEnabled {

		err = progress.Advance(p.Clue.ClueId, teamId)
		if err != nil {
			return nil, err
		}
		//RECURSION
		current, err := CurrentForTeam(teamId, NoExpectedId)
		if err != nil {
			return nil, err
		}

		if current.AdvancementReason == "" {
			current.AdvancementReason = DisabledAdvancement
		}

		return current, nil
	}

	current := newCurrent(p)

	if expectedClueId > 0 && expectedClueId != p.Clue.ClueId {
		current.AdvancementReason = AnsweredAdvancement
	}

	return current, nil
}
Example #6
0
File: ask.go Project: pjherring/ggc
//Ask should get the current hint for team
//It should return nothing when all hints have been taken
//This assumes each clue only has two hints
func Ask(teamId int64) (string, error) {

	currentClue, err := table.FindClueWithProgressForTeam(teamId)
	if err != nil {
		return "", err
	}

	if currentClue.HintCnt < 2 {
		err = table.IncrementHintsTakenForClueTeam(currentClue.Clue.ClueId, teamId)
		if err != nil {
			return "", err
		}
	}

	switch currentClue.HintCnt {
	case 0:
		return currentClue.Clue.HintOne, nil
	case 1:
		return currentClue.Clue.HintTwo, nil
	default:
		return "", NoHintsLeft
	}
}