Phaethon Posted September 9, 2007 Posted September 9, 2007 This is a fairly basic script, simply a heads/tails coin flipper. Kind of neat to play with though (at least if you enjoy the simple things lol).Source:expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.6.0 Author: Matt Script Function: Coin Toss By Matt #ce ---------------------------------------------------------------------------- #include <GUIConstants.au3> GUICreate("Coin Toss v1",330,280,-1,-1,$WS_SIZEBOX+$WS_SYSMENU) GUISetBkColor (0xFFFFFF) ;Sets the background color of the GUI. 0x followed by the hex code of the color to change this. $n=GUICtrlCreatePic("C:\images\coin_flip1.gif",100,60,103,125) GUICtrlCreateLabel("Coin Toss Program. Made by Matt.", 10,10) GUICtrlCreateLabel("To begin, simply click 'flip'.",10,30) $okbutton = GuiCtrlCreateButton ("Flip",50,200,70,20) ;creates the 'flip' button $cancelbutton = GuiCtrlCreateButton ("Done",180,200,70,20) ;creates the 'done' button $coin = 0 GuiSetState() While 1 $msg = GUIGetMsg() ;grabs which button the user clicked from the GUI Select Case $msg = $okbutton $coin = Random(1,2) ;generates a random number, which will represent the coin. $coin = Round($coin) ;rounds the random number to the closest integer. If $coin = 1 Then MsgBox(0,"Heads!", "The coin landed on heads.") ElseIf $coin = 2 Then MsgBox(0,"Tails!", "The coin landed on tails.") EndIf Case $msg = $cancelbutton ;when the user clicks the cancel button Exit Case $msg = $GUI_EVENT_CLOSE ;when the user clicks the 'x' button in the upper right of the app. Exit EndSelect WEndDownload: Coin_Flip.exe Coder's Helper >> Here[center][/center]
JustinReno Posted September 9, 2007 Posted September 9, 2007 Good Job! Very simple, and fun to play. And teaches about using random.
Phaethon Posted September 9, 2007 Author Posted September 9, 2007 Good Job! Very simple, and fun to play. And teaches about using random.Glad you like it.Took me a few minutes to realize I had to use the Round function as well. I was testing it, and I was like "why the heck isn't this working", then I thought.. decimals, DOH! Coder's Helper >> Here[center][/center]
BananaFredSoft Posted September 9, 2007 Posted September 9, 2007 (edited) Glad you like it.Took me a few minutes to realize I had to use the Round function as well. I was testing it, and I was like "why the heck isn't this working", then I thought.. decimals, DOH! You can also use Random(1, 2, 1) to return it w/o decimals. Edited September 9, 2007 by BananaFredSoft -ColinSite:www.bananafredsoft.comStuff:Simple Text Editor - MediaPlayer - Animator - BananaDB - BananaNotes - Chatta - Filesearch - Excuse GeneratorMy YouTube channel:http://www.youtube.com/user/colipat
_Kurt Posted September 9, 2007 Posted September 9, 2007 Hey, Cool script. Try to add in fake money so you can bet on heads/tails.. I love gambling Kurt Awaiting Diablo III..
GiulioM Posted March 24, 2010 Posted March 24, 2010 (edited) I've got another version, easier-made (this isn't always a honor!), but that also provides a function to communicate if they have won or lost.I'm working on adding an initial sum and the loss / win money. This is the code: #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Begin MsgBox(64, "Coin Toss", "Will be made a coin toss.") ; Question $previsto = MsgBox(4, "Head or Cross?", "Head or Cross? Choose Yes if you bet on Cross, No if you bet on Head.") - 6 ; "Launching" the coin; $esito = Random(0, 10) + Random(0, 10) + Random(0, 10) + Random(0, 10) If $esito <= 20 Then MsgBox(64, "Cross", "Cross.") $testacroce = 0 ; Changes output "Cross" into number "0". Else MsgBox(64, "Head", "Head.") $testacroce = 1 ; Changes output "Head" into number "1". EndIf ; Winner/Loser If $previsto + $testacroce = 0 Then MsgBox(64, "Have you win?", "You've Win!!! You've bet on Cross and the output was been Cross.") Else If $previsto + $testacroce = 2 Then MsgBox(64, "Have you win?", "You've Win!!! You've bet on Head and the output was been Head.") Else MsgBox(64, "Have you win?", "You've Losed!!! Retry.") EndIf EndIf Edited March 24, 2010 by GiulioM
GiulioM Posted March 24, 2010 Posted March 24, 2010 I've got another version, easier-made (this isn't always a honor!), but that also provides a function to communicate if they have won or lost.I'm working on adding an initial sum and the loss / win money.This is the code: (...)I've corrected it, thanks to @Fulano. There is also the possibility to bet. And, I've added 2 more coin toss.http://www.autoitscript.com/forum/index.php?app=core&module=attach§ion=attach&attach_id=30073
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now