@start
	*say
		Welcome to the Alexa Quiz Game. 
        [shortPause]
        Let's get ready for today's show, which is 3 questions long and has an estimated duration of 5 minutes.
        [shortPause]
	*then
	    set showId to 1
	    set questionNum to 1
	    set playerPoints to 0
	    set opponentPoints to 0
	    set previousPlayerPoints to 0
	    flag ftue
        <-> setupGame
        -> showIntro

@showIntro
    *say
		{showIntro}
	*then
        -> opponentIntro

@opponentIntro
    *say
        You will be playing against your opponent, {opponentName}. Good luck to both of you.
        [pause]
    *then
        -> setupQ

@setupQ
    *then
        <-> setupQuestionData
        -> introQ        

@introQ
    *say
		{questionIntro}
    *then
        -> q

@q
    *say
		{question}
    	Is the answer A, {answerA}, B, {answerB}, or C {answerC}
		<audio src='https://sfb-framework.s3.amazonaws.com/examples/sounds/Clock_2.mp3'/>
		What is your answer?
	*reprompt
		Is the answer A, {answerA}, B, {answerB}, or C {answerC}
		
	*then
		hear a, 1, 1st {
		    set answer to answerA
            -> answer
        }

		hear b, 2, 2nd {
		    set answer to answerB
            -> answer
        }

		hear c, 3, 3rd {
		    set answer to answerC
            -> answer
        }

        slot answer to 'AnswerSlotType'
        hear {answer}, the answer is {answer}, it's {answer}, I think it's {answer} {
            -> answer
        }

        hear i don't know, skip, next, continue {
            // Just jump past the right and wrong sounds and move to the next question
            -> answerQ
        }

        hear repeat the question, repeat, what are the choices {
            -> q
        }
        
        hear * {
            -> q
        }

        hear help {
            -> help
        }
        
@answer
    *say
        You chose {answer}. [shortPause]
    *then
    
        if answer == correctAnswer {
            -> answerCorrect
        }
        
        -> answerWrong
        
@answerCorrect
    *say
        <audio src='https://sfb-framework.s3.amazonaws.com/examples/sounds/Bell_1.mp3'/> [shortPause]
    *then
        set gainedPointsThisRound to answerPointsValue
        increase playerPoints by answerPointsValue
        -> answerQ


@answerWrong
    *say
        <audio src='https://sfb-framework.s3.amazonaws.com/examples/sounds/Boing_1.mp3'/> [shortPause]
    *then
        -> answerQ

@answerQ
    *say
        {questionAnswer}
    *then
        -> scoringUpdate
        
@scoringUpdate
    *then
        if playerPoints > previousPlayerPoints {
            <-> scoringUpdateGainedPoints
        }

        // Simulate opponent playing
        <-> simulateOpponentAnswer

        if opponentCorrect {
            <-> scoringUpdateOpponentCorrect
        }
        if !opponentCorrect {
            <-> scoringUpdateOpponentWrong
        }
        
        set previousPlayerPoints to playerPoints
        
        -> setupNextQuestion

@setupNextQuestion
    *then
        if questionNum == numQuestionsTotal {
            -> quizOver
        }
        
	    increase questionNum by 1
        -> setupQ

@scoringUpdateGainedPoints
    *say
        Yay! You gained {gainedPointsThisRound} points for a new total of {playerPoints} points.
        ||
        Great job! You gained {gainedPointsThisRound} points and now have {playerPoints} points.
        ||
        Very good! You now have {playerPoints} points total.
    *then
        >> RETURN

@simulateOpponentAnswer
    *then
        roll 1d100        
        // Have opponent be correct 60 percent of the time
        if rollResult <= 60 {
            flag opponentCorrect
            increase opponentPoints by answerPointsValue
            >> RETURN
        }
        
        unflag opponentCorrect
        >> RETURN

@scoringUpdateOpponentCorrect
    *say
        Your opponent {opponentName} got the answer correct and now has {opponentPoints} points.
        ||
        Your opponent was correct for {answerPointsValue} points.
        ||
        Your opponent got the answer right.
    *then
        >> RETURN

@scoringUpdateOpponentWrong
    *say
        Your opponent {opponentName} got the answer wrong.
        ||
        Your opponent {opponentName} was incorrect.
    *then
        >> RETURN

@quizOver
    *say
        [shortPause] The quiz is over, let's see how you did. <audio src='https://sfb-framework.s3.amazonaws.com/examples/sounds/Fairy_1.mp3'/> Today, you scored {playerPoints} points. [shortPause] Your opponent {opponentName} scored {opponentPoints} points.
    *then
        if playerPoints == opponentPoints {
            <-> quizOverTied
        }
        if playerPoints < opponentPoints {
            <-> quizOverLost
        }
        if playerPoints > opponentPoints {
            <-> quizOverWon
        }
    
        -> quizOverExit

@quizOverTied
    *say
        Oh boy, it was a tie. What a close game today.
    *then
        >> RETURN

@quizOverLost
    *say
        <audio src='https://sfb-framework.s3.amazonaws.com/examples/sounds/Boing_1.mp3'/> 
        
        Oh no, you lost. Better luck next time.
    *then
        >> RETURN

@quizOverWon
    *say
        <audio src='https://sfb-framework.s3.amazonaws.com/examples/sounds/Bell_1.mp3'/> 
        
        Yay! You won! Way to go.
    *then
        >> RETURN

@quizOverExit
    *say
        [pause] I hope you had fun, thank you very much for playing today. See you tomorrow for your next Alexa Quiz Game.
    *then
        >> END
        

// SPECIAL SCENE: @resume is a special scene that will play when the player comes back to the game after leaving
@resume
	*say
		Welcome back. Would you like to start where you left off?
	*then
		hear yes, ok {
            // Tell the framework to pick up where they last left off
			>> RESUME
		}
		hear no {
			>> RESTART
		}

@pause
	*say
		Thanks for playing.
	*then
		>> PAUSE

@end
	*say
		Thanks for playing.
	*then
		>> END

@help
    *say
        This is a multiple choice quiz game. For each question, please choose answer A, B, or C. If you need to repeat a question, say 'repeat the question'. If you don't know the answer, you can say 'i don't know' or 'skip'.
    *then
        >> BACK
        
@global prepend
    *show
        template: 'default'
        background: 'https://m.media-amazon.com/images/G/01/alexa-games/backgrounds/background_pencil_wgrid.png'
        

