Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
22 May, 2013, 20:22:18 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2   Go Down
  Print  
Author Topic: Numstrat - Stumbling into Lua -  (Read 1696 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
someone
LV3 Member (Next: 100)
***
Offline Offline

Gender: Male
Last Login: Today at 19:10:23
Date Registered: 12 January, 2012, 19:07:23
Posts: 48


Total Post Ratings: +9

View Profile
« on: 05 April, 2012, 02:52:28 »
+1

I redefined some variables, I think is more legible this way:


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
« Last Edit: 08 April, 2012, 20:22:41 by someone » Logged
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.218 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.