Advertisement
MissEshock2002

SexScripts Strip Jack Naked Example

Sep 7th, 2020
1,268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 3.75 KB | None | 0 0
  1. setInfos(9, "Strip Jack Naked Example",
  2.         "Strip Jack Naked card game",
  3.         "MissEshock2002",
  4.         "v1.0", 0x222222, "en", ["example", "tutorial", "card game"]);
  5.  
  6. // list to map the cards to the card images for "images/cards/deck0" or
  7. // the cards from the bacara packs
  8. // the index is the image name. example: IMAGE_MAP.indexOf("AC") -> "0.png"
  9. List<String> IMAGE_MAP = [
  10.         "AC", "AD", "AH", "AS", "2C", "2D", "2H", "2S", "3C", "3D", "3H", "3S", "4C", "4D", "4H", "4S",
  11.         "5C", "5D", "5H", "5S", "6C", "6D", "6H", "6S", "7C", "7D", "7H", "7S", "8C", "8D", "8H", "8S",
  12.         "9C", "9D", "9H", "9S", "TC", "TD", "TH", "TS", "JC", "JD", "JH", "JS", "QC", "QD", "QH", "QS",
  13.         "KC", "KD", "KH", "KS"
  14. ]
  15.  
  16. // a deck of cards is made of 13 ranks times 4 suits = 52 cards. 'T' is for 10
  17. List<Character> RANKS = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']
  18. List<Character> SUITS = ['C', 'D', 'H', 'S']
  19.  
  20.  
  21. // game vars:
  22. List<String> PENALTY_CARDS = ["J", "Q", "K", "A"]  // number of penalty cards = position in list + 1
  23. int player  // current player to draw a card, pay a penalty, or win central deck
  24. int draws = 1  // number of cards to draw
  25. boolean penalty = false
  26. //String card
  27. List<String> centralDeck = []
  28. List<List> decks = [[], []]  // player 0 deck = decks[0]; player 1 deck = decks[1]
  29.  
  30. // debug:
  31. String logText = ""
  32.  
  33.  
  34. def log = { String _log = "" ->
  35.     logText += "\n----" +
  36.             "\n${_log}" +
  37.             "\ndeck 0 = ${decks[0]}" +
  38.             "\ndeck c = ${centralDeck}" +
  39.             "\ndeck 1 = ${decks[1]}"
  40.     show(logText)
  41. }
  42.  
  43. def getDeck = {
  44.     /** return a shuffled deck of 52 cards */
  45.     List<String> _deck = []
  46.  
  47.     // put 13 ranks and 4 suits to 52 cards: "AC", "AD", "AH", ...
  48.     RANKS.each { rank ->
  49.         SUITS.each { suit ->
  50.             _deck.add(rank + suit)
  51.         }
  52.     }
  53.     // shuffle the deck befor returning
  54.     Collections.shuffle(_deck)
  55.     return _deck
  56. }
  57.  
  58. def resetGame = {
  59.     player = 0
  60.     centralDeck.clear()
  61.     // split a deck in half:
  62.     List<String> deck = getDeck() // make a deck of 52 cards
  63.     int halfDeckSize = (int) Math.ceil(deck.size() / 2)
  64.     decks[0] = deck[0..(halfDeckSize - 1)]
  65.     decks[1] = deck[halfDeckSize..(deck.size() - 1)]
  66. }
  67.  
  68. def switchPlayer = {
  69.     player = (player + 1) % 2
  70. }
  71.  
  72. def drawCard = { int _player ->
  73.     /** draw card from player and put on central deck */
  74.     String _card = decks[_player].pop()
  75.     centralDeck.add(_card)
  76.     return _card
  77. }
  78.  
  79.  
  80. boolean endGame = false
  81. while (!endGame) {
  82.     resetGame()
  83.  
  84.     // for debug:
  85. //    decks = [["0", "Q", "0", "0", "0"],
  86. //             ["1", "1", "1", "K", "1"]]
  87.  
  88.     log("Start")
  89.     showButton("Start ->")
  90.  
  91.     boolean gameOver = false
  92.     while (!gameOver) {
  93.  
  94.         draws = 1
  95.         penalty = false
  96.  
  97. //        while (draws > 0 && decks[0].size() > 0 && decks[1].size() > 0) {
  98.         while (draws > 0 && decks[player].size() > 0) {
  99.             draws--
  100.             String card = drawCard(player)
  101.             log("player ${player} draws ${card} - penalty = ${penalty}")
  102.             if (card[0] in PENALTY_CARDS) {
  103.                 penalty = true
  104.                 switchPlayer()
  105.                 draws = PENALTY_CARDS.indexOf(card[0]) + 1
  106.             }
  107.         }
  108.  
  109.         switchPlayer()
  110.  
  111.         // pay winner:
  112.         if (penalty) {
  113.             decks[player].addAll(centralDeck)
  114.             centralDeck.clear()
  115.             log("player ${player} wins central deck")
  116.         }
  117.  
  118.         if (decks[0].size() <= 0 || decks[1].size() <= 0) {
  119.             gameOver = true
  120.             log("player ${player} wins! opponent is out of cards")
  121.         }
  122.     }
  123.  
  124.     showButton("Game Over")
  125.  
  126.     if (!getBoolean("Play again?")) endGame = true
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement