05-19-2024, 04:39 PM
Hello!
I thought I would share a very short game in which the goal is to not remove the last match to win.
I thought I would share a very short game in which the goal is to not remove the last match to win.
Code: (Select All)
' Declare variables
DIM matches AS INTEGER
DIM turn AS INTEGER
DIM player1Matches AS INTEGER
DIM player2Matches AS INTEGER
DIM inputPick AS STRING
' Set initial number of matches
matches = 20
' Randomly choose starting player
turn = RND(2) ' 1 for player 1, 2 for player 2
' Game loop
DO WHILE matches > 0
' Display current state
CLS
Print ""
Color 7
Print "ßßßßßßßßßßßßß";
Color 4
print "ß"
Color 15
Print ""
PRINT "Matches left: " + STR$(matches)
PRINT "Player 1 matches" + STR$(player1Matches)
PRINT "Player 2 matches" + STR$(player2Matches)
Print ""
Color 7
Print "ßßßßßßßßßßßßß";
Color 4
print "ß"
Color 15
' Turn of current player
IF turn = 1 THEN
PRINT "Player 1's turn - Select 1, 2 or 3 matches to remove: "
ELSE
PRINT "Player 2's turn - Select 1, 2 or 3 matches to remove: "
END IF
' Get player input and validate
DO
inputPick = INKEY$
LOOP UNTIL (VAL(inputPick) >= 1) AND (VAL(inputPick) <= 3) AND (VAL(inputPick) <= matches)
pick = VAL(inputPick) ' Convert to integer here
' Update matches and current player
matches = matches - pick
IF turn = 1 THEN
player1Matches = player1Matches + pick
turn = 2
ELSE
player2Matches = player2Matches + pick
turn = 1
END IF
LOOP
' Declare winner
CLS
IF turn = 1 THEN
PRINT "Player 1 wins!"
ELSE
PRINT "Player 2 wins!"
END IF
Sleep
' End message
PRINT "Press any key"
Sleep
END