Skip to content
Browse files

initial game data and creation - early days!

  • Loading branch information...
1 parent a87a3e2 commit 757751e50e8a0d06d9d77d3cb718b35ebaefa698 @wooki committed Dec 10, 2012
View
30 application/controllers/games.php
@@ -0,0 +1,30 @@
+<?php
+class Games extends CI_Controller {
+
+ public function index() {
+
+ $this->view_data = array(
+ 'title' => 'Joinable Games - 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.'
+ );
+
+ $this->load->view('shared/_header.php', $this->view_data);
+ $this->load->view('games/index', $this->view_data);
+ $this->load->view('shared/_footer.php', $this->view_data);
+
+ }
+
+ public function create() {
+
+ $this->view_data = array(
+ 'title' => 'New Game - 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.'
+ );
+
+ this->load->view('shared/_header.php', $this->view_data);
+ $this->load->view('games/new', $this->view_data);
+ $this->load->view('shared/_footer.php', $this->view_data);
+ }
+
+
+}
View
43 application/models/game.php
@@ -0,0 +1,43 @@
+<?php
+class Game {
+
+ var $slug = '';
+ var $name = '';
+ var $state = '';
+ var $admin_name = '';
+
+ // load from disc, from json file
+ function static load($slug) {
+ $ci =& get_instance();
+ $ci->load->helper('file');
+ $json_data = $ci->file->read_file('./data/game-'.$slug.'.json');
+ if ($json_data != false) {
+ return json_decode($json_data);
+ } else {
+ return false;
+ }
+ }
+
+ // save to disc, as json
+ function static save($game) {
+ $ci =& get_instance();
+ $ci->load->helper('file');
+ $json_data = json_encode($game);
+ return $ci->file->write_file('./data/game-'.$game->slug.'.json', $json_data);
+ }
+
+ // create a new game
+ function static create($name) {
+ $g = new Game();
+ $g->name = $name;
+ $g->slug = Game::generate_slug($g->name);
+ $g->state = "joining";
+ }
+
+ // generate a slug for the game
+ function static generate_slug($name) {
+ $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $name);
+ return $slug;
+ }
+
+}
View
41 application/models/game_list.php
@@ -0,0 +1,41 @@
+<?php
+class GameList {
+
+ var $games = array();
+ var $games_list_file_path = './data/games.json';
+
+ // load from disc, from json file
+ function load() {
+
+ // check for file - and create an empty file if one doesn't exist
+ $ci =& get_instance();
+ $ci->load->helper('file');
+ $json_data = $ci->file->read_file($games_list_file_path);
+ if ($json_data != false) {
+ $this->games = json_decode($json_data);
+ }
+ }
+
+ // save to disc, as json
+ function save() {
+ $ci =& get_instance();
+ $ci->load->helper('file');
+ $json_data = json_encode($this->games);
+ $ci->file->write_file($games_list_file_path, $json_data);
+ }
+
+
+ // 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;
+ }
+ }
+ return $exists;
+ }
+
+}
View
24 application/views/games/index.php
@@ -0,0 +1,24 @@
+<div class="container page">
+
+ <div class="row">
+
+ <div class="span12">
+ <h1>Please join a game</h1>
+
+ </div>
+
+ </div>
+
+ <div class="row">
+
+ <div class="span12 game-cmd">
+ <?php foreach($games as $game) { ?>
+ <a class="btn btn-primary btn-large" href="/"><?= $game->name ?></a>
+ <?php } ?>
+ </div>
+
+ </div>
+
+
+</div>
+
View
23 application/views/games/new.php
@@ -0,0 +1,23 @@
+<div class="container page">
+
+ <div class="row">
+
+ <div class="span12">
+ <h1>Create game</h1>
+ <?= form_open('games/create') ?>
+ <fieldset>
+ <label>Game Name</label>
+ <?= form_input('name', $game->name); ?>
+
+ <label>Player Name</label>
+ <?= form_input('admin_name', $game->admin_name); ?>
+
+ <button type="submit" class="btn btn-primary btn-large">Create</button>
+ </fieldset>
+ </form>
+ </div>
+
+ </div>
+
+</div>
+
View
4 application/views/homepage.php
@@ -11,10 +11,10 @@
<div class="row">
<div class="span3 offset2 game-cmd">
- <a class="btn btn-primary btn-large" href="/">New Game</a>
+ <a class="btn btn-primary btn-large" href="/games/create">New Game</a>
</div>
<div class="span3 offset2 game-cmd">
- <a class="btn btn-primary btn-large" href="/">Join</a>
+ <a class="btn btn-primary btn-large" href="/games">Join</a>
</div>
</div>
View
2 application/views/shared/_header.php
@@ -3,7 +3,7 @@
<head>
<title><?= $title ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link href='http://fonts.googleapis.com/css?family=Londrina+Solid' rel='stylesheet' type='text/css'>
+ <link href='http://fonts.googleapis.com/css?family=Exo:800' rel='stylesheet' type='text/css'>
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<link href="css/application.css" rel="stylesheet" media="screen">
View
2 css/application.css
@@ -1,5 +1,5 @@
h1, h2, h3, h4, .brand {
- font-family: 'Londrina Solid', cursive;
+ font-family: 'Exo', sans-serif;
}
h1 {

0 comments on commit 757751e

Please sign in to comment.
Something went wrong with that request. Please try again.