{"id":29259045,"url":"https://github.com/glenncai/whack-a-mole","last_synced_at":"2026-05-19T09:09:48.315Z","repository":{"id":132943345,"uuid":"374140413","full_name":"glenncai/whack-a-mole","owner":"glenncai","description":"Microcontrollers and Embedded Systems Laboratory.","archived":false,"fork":false,"pushed_at":"2021-06-07T05:05:56.000Z","size":1610,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-22T15:48:51.643Z","etag":null,"topics":["assembly","c","embedded-systems","kernel","microcontroller"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glenncai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-06-05T14:53:24.000Z","updated_at":"2021-10-03T08:56:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"2760c8ec-a266-43e6-a006-c681c2c34848","html_url":"https://github.com/glenncai/whack-a-mole","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/glenncai/whack-a-mole","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glenncai%2Fwhack-a-mole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glenncai%2Fwhack-a-mole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glenncai%2Fwhack-a-mole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glenncai%2Fwhack-a-mole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glenncai","download_url":"https://codeload.github.com/glenncai/whack-a-mole/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glenncai%2Fwhack-a-mole/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33209614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-19T07:54:09.561Z","status":"ssl_error","status_checked_at":"2026-05-19T07:54:08.508Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assembly","c","embedded-systems","kernel","microcontroller"],"created_at":"2025-07-04T06:13:58.202Z","updated_at":"2026-05-19T09:09:48.275Z","avatar_url":"https://github.com/glenncai.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WHACK-a-Mole Game \n\n### `Microcontrollers and Embedded Systems`\n\n## I. OBJECTIVES\nThe “WHACK-a-Mole!!!” game aims to test players’ responsiveness. The player must tap the keys 1 to 9 if the layer has spotted a mole in the grids. Hit the moles as much as possible within a time range.\n\n### (A) HERE ARE THE DETAILED GAME RULES OF THIS GAME:\n1. After reset, the player will reach the start page of the game. The player will see the game instructions, including the game makers’ name, the game name, and the “PRESS ‘+’ to START GAME”.\n\n2. If the player wishes to start the game, press the “+” key on the keyboard to start the game.\n\n3. After entering the game, you will see a three by three grid. Some blue moles will be randomly pop out from one of the nine grids. Each mole will show up for 1 second. After that, only one mole will appear each second.\n\n4. To evaluate the performance of the player, we have the following calculation of score:\n(i) If a mole is hit, one mark will be awarded.\n(ii) If a mole is missed, no mark will be got.\n(iii) If the grid is empty and the player hit nothing, one mark will be deducted.\n(iv) The minimum possible mark is 0 mark (no negative mark setting), and the maximum possible mark is 60 marks.\n\n5. The duration of each game round is 1 minute.\n\n6. After the game ends, no moles are pop up in the grid, and the “GAME OVER” sign is shown. The buzzer will sound to indicate the game is over.\n\n7. Reset the game by pressing the reset button (We cannot finish the restart of the game by pressing the other key successfully due to the time limit).\n\n### (B) LIST OF HARDWARE USED:\n`LED:` Use LED to indicate whether a mole is hit. If a mole is hit, green light (DS1) will light. If nothing is hit (hit the blank cave/grid), the red light will light.\n\n`Reset Button:` For uploading the code to the board and reset.\n\n`TFTLCD:` Used as the primary display element for gaming graphical interface.\n\n`Interrupt:` We use the PS2 keyboard as the interrupt. First, press the “+” key will start the game. Then, press “1” to “9” keys (total nine keys) to hit the moles to get the score.\n\n`Two Timers (TIM3 \u0026 TIM4):`\nTIM3 is used to count the remaining time down of each game round. (From the 60s to 0s)\nTIM4 is used to display the mole locations at each second.\n\n`USART:` Used for debugging and uploading the program code to the board.\n\n`Buzzer:` Used to indicate the game over the condition.\n\n### (C) PROGRAM FLOW:\n\n\u003cimg src=\"img/project.jpg\" width = \"90%\"\u003e\n\n---\n\n## II. IMPLEMENTATION\nIn this part, we will illustrate several key functions in our code to help explain how the hardware is applied to our game in a detailed manner.\n(`We will ignore this part in GitHub`)\n\n--- \n\n## III. TESTING, DIFFICULTIES AND SOLUTIONS\nFirst, we tested the game introduction page, the countdown before the game started, the game main page and the game over page about 30 times, and they all worked normally.\n\nThen we started to test the effect of the game. At first we imagined that the player would add one point after hitting the mole. Unfortunately, we found that the player would add two points after hitting the mole. After checking, we found that the global moleflag that was originally defined was reset in another function. Therefore, we can solve this problem by setting it to -1.\nBesides, when the mole appeared and disappeared, we found that the screen was still mixed with other colours and was not completely refreshed. This greatly affects the user experience. Therefore, we judged in the if else statement that if it is not hit, the other caves maintain their original colors. This is solved.\nMoreover, we encountered great difficulties in formulating moles to appear randomly, and finally we thought of defining a constantly changing seed (rnd = rand()% 9) in while(1) to judge 1-9 caves. This solves this problem perfectly.\n\nFinally, we still have two difficulties that have not yet been resolved due to the relationship of time. The first one is about the LED light. We assume that when the player hits the mole, it will show a green light. When the player hits empty cave, a red light will be displayed. We think this is a problem with the keyboard because when we press hard, the green light and red light will not appear at the same time, it is perfect and working. But when we press lightly, sometimes these two lights will appear simultaneously, which is very strange. This is well worth continuing discussion. The second is about the problem of restarting the game except by pressing the reset button. We tried to let the user press key '0' in while(1) and then change the flag of the global variable to restart the game. But the value of the flag does not change after pressing. Therefore, we will continue to try to solve this problem in the follow-up.\n\n---\n\n## IV. SUMMARY\nIn this mini-project of making a \"WHACK-a-Mole\" game, we have used most of the 5 labs' components and computer organization knowledge.\n1. We have used the LED and buzzer attached to make effects of the game to attract the players' attention. We need to put them in the code where it is appropriate.\n2. We have used the USART cable for debugging and uploading the code smoothly to refine our game frequently and conveniently.\n3. We have used the TFTLCD (the monitor) to display the game interface and make it more colourful. We have learnt a lot about designing our game by drawing lines and pictures by getting the width and height in pixels writing C codes. We have also learnt how to apply ASCII code for typing Englishh words, creating own characters or objects using pixel drawing and mixing colors by trying different hex number representations.\n4. We have used the PS2 keyboard for making several interrupts for players to have more interactions with the game. We learnt that keys have their respective hex code for transmission. And hex code of 0xF0 is for key release. So using different keys can make the game more interesting.\n5. Using timers in the game can prevent the game from being endless. The player can get the duration of a game round accurately. Moreover, it makes the randomization and show-up time of the game object more regular and in order. Timer also increases flexibility since the game producer can adjust the timer counting frequency. It replaces the delay() function as timers allow interrupts of the game while delay() function don't.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglenncai%2Fwhack-a-mole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglenncai%2Fwhack-a-mole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglenncai%2Fwhack-a-mole/lists"}