forked from tropo/tropo-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimon.php
56 lines (46 loc) · 1.06 KB
/
simon.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
answer();
// Set initial state
$simon = array();
$win = true;
$inchar = "";
// keep going up to a pattern of 20 digits
while ( ($win == true) && (count($simon) <= 20) ) {
// add another character to the pattern and read the pattern to the caller
$simon[] = rand(0,9);
say("Simon says");
foreach($simon as $s) {
say($s);
}
// now get the user input
say("you say");
$i = 0;
while ($i < count($simon)) {
$event=ask("", array("choices" => "1,2,3,4,5,6,7,8,9,0"));
if ($event->name=='choice') {
$inchar = $event->value;
}
// read back each character of user input
say($inchar);
// if the user entered the incorrect character then we're done.
if ($inchar != $simon[$i]) {
$win = null;
say("Sorry, that's not right. goodbye.");
hangup();
break;
}
$i++;
} // while
// if the user won that round then see if we need to continue
if ($win == true) {
say("Good Job!");
wait(3);
if (count(simon) > 20) {
say("You beat simon!");
hangup();
} else {
say("Next round");
} // if
} // if
} // while
?>