Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

team approve

  • Loading branch information...
commit 62e830969ef8e19bddd690c5ae96206e3a233e37 1 parent 84b75dd
@wooki authored
View
82 application/controllers/missions.php
@@ -1,6 +1,83 @@
<?php
class Missions extends CI_Controller {
+ // display mission vote result and wait for final Continue click from players
+ // where we either revert to new leader and vote or go to the mission.
+ public function vote($slug=false) {
+
+ if ($slug == false) { show_404('page'); }
+
+ // load the game
+ $this->load->helper('form');
+ $this->load->model(array('game_list', 'game'));
+ $games_list = new Game_List();
+ $games_list->load();
+ $game = Game::load($slug, $games_list);
+
+ if ($game == false) {
+ $this->session->set_flashdata('error', 'Game does not exist');
+ redirect('/', 'location');
+ return;
+ } else if ($game->state != 'mission-vote') {
+ $this->session->set_flashdata('error', 'Game state has moved');
+ redirect(Game::get_url($game), 'location');
+ return;
+ }
+
+ // load current player
+ $guid = $this->session->userdata('player_id');
+ $player = Game::get_player($game, $guid);
+
+ if ($player == false) {
+ $this->session->set_flashdata('error', 'You are not a player in that game');
+ redirect('/', 'location');
+ return;
+ }
+
+ // first time player hits page set state, if they are posting back then update
+ $postback = $this->post('acknowledge');
+ if ($postback == '1') {
+ $player->state = 'mission-vote-acknowledge';
+ } else {
+ $player->state = 'mission-vote';
+ }
+ Game::update_player($game, $player);
+
+ // check success/fail
+ $vote_result = Game::check_vote($game);
+
+ // when all players have acknowledged we redirect top relevant step
+ if (Game::all_players_state($game, 'mission-vote-acknowledge') == true) {
+
+ // fail 5th - Game Over
+
+
+ // fail - next team leader
+
+ // success - go to mission
+
+ }
+
+ // finally save the game
+ Game::save($game, $games_list);
+
+ // set view data
+ $this->view_data = array(
+ 'title' => $game->name.' Mission Vote - Covert Mission - Group game with a star wars theme',
+ 'description' => 'Covert Mission is a group game with a star wars theme based around player deception and deduction of player motives, in the same genre as werewolf and mafia.',
+ 'game' => $game,
+ 'player' => $player,
+ 'leader' => Game::get_leader($game),
+ 'team' => $team,
+ 'vote_result' => $vote_result
+ );
+
+ $this->load->view('shared/_header.php', $this->view_data);
+ $this->load->view('missions/vote', $this->view_data);
+ $this->load->view('shared/_footer.php', $this->view_data);
+ }
+
+
// handle post from team leader of team
// move to approve team state and await
// player votes
@@ -69,7 +146,10 @@ public function approve($slug=false) {
// check if we have all votes
- if
+ if (Game::check_vote($game) != "Incomplete") {
+ // update state to mission-vote to redirect to show result page
+ $game-state = "mission-vote";
+ }
// finally save the game
Game::save($game, $games_list);
View
27 application/models/game.php
@@ -19,6 +19,10 @@ static function get_url($game) {
return '/missions/selection/'.$game->slug;
} else if ($game->state == 'mission-approve') {
return '/missions/approve/'.$game->slug;
+ } else if ($game->state == 'mission-vote') {
+ return '/missions/vote/'.$game->slug;
+ } else if ($game->state == 'mission-vote-acknowledge') {
+ return '/missions/vote/'.$game->slug;
} else {
return false;
}
@@ -83,6 +87,29 @@ static function get_player($game, $guid) {
return false;
}
+ // check if all players have voted and return vote result
+ static function check_vote($game) {
+ $not_voted = 0;
+ $voted_yes = 0;
+ $voted_no = 0;
+ foreach ($game->players as $player) {
+ if ($player->vote == "Approve") {
+ $voted_yes++;
+ } else if ($player->vote == "Reject") {
+ $voted_no++;
+ } else {
+ $not_voted++;
+ }
+ }
+ if ($not_voted > 0) {
+ return "Incomplete";
+ } else if ($voted_yes > $voted_no) {
+ return "Approved";
+ } else {
+ return "Rejected";
+ }
+ }
+
// check if all players are in the specified state
static function all_players_state($game, $state) {
foreach ($game->players as $player) {
View
37 application/views/missions/vote.php
@@ -0,0 +1,37 @@
+<div class="container page lobby">
+
+ <div class="row">
+
+ <div class="span12">
+ <h1><?= $game->name ?> Mission <?= display_mission($game->current_mission) ?> Team <?= $vote_result ?></h1>
+ <h4 class="player" data-role="<?= $player->role ?>" data-slug="<?= $player->slug ?>" data-admin="<?= $game->admin_name ?>">Playing as <?= $player->name ?></h4>
+ </div>
+
+ <div class="span4 offset4">
+
+ <p class="alert alert-info game_state">Mission vote complete</p>
+
+ <p>Mission leader is: <?= player_label($leader->name) ?></p>
+
+ <p>Team leader has picked:</p>
+ <?php foreach ($team as $p) { ?>
+ <?= player_label($p->name) ?>
+ <?php } ?>
+
+ <?= form_open('missions/vote/'.$game->slug, array('class' => 'vote-acknowledge')) ?>
+ <?= form_hidden('postback', '1'); ?>
+
+ <p>Acknowledge vote result</p>
+
+ <p class="validation-message">&nbsp;</p>
+
+ <button type="submit" class="btn btn-primary btn-large">Acknowledge</button>
+
+ </form>
+
+ </div>
+
+ </div>
+
+</div>
+
View
4 js/application.js
@@ -10,6 +10,10 @@ var covertmission = function() {
return 'Waiting for team leader';
} else if (state == 'mission-approve') {
return 'Waiting for player votes';
+ } else if (state == 'mission-vote') {
+ return 'Mission vote complete';
+ } else if (state == 'mission-vote-acknowledge') {
+ return 'Waiting for all players';
} else {
return 'Unknown state: '+state;
}
Please sign in to comment.
Something went wrong with that request. Please try again.