문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 | ||
cublocapp:an36011:index [2017/10/18 00:29] Comfile Technology 만듦 |
cublocapp:an36011:index [2017/10/18 00:32] (현재) Comfile Technology |
||
---|---|---|---|
줄 1: | 줄 1: | ||
+ | ====== AN36011 - 블랙잭 게임 ====== | ||
+ | 큐터치 CT1820 으로 만든 블랙잭 프로그램입니다. | ||
+ | |||
+ | {{ :cublocapp:an36011:cutouchblackjack.jpg?nolink |}} | ||
+ | |||
+ | <html><center> | ||
+ | <iframe width="560" height="315" src="https://www.youtube.com/embed/L3Rtk1d3MM0" frameborder="0" allowfullscreen></iframe> | ||
+ | </center></html> | ||
+ | |||
+ | ===== 소스 프로그램 ===== | ||
+ | |||
+ | {{ :cublocapp:an36011:cutouch_blackjack.zip |}} | ||
+ | |||
+ | <code xbasic> | ||
+ | 'Max's Vegas BlackJack Hustler v1.0 | ||
+ | |||
+ | 'v1.0 for ct1820 | ||
+ | 'v.0.0.4 Added PlayAgain menus, now the BlackJack is in operating condition, | ||
+ | 'There are several bugs I believe... | ||
+ | 'Need To add Double Down And Split... | ||
+ | 'Dealer hits on soft 17 just like Vegas! | ||
+ | 'v.0.0.3 Added Stand, Hit for Dealer and Player | ||
+ | |||
+ | |||
+ | |||
+ | #include "CT18XX" | ||
+ | #define PZ Ct18beep 20 | ||
+ | #define DEALERY 25 | ||
+ | #define PLAYERY 130 | ||
+ | Dim TX1 As Integer, TY1 As Integer | ||
+ | Dim mode As Byte | ||
+ | Dim cval As Integer | ||
+ | Dim clock As Long | ||
+ | Dim randnum As Byte | ||
+ | Dim DealerSum As Byte | ||
+ | Dim DealerAceSum As Byte 'When one of the Ace is counted as 11 | ||
+ | |||
+ | Dim PlayerSum As Byte | ||
+ | Dim PlayerAceSum As Byte | ||
+ | |||
+ | Dim DealerCard As Byte | ||
+ | Dim PlayerCard As Byte | ||
+ | Dim FirstCard As Byte | ||
+ | Dim SecondCard As Byte | ||
+ | Dim RandomCard As Byte | ||
+ | Dim DealerCardtype As Byte 'Dealer's Card Type 0 = Diamond, 1 = Spade, 2=Clover, 3= Heart | ||
+ | |||
+ | mode=0 | ||
+ | |||
+ | On Pad Gosub welovemax | ||
+ | On Timer(50) Gosub random | ||
+ | |||
+ | cval=Eeread(0,2) | ||
+ | |||
+ | If cval>200 Then cval=150 | ||
+ | |||
+ | Ct18contrast cval | ||
+ | |||
+ | Delay 100 | ||
+ | |||
+ | Defchr &hdb30, 0b00000001,0b10000000,_ | ||
+ | 0b00000011,0b11000000,_ | ||
+ | 0b00000111,0b11100000,_ | ||
+ | 0b00001111,0b11110000,_ | ||
+ | 0b00011111,0b11111000,_ | ||
+ | 0b00111111,0b11111100,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b11111111,0b11111111,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b00111111,0b11111100,_ | ||
+ | 0b00011111,0b11111000,_ | ||
+ | 0b00001111,0b11110000,_ | ||
+ | 0b00000111,0b11100000,_ | ||
+ | 0b00000011,0b11000000,_ | ||
+ | 0b00000001,0b10000000,_ | ||
+ | 0b00000000,0b00000000 | ||
+ | | ||
+ | | ||
+ | |||
+ | Defchr &hdb31, 0b00000001,0b10000000,_ | ||
+ | 0b00000011,0b11000000,_ | ||
+ | 0b00001111,0b11110000,_ | ||
+ | 0b00011111,0b11111000,_ | ||
+ | 0b00111111,0b11111100,_ | ||
+ | 0b00111111,0b11111100,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b00011111,0b11111000,_ | ||
+ | 0b00000001,0b10000000,_ | ||
+ | 0b00000111,0b11100000,_ | ||
+ | 0b00001111,0b11110000,_ | ||
+ | 0b00001111,0b11110000 | ||
+ | | ||
+ | Defchr &hdb32, 0b00000011,0b11000000,_ | ||
+ | 0b00000111,0b11100000,_ | ||
+ | 0b00000111,0b11100000,_ | ||
+ | 0b00000111,0b11100000,_ | ||
+ | 0b00000111,0b11100000,_ | ||
+ | 0b01110111,0b11101110,_ | ||
+ | 0b11111011,0b11011111,_ | ||
+ | 0b11111111,0b11111111,_ | ||
+ | 0b11111111,0b11111111,_ | ||
+ | 0b11111111,0b11111111,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b00111101,0b10111100,_ | ||
+ | 0b00000001,0b10000000,_ | ||
+ | 0b00000111,0b11100000,_ | ||
+ | 0b00001111,0b11110000,_ | ||
+ | 0b00001111,0b11110000 | ||
+ | Defchr &hdb33, 0b00111100,0b00111100,_ | ||
+ | 0b01111110,0b01111110,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b11111111,0b11111111,_ | ||
+ | 0b11111111,0b11111111,_ | ||
+ | 0b11111111,0b11111111,_ | ||
+ | 0b11111111,0b11111111,_ | ||
+ | 0b11111111,0b11111111,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b01111111,0b11111110,_ | ||
+ | 0b00111111,0b11111100,_ | ||
+ | 0b00011111,0b11111000,_ | ||
+ | 0b00001111,0b11110000,_ | ||
+ | 0b00000111,0b11100000,_ | ||
+ | 0b00000011,0b11000000,_ | ||
+ | 0b00000001,0b10000000 | ||
+ | | ||
+ | |||
+ | MainMenu | ||
+ | Do | ||
+ | |||
+ | Loop | ||
+ | |||
+ | random: | ||
+ | Incr clock | ||
+ | |||
+ | |||
+ | 'Debug Dec randnum,Cr | ||
+ | Return | ||
+ | |||
+ | |||
+ | welovemax: | ||
+ | TX1 = Sys(10) | ||
+ | TY1 = Sys(11) | ||
+ | If mode=0 Then | ||
+ | |||
+ | If Menucheck(0,TX1,TY1) = 1 Then | ||
+ | rbutton 0 | ||
+ | cval=cval+2 | ||
+ | Ct18contrast cval | ||
+ | Eewrite 0,cval,2 | ||
+ | Glocate 32,160 | ||
+ | Dprint " " | ||
+ | | ||
+ | Glocate 32,160 | ||
+ | Dprint Dec cval | ||
+ | Elseif Menucheck(1,TX1,TY1) = 1 Then 'Contrast - | ||
+ | rbutton 1 | ||
+ | cval=cval-2 | ||
+ | Ct18contrast cval | ||
+ | Eewrite 0,cval,2 | ||
+ | Glocate 32,160 | ||
+ | Dprint " " | ||
+ | | ||
+ | Glocate 32,160 | ||
+ | Dprint Dec cval | ||
+ | | ||
+ | Elseif Menucheck(2,TX1,TY1) = 1 Then 'Start | ||
+ | button 2 | ||
+ | DealMenu | ||
+ | End If | ||
+ | | ||
+ | Elseif mode=1 Then | ||
+ | If Menucheck(0,TX1,TY1) = 1 Then 'STAND | ||
+ | button 0 | ||
+ | |||
+ | PZ | ||
+ | card 1,0,DEALERY,SecondCard | ||
+ | Delay 500 | ||
+ | Do While DealerSum < 17 And DealerAceSum <18 | ||
+ | card DealerCard,0,DEALERY,100 | ||
+ | PZ | ||
+ | Delay 500 | ||
+ | DealerSum=randnum + DealerSum | ||
+ | DealerAceSum=randnum + DealerAceSum | ||
+ | |||
+ | Glocate 136,0 | ||
+ | Dprint " " | ||
+ | Glocate 136,0 | ||
+ | If DealerAceSum <21 And DealerAceSum > DealerSum Then | ||
+ | Gprint "Dealer Has: ", Dec2 DealerAceSum | ||
+ | Debug "Dealer Has: ", Dec2 DealerAceSum,Cr | ||
+ | Else | ||
+ | Gprint "Dealer Has: ", Dec2 DealerSum | ||
+ | Debug "Dealer Has: ", Dec2 DealerSum,Cr | ||
+ | End If | ||
+ | Incr DealerCard | ||
+ | Loop | ||
+ | |||
+ | Glocate 64,64 | ||
+ | Color 0 | ||
+ | Boxfill 50,60,300,90,0 | ||
+ | Color 1 | ||
+ | Box 50,60,300,90 | ||
+ | Font 6,1 | ||
+ | 'Style 1,1,0 | ||
+ | If DealerSum = 21 And PlayerSum <> 21 Then | ||
+ | Gprint "21! Dealer WINS!" | ||
+ | Elseif DealerSum > 21 Then | ||
+ | Gprint "Dealer BUST! " | ||
+ | Elseif DealerSum > PlayerSum Then | ||
+ | Gprint "Dealer WINS! " | ||
+ | Elseif DealerSum = PlayerSum Then | ||
+ | Gprint "PUSH! " | ||
+ | Else | ||
+ | Gprint "Player WINS! " | ||
+ | | ||
+ | End If | ||
+ | | ||
+ | mode=2 | ||
+ | PlayAgainMenu | ||
+ | Elseif Menucheck(1,TX1,TY1) = 1 Then 'HIT | ||
+ | rbutton 1 | ||
+ | card PlayerCard,0,PLAYERY,100 | ||
+ | 'PZ | ||
+ | 'Delay 500 | ||
+ | PlayerSum=randnum + PlayerSum | ||
+ | PlayerAceSum=randnum + PlayerAceSum | ||
+ | Incr PlayerCard | ||
+ | Glocate 136,100 | ||
+ | Dprint " " | ||
+ | Glocate 136,100 | ||
+ | If PlayerAceSum < 22 And PlayerAceSum > PlayerSum Then | ||
+ | Gprint "Player Has: ", Dec PlayerAceSum | ||
+ | Debug "Player Has: ", Dec PlayerAceSum,Cr | ||
+ | Else | ||
+ | Gprint "Player Has: ", Dec PlayerSum | ||
+ | Debug "Player Has: ", Dec PlayerSum,Cr | ||
+ | | ||
+ | End If | ||
+ | | ||
+ | 'Style 1,1,0 | ||
+ | If PlayerSum = 21 Then | ||
+ | Glocate 64,64 | ||
+ | Color 0 | ||
+ | Boxfill 50,60,300,90,0 | ||
+ | Color 1 | ||
+ | Box 50,60,300,90 | ||
+ | Font 6,1 | ||
+ | Gprint "21! Player WINS!" | ||
+ | mode=2 | ||
+ | PlayAgainMenu | ||
+ | |||
+ | Elseif PlayerSum > 21 Then | ||
+ | Glocate 64,64 | ||
+ | Color 0 | ||
+ | Boxfill 50,60,300,90,0 | ||
+ | Color 1 | ||
+ | Box 50,60,300,90 | ||
+ | Font 6,1 | ||
+ | Gprint "Player BUST! " | ||
+ | mode=2 | ||
+ | PlayAgainMenu | ||
+ | End If | ||
+ | |||
+ | | ||
+ | |||
+ | End If | ||
+ | | ||
+ | Elseif mode=2 Then | ||
+ | If Menucheck(0,TX1,TY1) = 1 Then 'Play Again | ||
+ | button 0 | ||
+ | mode=1 | ||
+ | DealMenu | ||
+ | Elseif Menucheck(1,TX1,TY1) = 1 Then 'Main Menu | ||
+ | button 1 | ||
+ | mode=0 | ||
+ | MainMenu | ||
+ | End If | ||
+ | | ||
+ | End If | ||
+ | |||
+ | Return | ||
+ | |||
+ | |||
+ | End | ||
+ | |||
+ | Sub button(k As Byte) | ||
+ | Menureverse k | ||
+ | PZ | ||
+ | Delay 500 | ||
+ | End Sub | ||
+ | |||
+ | Sub rbutton(k As Byte) | ||
+ | Menureverse k | ||
+ | ' Pulsout 18,50 | ||
+ | PZ | ||
+ | Delay 500 | ||
+ | Menureverse k | ||
+ | | ||
+ | End Sub | ||
+ | |||
+ | |||
+ | |||
+ | Sub card(cardnum As Byte,cardtype As Byte,sy As Integer, random As Byte) | ||
+ | Dim sp As Integer | ||
+ | Dim sx As Integer | ||
+ | ' Dim sy As Integer | ||
+ | Dim width As Integer, height As Integer | ||
+ | | ||
+ | |||
+ | sx=8 | ||
+ | ' sy=100 | ||
+ | | ||
+ | width=38 | ||
+ | height=65 | ||
+ | sp =width+3 | ||
+ | |||
+ | |||
+ | Box sx+(cardnum*sp),sy,sx+width+(cardnum*sp),sy+height | ||
+ | Glocate sx+(cardnum*sp)+3,sy + 5 | ||
+ | If random=100 Then | ||
+ | |||
+ | randnum=Rnd(0) | ||
+ | randnum=randnum+clock | ||
+ | randnum=randnum mod 52 | ||
+ | RandomCard = randnum | ||
+ | Else | ||
+ | randnum=random | ||
+ | Debug "randnum: ",Dec randnum,Cr | ||
+ | Color 0 | ||
+ | Box sx+(cardnum*sp)+3,sy+3,sx+width+(cardnum*sp)-3,sy+height-3 | ||
+ | Color 1 | ||
+ | End If | ||
+ | | ||
+ | | ||
+ | If cardtype=0 Then | ||
+ | If randnum<13 Then | ||
+ | Gprint Chr(&hdb30) | ||
+ | Glocate sx+width-18+(cardnum*sp),sy+height-18 | ||
+ | Gprint Chr(&hdb30) | ||
+ | |||
+ | Elseif randnum<26 Then | ||
+ | Gprint Chr(&hdb31) | ||
+ | Glocate sx+width-18+(cardnum*sp),sy+height-18 | ||
+ | Gprint Chr(&hdb31) | ||
+ | | ||
+ | Elseif randnum<39 Then | ||
+ | Gprint Chr(&hdb32) | ||
+ | Glocate sx+width-18+(cardnum*sp),sy+height-18 | ||
+ | Gprint Chr(&hdb32) | ||
+ | | ||
+ | Else ' Elseif cardtype=3 Then | ||
+ | Gprint Chr(&hdb33) | ||
+ | Glocate sx+width-18+(cardnum*sp),sy+height-18 | ||
+ | Gprint Chr(&hdb33) | ||
+ | | ||
+ | End If | ||
+ | |||
+ | Glocate sx+width/2+(cardnum*sp),sy+height/3 | ||
+ | Style 0,0,0 | ||
+ | Font 4,1 | ||
+ | | ||
+ | randnum=randnum mod 13 | ||
+ | randnum=randnum+1 | ||
+ | | ||
+ | If randnum = 1 Then | ||
+ | Gprint "A" | ||
+ | Elseif randnum = 11 Then | ||
+ | Gprint "J" | ||
+ | randnum=10 | ||
+ | Elseif randnum = 12 Then | ||
+ | Gprint "Q" | ||
+ | randnum=10 | ||
+ | Elseif randnum = 13 Then | ||
+ | Gprint "K" | ||
+ | randnum=10 | ||
+ | Else | ||
+ | |||
+ | Gprint Dec randnum | ||
+ | End If | ||
+ | | ||
+ | Elseif cardtype=1 Then | ||
+ | randnum=randnum mod 13 | ||
+ | randnum=randnum+1 | ||
+ | If randnum = 11 Then | ||
+ | randnum=10 | ||
+ | Elseif randnum = 12 Then | ||
+ | randnum=10 | ||
+ | Elseif randnum = 13 Then | ||
+ | randnum=10 | ||
+ | End If | ||
+ | | ||
+ | Linestyle 2 | ||
+ | Box sx+(cardnum*sp)+3,sy+3,sx+width+(cardnum*sp)-3,sy+height-3 | ||
+ | Linestyle 1 | ||
+ | End If | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | ' Menuset 1,2,30+(cardnum*50),130,80+(cardnum*50),200 | ||
+ | |||
+ | End Sub | ||
+ | |||
+ | Sub MainMenu() | ||
+ | Cls | ||
+ | Delay 100 | ||
+ | Welcome | ||
+ | Glocate 32,160 | ||
+ | Dprint Dec cval | ||
+ | |||
+ | |||
+ | 'card 2,0,80,0 | ||
+ | card 3,0,80,0 | ||
+ | card 4,0,80,23 | ||
+ | 'card 5,0,80,39 | ||
+ | |||
+ | End Sub | ||
+ | Sub DealMenu() | ||
+ | Cls | ||
+ | Delay 500 | ||
+ | Font 4,1 | ||
+ | Style 0,0,0 | ||
+ | Glocate 0,0 | ||
+ | Gprint "Dealer (MAX) " | ||
+ | Glocate 0,100 | ||
+ | Gprint "Player (You) " | ||
+ | | ||
+ | 'Dealer's First Card | ||
+ | card 0,0,DEALERY,100 | ||
+ | ' Pulsout 18,100 | ||
+ | PZ | ||
+ | Delay 500 | ||
+ | | ||
+ | DealerSum=randnum | ||
+ | If DealerSum=1 Then | ||
+ | DealerAceSum=11 | ||
+ | Else | ||
+ | DealerAceSum=randnum | ||
+ | End If | ||
+ | | ||
+ | Debug "Dealer 1st Card: ", Dec DealerSum,Cr | ||
+ | 'Dealer's Second Card | ||
+ | card 1,1,DEALERY,100 | ||
+ | DealerCard=2 | ||
+ | PlayerCard=2 | ||
+ | ' Pulsout 18,100 | ||
+ | PZ | ||
+ | Delay 500 | ||
+ | 'Save Dealer's Second Card | ||
+ | SecondCard=RandomCard | ||
+ | | ||
+ | DealerSum=randnum + DealerSum | ||
+ | If DealerAceSum <> 11 And randnum=1 Then | ||
+ | DealerAceSum=11 + DealerAceSum | ||
+ | End If | ||
+ | |||
+ | Debug "Dealer 2nd Card: ", Dec randnum,Cr | ||
+ | Glocate 136,0 | ||
+ | If DealerAceSum=21 Then | ||
+ | Gprint "Dealer Has: ", Dec DealerAceSum | ||
+ | Debug "Dealer Has: ", Dec DealerAceSum,Cr | ||
+ | Else | ||
+ | Gprint "Dealer Has: ", Dec DealerSum | ||
+ | Debug "Dealer Has: ", Dec DealerSum,Cr | ||
+ | End If | ||
+ | |||
+ | card 0,0,PLAYERY,100 | ||
+ | ' Pulsout 18,100 | ||
+ | PZ | ||
+ | Delay 500 | ||
+ | PlayerSum=randnum | ||
+ | If randnum=1 Then | ||
+ | PlayerAceSum=11 | ||
+ | Else | ||
+ | PlayerAceSum=randnum | ||
+ | End If | ||
+ | FirstCard=randnum | ||
+ | | ||
+ | card 1,0,PLAYERY,100 | ||
+ | ' Pulsout 18,100 | ||
+ | PZ | ||
+ | Delay 500 | ||
+ | PlayerSum=randnum+PlayerSum | ||
+ | If randnum=1 And PlayerAceSum <> 11 Then | ||
+ | PlayerAceSum=PlayerAceSum + 11 | ||
+ | Else | ||
+ | PlayerAceSum=PlayerAceSum + randnum | ||
+ | End If | ||
+ | | ||
+ | Glocate 136,100 | ||
+ | | ||
+ | If (PlayerAceSum > PlayerSum) And (PlayerSum <21) Then | ||
+ | Gprint "Player Has: ", Dec PlayerAceSum | ||
+ | Debug "Player Has: ", Dec PlayerAceSum,Cr | ||
+ | Else | ||
+ | Gprint "Player Has: ", Dec PlayerSum | ||
+ | Debug "Player Has: ", Dec PlayerSum,Cr | ||
+ | End If | ||
+ | ' Style 0,0,0 | ||
+ | Font 4,1 | ||
+ | Menuset 0,2,0,200,100,230 | ||
+ | Menutitle 0,10,10,"Stand" | ||
+ | |||
+ | Menuset 1,2,110,200,210,230 | ||
+ | Menutitle 1,10,10,"Hit" | ||
+ | | ||
+ | If randnum = FirstCard Then | ||
+ | Menuset 2,2,220,200,300,230 | ||
+ | Menutitle 2,10,10,"Split" | ||
+ | End If | ||
+ | | ||
+ | mode=1 | ||
+ | | ||
+ | If (DealerSum = 21 And PlayerSum <> 21) Or (DealerAceSum = 21 And PlayerSum <> 21)Then | ||
+ | PZ | ||
+ | card 1,0,DEALERY,SecondCard | ||
+ | Delay 500 | ||
+ | | ||
+ | Font 4,1 | ||
+ | Glocate 64,64 | ||
+ | Color 0 | ||
+ | Boxfill 50,60,300,90,0 | ||
+ | Color 1 | ||
+ | Box 50,60,300,90 | ||
+ | Gprint "BLACK JACK! Dealer WINS!" | ||
+ | mode=2 | ||
+ | PlayAgainMenu | ||
+ | |||
+ | Elseif (PlayerSum = 21 And DealerSum <> 21) Or (PlayerAceSum = 21 And DealerSum <> 21) Then | ||
+ | Font 4,1 | ||
+ | Glocate 64,64 | ||
+ | Color 0 | ||
+ | Boxfill 50,60,300,90,0 | ||
+ | Color 1 | ||
+ | Box 50,60,300,90 | ||
+ | Gprint "BLACK JACK! Player WINS!" | ||
+ | mode=2 | ||
+ | PlayAgainMenu | ||
+ | | ||
+ | End If | ||
+ | End Sub | ||
+ | Sub PlayAgainMenu() | ||
+ | Style 0,0,0 | ||
+ | Font 4,1 | ||
+ | Color 0 | ||
+ | Boxfill 0,200,319,230,0 | ||
+ | Color 1 | ||
+ | Menuset 0,2,0,200,100,230 | ||
+ | Menutitle 0,10,10,"Play Again" | ||
+ | |||
+ | Menuset 1,2,110,200,210,230 | ||
+ | Menutitle 1,10,10,"Main Menu" | ||
+ | End Sub | ||
+ | #include "BlackJack.inc" | ||
+ | |||
+ | |||
+ | </code> | ||
+ | |||
+ | blackjack.inc 파일입니다. | ||
+ | |||
+ | <code xbasic> | ||
+ | |||
+ | SUB WELCOME() | ||
+ | FONT 4,1 | ||
+ | STYLE 0,0,0 | ||
+ | GLOCATE 22,4 | ||
+ | GPRINT "Max Vegas Black Jack Hustler " | ||
+ | GLOCATE 22,20 | ||
+ | GPRINT "v.0.0.3" | ||
+ | FONT 0,0 | ||
+ | MENUSET 0,2,10,200,32,218 | ||
+ | MENUTITLE 0,7,1,"+" | ||
+ | MENUSET 1,2,38,200,62,218 | ||
+ | MENUTITLE 1,8,1,"-" | ||
+ | MENUSET 2,2,84,194,212,239 | ||
+ | MENUTITLE 2,46,14,"START" | ||
+ | GLOCATE 2,224 | ||
+ | GPRINT "Contrast" | ||
+ | FONT 4,0 | ||
+ | END SUB | ||
+ | |||
+ | SUB DEAL() | ||
+ | |||
+ | END SUB | ||
+ | |||
+ | </code> |