[Autoit] Carta,forbice e pietra

« Older   Newer »
  Share  
greywolf92
view post Posted on 5/2/2009, 22:59




Ecco finalmente terminato il mio primo gioco in Autoit: il classico carta,forbice e pietra !!!

image

Source (154 righe):
SPOILER (click to view)
CODICE
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.0.0
Author:       Greywolf

Script Function: Classico gioco carta, forbice e pietra.

#ce ----------------------------------------------------------------------------
#include <GUIConstants.au3>

$Form1 = GUICreate("Created by Greywolf",559, 453, 349, 271)
$Button1 = GUICtrlCreateButton("Carta ", 104, 352, 89, 81, 0)
$Button2 = GUICtrlCreateButton("Forbice", 224, 352, 91, 81, 0)
$Button3 = GUICtrlCreateButton("Pietra", 352, 352, 91, 81, 0)
$Button4 = GUICtrlCreateButton("Carta", 102, 70, 89, 81, 0)
$Button5 = GUICtrlCreateButton("Forbice", 222, 70, 91, 81, 0)
$Button6 = GUICtrlCreateButton("Pietra", 350, 70, 91, 81, 0)
$Group1 = GUICtrlCreateGroup("",96, 176, 353, 145)
$Label1 = GUICtrlCreateLabel(":::::::::::::::::::::::::::"& @CRLF &":::COMPUTER:::" & @CRLF &":::::::::::::::::::::::::::", 8, 88, 84, 73)
$Label2 = GUICtrlCreateLabel("::::::::::::::::::::::::::::"& @CRLF &":::::::::::TU::::::::::::"& @CRLF &"::::::::::::::::::::::::::::", 464, 376, 84, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("TU", 400, 8, 153, 49)
Dim $punt1=0,$punt2=0
$Label6 = GUICtrlCreateLabel($punt1, 430, 30, 36, 25)
$Label7 = GUICtrlCreateLabel($punt2, 505, 30, 44, 25)
$Group4 = GUICtrlCreateGroup("PC", 480, 8, 1, 50)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

Global $n,$comp,$r

While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
       Case $Button1
               $n="carta"
               $immag= GUICtrlCreatePic(@ScriptDir & "carta.jpg", 136, 208, 100, 81)
               Sleep(1000)
               gioco()
               punteggio()
               
       Case $button2
       $n="forbice"
               $immag= GUICtrlCreatePic(@ScriptDir & "forbice.jpg", 136, 208, 100, 81)
               Sleep(1000)
               gioco()
               punteggio()
       Case $button3
               $n="pietra"        
               $immag= GUICtrlCreatePic(@ScriptDir & "pietra.jpg", 136, 208, 100, 81)
               Sleep(1000)
               gioco()
               punteggio()
       Case $GUI_EVENT_CLOSE
                       Exit
       
       EndSwitch
       
WEnd        
       
       Func gioco()
       $comp =Int(Random(1,4))
       Switch $comp
       Case $comp= 1
               $immag2= GUICtrlCreatePic(@ScriptDir & "carta.jpg", 304, 208, 108, 81)
       Case $comp =2
               $immag2= GUICtrlCreatePic(@ScriptDir & "forbice.jpg", 304, 208, 108, 81)
       Case $comp =3
               $immag2= GUICtrlCreatePic(@ScriptDir & "pietra.jpg", 304, 208, 108, 81)
       EndSwitch
       
   if $n = "carta" and $comp = 1        Then
               Sleep(1000)
               MsgBox(0,"Game","Pareggio")
               $r="pareggio"
       ElseIf $n = "carta" and $comp = 2        Then
               Sleep(1000)
               MsgBox(0,"Game","Hai Perso")
               $r="perso"
       ElseIf $n = "carta" and $comp = 3        Then
               Sleep(1000)
               MsgBox(0,"Game","Hai Vinto")
               $r="vinto"
       ElseIf $n = "forbice" and $comp = 1        Then
               Sleep(1000)
               MsgBox(0,"Game","Hai Vinto")
               $r="vinto"
       ElseIf $n = "forbice" and $comp = 2        Then
               Sleep(1000)
               MsgBox(0,"Game","Pareggio")
               $r="pareggio"
       ElseIf $n = "forbice" and $comp = 3        Then
               Sleep(1000)
               MsgBox(0,"Game","Hai Perso")
               $r="perso"
       ElseIf $n = "pietra" and $comp = 1        Then
               Sleep(1000)
               MsgBox(0,"Game","Hai Perso")
               $r="perso"
       ElseIf $n = "pietra" and $comp = 2        Then
               Sleep(1000)
               MsgBox(0,"Game","Hai Vinto")
               $r="vinto"
       ElseIf $n = "pietra" and $comp = 3        Then
               Sleep(1000)
               MsgBox(0,"Game","Pareggio")
               $r="pareggio"
       EndIf
               GUICtrlDelete ($immag)
               GUICtrlDelete ($immag2)
       EndFunc
       
       Func Punteggio()
               If $r="vinto" Then
                       $punt1=$punt1 + 1
               ElseIf $r="perso" Then
                   $punt2=$punt2 + 1
               EndIf
               $Label6 = GUICtrlCreateLabel($punt1, 430, 30, 36, 25)
               $Label7 = GUICtrlCreateLabel($punt2, 505, 30, 44, 25)
               If $punt1=5 Then
                       vittoria()
               ElseIf $punt2=5 Then
                       sconfitta()
               EndIf
       EndFunc
       
       Func Vittoria()
           Switch MsgBox(4,"Game","Complimenti hai vinto!!!" & @CRLF & "Vuoi rigiocare ??")
                       Case 6
                               $punt1=0
                               $punt2=0
                               $Label6 = GUICtrlCreateLabel($punt1, 430, 30, 36, 25)
                               $Label7 = GUICtrlCreateLabel($punt2, 505, 30, 44, 25)
                       Case 7
                               MsgBox(0,"Game", "A presto... Ciao!!!")
                               Exit
               EndSwitch
       EndFunc
       
       Func Sconfitta()
               switch MsgBox(4,"Game","Mi dispiace hai perso...!!!" & @CRLF & "Vuoi rigiocare ??")
                       Case 6
                               $punt1=0
                               $punt2=0
                               $Label6 = GUICtrlCreateLabel($punt1, 430, 30, 36, 25)
                               $Label7 = GUICtrlCreateLabel($punt2, 505, 30, 44, 25)
                       Case 7
                               MsgBox(0,"Game", "A presto... Ciao!!!")
                               Exit
               EndSwitch
       EndFunc

-Una volta scelto tra carta,forbice e pietra, apparirΰ al centro l' immaggine della tua scelta e si affiancherΰ la scelta del computer. In seguito apparirΰ una finestra che ti avvisa se hai vinto o perso.
-Il punteggio si accumulerΰ nella tabella in alto a destra. Chi arriva per primo a 5 punti vince.
-Il computer farΰ delle scelte del tutto casuali

Ci ho perso un bel pς di tempo... spero che vi piaccia :D
Se volete provarlo dovete scaricare il rar perchθ contiene le immagini per il gioco.
Download qui
 
Top
*Kuja*
view post Posted on 6/2/2009, 17:24




che figata...io credo di non essere in grado
 
Top
*Kuja*
view post Posted on 6/2/2009, 22:39




tnt inparo XD
 
Top
•Fisher92•
view post Posted on 7/2/2009, 17:21




Wow! Troppo bello!!
 
Top
4 replies since 5/2/2009, 22:59   177 views
  Share