Sign in to follow this  
Followers 0
AlmarM

PHP to AutoIt

6 posts in this topic

Hey,

I found this Hangman PHP script and I wanted to convert it to autoit, but im stuck at the part where it checks for the position of the dots (where the letter should come).

I just made gui, can't figure out whats next. =/

PHP Script (variables and comments are in Dutch)

<?php 

$woorden=array("tandepastatubedopje", "onderwaterhockeyhandschoenen", 
"arbeidsongeschiktheidspensioen", "arbeidsvoorwaardenontwikkeling", "huwelijksvruchtbaarheidscijfer", 
"levensverzekeringsovereenkomst", "staatsinvesteringsmaatschappij", 
"televisieproductiemaatschappij", "verantwoordelijkheidsstructuur", 
"ziekteverzekeringsmaatschappij", "arbeidsongeschiktheidsregeling", 
"centraleverwarmingsinstallatie", "elektriciteitsproductiebedrijf", 
"levensverzekeringsmaatschappij", "vastgoedbeleggingsmaatschappij", 
"verantwoordelijkheidsverdeling", "arbeidsongeschiktheidsuitkering", 
"kredietverzekeringsmaatschappij", "rioolwaterzuiveringsinstallatie", 
"vertegenwoordigingsovereenkomst", "ziektekostenverzekeringsbedrijf", 
"belangenbehartigingsorganisatie", "huisvuilverbrandingsinstallatie", 
"kunstnijverheidstentoonstelling", "rookgasontzwavelingsinstallatie", 
"arbeidsongeschiktheidsverzekering", "geneesmiddelenvergoedingssysteem", 
"arbeidsongeschiktheidsvoorziening", "elektriciteitsproductiemaatschappij", 
"appelmoesdopaandraaier", "antibandenslijtage", "kapitaalmarktspaarrekeningen", 
"correspondentie","betalingsopdrachten", 
"kauwgomballenautomaat","computerhardwarefabriek", 
"koeienontlasting","reuzewalvislevertraanverkoper", 
"systeemnetwerkkabel","gekkekoeienziektevirus", "afvalbakkenontwerper"); 


if(isset($_POST["woord"])) 
{ 
   $woord=$_POST["woord"]; 
} 
else 
{ 
$woord=$woorden[array_rand($woorden,1)]; 
} 

if(isset($_POST["letter"])) 
{ 
   $letter=$_POST["letter"]; 
} 
else 
{ 
        $letter=NULL; 
} 

if(isset($_POST["geproblet"])) 
{ 
   $geproblet=$_POST["geproblet"]; 
} 
else 
{ 
        $geproblet=NULL; 
} 

if(isset($_POST["pogingen"])) 
{ 
   $poging=$_POST["pogingen"]; 
} 
else 
{ 
        $poging=0; 
} 

// genereert de punten aan het begin 
if(isset($_POST["bezig"])) 
{ 
   $punten=$_POST["bezig"]; 
} 
else 
{ 
  $lengte=strlen($woord); 
  $x=0; 
  if(!isset($punten)) 
  { 
      $punten=NULL; 
      while(($x < $lengte)) 
        { 
             $punten .= "."; 
             $x++; 
        } 
} 
} 


//hieronder het script dat de punten vervangt door letters 

$offset=0; 
$positie = 0; 
$positie = strpos($woord,$letter,$offset); 
while($positie!== false) 
{ 
    $positie = strpos($woord,$letter,$offset); 
    $offset=$positie+1; 
    if($positie != '0') 
    { 
        $punten = substr_replace($punten,$letter,$positie,1); 
    } 
    else 
    { 
        if(strpos($woord,$letter,0)=='0') 
        { 
           $punten = substr_replace($punten,$letter,0,1); 
        } 
    } 
} 

if((strpos($woord,$letter)===false) and (isset($letter))) 
{ 
        echo "<u>Niet voorkomende letter!:</u>  "; 
        $poging++; 
} 
$geproblet .= $letter; 

echo "<b>$letter</b>"; 

echo "<h2>".$punten."</h2>"; 

echo "fouten: $poging"; 

echo "<br><br>"; 

echo "geprobeerde letters: $geproblet"; 


echo "<br> 
<FORM ACTION='galgje.php' width='150' METHOD='POST'> 
<B>Probeer de letter:<br> 
<INPUT TYPE='text' NAME='letter' SIZE='1' MAXLENGTH='1'><br> 
<INPUT TYPE='hidden' NAME='woord' VALUE='$woord'> 
<INPUT TYPE='hidden' NAME='bezig' VALUE='$punten'> 
<INPUT TYPE='hidden' NAME='pogingen' VALUE='$poging'> 
<INPUT TYPE='hidden' NAME='geproblet' VALUE='$geproblet'> 
<INPUT TYPE='submit' VALUE='Probeer'>"; 


// de slashes hieronder weghalen als je het woord wilt zien.. 
//echo "<br><br><br><i>$woord</i>"; 

?>

My try ;)

#include <String.au3>

Global $vFouten = 0, $FoutenLetters = "", $GeprobeerdeLetters = ""
Global $Woorden[2] = ['woord1', 'example']

$RandomWoord = $Woorden[Random(2)]

$GUI = GUICreate("Galgje", 200, 180)
$cFoutenLetters = GUICtrlCreateLabel("Fouten letters: " & $FoutenLetters, 10, 10)
$cWoord = GUICtrlCreateLabel("", 10, 30, 300, 20)

GUICtrlSetData($cWoord, _StringRepeat(".", StringLen($RandomWoord)))

$cFouten = GUICtrlCreateLabel("Fouten: " & $vFouten, 10, 70)
$cGeprobeerdeLetters = GUICtrlCreateLabel("Geprobeerde letters: " & $GeprobeerdeLetters, 10, 100)
GUICtrlCreateLabel("Probeer letter:", 10, 130)
$cLetter = GUICtrlCreateInput("", 10, 150, 15)
$cProbeer = GUICtrlCreateButton("Probeer", 40, 150, 60, 20)

GUICtrlSetFont($cWoord, 15)
GUISetState()
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    Case $cProbeer
        $Read = GUICtrlRead($cLetter)
        
    EndSwitch
WEnd

>.<'


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites



#include <String.au3>

Global $vFouten = 0, $FoutenLetters = "", $GeprobeerdeLetters = ""
Global $Woorden[2] = ['woord1', 'example']

$RandomWoord = $Woorden[Random(2)]

$GUI = GUICreate("Galgje", 200, 180)
$cFoutenLetters = GUICtrlCreateLabel("Fouten letters: " & $FoutenLetters, 10, 10)
$cWoord = GUICtrlCreateLabel("", 10, 30, 300, 20)

GUICtrlSetData($cWoord, _StringRepeat(".", StringLen($RandomWoord)))

$cFouten = GUICtrlCreateLabel("Fouten: " & $vFouten, 10, 70)
$cGeprobeerdeLetters = GUICtrlCreateLabel("Geprobeerde letters: " & $GeprobeerdeLetters, 10, 100)
GUICtrlCreateLabel("Probeer letter:", 10, 130)
$cLetter = GUICtrlCreateInput("", 10, 150, 15)
$cProbeer = GUICtrlCreateButton("Probeer", 40, 150, 60, 20)

GUICtrlSetFont($cWoord, 15)
GUISetState()
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    Case $cProbeer
        $Read = GUICtrlRead($cLetter)
        If (StringInStr($RandomWoord, $Read)) Then
            ; This is a valid letter

            ; Add this letter to the list of valid attempts

            ; Update the guessed word
        Else
            ; Wrong guess! HANG HIM!!! BRING OUT THE PITCHFORKS AND BURNING OIL.

            ; Add this letter to the list of invalid attempts
        EndIf
    EndSwitch
WEnd

P.S. You cheat at galgje.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#include <String.au3>

Global $vFouten = 0, $FoutenLetters = "", $GeprobeerdeLetters = ""
Global $Woorden[2] = ['woord1', 'example']

$RandomWoord = $Woorden[Random(2)]

$GUI = GUICreate("Galgje", 200, 180)
$cFoutenLetters = GUICtrlCreateLabel("Fouten letters: " & $FoutenLetters, 10, 10)
$cWoord = GUICtrlCreateLabel("", 10, 30, 300, 20)

GUICtrlSetData($cWoord, _StringRepeat(".", StringLen($RandomWoord)))

$cFouten = GUICtrlCreateLabel("Fouten: " & $vFouten, 10, 70)
$cGeprobeerdeLetters = GUICtrlCreateLabel("Geprobeerde letters: " & $GeprobeerdeLetters, 10, 100)
GUICtrlCreateLabel("Probeer letter:", 10, 130)
$cLetter = GUICtrlCreateInput("", 10, 150, 15)
$cProbeer = GUICtrlCreateButton("Probeer", 40, 150, 60, 20)

GUICtrlSetFont($cWoord, 15)
GUISetState()
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    Case $cProbeer
        $Read = GUICtrlRead($cLetter)
        If (StringInStr($RandomWoord, $Read)) Then
            ; This is a valid letter

            ; Add this letter to the list of valid attempts

            ; Update the guessed word
        Else
            ; Wrong guess! HANG HIM!!! BRING OUT THE PITCHFORKS AND BURNING OIL.

            ; Add this letter to the list of invalid attempts
        EndIf
    EndSwitch
WEnd

P.S. You cheat at galgje.

Ugh, ofcourse :evil:

Wait what? How do I update it? ;)

How would the script know where the guesses letter should be?

P.S. Waarom cheat ik?

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Read my edit please ;)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

I'm sorry for writing the code already, I imagine you wanted to do that but it was the only way for me to accurately explain.

#include <String.au3>
#include <Array.au3>

Global $vFouten = 0, $FoutenLetters[1], $GeprobeerdeLetters[1]
Global $Woorden[2] = ['woord1', 'example']

$RandomWoord = $Woorden[Random(2)]

$GUI = GUICreate("Galgje", 200, 180)
$cFoutenLetters = GUICtrlCreateLabel("Fouten letters: " & $FoutenLetters, 10, 10)
$cWoord = GUICtrlCreateLabel("", 10, 30, 300, 20)

GUICtrlSetData($cWoord, _StringRepeat(".", StringLen($RandomWoord)))

$cFouten = GUICtrlCreateLabel("Fouten: " & $vFouten, 10, 70)
$cGeprobeerdeLetters = GUICtrlCreateLabel("Geprobeerde letters: ", 10, 100)
GUICtrlCreateLabel("Probeer letter:", 10, 130)
$cLetter = GUICtrlCreateInput("", 10, 150, 15)
$cProbeer = GUICtrlCreateButton("Probeer", 40, 150, 60, 20)

GUICtrlSetFont($cWoord, 15)
GUISetState()
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    Case $cProbeer
        $Read = GUICtrlRead($cLetter)
        If (StringInStr($RandomWoord, $Read)) Then
            ; This is a valid letter

            ; Add this letter to the list of valid attempts
            _ArrayAdd($GeprobeerdeLetters, $Read)

            ; Update the guessed word
            _updateWord()

            ; Update rest of the GUI
            _updateGUI()
        Else
            ; Wrong guess! HANG HIM!!! BRING OUT THE PITCHFORKS AND BURNING OIL.

            ; Add this letter to the list of invalid attempts
            _ArrayAdd($FoutenLetters, $Read)
            $vFouten += 1

            ; Update rest of the GUI
            _updateGUI()
        EndIf
    EndSwitch
WEnd

Func _updateWord()
    $new = ""
    $a_chr = StringSplit($RandomWoord, '')
    ; Check each character in the word that we should guess
    For $x = 1 to UBound($a_chr)-1
        ; Assume this was not guessed
        $guessed = False
        ; Now check if this character _has_ been guessed
        For $y = 1 to UBound($GeprobeerdeLetters)-1
            ; If current char equals a guessed char
            If $a_chr[$x] = $GeprobeerdeLetters[$y] Then
                ; This has been guessed
                $guessed = True
            EndIf
        Next
        ; Update the final string
        If $guessed Then
            ; if this letter has been guessed we add that letter
            $new &= $a_chr[$x]
        Else
            ; if this letter has not been guessed we add a .
            $new &= "."
        EndIf
    Next
    ; Update the GUI element
    GUICtrlSetData($cWoord, $new)
    ; Check if all has been guessed
    if $new = $RandomWoord Then
        ; The user has won ^^
        MsgBox(4,"", "Victorie! Gefeliciteerd, u heeft gewonnen in 15.2 seconden. Dit is een nieuw record!! Wilt u uw score opsturen?")
    EndIf
EndFunc

Func _updateGUI()
    ; Update number of errors

    ; Update the correctly guessed letters

    ; Update the wrongly guessed letters
EndFunc

Share this post


Link to post
Share on other sites

I'm sorry for writing the code already, I imagine you wanted to do that but it was the only way for me to accurately explain.

#include <String.au3>
#include <Array.au3>

Global $vFouten = 0, $FoutenLetters[1], $GeprobeerdeLetters[1]
Global $Woorden[2] = ['woord1', 'example']

$RandomWoord = $Woorden[Random(2)]

$GUI = GUICreate("Galgje", 200, 180)
$cFoutenLetters = GUICtrlCreateLabel("Fouten letters: " & $FoutenLetters, 10, 10)
$cWoord = GUICtrlCreateLabel("", 10, 30, 300, 20)

GUICtrlSetData($cWoord, _StringRepeat(".", StringLen($RandomWoord)))

$cFouten = GUICtrlCreateLabel("Fouten: " & $vFouten, 10, 70)
$cGeprobeerdeLetters = GUICtrlCreateLabel("Geprobeerde letters: ", 10, 100)
GUICtrlCreateLabel("Probeer letter:", 10, 130)
$cLetter = GUICtrlCreateInput("", 10, 150, 15)
$cProbeer = GUICtrlCreateButton("Probeer", 40, 150, 60, 20)

GUICtrlSetFont($cWoord, 15)
GUISetState()
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    Case $cProbeer
        $Read = GUICtrlRead($cLetter)
        If (StringInStr($RandomWoord, $Read)) Then
            ; This is a valid letter

            ; Add this letter to the list of valid attempts
            _ArrayAdd($GeprobeerdeLetters, $Read)

            ; Update the guessed word
            _updateWord()

            ; Update rest of the GUI
            _updateGUI()
        Else
            ; Wrong guess! HANG HIM!!! BRING OUT THE PITCHFORKS AND BURNING OIL.

            ; Add this letter to the list of invalid attempts
            _ArrayAdd($FoutenLetters, $Read)
            $vFouten += 1

            ; Update rest of the GUI
            _updateGUI()
        EndIf
    EndSwitch
WEnd

Func _updateWord()
    $new = ""
    $a_chr = StringSplit($RandomWoord, '')
    ; Check each character in the word that we should guess
    For $x = 1 to UBound($a_chr)-1
        ; Assume this was not guessed
        $guessed = False
        ; Now check if this character _has_ been guessed
        For $y = 1 to UBound($GeprobeerdeLetters)-1
            ; If current char equals a guessed char
            If $a_chr[$x] = $GeprobeerdeLetters[$y] Then
                ; This has been guessed
                $guessed = True
            EndIf
        Next
        ; Update the final string
        If $guessed Then
            ; if this letter has been guessed we add that letter
            $new &= $a_chr[$x]
        Else
            ; if this letter has not been guessed we add a .
            $new &= "."
        EndIf
    Next
    ; Update the GUI element
    GUICtrlSetData($cWoord, $new)
    ; Check if all has been guessed
    if $new = $RandomWoord Then
        ; The user has won ^^
        MsgBox(4,"", "Victorie! Gefeliciteerd, u heeft gewonnen in 15.2 seconden. Dit is een nieuw record!! Wilt u uw score opsturen?")
    EndIf
EndFunc

Func _updateGUI()
    ; Update number of errors

    ; Update the correctly guessed letters

    ; Update the wrongly guessed letters
EndFunc

Thats cool, I was just curious about how is should be done. Thanks! ;)

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
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
Sign in to follow this  
Followers 0