Jump to content

Rock Paper Scissors Script


Bradness
 Share

Recommended Posts

Hey guys. Just made this neat little script, thought it would amuse someone. Ive never seen a Rock Paper Scissors script, so have fun!

#include <GUIConstants.au3>
#include <GuiConstants.au3>

Global $GuiX, $GuiY, $GuiW $GuiH, $NewPlayerScore, $NewCPUScore
Global $CPUScore = 0
Global $PlayerScore = 0
Dim $Choose, $Rock, $Paper, $Scissors, $Random, $User, $RPSWords, $RPS
$Choose = GUICreate("Rock, Paper, Scissors...", 300, 325)
$About = GUICtrlCreateButton("?", 100, 300, 30, 25)
$Rock = GUICtrlCreateButton("Rock", 0, 0, 200, 100)
$Paper = GUICtrlCreateButton("Paper", 0, 100, 200, 100)
$Scissors = GUICtrlCreateButton("Scissors", 0, 200, 200, 100)
$Random = GUICtrlCreateButton("Random", 200, 0, 100, 300)
$PlayerScoreLabel = GUICtrlCreateLabel("Player Score:" & $PlayerScore, 0, 310)
$CPUScoreLabel = GUICtrlCreateLabel("CPU Score:" & $CPUScore, 150, 310)

GUICtrlSetOnEvent($Rock, "_Rock")
GUICtrlSetOnEvent($Paper, "_Paper")
GUICtrlSetOnEvent($Scissors, "_Scissors")
GUICtrlSetOnEvent($Random, "_Random")
GUICtrlSetOnEvent($About, "_About")
GUISetState()

While 1
    $MSG = GUIGetMsg()
    Select
        Case $MSG = $GUI_EVENT_CLOSE
            _RollUpGui($Choose, 10)
        Case $MSG = $Rock
            _Rock()
        Case $MSG = $Paper
            _Paper()
        Case $MSG = $Scissors
            _Scissors()
        Case $MSG = $Random
            _Random()
        Case $MSG = $About
            _About()
    EndSelect
WEnd

Func _About()
    MsgBox(0, "About", "Created by Bradness of the AutoIt Forums.")

EndFunc   ;==>_About

Func _Rock()
    _RPS("Rock")
EndFunc   ;==>_Rock

Func _Paper()
    _RPS("Paper")
EndFunc   ;==>_Paper

Func _Scissors()
    _RPS("Scissors")
EndFunc   ;==>_Scissors

Func _RPS($userchoice)
    Local $anR[16] = ['', 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]
    Local $aRPSWords[4] = ['', 'Rock', 'Paper', 'Scisors' ]
    Return MsgBox(0, "Rock, Paper, Scissors... Shoot!", "Your Choice: " & $userchoice & @CRLF & "Computers Choice: " & $aRPSWords[$anR[Random(1, 15, 1) ]])
    If $userchoice = "Rock"  Then
        If $RPSWords = "Rock"  Then
            MsgBox(0, "Rock, Paper, Scissors... Shoot!", "Tie. No Score added to either user.")
            GUICtrlSetData($CPUScoreLabel, "CPU Score:" & $CPUScore)
            GUICtrlSetData($PlayerScoreLabel, "Player Score:" & $PlayerScore)
        ElseIf $RPSWords = "Paper"  Then
            MsgBox(0, "Rock, Paper, Scissors... Shoot!", "CPU Wins.")
            _Score("C")
            GUICtrlSetData($CPUScoreLabel, "CPU Score:" & $CPUScore)
            GUICtrlSetData($PlayerScoreLabel, "Player Score:" & $PlayerScore)
        ElseIf $RPSWords = "Scissors"  Then
            MsgBox(0, "Rock, Paper, Scissors... Shoot!", "You Win!")
            _Score("P")
            GUICtrlSetData($CPUScoreLabel, "CPU Score:" & $CPUScore)
            GUICtrlSetData($PlayerScoreLabel, "Player Score:" & $PlayerScore)
        EndIf
    ElseIf $userchoice = "Paper"  Then
        If $RPSWords = "Paper"  Then
            MsgBox(0, "Rock, Paper, Scissors... Shoot!", "Tie. No Score added to either user.")
            GUICtrlSetData($CPUScoreLabel, "CPU Score:" & $CPUScore)
            GUICtrlSetData($PlayerScoreLabel, "Player Score:" & $PlayerScore)
        ElseIf $RPSWords = "Scissors"  Then
            MsgBox(0, "Rock, Paper, Scissors... Shoot!", "CPU Wins.")
            _Score("C")
            GUICtrlSetData($CPUScoreLabel, "CPU Score:" & $CPUScore)
            GUICtrlSetData($PlayerScoreLabel, "Player Score:" & $PlayerScore)
        ElseIf $RPSWords = "Rock"  Then
            MsgBox(0, "Rock, Paper, Scissors... Shoot!", "You Win!")
            _Score("P")
            GUICtrlSetData($CPUScoreLabel, "CPU Score:" & $CPUScore)
            GUICtrlSetData($PlayerScoreLabel, "Player Score:" & $PlayerScore)
        EndIf
    ElseIf $userchoice = "Scissors"  Then
        If $RPSWords = "Scissors"  Then
            MsgBox(0, "Rock, Paper, Scissors... Shoot!", "Tie. No Score added to either user.")
            GUICtrlSetData($CPUScoreLabel, "CPU Score:" & $CPUScore)
            GUICtrlSetData($PlayerScoreLabel, "Player Score:" & $PlayerScore)
        ElseIf $RPSWords = "Rock"  Then
            MsgBox(0, "Rock, Paper, Scissors... Shoot!", "CPU Wins.")
            _Score("C")
            GUICtrlSetData($CPUScoreLabel, "CPU Score:" & $CPUScore)
            GUICtrlSetData($PlayerScoreLabel, "Player Score:" & $PlayerScore)
        ElseIf $RPSWords = "Paper"  Then
            MsgBox(0, "Rock, Paper, Scissors... Shoot!", "You Win!")
            _Score("P")
            GUICtrlSetData($CPUScoreLabel, "CPU Score:" & $CPUScore)
            GUICtrlSetData($PlayerScoreLabel, "Player Score:" & $PlayerScore)
        EndIf
    EndIf
EndFunc   ;==>_RPS

Func _Random()
    $UserRPS = Random(1, 15, 1)
    Switch $UserRPS
        Case 1
            $User = "Rock" 
        Case 2
            $User = "Paper" 
        Case 3
            $User = "Scissors" 
        Case 4
            $User = "Rock" 
        Case 5
            $User = "Paper" 
        Case 6
            $User = "Scissors" 
        Case 7
            $User = "Rock" 
        Case 8
            $User = "Paper" 
        Case 9
            $User = "Scissors" 
        Case 10
            $User = "Rock" 
        Case 11
            $User = "Paper" 
        Case 12
            $User = "Scissors" 
        Case 13
            $User = "Rock" 
        Case 14
            $User = "Paper" 
        Case 15
            $User = "Scissors" 
    EndSwitch
    _RPS($User)
EndFunc   ;==>_Random

Func _Score($Who)
    If $Who = "C"  Then
        $NewCPUScore = $CPUScore + 1
        $CPUScore = $NewCPUScore
        $NewCPUScore = ""
    ElseIf $Who = "P"  Then
        $NewPlayerScore = $PlayerScore + 1
        $PlayerScore = $NewPlayerScore
        $NewPlayerScore = ""
    EndIf
EndFunc   ;==>_Score

Func _RollUpGui($hWnd, $step, $delay = "default")
    Local $GuiClientH, $MinH
    $GuiClientSize = WinGetClientSize($hWnd)
    $GuiClientH = $GuiClientSize[1]
    _GuiGetPos($hWnd)
    $MinH = $GuiH - $GuiClientH
    
        WinMove($hWnd, "", $GuiX, $GuiY, $GuiW, $GuiH)
        If $delay = "default"  Then $delay = ($step * 2) + ($step / 2)
        Sleep($delay)
    WEnd
    For $i = 250 To 0 Step - 10
        WinSetTrans($hWnd, "", $i)
        Sleep(50)
    Next
EndFunc   ;==>_RollUpGui
Func _GuiGetPos($hWnd)
    $GuiPos = WinGetPos($hWnd)

EndFunc   ;==>_GuiGetPos
Edited by Bradness
My Programs:Rock Paper ScissorsMy UDFs:NONE
Link to comment
Share on other sites

  • Moderators

Some food for thought (you could do this with the other function as well), I'm assuming you are going Random(1,15,1) (to 15) for more of a random option... You could shrink that down (more than this, but I was too lazy to write out the Rock,Paper,Scissors 5 times each).

This

Func _RPS($userchoice)
$RPS = Random( 1, 15, 1 )
Switch $RPS
    Case 1
        $RPSWords = "Rock"
    Case 2
        $RPSWords = "Paper"
    Case 3
        $RPSWords = "Scissors"
    Case 4
        $RPSWords = "Rock"
    Case 5
        $RPSWords = "Paper"
    Case 6
        $RPSWords = "Scissors"
    Case 7
        $RPSWords = "Rock"
    Case 8
        $RPSWords = "Paper"
    Case 9
        $RPSWords = "Scissors"
    Case 10
        $RPSWords = "Rock"
    Case 11
        $RPSWords = "Paper"
    Case 12
        $RPSWords = "Scissors"
    Case 13
        $RPSWords = "Rock"
    Case 14
        $RPSWords = "Paper"
    Case 15
        $RPSWords = "Scissors"
EndSwitch
MsgBox( 0, "Rock, Paper, Scissors... Shoot!", "Your Choice: " & $userchoice & @CRLF & "Computers Choice: " & $RPSWords )
EndFuncoÝ÷ Ùj.ÖÞrjëh×6Func _RPS($userchoice)
    Local $anR[16] = ['',1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3]
    Local $aRPSWords[4] = ['','Rock','Paper','Scisors']
    Return MsgBox( 0, "Rock, Paper, Scissors... Shoot!", "Your Choice: " & $userchoice & @CRLF & "Computers Choice: " & $aRPSWords[$anR[Random(1,15,1)]])
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hey guys. Just made this neat little script, thought it would amuse someone. Ive never seen a Rock Paper Scissors script, so have fun!

Why do you have Random(1,15,1)? I mean why not Random(1,3,1)?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I'm assuming you are going Random(1,15,1) (to 15) for more of a random option..

Please tell me you're joking SmOke_N? :) As a long time admirer of yours, don't do this to me.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

That could make sense because autoit does not generate truly random numbers

Looks like I'm getting out-numbered.

How does it make sense?

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

Looks like I'm getting out-numbered.

How does it make sense?

I never said it made sense... just made an assumption on what the OP was thinking.

@sccrstvn93

Might want to take a look at the source again...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I made something similar to this a few years back. Nice job though!

http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]
Link to comment
Share on other sites

  • 2 months later...

Fixed, but score doesnt work.

I noticed a few things that should be improved:

-- Your script doesn't exit (the _RolUpGUI() function needs an Exit statement at the end)

-- You have several functions listed as GuiCtrlSetOnEvent(). Those are not doing anything because you need the correct Opt().

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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