///////////////////////////////////////////////////////////////////////////// // threecardmonty.mel Version 1.0 by Andrew Osiow Copyright 2009 // // Fun script to play three card monty game in Maya // User shuffles the cards and then trys to pick the Queen // // Script displays a message whether the user was successful or not // ///////////////////////////////////////////////////////////////////////////// global proc threecardmonty() {// opens a three card monty interface // delete any three card monty window preferences if (`windowPref -ex threeCardMontyWindow`) windowPref -remove threeCardMontyWindow; // delete any three card monty window structures if (`window -ex threeCardMontyWindow`) deleteUI threeCardMontyWindow; // create a window structure string $threeCardMontyWin = `window -title "3 Card Monty! v1.0" -iconName "3 Card Monty" -rtf 1 -s 0 // resize to fit - no size gadget threeCardMontyWindow`; // create Crystal Ball layout string $threeCardMontyForm = `formLayout -w 200 -h 90 -numberOfDivisions 100`; text -label "Ready to Play? - Then press Shuffle." monTitleText; button -en 0 -width 60 -height 26 -label "Jack" -align "center" -command "" card1Button; button -en 0 -width 60 -height 26 -label "Queen" -align "center" -command "" card2Button; button -en 0 -width 60 -height 26 -label "Jack" -align "center" -command "" card3Button; button -width 90 -height 26 -label "Shuffle" -align "center" -command "montyShuffle" shuffleMontyButton; // Shuffle Cards button -width 90 -height 26 -label "I'm Done." -command "deleteUI threeCardMontyWindow" closeMontyButton; // Closes Interface formLayout -e -af "monTitleText" "left" 14 -af "monTitleText" "top" 6 -af "card1Button" "left" 6 -af "card1Button" "top" 26 -af "card2Button" "left" 70 -af "card2Button" "top" 26 -af "card3Button" "left" 134 -af "card3Button" "top" 26 -af "shuffleMontyButton" "left" 4 -af "shuffleMontyButton" "top" 60 -af "closeMontyButton" "top" 60 -af "closeMontyButton" "right" 4 $threeCardMontyForm; // display three card monty window showWindow $threeCardMontyWin; } global proc montyResults(int $card, int $button) { // return the Results detepending on what was found switch ($card) { case 1: button -e -en 0 -label "Queen" -w 60 card1Button; button -e -en 0 -label "Jack" -w 60 card2Button; button -e -en 0 -label "Jack" -w 60 card3Button; break; case 2: button -e -en 0 -label "Jack" -w 60 card1Button; button -e -en 0 -label "Queen" -w 60 card2Button; button -e -en 0 -label "Jack" -w 60 card3Button; break; case 3: button -e -en 0 -label "Jack" -w 60 card1Button; button -e -en 0 -label "Jack" -w 60 card2Button; button -e -en 0 -label "Queen" -w 60 card3Button; break; } if ($card==$button) text -e -label "Great! You won. Play Again?" monTitleText; else text -e -label "Oops! Too bad. Play Again?" monTitleText; button -e -en 1 shuffleMontyButton; } global proc montyShuffle() {// Shuffle the deck and hide the queen global int $randomCard; // get the current Time string $timeResult = system("time"); // break apart string to get at hundredth of a second string $tokenResults[]; int $tokenNumber = tokenize( $timeResult,".",$tokenResults); string $timeString = substring($tokenResults[1],1,2); int $randomTime = ($timeString); // use time to seed the random generator seed ($randomTime); button -e -en 0 shuffleMontyButton; button -e -label "?" -en 0 -w 60 -command "montyResults($randomCard,1)" card1Button; button -e -label "?" -en 0 -w 60 -command "montyResults($randomCard,2)" card2Button; button -e -label "?" -en 0 -w 60 -command "montyResults($randomCard,3)" card3Button; text -e -label "Shuffling " monTitleText; for ($shuffle = 1; $shuffle<30; $shuffle++) { // generate a random number $randomCard = rand(3)+1; string $shuffleString = `text -q -label monTitleText`; $shuffleString = $shuffleString + "*"; text -e -label $shuffleString monTitleText; if ($shuffle>28) { text -e -label "Pick a card. Good Luck." monTitleText; button -e -en 1 card1Button; button -e -en 1 card2Button; button -e -en 1 card3Button; } } }