Jump to content

Recommended Posts

Posted

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:

#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
WEnd

Download: Coin_Flip.exe

Coder's Helper >> Here[center][/center]

Posted

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]

Posted (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 by BananaFredSoft
Posted

Hey,

Cool script. Try to add in fake money so you can bet on heads/tails.. I love gambling :)

Kurt

Awaiting Diablo III..

  • 2 years later...
Posted (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 by GiulioM
Posted

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&section=attach&attach_id=30073

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...