예제 #1
0
파일: answer.go 프로젝트: pjherring/ggc
//Answer will try the potential answer and advance the progress if correct
func Answer(clueId, teamId int64, potential string) error {
	clue, err := table.FindClue(clueId)
	if err != nil {
		return err
	}

	if !clue.TryAnswer(potential) {
		return WrongAnswer
	}

	return progress.Advance(clueId, teamId)
}
예제 #2
0
파일: current.go 프로젝트: pjherring/ggc
//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
}