Programming challenge - a Snake game

This is one of the benchmark programs I am using to compare one language to another. Try building this game in your language of choice, and submit your program and we will analyze your code and show how it stacks up compared to other implementations. There is a live programming tutorial on YouTube that builds a more rudimentary version of the snake program in under 5 minutes. However, that 5 minute program has numerous flaws and is only about half of this specification. It does show how flexible and fast JavaScript is. 

The game runs at 6 frames per second, and the snake moves one cell per frame.  If the snake moves into the apple the length is increased by one, a crunch sound is emitted, and the apple is moved to a new cell. If the snake crosses over itself, then a beep is emitted and the part of the snake from that cell onward is erased. The snake wraps around the board in all four directions.

            The playing board, drawn solid black, is subdivided into square cells of 42 points. At the start, the snake is set to length 1 and positioned at cell (4,4). The apple, which is the goal of the snake to eat, is one cell drawn as a circle in HTML color crimson, and is placed at a random location on the board.

 

At the start of the game the snake is paused. As soon as an arrow key is pressed, the snake begins to move in that direction, and leaves a trail behind. Initially the trail is limited to 5 cells total. If the snake moves into the Apple, the snake's length grows by 1. Once the apple is eaten, it is immediately respawned into a random new cell. The apple may end up on occasion placed inside the body of the snake, however, the snake only is considered to have eaten the apple if the head moves onto the apple.  The snake cells are drawn as 40 pt squares with 2pts on the right and bottom to create a separation. The snake cells are drawn in alternating colors lime green and lawn green. The head of the snake is drawn as a rounded rectangle with a corner radius of 8 pt and a border of 2 pt dark green. The remaining cells of the snake are drawn as a rounded rectangle with 2 pt corner radius.

            The only input to the game is the keyboard. The arrow keys change the direction of the snake, however, to prevent frustration the player is not allowed to move the snake head back into itself. So if the snake is traveling east, the attempted movement west is ignored. A command to move in the direction already in motion is ignored. To permit fast maneuvers the direction inputs are queued, so that one can do WEST - SOUTH - EAST to perform a 180 degree turn in 3 consecutive frames.  Pressing the space bar pauses or resumes the game.

            As the snake grows and shrinks, the current size and high score is reported at the top of the screen as a topmost layer at 30% opacity, centered in 28 pt black text, for example: "8 high:22".

            The default starting window size is 700 x 700 interior pixels. If the user resizes the window, the game is reset back to the starting state.

            Note: since the window size will not usually be an even multiple of 42 points, the cells are slightly stretched to not have any dead space leftover.  So the program must first figure out how many whole 42 point cells can fit in the X and Y directions, then divide the width and height by the number of cells in each direction.

To help you with your game, here is the specification in PDF format and the sound files as a zip file.