-
Notifications
You must be signed in to change notification settings - Fork 748
Create JJk.html #1795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create JJk.html #1795
Conversation
Summary of ChangesHello @bkhiemm, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new standalone HTML file that serves as a basic interactive web game. The game, themed around 'Jujutsu Kaisen', allows users to engage in a simple boss battle by selecting different attack moves, which then dynamically updates the boss's health and provides real-time feedback on the game's state. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new HTML file for a simple browser-based game. The code is a good starting point, but I've identified a few key areas for improvement in the JavaScript logic. My review focuses on fixing a critical bug where the game doesn't end correctly, improving the user experience by adjusting how messages are displayed, and enhancing code maintainability by suggesting the removal of hardcoded 'magic numbers'. These changes will make the game more robust and easier to build upon.
|
|
||
| document.getElementById('hp-fill').style.width = bossHP + "%"; | ||
| document.getElementById('message').innerText = msg; | ||
| if(bossHP <= 0) document.querySelector('#game-box').innerHTML += "<h3>VICTORY!</h3>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two issues with the game's end state:
- The attack buttons are not disabled after the boss is defeated. This allows the player to keep clicking them, which repeatedly appends "VICTORY!" messages.
- Using
innerHTML += ...is inefficient for appending elements and can have unintended side effects. It's better practice to create and append a new element usingdocument.createElement()andappendChild().
This suggestion fixes both issues.
if(bossHP <= 0) {
const victoryEl = document.createElement('h3');
victoryEl.textContent = "VICTORY!";
document.querySelector('#game-box').appendChild(victoryEl);
document.querySelectorAll('button').forEach(b => b.disabled = true);
}| let bossHP = 100; | ||
| function attack(move) { | ||
| let damage = 0; | ||
| let msg = ""; | ||
| if(move === 'Black Flash') { | ||
| if(Math.random() > 0.3) { | ||
| damage = 35; | ||
| msg = "KHOẢNH KHẮC CỦA TIA CHỚP ĐEN! Bạn gây " + damage + " sát thương!"; | ||
| } else { | ||
| msg = "Hắc thiểm thất bại! Bạn bị phản đòn!"; | ||
| } | ||
| } else { | ||
| damage = 15; | ||
| msg = "Bạn dùng Kính Đấm trúng đích! Gây " + damage + " sát thương."; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script uses several "magic numbers" and strings (e.g., 100, 'Black Flash', 0.3, 35, 15). Hardcoding these values makes the code harder to read, maintain, and balance. Consider defining them as constants at the top of the script with descriptive names. This will make your game logic much clearer and easier to tweak in the future.
For example:
const BOSS_MAX_HP = 100;
const BLACK_FLASH_HIT_CHANCE = 0.7; // (1 - 0.3)
const BLACK_FLASH_DAMAGE = 35;
// etc.| if(bossHP <= 0) { | ||
| bossHP = 0; | ||
| msg = "CHÚC MỪNG! Bạn đã thanh tẩy Nguyền hồn!"; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The victory message ("CHÚC MỪNG! ...") overwrites the message from the final, winning attack. This means the player doesn't get to see which attack finished the fight. It would provide a better user experience to append the victory message to the attack message instead of replacing it entirely.
| if(bossHP <= 0) { | |
| bossHP = 0; | |
| msg = "CHÚC MỪNG! Bạn đã thanh tẩy Nguyền hồn!"; | |
| } | |
| if(bossHP <= 0) { | |
| bossHP = 0; | |
| msg += " CHÚC MỪNG! Bạn đã thanh tẩy Nguyền hồn!"; | |
| } |
No description provided.