Sure! Here's an example implementation of the game you described:
You can copy and paste the above code into a single HTML file and open it in a browser to play the game. Use the arrow keys to move the square through the maze, and press the space bar to shoot at and delete the ghost when it's adjacent to you. Your score increases by 1 if you reach the green flag, and resets to 0 if you collide with the ghost or fail to reach the green flag.