#///////////////////////////////////////////////////////////////////////////// #// threecardmonty.py Version 1.p by Stephen Weber Copyright 2009 #// conversion from mel script #// 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 #// #///////////////////////////////////////////////////////////////////////////// import maya.cmds as cmds import time import random randomCard def threecardmonty(): if cmds.windowPref('threeCardMontyWindow',exists=1): cmds.windowPref('threeCardMontyWindow',remove=1) if cmds.window('threeCardMontyWindow',exists=1): cmds.deleteUI('threeCardMontyWindow',window=1) threeCardMontyWin= cmds.window('threeCardMontyWindow',title="3 Card Monty! v1.p",iconName="3 Card Monty",rtf =1,s=0) threeCardMontyForm=cmds.formLayout(numberOfDivisions=100,width=200,height=90) cmds.text('monTitleText',label="Ready to Play? - Then press Shuffle.") cmds.button('card1Button',width=60,height=26,label="Jack",align="center",enable=0) cmds.button('card2Button',width=60,height=26,label="Queen",align="center",enable=0) cmds.button('card3Button',width=60,height=26,label="Jack",align="center",enable=0) cmds.button('shuffleMontyButton',width=90,height=26,label="Shuffle",align="center",command=montyShuffle) cmds.button('closeMontyButton',width=90,height=26,label="I'm Done.",command="import maya.cmds as cmds\ncmds.deleteUI('threeCardMontyWindow')") cmds.formLayout(threeCardMontyForm,edit=True, attachForm=[ ('monTitleText','left',14), ('monTitleText','top',6), ('card1Button','left',6), ('card1Button','top',26), ('card2Button','left',70), ('card2Button','top',26), ('card3Button','left',134), ('card3Button','top',26), ('shuffleMontyButton','left',4), ('shuffleMontyButton','top',60), ('closeMontyButton','top',60), ('closeMontyButton','right',4)]) cmds.showWindow('threeCardMontyWindow') #end def montyResults(card =int,button=int): #dictionary in python calling it switch def one(): cmds.button("card1Button",edit=1,enable=0,label="Queen",w=60) cmds.button("card2Button",edit=1,enable=0,label="Jack",w=60) cmds.button("card3Button",edit=1,enable=0,label="Jack",w=60) def two(): cmds.button("card1Button",edit=1,enable=0,label="Jack",w=60) cmds.button("card2Button",edit=1,enable=0,label="Queen",w=60) cmds.button("card3Button",edit=1,enable=0,label="Jack",w=60) def three(): cmds.button("card1Button",edit=1,enable=0,label="Jack",w=60) cmds.button("card2Button",edit=1,enable=0,label="Jack",w=60) cmds.button("card3Button",edit=1,enable=0,label="Queen",w=60) switch = { 1 :one, 2 :two, 3 :three } switch.get(card)() if (card==button): cmds.text("monTitleText",e=1,label="great! You won. Play Again?") else : cmds.text("monTitleText",e=1,label="Opps! Too bad. Play Again?") cmds.button("shuffleMontyButton",e=1,en=1) #end montyResults def montyShuffle(*args): #note the system command does not have a python equivalent #note the seed command does not have a python equivalent #note random.seed a python code runs on any input for seed using python time to keep it like mel code # left out tokenizing the readable "time" which needed system to reach randomTime=time.clock() random.seed(randomTime) cmds.button("shuffleMontyButton",e=1,en=0) cmds.button("card1Button",e=1,label="?",en=0,w=60,command='threecardmonty.montyResults(threecardmonty.randomCard,1)') cmds.button("card2Button",e=1,label="?",en=0,w=60,command='threecardmonty.montyResults(threecardmonty.randomCard,2)') cmds.button("card3Button",e=1,label="?",en=0,w=60,command='threecardmonty.montyResults(threecardmonty.randomCard,3)') cmds.text("monTitleText",e=1,label="Shuffling") shuffleString="**" #fixed up the code here so there is a visual pause for shuffling cards for shuffle in range(1,300): randomCard=(random.randint(1,3)) #shuffleString=str(cmds.text("monTitleText",q=1)) shuffleString+="*" cmds.text("monTitleText",e=1,label=shuffleString) cmds.refresh() if (shuffle>298): cmds.text("monTitleText",e=1,label="Pick a card, Good Luck.") cmds.button("card1Button",e=1,en=1) cmds.button("card2Button",e=1,en=1) cmds.button("card3Button",e=1,en=1)