Make the program wait for my click?


ok @ this:

for p = 1 2
  turn = 1 3
    put = 1 turn
      setdown()
    endfor
  endfor
endfor

i doing game battleship. little thing there must this:

- progressively player 1 , 2 (p) asked put ships.

- both put, 1 time ship type1. 2 times ships type2 , @ last 3 times ships type3 on boards.

 

ok setdown subroutine. in other parts of program created buttons in each spot.

so getting bit of trouble making sub has this...

- controls.lastclickedbutton , if value in button right, "you hit it" or if not "missed". whatever.

now don't know how smallbasic works (still noob). want program wait click set down ship1, after click pass next waiting next ship. mean.

 

^^ can more experienced give me little help?

a bit first did put x value everywhere:

for p = 1 2
  = 1 10
    j = 1 10
      boxes[p][i][j] = controls.addbutton("x",i*width + positionx[p],j*height)
    endfor
  endfor
endfor

 

so if u give me answer using arrays , so, that's idea had use, blocked here... xd how heck can make program wait clicks on buttons?

anyway can use turn variable modify name of boat inserted. ( ship[true] ) using stupid loop there. xd

 

thanks helping. :)

 

 

 

the setdown routine can wait click, update box:

sub setdown
  clicked = 0
  while (clicked = 0) 'wait box found
    program.delay(100)
  endwhile
  if (player = p , controls.getbuttoncaption(box) = " ") then
    controls.setbuttoncaption(box,turn+"_"+put) 'valid go
  else
    setdown() 'invalid go - try again
  endif
endsub


checking whether box clicked (clicked ) , box (box ) , player correspnds (p ) - set in event:

sub onbuttonclicked
  box = controls.lastclickedbutton 'box clicked
  clicked = 1 'flag show have box
  'find p,i,j box was
  p = 1 2
    = 1 10
      j = 1 10
        if (box = boxes[p][i][j]) then
          goto found
        endif
      endfor
    endfor
  endfor
  found: 'box found
endsub 

now need initialise boxes, , start event, cycle through setup.  here together, easier example rather trying describe.

'create positions
width = 40
height = 30
graphicswindow.width = 10*2*width+width
graphicswindow.height = 10*height
p = 1 2
  positionx[p] = (p-1)*11*width
  = 1 10
    j = 1 10
      boxes[p][i][j] = controls.addbutton(" ",(i-1)*width+positionx[p],(j-1)*height) 'blank box @ first
    endfor
  endfor
endfor

'start event check buttons clicked
controls.buttonclicked = onbuttonclicked

'now put position's in
player = 1 2
  turn = 1 3
    put = 1 turn
      graphicswindow.title = "player "+player+" turn "+turn+" put "+put
      setdown()
    endfor
  endfor
endfor

sub setdown
  clicked = 0
  while (clicked = 0) 'wait box found
    program.delay(100)
  endwhile
  if (player = p , controls.getbuttoncaption(box) = " ") then
    controls.setbuttoncaption(box,turn+"_"+put) 'valid go
  else
    setdown() 'invalid go - try again
  endif
endsub

sub onbuttonclicked
  box = controls.lastclickedbutton 'box clicked
  clicked = 1 'flag show have box
  'find p,i,j box was
  p = 1 2
    = 1 10
      j = 1 10
        if (box = boxes[p][i][j]) then
          goto found
        endif
      endfor
    endfor
  endfor
  found: 'box found
endsub



Learning  >  Small Basic



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........