Permalink
Browse files

align buttons on homepage

  • Loading branch information...
1 parent bf369a7 commit 7adac6b48f1927c7a477b1df08e4f3e1f5e30186 @wooki committed Dec 19, 2012
Showing with 54 additions and 52 deletions.
  1. +43 −41 application/models/game.php
  2. +10 −10 application/models/game_list.php
  3. +1 −1 application/views/homepage.php
@@ -1,6 +1,6 @@
<?php
class Game {
-
+
var $slug = '';
var $name = '';
var $state = '';
@@ -11,42 +11,43 @@ class Game {
var $success = 0;
var $fail = 0;
var $last_mission = false;
-
+ var $updated = date(DateTime::ATOM);
+
// work out the correct url for viewing this game
static function get_url_for_state($state, $slug) {
if ($state == 'joining') {
- return '/games/lobby/'.$slug;
+ return '/games/lobby/'.$slug;
} else if ($state == 'starting') {
- return '/games/start/'.$slug;
+ return '/games/start/'.$slug;
} else if ($state == 'mission-selection') {
- return '/missions/selection/'.$slug;
+ return '/missions/selection/'.$slug;
} else if ($state == 'mission-approve') {
- return '/missions/approve/'.$slug;
+ return '/missions/approve/'.$slug;
} else if ($state == 'mission-vote') {
- return '/missions/vote/'.$slug;
+ return '/missions/vote/'.$slug;
} else if ($state == 'mission-vote-acknowledge') {
- return '/missions/vote/'.$slug;
+ return '/missions/vote/'.$slug;
} else if ($state == 'mission-execute') {
- return '/missions/execute/'.$slug;
+ return '/missions/execute/'.$slug;
} else if ($state == 'mission-result') {
- return '/missions/result/'.$slug;
+ return '/missions/result/'.$slug;
} else if ($state == 'game-over') {
- return '/';
+ return '/';
} else {
return false;
- }
+ }
}
-
+
// util for calling the above function
static function get_url($game) {
return Game::get_url_for_state($game->state, $game->slug);
}
-
+
// work out how many spies there should be
static function how_many_spies($game) {
return round(count($game->players) * 0.33);
}
-
+
// work out how many agents there should be
static function how_many_agents($game, $mission_index) {
$agents = array(
@@ -58,26 +59,27 @@ static function how_many_agents($game, $mission_index) {
);
return $agents[$mission_index][count($game->players)-5];
}
-
+
// work out how many fail cards are required
static function how_many_fails($game, $mission_index) {
$agents = array(
array(1, 1, 1, 1, 1, 1),
array(1, 1, 1, 1, 1, 1),
array(1, 1, 1, 1, 1, 1),
array(1, 1, 2, 2, 2, 2),
- array(1, 1, 1, 1, 1, 1)
+ array(1, 1, 1, 1, 1, 1)
);
return $agents[$mission_index][count($game->players)-5];
}
-
+
// load from disc, from json file
static function load($slug, $game_list) {
- return $game_list->get_game($slug);
+ return $game_list->get_game($slug);
}
// save to disc, as json
static function save($game, $game_list) {
+ $this->updated = date(DateTime::ATOM);
return $game_list->update_game($game);
}
@@ -87,13 +89,13 @@ static function create($name, $admin_name) {
$g->name = $name;
$g->admin_name = $admin_name;
$g->slug = Game::generate_slug($g->name);
- $g->state = "joining";
+ $g->state = "joining";
$g->success = 0;
$g->fail = 0;
$g->last_mission = false;
return $g;
}
-
+
// record mission success and move state, plus ready
// for next mission
static function mission_success($game) {
@@ -104,7 +106,7 @@ static function mission_success($game) {
$game->current_team = 0;
$game->current_mission++;
}
-
+
// record mission fail and move state, plus ready
// for next mission
static function mission_fail($game) {
@@ -113,16 +115,16 @@ static function mission_fail($game) {
$game->last_mission = "Fail";
Game::next_team($game); // reset team and next leader
$game->current_team = 0;
- $game->current_mission++;
+ $game->current_mission++;
}
-
+
// start mission, resets votes but thats it
static function start_mission($game) {
foreach ($game->players as &$player) {
$player->vote = false;
}
}
-
+
// next team number, reset votes and new leader
static function next_team($game) {
$game->current_team++;
@@ -142,14 +144,14 @@ static function next_team($game) {
$player->vote = false;
$player->state = $game->state;
}
-
+
// if we have still got the current leader then set to 1st player
if ($current_leader == true) {
$game->players[0]->leader = true;
}
-
+
}
-
+
// gets the player data for the specified guid, returns false if not found
static function get_player($game, $guid) {
foreach ($game->players as $player) {
@@ -159,7 +161,7 @@ static function get_player($game, $guid) {
}
return false;
}
-
+
// check if all players have voted and return vote result
static function check_mission_vote($game) {
$not_voted = 0;
@@ -185,7 +187,7 @@ static function check_mission_vote($game) {
return "Success";
}
}
-
+
// check if all players have voted and return vote result
static function check_team_vote($game) {
$not_voted = 0;
@@ -208,7 +210,7 @@ static function check_team_vote($game) {
return "Rejected";
}
}
-
+
// check if all players are in the specified state
static function all_players_state($game, $state) {
foreach ($game->players as $player) {
@@ -218,7 +220,7 @@ static function all_players_state($game, $state) {
}
return true;
}
-
+
// set current team
static function set_team($game, $team) {
foreach ($game->players as &$player) {
@@ -233,29 +235,29 @@ static function set_team($game, $team) {
}
return false;
}
-
+
// get team
static function get_team($game) {
$team = array();
foreach ($game->players as $player) {
if ($player->team === true) {
- $team[] = $player;
+ $team[] = $player;
}
}
return $team;
}
-
+
// get spies
static function get_spies($game) {
$spies = array();
foreach ($game->players as $player) {
if ($player->role === "Rebel Spy") {
- $spies[] = $player;
+ $spies[] = $player;
}
}
return $spies;
}
-
+
// get leader
static function get_leader($game) {
foreach ($game->players as $player) {
@@ -265,7 +267,7 @@ static function get_leader($game) {
}
return false;
}
-
+
// update an existing player with new data
static function update_player($game, $player) {
foreach ($game->players as &$p) {
@@ -281,7 +283,7 @@ static function update_player($game, $player) {
}
}
}
-
+
// add a player to the game, returning a random guid for mapping
// that players requests to this player in the game
static function add_player($game, $name) {
@@ -309,11 +311,11 @@ static function add_player($game, $name) {
return $guid;
}
}
-
+
// generate a slug for the game
static function generate_slug($name) {
$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $name);
- return $slug;
+ return $slug;
}
}
@@ -1,12 +1,12 @@
<?php
class Game_List {
-
+
var $games = array();
var $games_list_file_path = './data/games.json';
-
+
// load from disc, from json file
- function load() {
-
+ function load() {
+
// check for file - and create an empty file if one doesn't exist
$json_data = read_file($this->games_list_file_path);
if ($json_data != false) {
@@ -19,8 +19,8 @@ function load() {
function save() {
$json_data = json_encode($this->games);
return write_file($this->games_list_file_path, $json_data, 'w');
- }
-
+ }
+
function update_game($game) {
$updated = false;
foreach ($this->games as &$g) {
@@ -34,10 +34,10 @@ function update_game($game) {
}
return $this->save();
}
-
+
// get the specified game
function get_game($slug) {
-
+
$exists = false;
foreach ($this->games as $game) {
if ($slug == $game->slug) {
@@ -48,12 +48,12 @@ function get_game($slug) {
}
// check if the specified item exists in the collection
function game_exists($name, $slug) {
-
+
$exists = false;
foreach ($this->games as $game) {
if ($name == $game->name ||
$slug == $game->slug) {
-
+
return true;
}
}
@@ -38,7 +38,7 @@
to complete the mission. Rebel Spies will try to saboutage the mission. This is done simply by
voting for mission success or failure.</p>
- <p>You must complete 3 our of the 5 missions that you will be set to win the game.</p>
+ <p>The first side to win three missions wins the game. Good luck!</p>
</div>

0 comments on commit 7adac6b

Please sign in to comment.