Welcome Guest, Not a member yet? Register   Sign In
Developing a Codeigniter game
#1

[eluser]Unknown[/eluser]
I have a pretty reasonable amount of experience in PHP (around ~5 years of experience with some websites made and two browser games). This is the first time I've really messed around with a core engine instead of just developing a plugin or module for something like Joomla. I have an extensive amount of experience in other object oriented languages (such as Java).

My question is, I find myself developing the site much like a normal site, but I want it to be more flexible than that and I'm not sure I'm "doing it right". In a way, I feel like I'm building half a CMS.

For example, I have the main page set up through a controller that controls what views are currently being displayed. The main view page looks like this:

Code:
<?php $this->load->view("headerview"); ?>
<?php $this->load->view($contentview); ?>
<?php $this->load->view("footerview"); ?>

in a view file itself (so I can dynamically load the contentview, the others don't really change). This is my first question, since I do ALL the control through my main control file, is this correct?

My index function sets the mainview as the view to be loaded with variables for the "contentview" and "gameview". When "contentview" is the game, it has a split pane, one showing the players stats and such, and the other showing whichever page the player is currently on (the merchant shop, in a battle, exploring the world, etc.). What determines what is being shown here is the "gamecontent" variable (also passed in the "main" controller).

Code:
<?php $this->load->view("menubar"); ?>
<?php $this->load->view($gamecontent); ?>

In short, all view handling is currently being done in the main controller, i.e. one single controller.

Code:
$data['title'] = "Experimental Page";
$data['maincontent'] = "gameview";
if($page == 1) {
    $data['gamecontent'] = "townview";
} else if ($page == 2) {
    $data['gamecontent'] = "merchantview";
} else if ($page == 3) {
    $data['gamecontent'] = "explorationview";
} else if ($page == 4) {
    $data['gamecontent'] = "hospitalview";
} else if ($page == 5) {
    $data['gamecontent'] = "fightview";
} else if ($page == 6) {
    $data['gamecontent'] = "adminview";
}

$this->load->helper(array('form','url'));
$this->load->library('form_validation');
$this->load->view('mainview', $data);

I haven't started adding the fighting and shopping functions yet, but I can see this controller getting very large, very fast. This seems wrong to me, but somehow I can't formulate how to properly arrange the core setup.

My goal is to (hopefully) split up the controllers so that each one handles a separate game function, like healing, fighting, exploring and so on, and is separated much like my models are (user, mobs, items, etc.).

Can anyone help me figure out how to properly arrange this project?
#2

[eluser]Unknown[/eluser]
Is there anyone willing to drop a little info in here?
#3

[eluser]Cesar Kohl[/eluser]
In the next months I'll probably try to make a game too, and I see no reason for you to escape from the best practices documented in CodeIgniter's User Guide.

Mostly, for repeatable codes, I would separate everything into models (when getting data from database) and libraries (when not).

To have a large controller doesn't necessarily means you are coding it wrong.

In the case of 'header,content,footer', I use a template library to boost up consistency. The code is here: http://maestric.com/doc/php/codeigniter_template

I have some experience with CI and can help you as you progress.




Theme © iAndrew 2016 - Forum software by © MyBB