// File: /workspace/github_cpp_makefile_star2_O2/MichaelXanth[P]RPG_Game/Game/Game.cpp
// Function: Game::Play()
void Game::Play(void)
{
    bool gameover = false;

    while(gameover == false) {

        grid.DisplayGrid(heroes);

        char input = GetInput();

        // Enters inventory
        if (input == 'i') {

            int herochoice = 1;
            int arrow      = 0;

            cout << "Press 'e' to exit the inventory" << endl;

            if (heroes.size() != 1)
                cout << "Switch between heroes using numbers in range [1-" << heroes.size() << "]: ";

            cout << endl;

            while(true) {
                bool changeHero = false;
                char selection = ' ';

                cout << "\nSelected Hero: \033[38;5;220m" << heroes[herochoice - 1]->GetName() << "\033[0m" << endl << endl;

                while(true) {
                    if (selection == '\n')
                        cout << "\033[3A\033[J";

                    // Prints and handles the arrow menu
                    do {

                        DisplayActions(arrow,true);

                        selection = getch();

                        if (selection == 'w' && arrow)
                            arrow--;
                        else if (selection == 's' && arrow < 2)
                            arrow++;
                        else if (selection > '0' && selection <= '0' + heroes.size()) {
                            herochoice = selection - '0';
                            changeHero = true;
                            cout << "\033[3A";
                        }

                        if (selection != '\n')
                            cout << "\033[3A\033[J";

                    } while(selection != 'e' && selection != '\n' && changeHero != true);

                    if (selection == 'e' || changeHero == true)
                        break;

                    OpenInventory(*heroes[herochoice - 1] , arrow + 1);
                }

                if (selection == 'e')
                    break;

            }
        
        } else if (input == 'q') {
            char ch;
            cout << "Do you want to quit the game? [y/n]: " << endl;
            ch = getch();
            if (ch == 'y' || ch == 'Y' || ch == '\n')
                gameover = true;
        
        } else {
            bool moved = false;

            moved = grid.MoveHeroes(input);  

            // If the heroes are inside the store then the store menu opens
            if (grid.IsInStore() == true) {
                Trade();  
                grid.HeroExitedStore();
            
            // If the conditions are met a battle starts
            } else if (moved == true && grid.IsInStore() == false && Battle::BattleHappens() == true) {
                StartBattle(); 
            
            /* If a battle does not happen then the heroes restore some of their HP and some of their MP*/
            } else if (moved == true && grid.IsInStore() == false) { 
                for (int k = 0; k < heroes.size(); k++)
                    heroes[k]->EndTurnRefill();
            }
        }
    }
    cout << "Thanks for playing!" << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbp
xorl %ebx, %ebx
movq 0x1d7da(%rip), %r14     # 0x26fc8
leaq 0x28(%rsp), %r15
leaq 0x11b8f(%rip), %r13     # 0x1b389
movq %rdi, 0x10(%rsp)
testb %bl, %bl
jne 0x9aef
movq (%rbp), %rdi
movq 0x10(%rbp), %rsi
callq 0xc1a0
callq 0x97b6
cmpb $0x71, %al
je 0x9a07
movzbl %al, %ecx
cmpl $0x69, %ecx
jne 0x9a3f
movq %rbx, 0x18(%rsp)
movq %r14, %rdi
leaq 0x11ae0(%rip), %rsi     # 0x1b31c
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0x8, %rcx
je 0x988f
movq %r14, %rdi
leaq 0x11ad8(%rip), %rsi     # 0x1b33c
callq 0x31d0
movq 0x10(%rbp), %rcx
movq 0x8(%rcx), %rsi
subq (%rcx), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
leaq 0x11b2e(%rip), %rsi     # 0x1b3b8
callq 0x31d0
movq %r14, %rdi
callq 0x30d0
xorl %ebx, %ebx
pushq $0x1
popq %r12
movq %r14, %rdi
leaq 0x11ac6(%rip), %rsi     # 0x1b36d
callq 0x31d0
movq %rax, 0x20(%rsp)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movl %r12d, 0xc(%rsp)
movl %r12d, %ecx
movq -0x8(%rax,%rcx,8), %rsi
movq %r15, %rdi
callq 0xced6
movq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x3190
movq %rax, %rdi
leaq 0x14500(%rip), %rsi     # 0x1dde4
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x30d0
movq %r15, %rdi
callq 0x30c0
movb $0x20, %r12b
xorl %ebp, %ebp
cmpb $0xa, %r12b
jne 0x9917
movq %r14, %rdi
movq %r13, %rsi
callq 0x31d0
movl %ebx, 0x28(%rsp)
movq %r15, %rsi
pushq $0x1
popq %rdx
callq 0x9b2e
callq 0xcd74
movl %eax, %r12d
cmpb $0x77, %al
sete %al
testl %ebx, %ebx
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x9943
decl %ebx
jmp 0x99a8
cmpb $0x73, %r12b
sete %al
cmpl $0x2, %ebx
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x995b
incl %ebx
jmp 0x99a8
cmpb $0x31, %r12b
jl 0x99a2
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
movzbl %r12b, %eax
sarq $0x3, %rcx
addq $0x30, %rcx
cmpq %rax, %rcx
jb 0x99a8
leal -0x30(%r12), %eax
movzbl %al, %eax
movl %eax, 0xc(%rsp)
movq %r14, %rdi
leaq 0x119f9(%rip), %rsi     # 0x1b391
callq 0x31d0
movb $0x1, %bpl
jmp 0x99a8
cmpb $0xa, %r12b
je 0x99cd
movq %r14, %rdi
movq %r13, %rsi
callq 0x31d0
cmpb $0x65, %r12b
je 0x99c3
movl %ebp, %eax
andb $0x1, %al
je 0x9917
cmpb $0x65, %r12b
je 0x9a71
testb $0x1, %bpl
jne 0x99f8
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movl 0xc(%rsp), %ecx
movq -0x8(%rax,%rcx,8), %rsi
leal 0x1(%rbx), %eax
movswl %ax, %edx
callq 0x9c6a
jmp 0x9906
movq 0x10(%rsp), %rbp
movl 0xc(%rsp), %r12d
jmp 0x989d
movq %r14, %rdi
leaq 0x11985(%rip), %rsi     # 0x1b396
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
callq 0xcd74
cmpb $0xa, %al
je 0x9a38
movzbl %al, %eax
cmpl $0x79, %eax
je 0x9a38
cmpl $0x59, %eax
jne 0x97ff
movb $0x1, %bl
jmp 0x97ff
movq (%rbp), %rdi
movsbl %al, %esi
callq 0xc942
movl %eax, %r12d
movq (%rbp), %rdi
callq 0xcab6
testb %al, %al
je 0x9a80
movq %rbp, %rdi
callq 0x9c9a
movq (%rbp), %rdi
callq 0xcaba
jmp 0x97ff
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %rbx
jmp 0x97ff
testb %r12b, %r12b
je 0x97ff
movq (%rbp), %rdi
callq 0xcab6
testb %al, %al
jne 0x9aac
callq 0x9108
testb %al, %al
je 0x9aac
movq %rbp, %rdi
callq 0x9cb0
jmp 0x97ff
movq (%rbp), %rdi
callq 0xcab6
testb %al, %al
jne 0x97ff
movq %rbx, %r12
xorl %ebx, %ebx
movq 0x10(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
jbe 0x9ae7
movq (%rax,%rbx,8), %rdi
callq 0xd646
incq %rbx
jmp 0x9ac2
movq %r12, %rbx
jmp 0x97ff
movq 0x1d4d2(%rip), %rdi     # 0x26fc8
leaq 0x118bf(%rip), %rsi     # 0x1b3bc
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x3330