// File: Matlock42[P]Jeopardy/jgameClass.cpp
// Function: Game::showQuestion(int)
bool Game::showQuestion(int aPrompt)
{	
	int lCatagory, lPrice;
	int lPrompt;
	bool lCorrect;
	// split 2 digit prompt into category and price (and make base zero)
	lCatagory = (aPrompt / 10 % 10) - 1;	// tens digit
	lPrice = (aPrompt % 10) - 1;			// ones digit

	// make sure selection is a valid choice
	if( lCatagory >= 0 && lCatagory < this->mSize && lPrice >= 0 && lPrice < this->mSize)
	{
		// make sure it hasn't been played before
		if(!mQuestionSet[lCatagory][lPrice]->hasBeenPlayed())
		{
			// display the question from the questionSet
			mQuestionSet[lCatagory][lPrice]->askQuestion();
			cout << "\n\n";
			mQuestionSet[lCatagory][lPrice]->showAnswers();
		}
		else // has been played
		{
			cout << "This question has already been played.\n";
			return false;
		}
	}
	else // not a valid choice
	{
		cout << "Invalid input: out of bounds.\n";
		return false;
	}

	// validate the input
	bool lInputError = false;
	do
	{
		cout << "What is your answer: \n";
	    if (cin >> lPrompt) // Sanitize input to an integer
	    {
	    	lInputError = false;
	    } 
	    else
	    {
	        cout << "Entered value is not an Integer.\n\n";
	        cin.clear();
	        cin.ignore(numeric_limits<streamsize>::max(), '\n');
	        lInputError = true;
	    }
	    // ensure that the prompt is 1,2,3,4
	    if (lPrompt > 4 || lPrompt < 1)
	    {
	    	cout << "Not a valid answer.\n\n";
	    	lInputError = true;
	    }
	} while (lInputError);

	// Play the user's answer
	lCorrect = mQuestionSet[lCatagory][lPrice]->play(lPrompt);
	
	if(lCorrect)
	{
		cout << "That is correct!\n";
		// add to the score
		mScore += ((lPrice + 1) * 100);
	}
	else
	{
		cout << "That is incorrect.\n";
	}
	
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl $0xa, %ecx
cltd
idivl %ecx
subl $0x1, %edx
movl %edx, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
subl $0x1, %edx
movl %edx, -0x1c(%rbp)
cmpl $0x0, -0x18(%rbp)
jl 0x49f3
movq -0x30(%rbp), %rcx
movl -0x18(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x49f3
cmpl $0x0, -0x1c(%rbp)
jl 0x49f3
movq -0x30(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x49f3
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xb1f0
testb $0x1, %al
jne 0x49d5
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xb290
movq 0xd61e(%rip), %rdi      # 0x11fc8
leaq 0x77e0(%rip), %rsi      # 0xc191
callq 0x3280
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xb2c0
jmp 0x49f1
movq 0xd5ec(%rip), %rdi      # 0x11fc8
leaq 0x7730(%rip), %rsi      # 0xc113
callq 0x3280
movb $0x0, -0x1(%rbp)
jmp 0x4b36
jmp 0x4a0f
movq 0xd5ce(%rip), %rdi      # 0x11fc8
leaq 0x773a(%rip), %rsi      # 0xc13b
callq 0x3280
movb $0x0, -0x1(%rbp)
jmp 0x4b36
movb $0x0, -0x22(%rbp)
movq 0xd5ae(%rip), %rdi      # 0x11fc8
leaq 0x7739(%rip), %rsi      # 0xc15a
callq 0x3280
movq 0xd5ab(%rip), %rdi      # 0x11fd8
leaq -0x20(%rbp), %rsi
callq 0x3170
movq %rax, %rdi
movq (%rdi), %rax
addq -0x18(%rax), %rdi
callq 0x3320
testb $0x1, %al
jne 0x4a4b
jmp 0x4a51
movb $0x0, -0x22(%rbp)
jmp 0x4a9d
movq 0xd570(%rip), %rdi      # 0x11fc8
leaq 0x7712(%rip), %rsi      # 0xc171
callq 0x3280
movq 0xd56d(%rip), %rax      # 0x11fd8
movq (%rax), %rax
movq 0xd563(%rip), %rdi      # 0x11fd8
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x3460
callq 0x5620
movq %rax, %rsi
movq 0xd549(%rip), %rdi      # 0x11fd8
movl $0xa, %edx
callq 0x3190
movb $0x1, -0x22(%rbp)
cmpl $0x4, -0x20(%rbp)
jg 0x4aa9
cmpl $0x1, -0x20(%rbp)
jge 0x4ac0
movq 0xd518(%rip), %rdi      # 0x11fc8
leaq 0x76dd(%rip), %rsi      # 0xc194
callq 0x3280
movb $0x1, -0x22(%rbp)
jmp 0x4ac2
testb $0x1, -0x22(%rbp)
jne 0x4a13
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x20(%rbp), %esi
callq 0xb210
andb $0x1, %al
movb %al, -0x21(%rbp)
testb $0x1, -0x21(%rbp)
je 0x4b1f
movq 0xd4ca(%rip), %rdi      # 0x11fc8
leaq 0x76a5(%rip), %rsi      # 0xc1aa
callq 0x3280
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
imull $0x64, %ecx, %ecx
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
jmp 0x4b32
movq 0xd4a2(%rip), %rdi      # 0x11fc8
leaq 0x768f(%rip), %rsi      # 0xc1bc
callq 0x3280
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)