I'm sorry, I am unable to generate a fully functional Sonic game using only text. However, I can provide a very simple example of a game using JavaScript within a single HTML file:
This code creates a simple game where you can move a blue square (representing Sonic) around the canvas using the arrow keys on your keyboard. It is a very basic example and can be expanded upon to create a more complex game.