// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %rdi, 0x8(%rsp)
movq 0x2385e(%rip), %rbx     # 0x2efc8
leaq 0x18(%rsp), %r13
leaq 0x18c13(%rip), %r15     # 0x24389
movq 0x8(%rsp), %r14
movq (%r14), %rdi
movq 0x10(%r14), %rsi
callq 0xf30e
movl $0x440009, %ebp         # imm = 0x440009
callq 0x10684
movzbl %al, %ecx
addl $-0x61, %ecx
cmpl $0x16, %ecx
ja 0xb78c
btl %ecx, %ebp
jb 0xb811
cmpl $0x8, %ecx
je 0xb87c
cmpl $0x10, %ecx
jne 0xb78c
movl $0x25, %edx
movq %rbx, %rdi
leaq 0x18bd8(%rip), %rsi     # 0x24396
callq 0x31e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
callq 0x10684
cmpb $0xa, %al
je 0xbb6d
movzbl %al, %eax
cmpl $0x59, %eax
je 0xbb6d
cmpl $0x79, %eax
jne 0xb776
jmp 0xbb6d
movq (%r14), %rdi
movsbl %al, %esi
callq 0x100aa
movl %eax, %ebp
movq (%r14), %rdi
callq 0x10232
testb %al, %al
je 0xb844
movq 0x8(%r14), %rdi
movq 0x10(%r14), %rsi
callq 0x225f6
movq (%r14), %rdi
callq 0x10236
jmp 0xb776
testb %bpl, %bpl
je 0xb776
movq 0x8(%rsp), %r14
movq (%r14), %rdi
callq 0x10232
testb %al, %al
jne 0xbb17
callq 0xaec0
testb %al, %al
je 0xbb17
movq %r14, %rdi
callq 0xbe94
jmp 0xb776
movl $0x1f, %edx
movq %rbx, %rdi
leaq 0x18a91(%rip), %rsi     # 0x2431c
callq 0x31e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x10(%r14), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0x8, %rcx
je 0xb907
movl $0x30, %edx
movq %rbx, %rdi
leaq 0x18a65(%rip), %rsi     # 0x2433c
callq 0x31e0
movq 0x10(%r14), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x3, %rsi
movq %rbx, %rdi
callq 0x30f0
movl $0x3, %edx
movq %rax, %rdi
leaq 0x18ab6(%rip), %rsi     # 0x243b8
callq 0x31e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl $0x1, %ebp
xorl %r12d, %r12d
movl $0x1b, %edx
movq %rbx, %rdi
leaq 0x18a28(%rip), %rsi     # 0x2436d
callq 0x31e0
movq 0x10(%r14), %rax
movq (%rax), %rax
movl %ebp, 0x14(%rsp)
movl %ebp, %ecx
movq -0x8(%rax,%rcx,8), %rsi
movq %r13, %rdi
callq 0x10812
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq 0x31e0
movq %rax, %rbp
movl $0x4, %edx
movq %rax, %rdi
leaq 0x1b45c(%rip), %rsi     # 0x26de4
callq 0x31e0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xb9fb
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31b0
movb $0x20, %bpl
xorl %r14d, %r14d
cmpb $0xa, %bpl
jne 0xba17
movl $0x7, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x31e0
movl %r12d, 0x18(%rsp)
movq %r13, %rsi
movl $0x1, %edx
callq 0xbbde
callq 0x10684
movl %eax, %ebp
cmpb $0x77, %al
sete %al
testl %r12d, %r12d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xba47
decl %r12d
jmp 0xbab1
cmpb $0x73, %bpl
sete %al
cmpl $0x2, %r12d
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xba61
incl %r12d
jmp 0xbab1
cmpb $0x31, %bpl
jl 0xbaab
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
movzbl %bpl, %eax
sarq $0x3, %rcx
addq $0x30, %rcx
cmpq %rax, %rcx
jb 0xbab1
leal -0x30(%rbp), %eax
movzbl %al, %eax
movl %eax, 0x14(%rsp)
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x188f0(%rip), %rsi     # 0x24391
callq 0x31e0
movb $0x1, %r14b
jmp 0xbab1
cmpb $0xa, %bpl
je 0xbadc
movl $0x7, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x31e0
cmpb $0x65, %bpl
je 0xbad2
movl %r14d, %eax
andb $0x1, %al
je 0xba17
cmpb $0x65, %bpl
je 0xb776
testb $0x1, %r14b
jne 0xbb09
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movl 0x14(%rsp), %ecx
movq -0x8(%rax,%rcx,8), %rsi
leal 0x1(%r12), %eax
movswl %ax, %edx
callq 0xbe4e
jmp 0xba01
movq 0x8(%rsp), %r14
movl 0x14(%rsp), %ebp
jmp 0xb936
movq (%r14), %rdi
callq 0x10232
testb %al, %al
jne 0xb776
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0xb776
xorl %r14d, %r14d
movq (%rax,%r14,8), %rdi
callq 0x11180
incq %r14
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
ja 0xbb40
jmp 0xb776
leaq 0x18848(%rip), %rsi     # 0x243bc
movl $0x13, %edx
movq %rbx, %rdi
callq 0x31e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xbbd6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31b0
movq %rbx, %rdi
callq 0x32f0