Guest User

Playing Cards

a guest
Feb 14th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. if(!isObject(DeckDataGroup))
  2. {
  3. new SimGroup(DeckDataGroup);
  4. new SimGroup(DeckGroup);
  5. }
  6.  
  7. function newDeckData(%name,%values)
  8. {
  9. if(getWordCount(%values) > 15)
  10. {
  11. error("Deck " @ %name @ " contains more than 15 values");
  12. return;
  13. }
  14. %d = "Deck" @ %name @ "Data";
  15. if(isObject(%d))
  16. {
  17. error("Deck " @ %name @ " exists, replacing.");
  18. %d.delete();
  19. }
  20. %do = new ScriptObject()
  21. {
  22. class = "DeckDataSO";
  23. name = %name;
  24. };
  25. %do.setName(%d);
  26. for(%x=0;%x<getWordCount(%values);%x++)
  27. %do.value[%x] = getWord(%values,%x);
  28. %do.values = %x;
  29. %do.cards = 0;
  30. DeckDataGroup.add(%do);
  31. }
  32.  
  33. function DeckDataSO::addCard(%this,%v0,%v1,%v2,%v3,%v4,%v5,%v6,%v7,%v8,%v9,%v10,%v11,%v12,%v13,%v14)
  34. {
  35. for(%x=0;%x<%this.values;%x++)
  36. %this.cv[%this.cards,%this.value[%x]] = %v[%x];
  37. %this.cards++;
  38. }
  39.  
  40. function DeckDataSO::makeDeck(%this)
  41. {
  42. %do = new ScriptObject()
  43. {
  44. class = "DeckSO";
  45. cards = %this.cards;
  46. data = %this;
  47. };
  48. for(%x=0;%x<%this.cards;%x++)
  49. %do.card[%x] = %x;
  50. DeckGroup.add(%do);
  51. return %do;
  52. }
  53.  
  54. function DeckSO::shuffleDeck(%this)
  55. {
  56. for(%x=0;%x<%this.cards;%x++)
  57. %temp[%x] = %this.card[%x];
  58. for(%x=0;%x<%this.cards;%x++)
  59. {
  60. %tlcount = 0;
  61. for(%y=0;%y<%this.cards;%y++)
  62. if(!%ct[%y])
  63. {
  64. %tl[%tlcount] = %y;
  65. %tlcount++;
  66. }
  67. %c = getRandom(0,%tlcount-1);
  68. %ct[%tl[%c]] = 1;
  69. %this.card[%x] = %temp[%tl[%c]];
  70. }
  71. }
  72.  
  73. function DeckSO::drawCard(%this)
  74. {
  75. //We draw from the 'top', to make things simple, it's the highest .card[%x]
  76. %card = %this.card[%this.cards-1];
  77. %this.card[%this.cards-1] = "";
  78. %this.cards--;
  79. return %card;
  80. }
  81.  
  82. function DeckSO::drawCardPos(%this,%pos)
  83. {
  84. if(%pos >= %this.cards || %pos < 0 || !isInt(%pos))
  85. {
  86. error("Invalid position, drawing from top instead. (DECK ID: " @ %this @ ")");
  87. return %this.drawCard();
  88. }
  89. %card = %this.card[%pos];
  90. for(%x=%pos;%x<%this.cards;%x++)
  91. %this.card[%x] = %this.card[%x+1];
  92. %this.cards--;
  93. return %card;
  94. }
  95.  
  96. function DeckSO::drawCardNum(%this,%num)
  97. {
  98. %flag = 1;
  99. for(%x=0;%x<%this.cards;%x++;)
  100. {
  101. if(%this.card[%x] == %num)
  102. {
  103. %flag = 0;
  104. %pos = %x;
  105. break;
  106. }
  107. }
  108. if(%flag || !isInt(%num))
  109. {
  110. error("Invalid card, drawing from top instead. (DECK ID: " @ %this @ ")");
  111. return %this.drawCard();
  112. }
  113. for(%x=%pos;%x<%this.cards;%x++)
  114. %this.card[%x] = %this.card[%x+1];
  115. %this.cards--;
  116. return %num;
  117. }
  118.  
  119. function DeckSO::addCard(%this,%num,%pos)
  120. {
  121. //%pos is 0 for bottom, 1 for top
  122. for(%x=0;%x<%this.cards;%x++)
  123. {
  124. if(%this.card[%x] == %num)
  125. {
  126. error("Card " @ %this.data.cv[%num,0] @ " (" @ %num @ ") already in deck.");
  127. return;
  128. }
  129. }
  130. if(%pos)
  131. {
  132. for(%x=%this.cards-1;%x>=0;%x--)
  133. %this.card[%x+1] = %this.card[%x];
  134. %this.card[0] = %num;
  135. }
  136. else
  137. %this.card[%this.cards] = %num;
  138. %this.cards++;
  139. }
  140.  
  141. if(!isFunction(isInt))
  142. exec("./isint.cs");
  143.  
  144.  
  145.  
  146.  
  147. //Standard Decks//
  148.  
  149.  
  150.  
  151. newDeckData("Standard","name suit color rank");
  152. newDeckData("JokersStandard","name suit color rank");
  153. for(%x=0;%x<4;%x++)
  154. {
  155. switch(%x)
  156. {
  157. case 0:
  158. %s = "Spades";
  159. %c = "Black";
  160. case 1:
  161. %s = "Hearts";
  162. %c = "Red";
  163. case 2:
  164. %s = "Clubs";
  165. %c = "Black";
  166. case 3:
  167. %s = "Diamonds";
  168. %c = "Red";
  169. }
  170. %n = "Ace";
  171. DeckStandardData.addCard(%n @ " of " @ %s,%s,%c,%n);
  172. DeckJokersStandardData.addCard(%n @ " of " @ %s,%s,%c,%n);
  173. for(%y=2;%y<11;%y++)
  174. {
  175. %n = %y;
  176. DeckStandardData.addCard(%n @ " of " @ %s,%s,%c,%n);
  177. DeckJokersStandardData.addCard(%n @ " of " @ %s,%s,%c,%n);
  178. }
  179. %n = "Jack";
  180. DeckStandardData.addCard(%n @ " of " @ %s,%s,%c,%n);
  181. DeckJokersStandardData.addCard(%n @ " of " @ %s,%s,%c,%n);
  182. %n = "Queen";
  183. DeckStandardData.addCard(%n @ " of " @ %s,%s,%c,%n);
  184. DeckJokersStandardData.addCard(%n @ " of " @ %s,%s,%c,%n);
  185. %n = "King";
  186. DeckStandardData.addCard(%n @ " of " @ %s,%s,%c,%n);
  187. DeckJokersStandardData.addCard(%n @ " of " @ %s,%s,%c,%n);
  188. }
  189. DeckJokersStandardData.addCard("Black Joker",Joker,Black,Joker);
  190. DeckJokersStandardData.addCard("Red Joker",Joker,Red,Joker);
Advertisement
Add Comment
Please, Sign In to add comment