Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name BlackJackPlayer
- @inputs MoneyPot Dealer Screen:wirelink
- @outputs EmptyPot Money
- @persist Cards:table Name:string
- if(first()) {
- function void wirelink:centerHString(String:string, Y, Clr) {
- X = 15-round(String:length()/2)
- This:writeString(String, X, Y, Clr)
- }
- function string getCardName(Pos) {
- Card = Cards[Pos,vector2]
- if(Card:x()==10) {
- String = "Jack of "
- } elseif(Card:x()==11) {
- String = "Queen of "
- } elseif(Card:x()==12) {
- String = "King of "
- } elseif(Card:x()==0) {
- String = "Ace of "
- } else {
- String = (Card:x()+1)+" of "
- }
- if(Card:y()==1) {
- String += "Hearts"
- } elseif(Card:y()==2) {
- String += "Diamonds"
- } elseif(Card:y()==3) {
- String += "Clubs"
- } elseif(Card:y()==4) {
- String += "Spades"
- }
- return String
- }
- function number totalCount() {
- local Count = 0
- Aces = 0
- for(I=1, Cards:count()) {
- Card = Cards[I,vector2]
- Number = Card:x()+1
- if(Number>=2 & Number<=10) {
- Count += Number
- }
- if(Number==1) {
- Aces++
- }
- if(Number>10) {
- Count += 10
- }
- }
- for(I=1,Aces) {
- if(Count+11>21) {
- Count++
- } else {
- Count += 11
- }
- }
- return Count
- }
- function void updateScreen() {
- Screen[2041] = 1
- Screen:centerHString("Robby's Blackjack", 0, 900)
- if(Money) {
- Screen:centerHString(Name, 1, 339)
- Screen:centerHString("Cards", 3, 933)
- for(I=1, Cards:count()) {
- String = getCardName(I)
- Screen:centerHString(String, I+3, 999)
- }
- Screen:centerHString("Total", Cards:count()+5, 393)
- Screen:centerHString(totalCount():toString(), Cards:count()+6, 999)
- Screen:centerHString("Bid: "+Money, 17, 90)
- } else {
- Screen:centerHString("Bid required to play.", 8, 9)
- }
- }
- }
- if(~MoneyPot & MoneyPot) {
- findByClass("player")
- findSortByDistance(Screen:entity():boxCenterW()+Screen:entity():up()*10)
- Array = findToArray()
- Name = Array[1,entity]:name()
- dsSendDirect("Name", entity(Dealer), Name)
- Money = MoneyPot
- EmptyPot = MoneyPot
- } else {
- EmptyPot = 0
- }
- if(dsClk("Deal")) {
- Cards:pushVector2(dsGetVector2())
- dsSendDirect("Count", entity(Dealer), totalCount())
- }
- if(dsClk("Reset")) {
- Cards = table()
- Name = ""
- Money = 0
- dsSendDirect("Count", entity(Dealer), 0)
- }
- updateScreen()
Advertisement
Add Comment
Please, Sign In to add comment