### Author Topic: Square Elimination Game  (Read 715 times)

#### B+

• Full Member
• Posts: 215
##### Square Elimination Game
« on: June 05, 2015 »
Finally I got a NaaLaa version of this game going! I had to figure out a different way to catch mouse down and mouse up events. It works very nicely with NaaLaa.

Code: [Select]
`rem Square Elimination game.txt for NaaLaa 2015-06-05procedure update() set color 0,0,0 draw rect tlx-1,tly-1,sq*10+1,sq*10+1,true   for x=1 to 10      for y=1 to 10         if board\$[x][y]="R"            set color 255,0,0         elseif board\$[x][y]="B"            set color 0,0,255         else            set color 0,0,0         endif         draw rect tlx+sq*(x-1),tly+sq*(y-1),sq-1,sq-1,true      next   nextendprocfunction bx(mx)   rtn=(mx-tlx)/sq +1   if rtn<11 and rtn>0      return rtn   else      return 0   endifendfuncfunction by(my)   rtn=(my-tly)/sq +1   if rtn<11 and rtn>0 then      return rtn   else      return 0   endifendfuncfunction moved(x1,y1,x2,y2)   if x1 and y1 and x2 and y2      if x1=x2         if y1-y2=1            return 1         elseif y2-y1=1            return 3         else            return 0         endif      elseif y1=y2         if x1-x2=1            return 4         elseif x2-x1=1            return 2         else            return 0         endif      else         return 0      endif   else      return 0   endifendfuncrem =============================== mainrandomize(time())visible:board\$[11][11]wside=700th=18tly=3*thsq=(wside-5*th)/10tlx=(wside-10*sq)/2hidden:set window (screenw()-wside)/2,20,wside,wsideset redraw offset color 0, 220, 220set caret wside/2, 0center"SQUARE ELIMINATION: Mouse down and move over to like color square,"center"release, this slides row or column leaving blank at end. Perfect game"center"is 2 squares left on board. Good luck!  <esc> to quit with score."rem setup boardfor y=1 to 10   for x=1 to 10      board\$[x][y]= mid\$("RB",rnd(2),1)   nextnextdx=0;dy=0;ux=0;uy=0rem =========================================== main loopdo mx=mousex() my=mousey() _update if mx>tlx and mx<tlx+10*sq and my>tly and my<tly+10*sq if mousebutton(0) if dx<>0 and dy<>0 and board\$[dx][dy]<>" " set color 255,255,255 draw rect tlx+sq*(dx-1)-1,tly+sq*(dy-1)-1,sq+1,sq+1 endif if dx=0 and dy=0 dx=bx(mx) dy=by(my) ux=0;uy=0 endif else if dx and dy ux=bx(mx) uy=by(my) moov=moved(dx,dy,ux,uy)    if moov and board\$[dx][dy]=board\$[ux][uy] and board\$[dx][dy]<>" "      if moov=1          rem  Moved up            for i=dy to 10               board\$[dx][i-1]=board\$[dx][i]            next            board\$[dx][10]=" "      elseif moov=2          rem Moved right          for i=dx downto 1               board\$[i+1][dy]=board\$[i][dy]            next            board\$[1][dy]=" "      elseif moov=3 rem Moved down            for i=dy downto 1               board\$[dx][i+1]= board\$[dx][i]            next            board\$[dx][1]=" "      elseif moov=4          rem Moved left            for i=dx to 10               board\$[i-1][dy]= board\$[i][dy]            next            board\$[10][dy]=" "      endif    endif dx=0;dy=0 endif endif endif redraw wait 10until keydown(27)lcount=0for i=1 to 10   for j=1 to 10      if board\$[i][j]<>" " then lcount=lcount +1   nextnextset color 0, 200, 200set caret wside/2, th*3+sq*10center"You have left "+str(lcount)+" squares of 100 on board."center"Thanks for playing!  press any key..."redrawwait keydown`
B+

#### johnno56

• Guest
##### Re: Square Elimination Game
« Reply #1 on: June 06, 2015 »
Ran it on my Linux box via Wine and ran like a charm... still a cool game...

J

#### B+

• Full Member
• Posts: 215
##### Re: Square Elimination Game
« Reply #2 on: June 06, 2015 »
Ran it on my Linux box via Wine and ran like a charm... still a cool game...

J

Thanks this is reassuring. I like the smaller size of the exe (comparing to sdlBasic) plus I think it runs a shade faster highliting the mouse down squares.

B+
B+

#### johnno56

• Guest
##### Re: Square Elimination Game
« Reply #3 on: June 06, 2015 »
As long as it runs as quick as you anticipated.

J

#### Rick3137

• Sr. Member
• Posts: 347
• May the Force be with You
##### Re: Square Elimination Game
« Reply #4 on: June 07, 2015 »
Nice game. A little hard on the brain. I had about 7 left over. Some day, when I get my brain working again, I'll give it another try.
Can I put it on my website?

#### Rick3137

• Sr. Member
• Posts: 347
• May the Force be with You
##### Re: Square Elimination Game
« Reply #5 on: June 07, 2015 »
3 squares left, this time. This is one tricky little game.

#### B+

• Full Member
• Posts: 215
##### Re: Square Elimination Game
« Reply #6 on: June 07, 2015 »
Hi Rick,

Yes, I am pleased you like it!

I like to think you can't win every time, like in Solitaire, it depends on what you are dealt. BUT if you get one side red and the other blue then you better win!

Wait I just realized you could get all one color, 2 ways red or blue, 2^100/2=2^99.

And I was wondering if more "points" should be awarded according to distance between the red square and blue at the end of a "perfect" game. In which case, having the red and blue at opposite corners would be the ultimate win (other than winning the "lottery" of all one color).
But this is after the game becomes automatic.

This is what I live for, freely sharing fun!

Mark
B+