QuickJack

From Second Life Wiki
Jump to navigation Jump to search

Created by Kira Komarov.

Introduction

QuickJack, as the name implies, is a quick game of blackjack against the computer which is played by triggering touch-only events: no textboses, no dialogs, etc... It is a minimalist version of blackjack lacking the ace (the ace is considered to have the value 1).

Setup

Simply dump the script below into a primitive and you are ready to go.

Playing

The goal of the game is to draw as many cards as necessary in order to reach a value as close as possible to 21 but without going over that value. If a player draws too many cards and they add up to a value over 21 then that player is considered busted and they lose the game. The gamble is to stop as close as possible to the value of 21 and hope that the other player (the computer in this script's case) gets busted trying to reach a value higher than the first player.

As you might have guessed, the cards you can draw have special values. The numeric cards:

❶ ❷ ❸ ❹ ❺ ❻ ❼ ❽ ❾ ❿

have the values that you see.

However, the special cards:

♠ ♣ ♥ ♦

all have a value of 10.

How to Play

  1. When the scripts starts, you touch the primitive and draw the first card.
  2. You have 10 seconds to touch the primitive again in order to draw another card.
  3. When you want to hold, you simply do not touch the primitive for 10 seconds.
  4. After not touching the primitive for 10 seconds, the house (computer) will start playing.
  5. The script will display the outcome and the script will reset.

Code

<lsl> ////////////////////////////////////////////////////////// // [K] Kira Komarov - 2012, License: GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html // // for legal details, rights of fair usage and // // the disclaimer and warranty conditions. // //////////////////////////////////////////////////////////

list cGraphics = ["❶","❷","❸","❹","❺","❻","❼","❽","❾","❿","♠","♣","♥","♦"]; list cValues = [1,2,3,4,5,6,7,8,9,10,10,10,10,10];

integer player_amount = 0; integer house_amount = 0; string player_hand = ""; string house_hand = ""; string player_name = "";

default {

   state_entry() {
       llSetText("✪ Touch to play Quickjack! ✪", <1,1,1>, 1.0);
   }
   touch_start(integer num) {
       player_name = llDetectedName(0);
       state player;
   }

}

state player {

   state_entry() {
       integer rnd = (integer)llFrand(llGetListLength(cGraphics));
       player_amount += llList2Integer(cValues, rnd);
       if(player_amount > 21) {
           llSay(0, player_name + " is busted.");
           llResetScript();
       }
       player_hand += llList2String(cGraphics, rnd);
       llSetText(player_name + "'s hand is: " + player_hand, <1,1,1>, 1.0);
       llSetTimerEvent(10);
   }
   touch_start(integer total_number) {
       if(llDetectedName(0) != player_name) return;
       integer rnd = (integer)llFrand(llGetListLength(cGraphics));
       player_amount += llList2Integer(cValues, rnd);
       if(player_amount > 21) {
           llSetText(player_name + " is busted: " + (string)player_amount + "!", <1,1,1>, 1.0);
           state busted;
       }
       player_hand += llList2String(cGraphics, rnd);
       llSetText(player_name + "'s hand is: " + player_hand, <1,1,1>, 1.0);
       llSetTimerEvent(10);
   }
   timer() {
       state player_house;
   }

}

state player_house {

   state_entry() {
       llSetTimerEvent(1+llFrand(4));
   }
   timer() {
       integer rnd = (integer)llFrand(llGetListLength(cGraphics));
       house_amount += llList2Integer(cValues, rnd);
       if(house_amount > 21) {
           llSetText("House is busted: " + (string)house_amount + "!", <1,1,1>, 1.0);
           state busted;
       }
       if(house_amount >= player_amount)
           state score;
       house_hand += llList2String(cGraphics, rnd);
       llSetText(player_name + "'s hand is: " + player_hand + "\nHouse hand is: " + house_hand, <1,1,1>, 1.0);
   }

}

state score {

   state_entry() {
       if(player_amount <= house_amount) {
           llSetText("House wins with: " + (string)house_amount, <1,1,1>, 1.0);
           llSetTimerEvent(10);
           return;
       }
       llSetText(player_name + " wins with: " + (string)house_amount, <1,1,1>, 1.0);
       llSetTimerEvent(10);
       return;
   }
   timer() {
       llResetScript();
   }

}

state busted {

   state_entry() {
       llSetTimerEvent(10);
   }
   timer() {
       llResetScript();
   }

}

</lsl>