맥스스크립트 심화

슬롯머신(6)

스크립팅하는애님 2019. 10. 1. 18:54
728x90
반응형

안녕하세요.

애니메이터가 들려주는 맥스 스크립트의 스크립팅하는 애님입니다.

오늘은 기필코 마무리를 짓겠습니다. ㅎㅎ

 

지금까지 작업한 스크립트를 열어주세요.

이제 이 스크립트의 하이라이트 부분(?)이라고 할 수 있는 결과 값 처리를 하겠습니다.

저는 슬롯머신의 룰을 잘 모르기 때문에 각 행에 같은 값이 나올 때 배팅한 코인의 두배 값을 돌려받도록 하겠습니다.

'on run_btn pressed do()'의 제일 밑에 다음을 추가 해 줍니다.

 

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
for i = 1 to 3 do
(
    if((slotNumArry[i][1== slotNumArry[i][2])and(slotNumArry[i][1== slotNumArry[i][3])) then
    (
        playerCoin += (betLineCoin[i] * 2)
        coin_lab.text = playerCoin as string
        tmp = "라인" + (i as string) + "에 " + (betLineCoin[i] as string) + "을(를) 배팅하여 " + ((betLineCoin[i] * 2)as string) + "를 받습니다."
        messagebox tmp
    )
else
(
tmp = "라인" + (i as string) + " 실패 했습니다."
messagebox tmp
)
)
 
for i = 1 to 3 do
(
    for j = 1 to 3 do
    (
        slotNum = 0
        (execute("slot_roll.slot" + (i as string) + (j as string) + "_lab")).text = "  " + (slotNum as string)
        slotNumArry[i][j] = slotNum
    )
    betLineCoin[i] = 0
    (execute("slot_roll.bet" + (i as string) + "_lab")).text = (betLineCoin[i] as string)            
)
betCoin = 0
 
cs

 

위 내용은 크게 for문으로 나뉘는데 위쪽의 for문이 결과 값을 계산하는 것이고,

아래쪽 for문은 결과를 다 계산한 후에 다시 배팅을 할 수 있도록 초기화 하는 것입니다.

 

우선 위쪽의 for문을 보겠습니다.

if문의 내용은 '같은 라인의 슬롯 3개의 값이 같을때'를 뜻합니다.

슬롯의 내용이 같으면

배팅한 값에 2를 곱하여 플레이어의 코인데 더합니다.

그리곤 플레이어의 코인을 UI로 표시를 해줍니다.

그냥 표시만 하고 넘어가면 너무 빠르게 끝나기 때문에 메시지 박스로 어떤 라인에서 얼마를 투자해 얼마를 벌었는지를 표시해줘 플레이어가 결과를 알 수 있게 합니다.

else문은 슬롯이 성공하지 못했을 때 출력을 해줍니다.

 

다음의 for문은 각 슬롯을 돌며 슬롯의 값을 0으로 바꿔 주고 해당 변수의 값도 0으로 바꿔 줍니다.

그리고 베팅한 값도 0으로 바꿔 주어 새롭게 배팅할 수 있도록 초기화해줍니다.

그리고 betCoin = 0로 하여 배팅되어 있는 코인도 0으로 바꿔 줍니다.

 

마지막으로 배팅을 하지 않았는데도 'Run'버튼을 누르면 실행이 되는데요.

'on run_btn pressed do ()' 이벤트를 전체적으로 감싸는 if문을 넣어 해결할 수 있습니다.

 

1
2
3
4
5
6
7
8
9
10
on run_btn pressed do
(
    if(betCoin != 0)do
    (
        .
        .
        .
        .
    )
)
cs

 

지금까지 작업한 내용은 다음과 같습니다.

 

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
betCoin = 0
slotCount = 0
betLineCoin = #(0, 0, 0)
playerCoin = 0
slotNumArry = #(#(0, 0, 0), #(0, 0, 0), #(0, 0, 0))
returnCoin = 0
 
 
try(destroydialog slot_roll) catch()
 
 
 
rollout slot_roll "슬롯머신"
(
    label slot11_lab "  0" pos:[30,10] width:20 height:20 style_sunkenedge:true
    label slot12_lab "  0" pos:[70,10] width:20 height:20 style_sunkenedge:true
    label slot13_lab "  0" pos:[110,10] width:20 height:20 style_sunkenedge:true
    
    label slot21_lab "  0" pos:[30,45] width:20 height:20 style_sunkenedge:true
    label slot22_lab "  0" pos:[70,45] width:20 height:20 style_sunkenedge:true
    label slot23_lab "  0" pos:[110,45] width:20 height:20 style_sunkenedge:true
    
    label slot31_lab "  0" pos:[30,80] width:20 height:20 style_sunkenedge:true
    label slot32_lab "  0" pos:[70,80] width:20 height:20 style_sunkenedge:true
    label slot33_lab "  0" pos:[110,80] width:20 height:20 style_sunkenedge:true
    
    label bet2_lab "0" pos:[15,12]
    label bet1_lab "0" pos:[15,47]
    label bet3_lab "0" pos:[15,82]
    
    label coin_lab "0" pos:[15,110]
    
    button add_btn "+" pos:[30,110] width:25 height:25
    button sub_btn "-" pos:[60,110] width:25 height:25
    button run_btn "Run" pos:[90,110] width:40 height:25
    
 
    on add_btn pressed do
    (
        if(playerCoin > 0do
        (
            betCoin += 1
            slotCount += 1
            playerCoin -= 1
            coin_lab.text = playerCoin as string
            
            if(slotCount == 1) then
            (
                betLineCoin[1+= 1
                bet1_lab.text = (betLineCoin[1] as string)
            )
            else if (slotCount == 2) then
            (
                betLineCoin[2+= 1
                bet2_lab.text = (betLineCoin[2] as string)
            )
            else
            (
                betLineCoin[3+= 1
                bet3_lab.text = (betLineCoin[3] as string)
                slotCount = 0
            )
        )
    )
    
    on sub_btn pressed do
    (
        if(betCoin > 0do
        (
            betCoin -= 1
            playerCoin += 1
            coin_lab.text = playerCoin as string
            
            if(slotCount == 1) then
            (
                betLineCoin[1-= 1
                bet1_lab.text = (betLineCoin[1] as string)
                slotCount -= 1
            )
            else if (slotCount == 2) then
            (
                betLineCoin[2-= 1
                bet2_lab.text = (betLineCoin[2] as string)
                slotCount -= 1
            )
            else
            (
                betLineCoin[3-= 1
                bet3_lab.text = (betLineCoin[3] as string)            
                slotCount = 2
            )
        )
    )
    
    on run_btn pressed do
    (
        if(betCoin != 0)do
        (
            for i = 1 to 3 do
            (
                for j = 1 to 3 do
                (
                    slotNum = random 1 9
                    (execute("slot_roll.slot" + (i as string) + (j as string) + "_lab")).text = "  " + (slotNum as string)
                    slotNumArry[i][j] = slotNum
                )
            )
            
            for i = 1 to 3 do
            (
                if((slotNumArry[i][1== slotNumArry[i][2])and(slotNumArry[i][1== slotNumArry[i][3])) then
                (
                    playerCoin += (betLineCoin[i] * 2)
                    coin_lab.text = playerCoin as string
                    tmp = "라인" + (i as string) + "에 " + (betLineCoin[i] as string) + "을(를) 배팅하여 " + ((betLineCoin[i] * 2)as string) + "를 받습니다."
                    messagebox tmp
                )
                else
                (
                    tmp = "라인" + (i as string) + " 실패 했습니다."
                    messagebox tmp
                )
            )
            
            for i = 1 to 3 do
            (
                for j = 1 to 3 do
                (
                    slotNum = 0
                    (execute("slot_roll.slot" + (i as string) + (j as string) + "_lab")).text = "  " + (slotNum as string)
                    slotNumArry[i][j] = slotNum
                )
                betLineCoin[i] = 0
                (execute("slot_roll.bet" + (i as string) + "_lab")).text = (betLineCoin[i] as string)            
            )
            betCoin = 0
        )
    )
    
    on slot_roll mbuttondown pos do
    (
        playerCoin += 10
        coin_lab.text = playerCoin as string
    )
)
createdialog slot_roll width:140 height:140
 
cs

 

이렇게 슬롯머신에 대해서 알아보았습니다.

만들면서 강의를 하려니 저도 힘이 드네요. ㅎㅎ

다음 내용을 정하지는 않았지만 좀 더 가벼운 것을 했으면 좋겠네요.

728x90
반응형