23 Matches
Original author: Bob Albrecht
Description: 23 matches is one version of popular game where idea is to remove items from a table.
In this case, there is 23 matches at table. You can remove one, two or three matches at once, as can computer too.
Wich ever is forced to remove last match, is a loser.
Crucial moments for players are starting when there is less than ten matches at the table. If you dont think then what you are goin to remove, you are goin to get beated.
' =============================================
' = 23 Matches =
' = Creative Computing Morristown, New Jersey =
' =============================================
' Remade for FreeBASIC by E.K.Virtanen.
' www.ascii-world.com
' Public Domain
Function ScreenWidth AS Integer
RETURN VAL(STR((Width) And 65535))
End Function
SUB APrint(SubString AS String)
Locate ,INT(ScreenWidth - (LEN(SubString))) / 2, 0
Print SubString
End SUB
Screen 12
Randomize TIMER
DIM AS Integer Matches, Turn, Howmany, Manyhow
CONST Computer = 1
Const Player = 2
DIM AS String YesNo
DO
Matches = 23
CLS
Color 14, 0
APrint("23 Matches")
APrint("Creative Computing Morristown, New Jersey")
Color 7, 0
APrint("Remade for FreeBASIC by E.K.Virtanen.")
APrint("www.ascii-world.com")
APrint("Public Domain")
Print ""
Color 15, 0
APrint("This is a game called '"+ STR(Matches) + " Matches'.")
Print ""
APrint("When it is your turn, you may take one, two or three matches.")
APrint("The object of the game is not to have to take the last match.")
Print ""
APrint("Let's flip a coin to see who goes first.")
APrint("If it comes up heads, i will win the toss.")
Print ""
APrint("Press any key to play") : SLEEP
While INKEY$ <> "" : Wend
CLS
IF INT(Rnd * 2) + 1 = Computer Then
APrint("Heads! I win! HA! HA!")
APrint("Prepare to lose, MEATBALL-NOSE !!")
Turn = Computer
ELSE
APrint("You win coin flip so you can start.")
Print ""
Turn = Player
END IF
Print
APrint("Now press a key to see how i beat you!")
SLEEP : While INKEY$ <> "" : Wend
DO
IF Turn = Player Then
Turn = Computer
Color 14, 0
APrint("The number of matches is now: " + STR(Matches))
Color 15, 0
Print ""
APrint("Your turn -- You may take 1, 2 or 3 matches.")
APrint("How many do you wish to remove: ")
DO
LOCATE , (ScreenWidth / 2) : INPUT Howmany
IF Howmany > 3 OR Howmany <= 0 Then
APrint("Very funny! Dummy!")
APrint("Do you want to play or goof around?")
APrint( "Now how many matches do you want:")
END IF
LOOP Until Howmany <= 3 AND Howmany > 0
Matches = (Matches - Howmany)
END IF
IF Turn = Computer Then
IF Matches <= 1 Then EXIT DO
Turn = Player : CLS : Color 14, 0
APrint("There are now " + STR(Matches) + " matches remaining.")
Color 15, 0
Print ""
APrint("My turn. hmm... i'll take...") : SLEEP (1000 + (INT(RND * 20) * 100))
IF Matches > 15 THEN Manyhow = INT(RND * 3) + 1
IF Matches > 4 AND Matches < 16 THEN Manyhow = (4 - Howmany)
IF Matches < 5 THEN Manyhow = (Matches - 1)
APrint( STR(Manyhow) + " matches.")
Print ""
Matches = (Matches - Manyhow)
IF Matches <= 1 Then Turn = Player : EXIT DO
END IF
Loop
IF Turn = Player THEN
Print ""
APrint("You poor boob! You took the last match! I gotcha!!")
APrint("HA! HA! I beat you!!!")
Print ""
APrint("Good bye loser!")
END IF
IF Turn = Computer THEN
APrint("You won, floppy ears!")
APrint("Think you're pretty smart?")
APrint("Lets play again and i'll blow your shoes off!!")
END IF
APrint("Play again? (Y / N)")
LOCATE , (ScreenWidth / 2) : INPUT YesNo
Loop Until UCASE(YesNo) <> "Y"
END