0 Members and 1 Guest are viewing this topic.
Is there any advantage with using on.create?
15.13 createon.create()This routine is called when the script application is created. The window size and graphics context are valid at this point.Use this routine to initialize graphical objects based on the window size. Don’t actually paint the screen in this routine since the on.paint event handler will be called soon after this routine finishes.
I never played that game so I have no clue how it goes on, but I'll probably give this a try once it's finished to see how it is. Glad to see you working on Nspire projects.
Cool!How much has to happen in order to get a stack overflow?Its in an area where some functions call each other, so it kinda makes sense
function turn() --function finished/near finished get() count[land]=0 --reset count land=click --set to change table pos to click for e=1, d do land=land+1 set(find[e]) platform.window:invalidate() for pause=1, 250 do end end check() end
-- GLOBALS --click=1 land=1player1=true extra=false canMove=true color={}find={} coord={} coordL={0} coordR={0} count={3,3,3,3,3,3,nil,3,3,3,3,3,3,nil}----------------------------------------------------------------------------------function on.create()-------------------------------------------------------------------------------- local pos=0 for a=1, 14 do for b=1, 3 do pos=a*9+b*3-11 if a~=7 and a~=14 then coord[pos]=a coord[pos+1]=math.random(0,16) coord[pos+2]=math.random(0,14) else coord[pos]=a coord[pos+1]=nil coord[pos+2]=nil end end end --For the beans colors for i=1, 42 do color[i]={math.random(0,255), math.random(0,255), math.random(0,255)} end--end --------------------------------------------------------------------------------function on.paint(gc)-------------------------------------------------------------------------------- paintBoard(gc) local pos=0 for a=1, 42 do pos=a*3-2 if coord[pos]~=7 and coord[pos]~=14 then if coord[pos]>7 then paintSeeds(a, gc, (coord[pos]-7)*34+coord[pos+1]+25, coord[pos+2]+ 49, 10, 10, 0, 360) else paintSeeds(a, gc, (coord[pos]-0)*34+coord[pos+1]+25, coord[pos+2]+141, 10, 10, 0, 360) end elseif coord[pos]==7 then if coordR[1]~=0 then for c=2, coordR[1] do if coordR[c]==nil then coordR[c*2]=math.random(0,35) coordR[c*2+1]=math.random(45,112) end paintSeeds(a, gc, coordR[c*2]+263, coordR[c*2+1], 10, 10, 0, 360) end end elseif coord[pos]==14 then if coordL[1]~=0 then for c=2, coordL[1] do if coordL[c]==nil then coordL[c*2]=math.random(0,35) coordL[c*2+1]=math.random(0,122) end paintSeeds(a, gc, coordL[c*2]+20, coordL[c*2+1], 10, 10, 360) end end end end end--------------------------------------------------------------------------------function paintBoard(GC)-------------------------------------------------------------------------------- --Background GC:setColorRGB(210,240,255) GC:fillRect(0,0,318,212) --Text GC:setColorRGB(0,30,60) GC:setFont("serif","b",30) GC:drawString("Mancala",95,0,"top") GC:setFont("serif","b",10) GC:drawString("by epic7",255,190,"top") --Board Fill GC:setColorRGB(245,222,179) GC:fillRect(15,40,288,132) --Board Details GC:setColorRGB(125,102,59) GC:drawRect(14,39,289,133) -- Outer border GC:drawRect(20,45,35,122) -- Left pit GC:drawRect(263,45,35,122) -- Right pit --Circles local width=30 local height=50 for row=0, 1 do for circle=1, 6 do GC:drawArc(circle*34+25, row*(122-height)+45, width, height, 0, 360) end endend--------------------------------------------------------------------------------function paintSeeds(index, GC, x, y)-------------------------------------------------------------------------------- local width=10 local height=6 GC:setColorRGB(0, 0, 0) --border GC:drawArc(x-1, y-1, width+1, height+1, 0, 360) GC:setColorRGB(unpack(color[index])) --Colored beans GC:fillArc(x, y, width, height, 0, 360)end--------------------------------------------------------------------------------function setClick() --function finished-------------------------------------------------------------------------------- if player1 then click=1 else click=8 end end --------------------------------------------------------------------------------function win(player) --------------------------------------------------------------------------------end --------------------------------------------------------------------------------function on.enterKey() --function finished-------------------------------------------------------------------------------- if canMove then turn() canMove=false end end --------------------------------------------------------------------------------function on.arrowKey(arrow) --function unfinished-------------------------------------------------------------------------------- if canMove then if arrow=="left" then if click>1 then click=click-1 end elseif arrow=="right" then if click<6 then click=click+1 end end end end --------------------------------------------------------------------------------function turn() --function finished/near finished-------------------------------------------------------------------------------- bean=0 get() count[land]=0 --reset count land=click --set to change table pos to click for a=1, bean do land=land+1 set(find[a]) platform.window:invalidate() for pause=1, 250 do end end check() end--------------------------------------------------------------------------------function get() --function finished-------------------------------------------------------------------------------- for a=1, 42 do if coord[a*3-2]==click then bean=1 while find[bean] do bean=bean+1 end find[bean]=a end end end--------------------------------------------------------------------------------function set(num) --function finished-------------------------------------------------------------------------------- toset=num*3-2 if land~=7 and land~=14 then --if not near mancala count[land]=count[land]+1 coord[toset]=coord[toset]+1 setrand() --set random coordinates elseif land==7 then --if before right side mancala if player1 then --if player 1 coord[toset]=7 --go into mancala coordR[1]=coordR[1]+1 --add one point else --if player 2 count[8]=count[8]+1 --add to next slot coord[toset]=8 --set to 8 land=8 --skip 7 setrand() --set random coordinates end elseif land==14 then --same but for left side mancala if not player1 then coord[toset]=14 coordL[1]=coordL[1]+1 else count[1]=count[1]+1 coord[toset]=1 land=1 setrand() end end end--------------------------------------------------------------------------------function setrand() --function finished-------------------------------------------------------------------------------- coord[toset+1]=math.random(0,16) coord[toset+2]=math.random(0,14) end--------------------------------------------------------------------------------function check() --function unfinished-------------------------------------------------------------------------------- if count[land]==0 then --add capture player1=not player1 canMove=true setClick() else turn() end if land==7 or land==14 then canMove=true setClick() end filled=false ch=1 while ch<7 and not filled do if count[ch]==0 then ch=ch+1 else filled=true end end if not filled then win(1) end ch=8 filled=false while ch<14 and not filled do if count[ch]==0 then ch=ch+1 else filled=true end end if not filled then win(2) end end