Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Merge branch 'stupidrobot-score' into development
Browse files Browse the repository at this point in the history
Conflicts:
	www/protected/modules/games/views/stupidRobot/index.php

The stupidrobot-score branch adds score functionality to StupidRobot, both in-
game and on the scoreboard. See the individual commits for more details.
  • Loading branch information
ssolbeck committed Jul 25, 2014
2 parents 6718b13 + fc1827f commit 6b50ce9
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 24 deletions.
24 changes: 22 additions & 2 deletions www/protected/modules/api/controllers/GamesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class GamesController extends ApiController {

public function filters() {
return array( // add blocked IP filter here
'throttle - messages, abort, abortpartnersearch, postmessage, play, saveLog, gameApi',
'throttle - messages, abort, abortpartnersearch, postmessage, play, saveLog, reset, gameApi',
'IPBlock',
'APIAjaxOnly', // custom filter defined in this class accepts only requests with the header HTTP_X_REQUESTED_WITH === 'XMLHttpRequest'
'accessControl - messages, abort, abortpartnersearch, gameApi, postmessage',
Expand All @@ -18,7 +18,7 @@ public function filters() {
public function accessRules() {
return array(
array('allow',
'actions'=>array('index', 'scores', 'play', 'saveLog', 'partner', 'messages', 'abort', 'abortpartnersearch', 'gameApi', 'postmessage'),
'actions'=>array('index', 'scores', 'play', 'saveLog', 'reset', 'partner', 'messages', 'abort', 'abortpartnersearch', 'gameApi', 'postmessage'),
'users'=>array('*'),
),
array('deny',
Expand Down Expand Up @@ -506,6 +506,26 @@ public function actionSaveLog($gid) {
*/
}

/**
* Resets the game_engine and creates a new PlayedGame object to store the next session.
* In addition, this action saves the user's score to the database.
* - this only needs to be called for games which do not reload between game sessions
*/
public function actionReset($gid, $pid=null) {
$game = GamesModule::loadGame($gid);
$played_game = PlayedGame::model()->findByPk($pid);
$score = $played_game->score_1;
$this->_saveUserToGame($game, $score);

$game_engine = GamesModule::getGameEngine($gid);
$this->_createPlayedGame($game, $game->game_model, $game_engine);
$game_engine->reset();

$data['played_game_id'] = $game->played_game_id;
$data['status'] = "Score saved successfully";
$this->sendResponse($data);
}

/**
* Attempts to pair the waiting player with a second one.
*
Expand Down
33 changes: 24 additions & 9 deletions www/protected/modules/games/assets/stupidrobot/css/main_new.css
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ textarea {
}

.underlinedText{
display: inline;
font-size:1.71em;
text-transform:uppercase;
font-family:"telegrama-render";
Expand Down Expand Up @@ -378,20 +379,34 @@ textarea {
margin-bottom:15px;

}
#score br{
clear:both;

#score table {
margin-left: auto;
margin-right: auto;
}

#score span{
#finalScoreRow{
border-top: thin solid gray;
font-size: 1.5em;
text-align: right;
color: green;
font-family:"telegrama-render";
}
#finalScoreRow td { vertical-align: baseline; }

display:inline-block;
width:auto;
line-height:1.1em;
margin:1px;
#finalScore{
font-size: 1.1em;
padding-top: 10px;
}

#score .leftBox{
text-align:center;
.scorePlus {
width: 60px;
visibility: hidden;
color: blue;
font-family:"telegrama-render";
font-size: 0em;
padding-left: 10px;
text-align: right;
}

#score .button{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ MG_GAME_STUPIDROBOT = function ($) {
scorestage: null,
scorelevel: 0,

finalScore: 0,
scoreIncrease: 0,
scoreIndex: 0,

// new added for splash page
idx_paragraphArray: null,
idx_introText: ["Meet Stupid Robot.",
Expand Down Expand Up @@ -886,9 +890,10 @@ MG_GAME_STUPIDROBOT = function ($) {
MG_GAME_STUPIDROBOT.p = MG_GAME_STUPIDROBOT.wordSpaces[MG_GAME_STUPIDROBOT.activeLine];
MG_GAME_STUPIDROBOT.i++;
// console.log("activeLine: " + MG_GAME_STUPIDROBOT.activeLine);
if (MG_GAME_STUPIDROBOT.activeLine >= 10) {
if (MG_GAME_STUPIDROBOT.activeLine >= 7) {
// scroll is finished

MG_GAME_STUPIDROBOT.displayScore();
createjs.Ticker.setFPS(24);
createjs.Ticker.addListener(MG_GAME_STUPIDROBOT.scorestage);
return;
Expand Down Expand Up @@ -919,7 +924,38 @@ MG_GAME_STUPIDROBOT = function ($) {
setTimeout("MG_GAME_STUPIDROBOT.scrollIn()", 25);
},

displayScore: function() {
if (MG_GAME_STUPIDROBOT.scoreIncrease > 0) {
MG_GAME_STUPIDROBOT.scoreIncrease--;
MG_GAME_STUPIDROBOT.finalScore++;
document.getElementById("finalScore").innerHTML = MG_GAME_STUPIDROBOT.finalScore;
} else {
if (MG_GAME_STUPIDROBOT.scoreIndex >= 7) {
return;
} else if (MG_GAME_STUPIDROBOT.wordArray[MG_GAME_STUPIDROBOT.scoreIndex] != "!") {
var length = MG_GAME_STUPIDROBOT.scoreIndex + 4;
$(".scorePlus").eq(MG_GAME_STUPIDROBOT.scoreIndex)
.css("visibility", "visible")
.animate({"font-size": "1.5em"}, 100);
MG_GAME_STUPIDROBOT.scoreIncrease = length;
}
MG_GAME_STUPIDROBOT.scoreIndex++;
}
setTimeout(MG_GAME_STUPIDROBOT.displayScore, 100);
},

renderFinal: function () {
MG_API.ajaxCall('/games/reset/gid/' + MG_GAME_API.settings.gid
+ '/pid/' + MG_GAME_STUPIDROBOT.game.played_game_id,
function (response) {
if (MG_API.checkResponse(response)) {
MG_GAME_STUPIDROBOT.game.played_game_id = response.played_game_id;
console.log(response.status);
}
return false;
}, {type: 'get'}
);

if (MG_GAME_STUPIDROBOT.isRenderFinaled == true)
return;
else
Expand Down Expand Up @@ -1060,6 +1096,10 @@ MG_GAME_STUPIDROBOT = function ($) {
MG_GAME_STUPIDROBOT.scorestage = null;
MG_GAME_STUPIDROBOT.scorelevel = 0;

MG_GAME_STUPIDROBOT.finalScore = 0;
MG_GAME_STUPIDROBOT.scoreIncrease = 0;
MG_GAME_STUPIDROBOT.scoreIndex = 0;

$("#loadgame").remove();
$("#score").remove();
$("#game").remove();
Expand Down
14 changes: 14 additions & 0 deletions www/protected/modules/games/components/StupidRobotGame.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,20 @@ private function getMediaTags(StupidRobotDTO $level, $mediaId)
return $mediaTags;
}
}

public function getScore(&$game, &$game_model, &$tags)
{
$score = 0;
$api_id = Yii::app()->fbvStorage->get("api_id", "MG_API");
$levels = Yii::app()->session[$api_id . '_STUPIDRORBOT_LEVELS'];
if ($levels) {
$level = unserialize(end($levels));
if ($level->isAccepted) {
$score += strlen($level->tag);
}
}
return $score;
}
}

class StupidRobotDTO
Expand Down
29 changes: 17 additions & 12 deletions www/protected/modules/games/views/stupidRobot/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,23 @@
<div id="container">
<div class="leftBox clearfix">
<span id="endgameMessage">I NOW COMPREHEND 6 NEW WORDS<br>I AM SOMEWHAT SMARTER!</span>
<br><span class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;</span>
<br><span class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<br><span class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<br><span class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<br><span class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<br><span class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<br><span class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<br><span
class="underlinedText hideBox">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<br><span
class="underlinedText hideBox">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<br><span class="underlinedText hideBox">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<table>
<tr><td class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td class="scorePlus">+4</td></tr>
<tr><td class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td class="scorePlus">+5</td></tr>
<tr><td class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td class="scorePlus">+6</td></tr>
<tr><td class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td class="scorePlus">+7</td></tr>
<tr><td class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td class="scorePlus">+8</td></tr>
<tr><td class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td class="scorePlus">+9</td></tr>
<tr><td class="underlinedText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td class="scorePlus">+10</td></tr>
<tr id="finalScoreRow"><td>FINAL SCORE:</td><td id="finalScore">0</td></tr>
</table>
<br><a class="button" id="reboot">REBOOT</a>
</div>
<div class="rightBox" id="imageContainer">
Expand Down

0 comments on commit 6b50ce9

Please sign in to comment.