neozf
09-05-2007, 04:22 PM
Scraped the original post since a few changes were made.
Source code for the game.
/*HIGHER OR LOWER*/
if (preg_match("/^\:\^HoL$/i",$command)){
$playing=true;$currentnumber=rand(1,100);
$point=0;
$turn=1;
fputs($socket, "PRIVMSG $ex[2] :The current number is $currentnumber, do you think the next one would be Higher or Lower?($turn/10)\n");
}
if ($playing==true&&$turn<10){
$nextnumber=rand(1,100);
if (preg_match("/Higher/i",$text) && $nextnumber > $currentnumber){
$turn=$turn+1;
fputs($socket, "PRIVMSG $ex[2] :Correct, you get one point, the next number is $nextnumber, Higher or Lower?($turn/10)\n");
$point = $point+1;
$currentnumber = $nextnumber;
} elseif (preg_match("/Higher/i",$text) && $nextnumber < $currentnumber) {
$turn=$turn+1;
fputs($socket, "PRIVMSG $ex[2] :Incorrect, you don't get a point, the next number was $nextnumber, Higher or Lower?($turn/10)\n");
$currentnumber = $nextnumber;
} elseif (preg_match("/Lower/i",$text) && $nextnumber < $currentnumber){
$turn=$turn+1;
fputs($socket, "PRIVMSG $ex[2] :Corrent, you get one point, the next number is $nextnumber, Higher or Lower?($turn/10)\n");
$point = $point+1;
$currentnumber = $nextnumber;
} elseif (preg_match("/Lower/i",$text) && $nextnumber > $currentnumber) {
$turn=$turn+1;
fputs($socket, "PRIVMSG $ex[2] :Incorrect, you don't get a point, the next number was $nextnumber, Higher or Lower?($turn/10)\n");
$currentnumber = $nextnumber;
}
}
if ($turn==10){
if (preg_match("/Higher/i",$text) && $nextnumber > $currentnumber){
fputs($socket, "PRIVMSG $ex[2] :LAWLCorrect, you get one point, the next number was $nextnumber.\n");
$point = $point+1;
fputs($socket, "PRIVMSG $ex[2] :Game ended, you got $point Points.\n");
$playing=false;
} elseif (preg_match("/Higher/i",$text) && $nextnumber < $currentnumber) {
fputs($socket, "PRIVMSG $ex[2] :LAWLIncorrect, you don't get a point, the next number was $nextnumber. \n");
fputs($socket, "PRIVMSG $ex[2] :Game ended, you got $point Points.\n");
$playing=false;
} elseif (preg_match("/Lower/i",$text) && $nextnumber < $currentnumber){
fputs($socket, "PRIVMSG $ex[2] :LAWLCorrent, you get one point, the next number was $nextnumber.\n");
$point = $point+1;
fputs($socket, "PRIVMSG $ex[2] :Game ended, you got $point Points.\n");
$playing=false;
} elseif (preg_match("/Lower/i",$text) && $nextnumber > $currentnumber) {
fputs($socket, "PRIVMSG $ex[2] :LAWLIncorrect, you don't get a point, the next number was $nextnumber.\n");
fputs($socket, "PRIVMSG $ex[2] :Game ended, you got $point Points.\n");
$playing=false;
}
}
I also added a piece of code which will show the current turn and how many points you have.
What happens when I test it.
[21:43] <AppleBot> Hey guys!
[21:43] > ^hol
[21:43] <AppleBot> The current number is 64, do you think the next one would be Higher or Lower?(1/10)
[21:43] > ^turn lower
[21:43] <AppleBot> Corrent, you get one point, the next number is 39, Higher or Lower?(2/10)
[21:43] <AppleBot> 2 , 1
[21:43] > ^turn lower
[21:43] <AppleBot> Corrent, you get one point, the next number is 13, Higher or Lower?(3/10)
[21:43] <AppleBot> 3 , 2
[21:43] > ^turn lower
[21:43] <AppleBot> Incorrect, you don't get a point, the next number was 49, Higher or Lower?(4/10)
[21:43] <AppleBot> 4 , 2
[21:43] > ^turn lower
[21:43] <AppleBot> Incorrect, you don't get a point, the next number was 84, Higher or Lower?(5/10)
[21:43] <AppleBot> 5 , 2
[21:43] > ^turn lower
[21:43] <AppleBot> Corrent, you get one point, the next number is 38, Higher or Lower?(6/10)
[21:43] <AppleBot> 6 , 3
[21:43] > ^turn lower
[21:43] <AppleBot> Corrent, you get one point, the next number is 19, Higher or Lower?(7/10)
[21:43] <AppleBot> 7 , 4
[21:43] > ^turn lower
[21:43] <AppleBot> Incorrect, you don't get a point, the next number was 23, Higher or Lower?(8/10)
[21:43] <AppleBot> 8 , 4
[21:43] > ^turn lower
[21:43] <AppleBot> Incorrect, you don't get a point, the next number was 47, Higher or Lower?(9/10)
[21:43] <AppleBot> 9 , 4
[21:43] > ^turn lower
[21:43] <AppleBot> Incorrect, you don't get a point, the next number was 67, Higher or Lower?(10/10)
[21:43] <AppleBot> 10 , 4
[21:43] > ^turn lower
[21:43] <AppleBot> 10 , 4
^hol starts the game, ^turn checks the current turn and how many points you have. It stops when $turn gets to 10 since the second part of the source says to only do that bit if $turn<10, but it does not do the third part which it is meant to do once $turn==10. ^turn shows that the current turn is 10, which would mean $turn is 10, but for some reason it still doesn't work.
Anyone got an idea why this is?
Source code for the game.
/*HIGHER OR LOWER*/
if (preg_match("/^\:\^HoL$/i",$command)){
$playing=true;$currentnumber=rand(1,100);
$point=0;
$turn=1;
fputs($socket, "PRIVMSG $ex[2] :The current number is $currentnumber, do you think the next one would be Higher or Lower?($turn/10)\n");
}
if ($playing==true&&$turn<10){
$nextnumber=rand(1,100);
if (preg_match("/Higher/i",$text) && $nextnumber > $currentnumber){
$turn=$turn+1;
fputs($socket, "PRIVMSG $ex[2] :Correct, you get one point, the next number is $nextnumber, Higher or Lower?($turn/10)\n");
$point = $point+1;
$currentnumber = $nextnumber;
} elseif (preg_match("/Higher/i",$text) && $nextnumber < $currentnumber) {
$turn=$turn+1;
fputs($socket, "PRIVMSG $ex[2] :Incorrect, you don't get a point, the next number was $nextnumber, Higher or Lower?($turn/10)\n");
$currentnumber = $nextnumber;
} elseif (preg_match("/Lower/i",$text) && $nextnumber < $currentnumber){
$turn=$turn+1;
fputs($socket, "PRIVMSG $ex[2] :Corrent, you get one point, the next number is $nextnumber, Higher or Lower?($turn/10)\n");
$point = $point+1;
$currentnumber = $nextnumber;
} elseif (preg_match("/Lower/i",$text) && $nextnumber > $currentnumber) {
$turn=$turn+1;
fputs($socket, "PRIVMSG $ex[2] :Incorrect, you don't get a point, the next number was $nextnumber, Higher or Lower?($turn/10)\n");
$currentnumber = $nextnumber;
}
}
if ($turn==10){
if (preg_match("/Higher/i",$text) && $nextnumber > $currentnumber){
fputs($socket, "PRIVMSG $ex[2] :LAWLCorrect, you get one point, the next number was $nextnumber.\n");
$point = $point+1;
fputs($socket, "PRIVMSG $ex[2] :Game ended, you got $point Points.\n");
$playing=false;
} elseif (preg_match("/Higher/i",$text) && $nextnumber < $currentnumber) {
fputs($socket, "PRIVMSG $ex[2] :LAWLIncorrect, you don't get a point, the next number was $nextnumber. \n");
fputs($socket, "PRIVMSG $ex[2] :Game ended, you got $point Points.\n");
$playing=false;
} elseif (preg_match("/Lower/i",$text) && $nextnumber < $currentnumber){
fputs($socket, "PRIVMSG $ex[2] :LAWLCorrent, you get one point, the next number was $nextnumber.\n");
$point = $point+1;
fputs($socket, "PRIVMSG $ex[2] :Game ended, you got $point Points.\n");
$playing=false;
} elseif (preg_match("/Lower/i",$text) && $nextnumber > $currentnumber) {
fputs($socket, "PRIVMSG $ex[2] :LAWLIncorrect, you don't get a point, the next number was $nextnumber.\n");
fputs($socket, "PRIVMSG $ex[2] :Game ended, you got $point Points.\n");
$playing=false;
}
}
I also added a piece of code which will show the current turn and how many points you have.
What happens when I test it.
[21:43] <AppleBot> Hey guys!
[21:43] > ^hol
[21:43] <AppleBot> The current number is 64, do you think the next one would be Higher or Lower?(1/10)
[21:43] > ^turn lower
[21:43] <AppleBot> Corrent, you get one point, the next number is 39, Higher or Lower?(2/10)
[21:43] <AppleBot> 2 , 1
[21:43] > ^turn lower
[21:43] <AppleBot> Corrent, you get one point, the next number is 13, Higher or Lower?(3/10)
[21:43] <AppleBot> 3 , 2
[21:43] > ^turn lower
[21:43] <AppleBot> Incorrect, you don't get a point, the next number was 49, Higher or Lower?(4/10)
[21:43] <AppleBot> 4 , 2
[21:43] > ^turn lower
[21:43] <AppleBot> Incorrect, you don't get a point, the next number was 84, Higher or Lower?(5/10)
[21:43] <AppleBot> 5 , 2
[21:43] > ^turn lower
[21:43] <AppleBot> Corrent, you get one point, the next number is 38, Higher or Lower?(6/10)
[21:43] <AppleBot> 6 , 3
[21:43] > ^turn lower
[21:43] <AppleBot> Corrent, you get one point, the next number is 19, Higher or Lower?(7/10)
[21:43] <AppleBot> 7 , 4
[21:43] > ^turn lower
[21:43] <AppleBot> Incorrect, you don't get a point, the next number was 23, Higher or Lower?(8/10)
[21:43] <AppleBot> 8 , 4
[21:43] > ^turn lower
[21:43] <AppleBot> Incorrect, you don't get a point, the next number was 47, Higher or Lower?(9/10)
[21:43] <AppleBot> 9 , 4
[21:43] > ^turn lower
[21:43] <AppleBot> Incorrect, you don't get a point, the next number was 67, Higher or Lower?(10/10)
[21:43] <AppleBot> 10 , 4
[21:43] > ^turn lower
[21:43] <AppleBot> 10 , 4
^hol starts the game, ^turn checks the current turn and how many points you have. It stops when $turn gets to 10 since the second part of the source says to only do that bit if $turn<10, but it does not do the third part which it is meant to do once $turn==10. ^turn shows that the current turn is 10, which would mean $turn is 10, but for some reason it still doesn't work.
Anyone got an idea why this is?
