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
PRINT "You gained"; woodGain; "wood!"
PRINT "Total wood: "; p1wood
ELSE
p2wood = p2wood + woodGain
PRINT "You gained"; woodGain; "wood!"
PRINT "Total wood: "; p2wood
END IF
ELSEIF choice = 2 THEN
ironGain = INT(RND * 4)
IF player = 1 THEN
p1iron = p1iron + ironGain
PRINT "You gained"; ironGain; "iron!"
PRINT "Total iron: "; p1iron
ELSE
p2iron = p2iron + ironGain
PRINT "You gained"; ironGain; "iron!"
PRINT "Total iron: "; p2iron
END IF
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
PRINT "You dealt"; damage; "damage with wood!"
IF criticalHit THEN PRINT "CRITICAL HIT!"
PRINT "Remaining wood: "; p1wood
IF p2health <= 0 THEN
p2health = 0
GOTO GameOver
END IF
ELSE
p2wood = p2wood - 5
p1health = p1health - damage
PRINT "You dealt"; damage; "damage with wood!"
IF criticalHit THEN PRINT "CRITICAL HIT!"
PRINT "Remaining wood: "; p2wood
IF p1health <= 0 THEN
p1health = 0
GOTO GameOver
END IF
END IF
ELSE
IF player = 1 THEN
PRINT "Not enough wood! You need 5 wood to attack. You have"; p1wood; "wood."
ELSE
PRINT "Not enough wood! You need 5 wood to attack. You have"; p2wood; "wood."
END IF
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
PRINT "You dealt"; damage; "damage with iron!"
IF criticalHit THEN PRINT "CRITICAL HIT!"
PRINT "Remaining iron: "; p1iron
IF p2health <= 0 THEN
p2health = 0
GOTO GameOver
END IF
ELSE
p2iron = p2iron - 3
p1health = p1health - damage
PRINT "You dealt"; damage; "damage with iron!"
IF criticalHit THEN PRINT "CRITICAL HIT!"
PRINT "Remaining iron: "; p2iron
IF p1health <= 0 THEN
p1health = 0
GOTO GameOver
END IF
END IF
ELSE
IF player = 1 THEN
PRINT "Not enough iron! You need 3 iron to attack. You have"; p1iron; "iron."
ELSE
PRINT "Not enough iron! You need 3 iron to attack. You have"; p2iron; "iron."
END IF
END IF
ELSEIF choice = 5 THEN
healthChange = INT(RND * 31) - 15 ' Ranges from -15 to +15
woodChange = INT(RND * 12) - 5 ' Ranges from -5 to +6
ironChange = INT(RND * 7) - 3 ' Ranges from -3 to +3
IF player = 1 THEN
p1health = p1health + healthChange
p1wood = p1wood + woodChange
p1iron = p1iron + ironChange
IF p1wood < 0 THEN p1wood = 0
IF p1iron < 0 THEN p1iron = 0
IF p1health > 100 THEN p1health = 100
IF p1health <= 0 THEN
p1health = 0
PRINT "Wheel spin results:"
PRINT "Health change:"; healthChange
PRINT "Wood change:"; woodChange
PRINT "Iron change:"; ironChange
PRINT "Total health: "; p1health
PRINT "Total wood: "; p1wood
PRINT "Total iron: "; p1iron
GOTO GameOver
END IF
PRINT "Wheel spin results:"
PRINT "Health change:"; healthChange
PRINT "Wood change:"; woodChange
PRINT "Iron change:"; ironChange
PRINT "Total health: "; p1health
PRINT "Total wood: "; p1wood
PRINT "Total iron: "; p1iron
ELSE
p2health = p2health + healthChange
p2wood = p2wood + woodChange
p2iron = p2iron + ironChange
IF p2wood < 0 THEN p2wood = 0
IF p2iron < 0 THEN p2iron = 0
IF p2health > 100 THEN p2health = 100
IF p2health <= 0 THEN
p2health = 0
PRINT "Wheel spin results:"
PRINT "Health change:"; healthChange
PRINT "Wood change:"; woodChange
PRINT "Iron change:"; ironChange
PRINT "Total health: "; p2health
PRINT "Total wood: "; p2wood
PRINT "Total iron: "; p2iron
GOTO GameOver
END IF
PRINT "Wheel spin results:"
PRINT "Health change:"; healthChange
PRINT "Wood change:"; woodChange
PRINT "Iron change:"; ironChange
PRINT "Total health: "; p2health
PRINT "Total wood: "; p2wood
PRINT "Total iron: "; p2iron
END IF
ELSE
PRINT "Invalid choice! Please select an option from 1 to 5."
END IF
PRINT "Press any key to continue..."
WHILE INKEY$ = "": WEND
PRINT STRING$(50, "_")
NEXT player
LOOP
GameOver:
CLS
IF p1health <= 0 THEN
PRINT "Player 2 wins!"
ELSEIF p2health <= 0 THEN
PRINT "Player 1 wins!"
END IF
PRINT "Final Health: "; p1health; " vs "; p2health
PRINT "Game Over!"
The code you've provided is a text-based, turn-based game written in QBasic for two players. Below is an explanation of how the game works, along with a breakdown of its main components:
Turn Loop:
Attacking Mechanics:
Spinning the Wheel:
Game Over:
Initialization:
CLS
RANDOMIZE TIMER
Variables:
p1health, p2health: Health of Player 1 and Player 2.p1wood, p2wood: Wood resources for both players.p1iron, p2iron: Iron resources for both players.Main Game Loop:
DO
FOR player = 1 TO 2
' Player's turn code
NEXT player
LOOP
Player's Turn:
INPUT "Choose action (1-5): ", choice
Action Implementation:
Mine Wood (Option 1):
woodGain = INT(RND * 8)
Mine Iron (Option 2):
ironGain = INT(RND * 4)
Attack with Wood (Option 3):
damage = INT(RND * 11)
Input Validation:
User Experience:
PRINT "Press any key to continue..."
SLEEP
Balance Adjustments:
Code Refactoring:
Enhanced Features:
DO
INPUT "Choose action (1-5): ", choice$
choice = VAL(choice$)
IF choice >= 1 AND choice <= 5 THEN
EXIT DO
ELSE
PRINT "Invalid choice! Please select an option from 1 to 5."
END IF
LOOP
Your game provides a fun and simple turn-based experience where players gather resources and decide how to use them strategically. By implementing some of the suggestions above, you can enhance the gameplay, improve user interaction, and make the code more efficient and maintainable.
Not yet included in a published release.
criticalHit = (RND < .2)
Attack with Iron (Option 4):
damage = INT(RND * 10) + 6
Spin the Wheel (Option 5):
healthChange = INT(RND * 31) - 15
woodChange = INT(RND * 12) - 5
ironChange = INT(RND * 7) - 3
Invalid Choice Handling:
PRINT "Invalid choice! Please select an option from 1 to 5."
Game Over Handling:
GameOver label.