// File: justinjo[P]Pacman/game.cpp
// Function: Game::play_level()
void Game::play_level()
{
        char move;
        while (p.is_alive() && !level_over){
                // Pacman moves
                move = getacharnow(2);
                if (move == CMD_QUIT){
                        level_over = true;
                        p.die();
                        return;
                } else if (move == CHEAT){
                        level_over = true;
                }
                if (p.move(board, move)){
                        eat_dot(p.get_row(), p.get_col());
                        level_over = !(p.get_dots() < level*DOTS_PER_LEVEL);
                }
                if (p.is_alive())   // Show Ghost if Pacman is eaten
                        p.place_on_board(board);
                screen_home();
                print_board();
                
                // Ghosts move
                if (p.get_num_moves()%GHOST_FREQ==0 && !level_over){
                        for (int i=0; i<NUM_GHOSTS; i++){
                                if (ghosts[i].move(board, p.get_row(),
                                                          p.get_col()))
                                        p.die();        // Pacman eaten
                                ghosts[i].place_on_board(board);
                        }
                }
                screen_home();
                print_board();
        }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2bc0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x19(%rbp)
jne 0x32a2
jmp 0x32b1
movq -0x18(%rbp), %rax
movb 0x508(%rax), %al
xorb $-0x1, %al
movb %al, -0x19(%rbp)
movb -0x19(%rbp), %al
testb $0x1, %al
jne 0x32bd
jmp 0x349f
movl $0x2, %edi
callq 0x3d80
movb %al, -0x9(%rbp)
movsbl -0x9(%rbp), %eax
cmpl $0x71, %eax
jne 0x32ef
movq -0x18(%rbp), %rdi
movb $0x1, 0x508(%rdi)
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2a50
jmp 0x349f
movsbl -0x9(%rbp), %eax
cmpl $0x47, %eax
jne 0x3303
movq -0x18(%rbp), %rax
movb $0x1, 0x508(%rax)
jmp 0x3305
movq -0x18(%rbp), %rsi
movq %rsi, %rdi
addq $0x50c, %rdi            # imm = 0x50C
movsbl -0x9(%rbp), %edx
callq 0x2680
testb $0x1, %al
jne 0x3322
jmp 0x3381
movq -0x18(%rbp), %rdi
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2b20
movq -0x18(%rbp), %rdi
movl %eax, -0x20(%rbp)
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2b00
movl -0x20(%rbp), %esi
movq -0x18(%rbp), %rdi
movl %eax, %edx
callq 0x3820
movq -0x18(%rbp), %rdi
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2c00
movl %eax, %ecx
movq -0x18(%rbp), %rax
imull $0x5, 0x504(%rax), %edx
cmpl %edx, %ecx
setl %cl
xorb $-0x1, %cl
andb $0x1, %cl
movb %cl, 0x508(%rax)
movq -0x18(%rbp), %rdi
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2bc0
testb $0x1, %al
jne 0x3397
jmp 0x33aa
movq -0x18(%rbp), %rsi
movq %rsi, %rdi
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2a70
callq 0x3f30
movq -0x18(%rbp), %rdi
callq 0x3570
movq -0x18(%rbp), %rdi
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2aa0
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x348c
movq -0x18(%rbp), %rax
testb $0x1, 0x508(%rax)
jne 0x348c
movl $0x0, -0x10(%rbp)
cmpl $0x4, -0x10(%rbp)
jge 0x348a
movq -0x18(%rbp), %rdi
movq %rdi, %rax
addq $0x524, %rax            # imm = 0x524
movslq -0x10(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2b20
movq -0x18(%rbp), %rdi
movl %eax, -0x24(%rbp)
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2b00
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
movl %eax, %ecx
callq 0x2cd0
testb $0x1, %al
jne 0x344e
jmp 0x345e
movq -0x18(%rbp), %rdi
addq $0x50c, %rdi            # imm = 0x50C
callq 0x2a50
movq -0x18(%rbp), %rsi
movq %rsi, %rdi
addq $0x524, %rdi            # imm = 0x524
movslq -0x10(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
callq 0x2e20
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x33f1
jmp 0x348c
callq 0x3f30
movq -0x18(%rbp), %rdi
callq 0x3570
jmp 0x3284
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)