View Full Version : In need of code.
E.K.Virtanen
08-11-2007, 18:55
Cant get thinBasic working with wine so i need tested code. I know this sounds "im lazy to do it myself" but hopefully this page explains why i want it :) http://www.ascii-world.com/guess-it
You can either post it here or register at ASCII-World and post it yourself.
Thank you for help.
E.K.Virtanen
www.ascii-world.com
ErosOlmi
08-11-2007, 19:10
Kristian,
maybe this post can help: http://community.thinbasic.com/index.php?topic=1287.0
Ciao
Eros
Sandy, you might want to take this one as you already wrote the mastermind game, this should be a lot easier.
But if you are busy, let us know, I don't mean to put any pressure. Just thought you wrote that nice game and this would be fun.
ErosOlmi
09-11-2007, 01:43
Should give a start ...
' Guess what number for thinBasic 1.5.0.1
' Eros Olmi. 2007, public domain
'---Load console module
uses "Console"
'---Start random number generator
Randomize TIMER
'---Define min and max bounds for random number
%MinNumber = 1
%MaxNumber = 100
'---Some variables
Dim Plr_guess as long '---Used to get user input
dim Randomed as long '---Number to guess
dim Rounds AS long '---Used to count user try
dim Found as long '---Used to indicate number has been found
'---Set size and window position
Console_SetScreenBufferSize(%MaxNumber, 25)
Console_ShowWindow(%Console_SW_MAXIMIZE)
'---Main program loop.
DO
'---Clear console screen
console_cls
'---Generate a random number between %MinNumber and %MaxNumber
Randomed = rnd(%MinNumber, %MaxNumber)
'---Init variables that need to be initialized at every re-game
Found = %FALSE
Rounds = 0
'---Gives some initial info about the sript
console_writeline "Ok, i think random number between " & %MinNumber & " and " & %MaxNumber & "."
console_writeline "Your job is to guess what it is in as minimal tries as possible."
console_writeline "After your every guess, ill give you hint if my number higher or lower than your guess."
console_writeline "You can exit by 'guessing' 0."
console_writeline string$(%MaxNumber - 1, "-")
console_writeline "Press any key to start game."
console_writeline string$(%MaxNumber - 1, "-")
console_waitkey
'---OK, let's start guessing loop
DO
'---Increment rounds
incr Rounds
'---Get number from user
console_write "This is round number: " & Rounds & ". "
Console_Write("Give your guess: ")
Plr_guess = val(Console_Read)
'---Check entered number
select case Plr_guess
case 0
exit do
case > Randomed
wInfo "My number is smaller...", -1
case < Randomed
wInfo "My number is higher...", 1
case Randomed
wInfo "--- You got it !!! ---"
Found = %TRUE
END select
LOOP While (Plr_Guess <> 0) and (Found = %FALSE)
'---If number was not found we have finished
IF Found = %FALSE THEN EXIT DO
console_writeline "It took " & Rounds & " rounds to guess right number."
console_writeline "Press 'Y' to play again. Any other key to quit."
if ucase$(Console_WaitKey) <> "[Y]" then exit do
Loop while %TRUE
console_writeline ""
console_writeline "--- Thanks for playing ---"
console_waitkey
'------------------------------------------------------------------------
' Write a result output
'------------------------------------------------------------------------
function wInfo(byval sDescrition as string, optional Level as long)
'---Save current color
dim OldColor as long = Console_GetTextAttribute
'---Use different color depending on level number
dim DescriptionColor as long = iif(Level < 0, 9, iif(Level > 0, 10, 12))
'---Set new color
Console_SetTextAttribute(DescriptionColor)
'---Write text
console_writeline sDescrition & " "
'---Restore previous color
Console_SetTextAttribute(OldColor)
end function
Eros, thanks for the sample. Wow you are fast and efficient, got it all working just fine.
These kind of games are always fun, now back to see if I can beat my average of 6 guesses.
sandyrepope
09-11-2007, 03:46
Sandy, you might want to take this one as you already wrote the mastermind game, this should be a lot easier.
But if you are busy, let us know, I don't mean to put any pressure. Just thought you wrote that nice game and this would be fun.
Although I have to go back to the hospital Friday ( 9th of Nov.) I plan to see what I can do as soon as I get back.
Thanks
Sandy
Hope your visit to the hospital is brief and successful Sandy. Don't worry about this as Eros did a great example. Just well wishes to you this Friday.
E.K.Virtanen
09-11-2007, 08:23
Should give a start ...
Thank you ErosOlmi.
I got thinBaisc run somehow with wine yesterday evening but it was slow as he**. Goin to find out how i could boost it up a bit later.
For now, i used your code at http://www.ascii-world.com/guess-it-thinbasic
E.K.Virtanen
Michael Hartlef
09-11-2007, 10:01
Sandy, you might want to take this one as you already wrote the mastermind game, this should be a lot easier.
But if you are busy, let us know, I don't mean to put any pressure. Just thought you wrote that nice game and this would be fun.
Although I have to go back to the hospital Friday ( 9th of Nov.) I plan to see what I can do as soon as I get back.
Thanks
Sandy
Best wishes to you Sandy.
Petr Schreiber
09-11-2007, 10:07
Sandy,
best wishes from my side too!
Petr