Sure! Here's an example of a simple Countryballs game implemented as a single HTML file using JavaScript:
Explanation:
- The game consists of displaying different countryballs on the screen, each represented by an emoji. The player needs to click on the countryball to earn a point and show an alert message displaying the country's name and the current score.
- The `countries` array holds the country objects with their names and corresponding emojis.
- The `score` variable keeps track of the player's score.
- The `displayCountries` function is called to populate the game container with countryballs.
- Each countryball is created dynamically using `document.createElement`, styled with CSS, and appended to the game container.
- An event listener is attached to each countryball to handle the click event and update the score.
- Finally, the `displayCountries` function is called to initially display the countryballs.
You can run the HTML file on any web browser, including smartphones, to play the game. Just tap on the countryballs to earn points and see your score!