Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
dhirajpatra committed May 21, 2017
1 parent f4f8f16 commit edf1037
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion LudoClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,9 @@ class LudoClass

public $players = array('red', 'blue', 'yellow', 'green');


/**
* LudoClass constructor.
*/
function __construct()
{
session_start();
Expand Down
13 changes: 11 additions & 2 deletions ludoProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 21,8 @@
}



/**
*
* this function will randomly generate dice result for specific player
*/
function diceRoll ($ludoObj) {
$player = null;
Expand Down Expand Up @@ -60,6 59,8 @@ function diceRoll ($ludoObj) {

/**
* this will check for every move requesting by player for a specific piece
* @param $post
* @param $ludoObj
*/
function move ($post, $ludoObj) {

Expand All @@ -86,13 87,17 @@ function move ($post, $ludoObj) {

// checking if this move is for specific player on which it requesting to move for
if (count($boxIdDetails) > 0 && $boxIdDetails[1] == substr($ludoObj->players[$_SESSION['turn']], 0, 1)) {

// is it a first move for the home piece
if ($_SESSION['last_result'] == 6 && $currentValue == '' && (!in_array($boxIdDetails[2], $_SESSION[$ludoObj->players[$player] . 'pieceNotInGame']))) {

$_SESSION[$ludoObj->players[$player].$boxIdDetails[2].'LatestPosition'] = $_SESSION[$ludoObj->players[$player].'FirstPosition'];

echo $_SESSION[$ludoObj->players[$player].$boxIdDetails[2].'LatestPosition'];

// or it is move for a piece which is already out of home
} elseif (strlen($currentValue) === 4 || $currentValue != '' && (!in_array($boxIdDetails[2], $_SESSION[$ludoObj->players[$player] . 'pieceNotInGame']))) {

$details = array(
'player' => $ludoObj->players[$player],
'piece' => $boxIdDetails[2],
Expand All @@ -106,6 111,7 @@ function move ($post, $ludoObj) {
} elseif ($currentValue == '' && $_SESSION['last_result'] < 6 && (!in_array($boxIdDetails[2], $_SESSION[$ludoObj->players[$player] . 'pieceNotInGame']))) { // also -1 means already reched end for that piece

echo 'This piece need 6 to move out from home. Try other piece.';

// already reached end
} elseif ($currentValue == -1) { // also -1 means already reched end for that piece
// remove that piece from game
Expand Down Expand Up @@ -137,15 143,18 @@ function nextMove ($details) {

// loop all positions for this player's specific piece
foreach ($positions as $position) {

// where is right now
if ($position === $latestPosition && $nowMoveCountStart == 0) {
$nowMoveCountStart = 1;
$toMove ;

// reach the point need to move from last point / box
} elseif ($toMove == $needToMove && $nowMoveCountStart == 1) {
$reached = 1;
$_SESSION[$details['player'].$details['piece'].'LatestPosition'] = $position;
break;

// not come where is existing place/box
} elseif($nowMoveCountStart == 1) {
$toMove ;
Expand Down

0 comments on commit edf1037

Please sign in to comment.