Esempio n. 1
0
 try {
     $db->startTransaction();
     // insert played piece
     $db->insert("played", $newPieces);
     // are we in overtime? remove from overtime bin
     if ($game['status'] === 'overtime') {
         $db->deleteWhere("overtime", "id='" . $piece . "' AND player='" . $game['turn'] . "'");
     }
     if (sizeof($newLockouts) > 0) {
         // insert lockouts
         $db->insert("lockouts", $newLockouts);
         if ($jumpedPieces) {
             // delete jumped pieces
             $db->deleteIn("played", "tile", $jumpedPieces['tiles']);
             // delete lockouts from jumped pieces
             $db->deleteWhereAll("lockouts", array('fromTile', 'toTile'), $jumpedPieces['tiles'], "OR");
             // add jumped pieces to overtime bins
             $db->insert("overtime", $overtimePieces);
         }
     }
     // update player turn
     $db->update("game", array('turn' => $nextPlayer), array('gameID' => $gameID));
     // set overtime?
     if ($newStatus) {
         $db->update("game", array('status' => $newStatus), array('gameID' => $gameID));
     }
     $db->commitTransaction();
 } catch (Exception $e) {
     $db->rollBackTransaction();
     echo "Failed: " . $e->getMessage();
 }