blurner

BlackJackPlayer

Dec 3rd, 2012
1,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. @name BlackJackPlayer
  2. @inputs MoneyPot Dealer Screen:wirelink
  3. @outputs EmptyPot Money
  4. @persist Cards:table Name:string
  5. if(first()) {
  6. function void wirelink:centerHString(String:string, Y, Clr) {
  7. X = 15-round(String:length()/2)
  8. This:writeString(String, X, Y, Clr)
  9. }
  10. function string getCardName(Pos) {
  11. Card = Cards[Pos,vector2]
  12. if(Card:x()==10) {
  13. String = "Jack of "
  14. } elseif(Card:x()==11) {
  15. String = "Queen of "
  16. } elseif(Card:x()==12) {
  17. String = "King of "
  18. } elseif(Card:x()==0) {
  19. String = "Ace of "
  20. } else {
  21. String = (Card:x()+1)+" of "
  22. }
  23. if(Card:y()==1) {
  24. String += "Hearts"
  25. } elseif(Card:y()==2) {
  26. String += "Diamonds"
  27. } elseif(Card:y()==3) {
  28. String += "Clubs"
  29. } elseif(Card:y()==4) {
  30. String += "Spades"
  31. }
  32. return String
  33. }
  34. function number totalCount() {
  35. local Count = 0
  36. Aces = 0
  37. for(I=1, Cards:count()) {
  38. Card = Cards[I,vector2]
  39. Number = Card:x()+1
  40. if(Number>=2 & Number<=10) {
  41. Count += Number
  42. }
  43. if(Number==1) {
  44. Aces++
  45. }
  46. if(Number>10) {
  47. Count += 10
  48. }
  49. }
  50. for(I=1,Aces) {
  51. if(Count+11>21) {
  52. Count++
  53. } else {
  54. Count += 11
  55. }
  56. }
  57. return Count
  58. }
  59. function void updateScreen() {
  60. Screen[2041] = 1
  61. Screen:centerHString("Robby's Blackjack", 0, 900)
  62. if(Money) {
  63. Screen:centerHString(Name, 1, 339)
  64. Screen:centerHString("Cards", 3, 933)
  65. for(I=1, Cards:count()) {
  66. String = getCardName(I)
  67. Screen:centerHString(String, I+3, 999)
  68. }
  69. Screen:centerHString("Total", Cards:count()+5, 393)
  70. Screen:centerHString(totalCount():toString(), Cards:count()+6, 999)
  71. Screen:centerHString("Bid: "+Money, 17, 90)
  72. } else {
  73. Screen:centerHString("Bid required to play.", 8, 9)
  74. }
  75. }
  76. }
  77. if(~MoneyPot & MoneyPot) {
  78. findByClass("player")
  79. findSortByDistance(Screen:entity():boxCenterW()+Screen:entity():up()*10)
  80. Array = findToArray()
  81. Name = Array[1,entity]:name()
  82. dsSendDirect("Name", entity(Dealer), Name)
  83. Money = MoneyPot
  84. EmptyPot = MoneyPot
  85. } else {
  86. EmptyPot = 0
  87. }
  88. if(dsClk("Deal")) {
  89. Cards:pushVector2(dsGetVector2())
  90. dsSendDirect("Count", entity(Dealer), totalCount())
  91. }
  92. if(dsClk("Reset")) {
  93. Cards = table()
  94. Name = ""
  95. Money = 0
  96. dsSendDirect("Count", entity(Dealer), 0)
  97. }
  98. updateScreen()
Advertisement
Add Comment
Please, Sign In to add comment