public static function setScore($input) { //need link and score and iduser to set the score $link = $input['link']; $user_id = $input['userID']; $score = $input["score"] + User::getScore($input); $link->query("UPDATE users SET score = {$score} where userID = {$user_id} "); /*if($link->Affected_rows){//just in case return true; } return false;*/ //i putt in comment for now for debug }
public function __construct() { global $database; $this->competitions = $database->getAllCompetitions(); $this->pages = $database->getAllPages(); if (loggedIn()) { $this->userGroups = $database->getUserGroups($_SESSION['userID']); $this->userGroupNames = array(); foreach ($this->userGroups as $groupId) { $this->userGroupNames[$groupId] = $database->getGroupName($groupId); } $this->money = $database->getMoney($_SESSION['userID']); $user = new \User($_SESSION['userID']); $this->score = number_format((double) $user->getScore(), 2, '.', '.'); } }
public static function findOpponent($input) { $user_id = User::getUserId(); $link = $input['link']; //the result will contain queueid and subjectid of other players that are searching for a game $result = $link->query("SELECT idQueue,idUser,idSubject FROM queue,users,queuedetail WHERE(users.isPlaying=false AND queue.id=queuedetail.idQueue AND users.id=queue.idUser AND users.id!='{$user_id}' AND ( queuedetail.idSubject IN (select idSubject FROM queue,users,queuedetail WHERE ( users.isPlaying=false AND queue.id=queuedetail.idQueue AND users.id=queue.idUser AND users.id='{$user_id}') ) OR queuedetail.idSubject=0 ) )"); //i don't know if we do need to check if the player is playing. because the queueId is still there, //it must be that he didn't find a battle just yet. so i guess it's unecessary to check if the other player !isPlaying //now we need to get matchmaking fair, so we need to check each player's score //basically min(abs(distance(scoreplayer1,scoreplayer2))) //this better be like if (!$result->num_rows) { return 0; } $row = $result->fetch_assoc(); $min_score_distance = GameMaker::scoreDistance(User::getScore(array('link' => $link, 'userId' => $row['idUser'])), User::getScore(array('link' => $link))); //now let's get the queueId and the subjectId $userId = $row['idUser']; $queueId = $row['idQueue']; $subjectId = $row['idSubject']; //hmm, if bother players didn't select nothing. let's randomly select a subject :D if ($subjectId == 0) { $result = $link->query("SELECT id from subjects ORDER BY RAND() LIMIT 1"); $row = $result->fetch_assoc(); $subjectId = $row['id']; } while ($row = $result->fetch_assoc()) { $current_distance = GameMaker::scoreDistance(User::getScore(array('link' => $link, 'userId' => $row['idUser'])), User::getScore(array('link' => $link))); if ($current_distance < $min_score_distance) { $min_score_distance = $current_distance; $userId = $row['idUser']; $queueId = $row['idQueue']; $subjectId = $row['idSubject']; //here we can have multip subject !! } } //we now have the closest two players considering their score //allocate the damn match already! :D return GameMaker::allocateBattle(array('link' => $link, 'userId' => $userId, 'queueId' => $queueId, 'subjectId' => $subjectId)); }
} require_once 'Slim/Slim.php'; require_once 'models/User.php'; $app = new Slim(); $user = new User(); $app->get('/users', function () use($user) { $user->getAll(); }); $app->get('/users/:id', function ($id) use($user) { $user->getById($id); }); $app->get('/users/:id/friends', function ($id) use($user) { $user->getFriends($id); }); $app->get('/users/:id/score', function ($id) use($user) { $user->getScore($id); }); $app->get('/users/:id/rewards', function ($id) use($user) { $user->getRewards($id); }); $app->get('/users/search/:name', function ($name) use($user) { $user->getByName($name); }); $app->delete('/users/:id', function ($id) use($user) { $user->delete($id); }); $app->post('/users', function () use($user, $app) { $request = $app->request(); $body = $request->getBody(); $vo = json_decode($body); $user->insert($vo);
<th>Action</th> </tr> </thead> <tbody> <?php $members = $this->getGroup()->getMembers(); foreach ($members as $memberId) { $user = new User($memberId); ?> <tr> <td><?php echo $user->getUserName(); ?> </td> <td><?php echo number_format((double) $user->getScore(), 2, '.', '.'); ?> </td> <td><?php echo $user->getMoney(); ?> </td> <?php if ($this->getGroup()->isUserOwner($_SESSION['userID']) && !$this->getGroup()->isUserOwner($memberId)) { ?> <form id="removeUser" class="form-horizontal" role="form" method="post" action="<?php echo SITE_URL; ?> group/<?php