Liberty BASIC Community Forum
« magic : 4 glasses trick »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 5:44pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: magic : 4 glasses trick  (Read 206 times)
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 936
xx magic : 4 glasses trick
« Thread started on: Jul 28th, 2017, 05:15am »

i got a problem whit this

the code does not wait on some moments

Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , state
winx = WindowWidth
winy = WindowHeight
nomainwin
button #m.btnOK , "OK" , [btnOK] , UL , winx/2-50 , winy - 150 , 100 , 100
open "4 glasses trick ." for graphics as #m
  #m "trapclose [quit]"
  #m "setfocus"
  timer 250 , [timer]
wait
[timer]
  scan
  #m "fill black"
  #m "color green"
  #m "backcolor black"
  #m "font 50"
  select case state
    case 0
      #m "goto 40 60"
      #m "\ Take 4 glasses and a bal and put them like this :"
      for i = 0 to 3
        #m "goto ";i*winx/4+winx/8;" 200"
        #m "down"
        #m "ellipse 200 20"
        #m "up"
        #m "goto ";i*winx/4+winx/8;" 600"
        #m "down"
        #m "ellipse 200 20"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8+100;" 200 ";i*winx/4+winx/8+100;" 600"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8-100;" 200 ";i*winx/4+winx/8-100;" 600"
        #m "up"
      next i
      #m "goto ";winx/8;" 550"
      #m "down"
      #m "circlefilled 50"
      #m "up"
    case 1
      timer 0
      notice chr$(13) _
      + "Take the bal and move it to a glass next to its in ." + chr$(13) _
      + "and repeed this several times ."
      prompt "Hom mavy times did you move the bal ?" ; in$
      i = val( in$ )
      if i and 1 then
        notice "Take the left glass away ."
      else
        notice "Take the right glass away ."
      end if
      notice "Move the bal 1 more time ."
      #m "fill black"
      #m "goto 40 60"
      #m "\ Your bal is here :"
      for i = 0 to 2
        #m "goto ";i*winx/4+winx/8;" 200"
        #m "down"
        #m "ellipse 200 20"
        #m "up"
        #m "goto ";i*winx/4+winx/8;" 600"
        #m "down"
        #m "ellipse 200 20"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8+100;" 200 ";i*winx/4+winx/8+100;" 600"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8-100;" 200 ";i*winx/4+winx/8-100;" 600"
        #m "up"
      next i
      #m "goto ";winx/4+winx/8;" 550"
      #m "down"
      #m "circlefilled 50"
      #m "up"


    case else
  end select
if state = 0 then wait
[quit]
  close #m
end
[btnOK]
  state = state + 1
wait


 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: magic : 4 glasses trick
« Reply #1 on: Jul 28th, 2017, 06:33am »

The timer and prompt don't coexist very well. I changed the program flow to cycle on each button press. Does away with the need for the timer. Logic of the trick may need tweaked.

Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , state
winx = WindowWidth
winy = WindowHeight
nomainwin
button #m.btnOK , "OK" , [btnOK] , UL , winx/2-50 , winy - 150 , 100 , 100
open "4 glasses trick ." for graphics as #m
  #m "trapclose [quit]"
  #m "setfocus"
    [cycle]
    #m "fill black"
    #m "color green"
    #m "backcolor black"
    #m "font 50"
    select case state
    case 0
      #m "goto 40 60"
      #m "\Take 4 glasses and a ball and put them like this :"
      for i = 0 to 3
        #m "goto ";i*winx/4+winx/8;" 200"
        #m "down"
        #m "ellipse 200 20"
        #m "up"
        #m "goto ";i*winx/4+winx/8;" 600"
        #m "down"
        #m "ellipse 200 20"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8+100;" 200 ";i*winx/4+winx/8+100;" 600"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8-100;" 200 ";i*winx/4+winx/8-100;" 600"
        #m "up"
      next i
      #m "goto ";winx/8;" 550"
      #m "down"
      #m "circlefilled 50"
      #m "up"
    case 1
      #m "goto 40 60"
      #m "\Take the ball and move it to a glass next to it"
      #m "\and repeat this several times ."
      prompt "How many times did you move the ball ?" ; in$
      i = val( in$ )
      if i and 1 then
        #m "goto 40 60"
        #m "\Take the left glass away .                                     "
        #m "\                                                               "
        wait
      else
        #m "goto 40 60"
        #m "\Take the right glass away .                                    "
        #m "\                                                               "
        wait
      end if
      wait
     case 3
      #m "goto 40 60"
      #m "\Move the bal 1 more time .                                       "
      #m "\                                                                 "
      wait
      case else
      #m "fill black"
      #m "goto 40 60"
      #m "\ Your bal is here :"
      for i = 0 to 2
        #m "goto ";i*winx/4+winx/8;" 200"
        #m "down"
        #m "ellipse 200 20"
        #m "up"
        #m "goto ";i*winx/4+winx/8;" 600"
        #m "down"
        #m "ellipse 200 20"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8+100;" 200 ";i*winx/4+winx/8+100;" 600"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8-100;" 200 ";i*winx/4+winx/8-100;" 600"
        #m "up"
      next i
      #m "goto ";winx/4+winx/8;" 550"
      #m "down"
      #m "circlefilled 50"
      #m "up"
  end select
 wait
[quit]
  close #m
end
[btnOK]
  state = state + 1
  if state=4 then [quit]
  goto [cycle]
wait
 
User IP Logged

bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 936
xx Re: magic : 4 glasses trick
« Reply #2 on: Jul 29th, 2017, 04:20am »

@ rod :
thanks for help

update :
i inproved the graphics
i rerote some logic

i think its ok now
Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , state
winx = WindowWidth
winy = WindowHeight
nomainwin
button #m.btnOK , "OK" , [btnOK] , UL _
, winx/2-50 , winy - 200 , 100 , 100
open "4 glasses trick ." for graphics as #m
  #m "trapclose [quit]"
  #m "setfocus"
  #m "size 5"
  [cycle]
    #m "fill black"
    #m "color green"
    #m "backcolor black"
    #m "font 50"
    select case state
    case 0
      #m "goto 40 60"
      #m "\Take 4 glasses and a ball and put them like this :"
      for i = 0 to 3
        #m "goto ";i*winx/4+winx/8;" 200"
        #m "down"
        #m "ellipse 200 40"
        #m "up"
        #m "goto ";i*winx/4+winx/8;" 600"
        #m "down"
        #m "ellipse 200 40"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8+100;" 200 ";i*winx/4+winx/8+100;" 600"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8-100;" 200 ";i*winx/4+winx/8-100;" 600"
        #m "up"
      next i
      #m "goto ";winx/8;" 550"
      #m "down"
      #m "circlefilled 50"
      #m "up"
    case 1
      #m "goto 40 60"
      #m "\Take the ball and move it to a glass next to it"
      #m "\and repeat this several times ."
      prompt "How many times did you move the ball ?" ; in$
      i = val( in$ )
      if i and 1 then
        #m "goto 40 60"
        #m "\Take the left glass away .                                     "
        #m "\                                                               "
      else
        #m "goto 40 60"
        #m "\Take the right glass away .                                    "
        #m "\                                                               "
      end if
      wait
    case 2
      #m "goto 40 60"
      #m "\Move the bal 1 more time .                                       "
      #m "\                                                                 "
      wait
    case 3
      #m "fill black"
      #m "goto 40 60"
      #m "\ Your bal is here :"
      for i = 0 to 2
        #m "goto ";i*winx/4+winx/8;" 200"
        #m "down"
        #m "ellipse 200 40"
        #m "up"
        #m "goto ";i*winx/4+winx/8;" 600"
        #m "down"
        #m "ellipse 200 40"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8+100;" 200 ";i*winx/4+winx/8+100;" 600"
        #m "up"
        #m "down"
        #m "line ";i*winx/4+winx/8-100;" 200 ";i*winx/4+winx/8-100;" 600"
        #m "up"
      next i
      #m "goto ";winx/4+winx/8;" 550"
      #m "down"
      #m "circlefilled 50"
      #m "up"
  end select
wait
[quit]
  close #m
end
[btnOK]
  state = state + 1
  if state = 4 then [quit]
  goto [cycle]
wait
 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls