1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| --[[Things to do: Declare variables first within a function Make things more fun and complex Points System: OLD: Atk -{1,2,3} +{4,5} Def +{1,2,3} -{4,5} NEW: Atk -{4,5} +{4,5} Def +{1,2,3} -{1,2,3} Any better ways? Maybe make Atk more risky, so it's less about luck]]--
chance = { [-1] = "", [0] = "unsuccessful . -", [1] = "successful . +" }
action = { nothing="", attack="Attack", defense="Defense"}
function initialize_variables() v = 0 t = 0 r1 = 0 r2 = -1 state = action.nothing end
--function on.create() initialize_variables() --end
function on.paint(gc) gc:setFont("sansserif","r",11) gc:setColorRGB(0,0,0) gc:drawString("[A]tk or [D]ef? [R]eset",10,10,"top") gc:drawString(v,10,30,"top")
if state == action.attack then gc:drawString("Attack was " .. chance[r2] .. r1, 10, 50, "top") elseif state == action.defense then gc:drawString("Defense was " .. chance[r2] .. r1, 10, 50, "top") end
gc:drawString("Turn " .. t,200,10,"top") if v~=0 or t~=0 then gc:drawString("Average " .. round(v/t,2), 200, 30, "top") end gc:setFont("sansserif","r",8) gc:drawString("Numstrat - Jason Ho",10,200,"top") end
function on.charIn(ch) if ch=="a" then state = action.attack r1=math.random(4,5) r2=math.random(0,1) if r2==1 then v=v+r1 else --if r2==0 then v=v-r1 end t=t+1 end
elseif ch=="d" then state = action.defense r1=math.random(1,3) r2=math.random(0,1) if r2==1 then v=v+r1 else --if r2==0 then v=v-r1 end state=action.defense t=t+1 end
elseif ch=="r" then initialize_variables() end
platform.window:invalidate() end
function round(value, digits) return string.format("%." .. digits .. "f", value) end |