我正在使用codeigniter为轮盘赌系统构建一个库。
我希望使代码非常高效且防黑客。
这是代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Name: Prad Roulette
*
* Version: 0.1
*
* Author: Pradyummna Reddy
* prad@hireprad.co.uk
*
*
* Location: https://github.com/pradyummna/prad_roulette
*
* Created: 21/10/2014
*
* Description: The library can be used for roulette system developers
*
* Requirements: PHP5 or above
*
*/
class Prad_roulette
{
/**
*
* Function to find if the number is a valid roulette number
*
* @param integer $number The number to which has to be checked
*
* @return boolean
*
* Anchor: 1num
*/
function isValidRouletteNumber($number)
{
if(ctype_digit($number) && $number < 37 && $number >= 0 ){return true;}else{return false;}
}
/**
* Function to finds the number's color` in a roulette table
*
* @param integer $number The number to which the colour is to be determined
*
* @return string
*
* Anchor : 2color
*/
function findColour($number)
{
// checking the input numbers
if(!($this->isValidRouletteNumber($number))){return 'InValidInput';}
$wheel = array('0','32','15','19','4','21','2','25','17','34','6','27','13','36','11','30','8','23','10','5','24','16','33','1','20','14','31','9','22','18','29','7','28','12','35','3','26');
$numberInArray = array_keys($wheel, $number);
if(isset($numberInArray[0]))
{
if($numberInArray[0] == '0')
{$blackRred='ZERO';}
else{
if($numberInArray[0] % 2 == 0)
{
//its black!!!
$blackRred='Black';
}
else{ $blackRred = 'Red'; }
}
}
else
{
$blackRred = 'OUT';
}
return $blackRred;
}
/**
* Function to finds the number's neighbours left to them
*
* @param integer $number The number to which the left neighbours is to be determined
* @param integer $howManyNeighbours The total neighbours to be found
* @return array
*
* Anchor: neiLside
*/
function neighboursLeft($number,$howManyNeighbours)
{
// checking the input numbers
if(!($this->isValidRouletteNumber($number)) || !($this->isValidRouletteNumber($howManyNeighbours))){return array('InValidInput');}
$x = $howManyNeighbours;
$wheel = array('0','32','15','19','4','21','2','25','17','34','6','27','13','36','11','30','8','23','10','5','24','16','33','1','20','14','31','9','22','18','29','7','28','12','35','3','26');
$numberInArray = array_keys($wheel, $number);
$neighboursLeft = null;
if(isset($numberInArray[0]))
{
$currentNumber = $numberInArray[0];
//finding the end of the array
$startValueInArray = reset($wheel);
//$endArrayKey = key($wheel);
//reset($wheel);
//moving to the current position value position in the array
while (key($wheel) !== $numberInArray[0]) next($wheel);
$neighboursLeft[0] = 'In';
for($i=0;$i<$x;$i++)
{
if(current($wheel) != $startValueInArray)
{
//echo next($wheel);echo '::'.$i; echo '<br/>';
$neighboursLeft[$i+1] = prev($wheel);
}
else
{
end($wheel);
//echo current($wheel);echo '::'.$i;echo '<br/>';
$neighboursLeft[$i+1] = current($wheel);
}
}
}
else
{
$neighboursLeft = array('OUT');
}
//$neighboursLeft[0] can be OUT or In
return $neighboursLeft;
}
/**
* Function to finds the number's neighbours right to them
*
* @param integer $number The number to which the right neighbours is to be determined
* @param integer $howManyNeighbours The total neighbours to be found
* @return array
*
* Anchor: neirside
*/
function neighboursRight($number,$howManyNeighbours)
{
// checking the input numbers
if(!($this->isValidRouletteNumber($number)) || !($this->isValidRouletteNumber($howManyNeighbours))){return array('InValidInput');}
$x = $howManyNeighbours;
$wheel = array('0','32','15','19','4','21','2','25','17','34','6','27','13','36','11','30','8','23','10','5','24','16','33','1','20','14','31','9','22','18','29','7','28','12','35','3','26');
$numberInArray = array_keys($wheel, $number);
$neighboursRight = null;
if(isset($numberInArray[0]))
{
$currentNumber = $numberInArray[0];
//finding the end of the array
$endValueInArray = end($wheel);
//$endArrayKey = key($wheel);
reset($wheel);
//moving to the current position value position in the array
while (key($wheel) !== $numberInArray[0]) next($wheel);
$neighboursRight[0] = 'In';
for($i=0;$i<$x;$i++)
{
if(current($wheel) != $endValueInArray)
{
//echo next($wheel);echo '::'.$i; echo '<br/>';
$neighboursRight[$i+1] = next($wheel);
}
else
{
reset($wheel);
//echo current($wheel);echo '::'.$i;echo '<br/>';
$neighboursRight[$i+1] = current($wheel);
}
}
}
else
{
$neighboursRight = array('OUT');
}
// $neighboursRight[0] can be OUT or In
return $neighboursRight;
}
/**
* Function to finds the number's neighbours right to them
*
* @param array $numbers The number to which the right neighbours is to be determined
* @param array $moneyOnNumbers The total neighbours to be found
* @param integer $winningNumber The winning number
* @return array payoutAmount, Profit, Invested amount
*
* Anchor: xPayoutProfit
*/
function payoutProfit($numbers,$moneyOnNumbers,$winningNumber)
{
// checking the input numbers
if(!($this->isValidRouletteNumber($number)) || !($this->isValidRouletteNumber($winningNumber))){return array('InValidInput');}
//find the payout
if(in_array($winningNumber,$numbers))
{
$amountOnNumber = $moneyOnNumbers[array_search($winningNumber)];
$payoutAmount = $amountOnNumber * 36;
}
else
{
$payoutAmount = 0;
}
$totalInvested = 0;
// find the amount invested on it
foreach($moneyOnNumbers as $money)
{
$totalInvested = $totalInvested + $money;
}
//calculate profit
$profit = $payoutAmount - $totalInvested;
//return
return array($payoutAmount,$totalInvested,$profit);
}
/**
* Function to finds the number's neighbour right to it
*
* @param integer $number The number to which the right xth neighbour is to be determined
* @param integer $distanceToXthNumber Distance to the xth neighbour
*
* @return integer number in the xth position
*
* Anchor: XthNeiRside
*/
function findXthNumberOnRight($number,$distanceToXthNumber)
{
// checking the input numbers
if(!($this->isValidRouletteNumber($number)) || !($this->isValidRouletteNumber($distanceToXthNumber))){return array('InValidInput');}
if($distanceToXthNumber != '0')
{
$xthNumber = $this->neighboursRight($number,$distanceToXthNumber);
$xthNumber = $xthNumber[$distanceToXthNumber];
}
else
{
return $number;
}
//find the payout
return $xthNumber;
}
/**
* Function to finds the number's xth neighbour left to it
*
* @param integer $number The number to which the left xth neighbour is to be determined
* @param integer $distanceToXthNumber Distance to the xth neighbour
*
* @return integer number in the xth position
*
* Anchor: XthNeiLside
*/
function findXthNumberOnLeft($number,$distanceToXthNumber)
{
// checking the input numbers
if(!($this->isValidRouletteNumber($number)) || !($this->isValidRouletteNumber($distanceToXthNumber))){return array('InValidInput');}
if($distanceToXthNumber != '0')
{
$xthNumber = $this->neighboursLeft($number,$distanceToXthNumber);
$xthNumber = $xthNumber[$distanceToXthNumber];
}
else
{
return $number;
}
//find the payout
return $xthNumber;
}
}
//1000861505
库中的功能 1.检查数字是否为有效数字的函数(输入:数字|输出:真/假)[锚:1num]
在左侧找到第x个邻居的功能(输入:number,distanceToXthNumber |输出:数字)[anchor:XthNeiLside]
找到邻居距离的功能(时钟方式)(输入:number1,number2 |输出:中间的总数)
答案 0 :(得分:5)
您应该执行以下操作将其用作库 的 1。将库文件放在application / third_party文件夹中。
2.在application / libraries文件夹中创建另一个文件并扩展如下所示的类。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once APPPATH."/third_party/Prad_roulette.php";
class Roulette extends Prad_roulette {
}
注意:如果需要在类中使用构造函数,请确保扩展父构造函数:
class Roulette extends Prad_roulette {
public function __construct()
{
parent::__construct();
}
}
3.最后加载您的库。
$this->load->library('roulette');
要检查库是否已加载,您可以执行method_exits函数,如下所示
if(method_exists($this->roulette,'isValidRouletteNumber')){ /* isValidRouletteNumber is the method of Prad_roulette class. */
echo "Library is loaded successfully";
}else{
echo "Couldn't load the library";
}