exit("game over");
}
include "ticketLoaderToRam.php";
include "catchHousefull.php";
include "catchFullSheet.php";
include "catchHaftSheet.php";
include "catchTopLine.php";
include "catchMiddleLine.php";
include "catchBottomLine.php";
include "catchEarly5.php";
include "catchQuick6.php";
include "catchQuick7.php";
include "catchBoxBonus.php";
include "catchStar.php";
include "catchCorner.php";
//------------------------------------------------------------------------------------------------------task------------------
//init functions---
//file_get_contents("http://".$_SERVER['HTTP_HOST']."/api/gameApi/onlineKiller.php");
/*security*/
date_default_timezone_set("Asia/Calcutta");
//India time (GMT+5:30)
//read start data
$gameSettingJSON=json_decode(fread(fopen('../../gameData/gameSettingJSON.txt','r'),1000));
$gameStartDateTime=$gameSettingJSON->dateTime;
//echo(date("m-d-Y h:i:s A"));
if(strtotime(date('d-m-Y h:i:s A'))>strtotime($gameStartDateTime)){
//run the game only when the timeleft is zero
addRand();
$winTicket=fread(fopen('../../gameData/winTicket.txt','r'),10000);
$winTicketArryStr='['.$winTicket.']';
$winTicketArry=json_decode($winTicketArryStr);
echo('Total='.count($winTicketArry).'
'.$winTicket);
}
else{
echo("Game will start on ".date('d-m-Y h:i:s A',strtotime( $gameStartDateTime )));
}
//------------------------------------------------------------------------------------------------------task------------------
//-------------------------------------------------------------------------custom fuynction
function addRand(){
$totalHousefull=(int)fread(fopen('../../gameData/totalHousefull.txt','r'),100);
$currentHousefull=getCurrentHusefull();
if($currentHousefull<$totalHousefull){
if(gameOver()==FALSE){
$winTicket=fread(fopen('../../gameData/winTicket.txt','r'),10000);
$winTicketArryStr='['.$winTicket.']';
$winTicketArry=json_decode($winTicketArryStr);
if(count($winTicketArry)<90){
$randNum=rand(1,90);
//--------------------------this code choose random number between 1-90
$exist=false;
for($i=0;
$i$i++){
if($winTicketArry[$i]==$randNum){
$exist=true;
}
}
if($exist==false){
if($winTicket==""){
fwrite(fopen('../../gameData/winTicket.txt','w'),$randNum);
$winTicket=fread(fopen('../../gameData/winTicket.txt','r'),10000);
$winTicketArryStr='['.$winTicket.']';
$winTicketArry=json_decode($winTicketArryStr);
catchedWinner($winTicketArry,true);
}
else{
if(gameOver()==FALSE){
fwrite(fopen('../../gameData/winTicket.txt','w'),$winTicket.','.$randNum);
$winTicket=fread(fopen('../../gameData/winTicket.txt','r'),10000);
$winTicketArryStr='['.$winTicket.']';
$winTicketArry=json_decode($winTicketArryStr);
catchedWinner($winTicketArry);
}
//---------------------------------------------catch the dividents
//still if game is not over then add rand
}
}
else{
addRand();
}
}
}
else{
echo("game over?-----------------
");
}
}
}
/*
*/
//--------------------------------------------------------------------------------------------------custom function
function catchedWinner($newWinTicketArry){
session_start();
$_SESSION["newCatchedDividentArry"]=array();
//---------------------------------------------catch the dividents
$totalHousefull=(int)fread(fopen('../../gameData/totalHousefull.txt','r'),100);
$currentHousefull=getCurrentHusefull();
if($currentHousefull<$totalHousefull){
catchHousefull($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Full Sheet Bonus');
//catch fullsheet if no one yet
$countHdB=count($hDb)-2;
if($countHdB==0){
catchFullSheetBonus($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Half Sheet Bonus');
//catch haftsheet if no one yet win
$countHdB=count($hDb)-2;
if($countHdB==0){
getHaftSheetBonus($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Top Line');
//catch haftsheet if no one yet win
$countHdB=count($hDb)-2;
if($countHdB==0){
catchTopLine($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Middle Line');
//catch haftsheet if no one yet win
$countHdB=count($hDb)-2;
if($countHdB==0){
catchMiddleLine($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Bottom Line');
//catch haftsheet if no one yet win
$countHdB=count($hDb)-2;
if($countHdB==0){
catchBottomLine($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Early 5');
//catch haftsheet if no one yet win
$countHdB=count($hDb)-2;
if($countHdB==0){
catchEarly5($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Quick6');
//catch haftsheet if no one yet win
$countHdB=count($hDb)-2;
if($countHdB==0){
catchQuick6($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Quick7');
//catch haftsheet if no one yet win
$countHdB=count($hDb)-2;
if($countHdB==0){
catchQuick7($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Box Bonus');
//catch haftsheet if no one yet win
$countHdB=count($hDb)-2;
if($countHdB==0){
catchBoxBonus($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Star');
//catch haftsheet if no one yet win
$countHdB=count($hDb)-2;
if($countHdB==0){
catchStar($newWinTicketArry);
}
$hDb=scandir('../../winnerDb/Corner');
//catch haftsheet if no one yet win
$countHdB=count($hDb)-2;
if($countHdB==0){
catchCorner($newWinTicketArry);
}
//after catching all the divident,save it to last divident
if(count($_SESSION["newCatchedDividentArry"])>0){
fwrite(fopen('../../gameData/lastDivident.txt','w'),json_encode(array_unique($_SESSION["newCatchedDividentArry"])));
}
}
function gameOver(){
$winTicketArry=json_decode("[".fread(fopen('../../gameData/winTicket.txt','r'),10000)."]");
$totalHousefull=(int)fread(fopen('../../gameData/totalHousefull.txt','r'),100);
$currentHousefull=getCurrentHusefull();
/*
echo("
Totalc set Housefull cathed ".$totalHousefull."
");
echo("
Totalc Housefull cathed ".$currentHousefull."
");
*/
$gameOvered=FALSE;
if($currentHousefull>=$totalHousefull || count($winTicketArry)>=90){
$gameOvered=TRUE;
}
return $gameOvered;
}
function getCurrentHusefull(){
$totalHousefull=0;
if((count(scandir('../../winnerDb/First Full House'))-2)>0){
$totalHousefull=$totalHousefull+1;
}
if((count(scandir('../../winnerDb/Second Full House'))-2)>0){
$totalHousefull=$totalHousefull+1;
}
if((count(scandir('../../winnerDb/Third Full House'))-2)>0){
$totalHousefull=$totalHousefull+1;
}
//echo("
Total current housefull is ".$totalHousefull."
");
return $totalHousefull;
}
function removeLastNum(){
// this is done when all house are full and additional number written by this script
$totalHousefull=(int)fread(fopen('../../gameData/totalHousefull.txt','r'),100);
$currentHousefull=getCurrentHusefull();
if($currentHousefull>=$totalHousefull){
$winTicket=fread(fopen('../../gameData/winTicket.txt','r'),1000);
$winTicket=substr($winTicket,0,-1);
$winTicket=substr($winTicket,0,-2);
fwrite(fopen('../../gameData/winTicket.txt','w'),$winTicket);
}
}
function getTimeDiff($date1,$date2){
// Formulate the Difference between two dates
$diff = abs($date2 - $date1);
// To get the year divide the resultant date into
// total seconds in a year (365*60*60*24)
$years = floor($diff / (365*60*60*24));
// To get the month, subtract it with years and
// divide the resultant date into
// total seconds in a month (30*60*60*24)
$months = floor(($diff - $years * 365*60*60*24)
/ (30*60*60*24));
// To get the day, subtract it with years and
// months and divide the resultant date into
// total seconds in a days (60*60*24)
$days = floor(($diff - $years * 365*60*60*24 -
$months*30*60*60*24)/ (60*60*24));
// To get the hour, subtract it with years,
// months & seconds and divide the resultant
// date into total seconds in a hours (60*60)
$hours = floor(($diff - $years * 365*60*60*24
- $months*30*60*60*24 - $days*60*60*24)
/ (60*60));
// To get the minutes, subtract it with years,
// months, seconds and hours and divide the
// resultant date into total seconds i.e. 60
$minutes = floor(($diff - $years * 365*60*60*24
- $months*30*60*60*24 - $days*60*60*24
- $hours*60*60)/ 60);
// To get the minutes, subtract it with years,
// months, seconds, hours and minutes
$seconds = floor(($diff - $years * 365*60*60*24
- $months*30*60*60*24 - $days*60*60*24
- $hours*60*60 - $minutes*60));
// Print the result
/*
printf("%d years, %d months, %d days, %d hours, "
. "%d minutes, %d seconds", $years, $months,
$days, $hours, $minutes, $seconds);
*/
//now convert all to hours
$totalHourInYrs=$years*365.24*24;
$totalHourInMonth=$months*30.417*24;
$totalHourInDay=$days*24;
$totalHourInHour=$hours;
$totalHourInMinute=$minutes/60;
$totalHourInSecond=$seconds/(60*60);
$totalHours=$totalHourInYrs+$totalHourInMonth+$totalHourInDay+$totalHourInHour;
//echo($totalHours);
return '{
"h":"'.$totalHours.'","m":"'.$minutes.'","s":"'.$seconds.'"
}
';
}
?>