Untitled conversation
- Userqbasic
- Assistant
CLS
RANDOMIZE TIMER
p1health = 100
p2health = 100
p1wood = 0
p2wood = 0
p1iron = 0
p2iron = 0
DO
FOR player = 1 TO 2
CLS
PRINT "Player"; player; "'s turn"
PRINT "Health: "; p1health; " vs "; p2health
IF player = 1 THEN
PRINT "Your resources - Wood:"; p1wood; " Iron:"; p1iron
ELSE
PRINT "Your resources - Wood:"; p2wood; " Iron:"; p2iron
END IF
PRINT "1. Mine wood"
PRINT "2. Mine iron"
PRINT "3. Attack with wood"
PRINT "4. Attack with iron"
PRINT "5. Spin the wheel"
INPUT "Choose action (1-5): ", choice
IF choice = 1 THEN
woodGain = INT(RND * 8)
IF player = 1 THEN p1wood = p1wood + woodGain ELSE p2wood = p2wood + woodGain
PRINT "You gained"; woodGain; "wood!"
ELSEIF choice = 2 THEN
ironGain = INT(RND * 4)
IF player = 1 THEN p1iron = p1iron + ironGain ELSE p2iron = p2iron + ironGain
PRINT "You gained"; ironGain; "iron!"
ELSEIF choice = 3 THEN
IF (player = 1 AND p1wood >= 5) OR (player = 2 AND p2wood >= 5) THEN
damage = INT(RND * 11)
criticalHit = (RND < .2) ' 20% chance for critical hit
IF criticalHit THEN damage = damage * 2
IF player = 1 THEN
p1wood = p1wood - 5
p2health = p2health - damage
ELSE
p2wood = p2wood - 5
p1health = p1health - damage
END IF
PRINT "You dealt"; damage; "damage with wood!"
IF criticalHit THEN PRINT "CRITICAL HIT!"
ELSE
PRINT "Not enough wood! You need 5 wood to attack."
END IF
ELSEIF choice = 4 THEN
IF (player = 1 AND p1iron >= 3) OR (player = 2 AND p2iron >= 3) THEN
damage = INT(RND * 10) + 6
criticalHit = (RND < .2) ' 20% chance for critical hit
IF criticalHit THEN damage = damage * 2
IF player = 1 THEN
p1iron = p1iron - 3
p2health = p2health - damage
ELSE
p2iron = p2iron - 3
p1health = p1health - damage
END IF
PRINT "You dealt"; damage; "damage with iron!"
IF criticalHit THEN PRINT "CRITICAL HIT!"
ELSE
PRINT "Not enough iron! You need 3 iron to attack."
END IF
ELSEIF choice = 5 THEN
healthChange = INT(RND * 31) - 15
woodChange = INT(RND * 12) - 5
ironChange = INT(RND * 7) - 3
IF player = 1 THEN
p1health = p1health + healthChange
p1wood = p1wood + woodChange
p1iron = p1iron + ironChange
ELSE
p2health = p2health + healthChange
p2wood = p2wood + woodChange
p2iron = p2iron + ironChange
END IF
PRINT "Wheel spin results:"
PRINT "Health change:"; healthChange
PRINT "Wood change:"; woodChange
PRINT "Iron change:"; ironChange
END IF
IF p1health <= 0 OR p2health <= 0 THEN EXIT FOR
PRINT "Press any key to continue..."
WHILE INKEY$ = "": WEND
NEXT player
IF p1health <= 0 OR p2health <= 0 THEN EXIT DO
LOOP
CLS
IF p1health <= 0 THEN
PRINT "Player 2 wins!"
ELSE
PRINT "Player 1 wins!"
END IF
PRINT "Final Health: "; p1health; " vs "; p2health
PRINT "Game Over!"
does this have any error in syntax, game logic, broken mechanism or any over powered thing. Check the whole code before responding. Are there any suggestions on improving it. Tell me.
The code you've provided is a fun and engaging turn-based game written in QBasic. Here's a detailed analysis of your code, including potential issues and suggestions for improvement:
Analysis:
Upon reviewing your code, there are no syntax errors. All the structures like loops, conditionals, and variable assignments are correctly used according to QBasic standards.
Conclusion:
Your code is syntactically correct.
Analysis:
In the wood attack, damage is calculated as:
damage = INT(RND * 11)
Since RND returns a value between 0 and less than 1, INT(RND * 11) can result in a value between 0 and 10, inclusive. This means there's a possibility of dealing 0 damage, which can be frustrating for players who spend resources but don't inflict any harm.
Suggestion:
Adjust the damage calculation to ensure a minimum of 1 damage:
damage = INT(RND * 10) + 1 ' Damage ranges from 1 to 10
Analysis:
When spinning the wheel, players can lose resources, potentially resulting in negative values for health, wood, or iron.
Suggestion:
Add checks after the wheel spin to prevent resources from becoming negative:
' After updating resources
IF player = 1 THEN
IF p1health < 0 THEN p1health = 0
IF p1wood < 0 THEN p1wood = 0
IF p1iron < 0 THEN p1iron = 0
ELSE
IF p2health < 0 THEN p2health = 0
IF p2wood < 0 THEN p2wood = 0
IF p2iron < 0 THEN p2iron = 0
END IF
Analysis:
Suggestions:
Balance Resource Gain:
Adjust Attack Costs:
Ensure Meaningful Damage:
Analysis:
The wheel spin can significantly impact the game due to the potential for large health changes (+/-15). While the randomness adds excitement, it might overshadow other strategic choices.
Suggestions:
Reduce Health Change Range:
-10 to +10, to lessen the impact.healthChange = INT(RND * 21) - 10 ' Now ranges from -10 to +10
Limit Resource Loss:
Provide Feedback on Insufficient Resources:
PRINT "Not enough wood! You need 5 wood to attack. You have"; p1wood; "wood."
Use Subroutines for Reusability:
Enhance User Interaction:
Add Health Caps:
IF player = 1 AND p1health > 100 THEN p1health = 100
IF player = 2 AND p2health > 100 THEN p2health = 100
Improve Randomness Seeding:
RANDOMIZE TIMER is correct, but it can be placed inside the DO loop to ensure different seeds each game.Your game is well-constructed and offers engaging gameplay. By addressing the minor issues above, you can improve the balance and enjoyment of the game. Implementing these suggestions will enhance player experience by ensuring fairness and preventing potential frustrations due to negative resources or ineffective attacks.
Keep coding and have fun refining your game!
Not yet included in a published release.