Game Finances: Amortization

Leave a comment Standard

What Is Amortization?

This is an accounting term for taking multiple payments over time or spreading a single payment out over a period of time.

Example 1: Taking Multiple Payments

One way you can use amortization to your benefit is to take multiple payments for something. So let’s say you have a yearly upgrade that costs $50. Amortization in this instance means you allow the player to break that payment down into multiple payments. For instance, they might make two payments instead of a single one; $25 for the first 6 months of the upgrade and then another $25 for the last 6 months. With amortization you can brake a payment down into as many smaller payment as you’d like. So instead of taking 2 payments you might decide to take 5 or 6 or 30 — however it best suits your player base and brings you good business. Generally speaking, most people tend to break payments down into no more than 12 just because it makes the accounting practices easier if you have one payment a month. If you broke this $50 upgrade into 12 payments then your players could become an upgraded member for only $4.20 a month.

Why Is Example 1 So Helpful?

Many people are more willing to make smaller payments. This means that even if you don’t get a full year’s upgrade from one member you’re still bringing in income. It also encourages people to try out your upgrade system with a much smaller risk to themselves. If they don’t like the upgrade they’ve only spent half or much less than half the money than if they’d paid for a full year. It also gives them the ability to come and go on their upgrade much more readily than if they had to pay the larger sum each year. They can buy one month and not the other, then come back for the month following that allowing them more flexibility to purchase and keep their upgrade.

What’s The Downside of Example 1?

You may not be bringing in as much money as you like. Because the payments are smaller you also have more online processing fees that are applied, however some payment services will allow you register as a micro-transaction account and will take lower fees since you will be bringing in a higher volume of payments. While payments are likely to happen more frequently they will only be in smaller amounts which may make it seem like your bank account is always struggling to stay at a more comfortable level when you have slower times.

Example 2: Taking One Payment and Spreading It Over a Period of Time

This other example is one that many of you may not know about. It applies the same kind of idea except you only take one payment and you only apply a portion of that payment to your income over a duration. For example, let’s say you got your $50 upgrade and we go back to our 2 payments example. Instead of thinking of that $50 as one payment you apply $25 to this month and then 6 months later you apply the other $25. You may still have the full amount of $50 but you’re not considering it income until a period of time has passed. This idea works best when you break a payment down into bi-annually, quarterly or monthly time periods. So in our second 12 month example, instead of getting $50 for this one payment you apply $4.20 from this payment across every month.

Why Is Example 2 So Helpful?

This is really the icing on the cake and most people don’t realize it! When you take in the one payment and spread it out amongst a period of time it gives you more solid, steady income. Instead of getting $50 one month, and nothing for the next 12 months, you now have a steady stream of income coming in all year long. Generally speaking, with games the upgrade tend to have highs and lows, where people are upgrading a lot and then not upgrading at all. You may get $4,000 in upgrades one month and then nothing or very little for the next two. With this kind of amortization that $4,000 is spread over the rest of the time period. So in our 12 month example you would be bringing in $334 a month instead of $4,000 in one lump sum. This also helps you keep a steady income for the entire year instead of getting less reliable income over the duration of the year, even if the overall total for whatever time period you’re shooting for is lower than what you bring in for a month. It’s great for budgeting and paying your bills and helping you keep your game open even in slower months.

What’s The Downside of Example 1?

This example takes discipline!! It’s a much different way of thinking about the income you’re bringing in because the balance in your bank account may reflect one thing while your calculations reflect another. It is very tempting to just look at your total balance and think I have $4,000 rather than I only have $334 to spend this month. It also requires some math to keep track of how much money you are amortizing over time whereas Example 1 is easier to keep track of because you immediately account for the money from each payment you get.

What do you think about amortization? Do or have you used it? Which type of amortization do you prefer?

I would love to hear your thoughts, comments, questions and experiences!

The Game Plan: Getting Started

Leave a comment Standard

Your game design can run fairly smoothly or it can be a continuous cesspool of hardships and setbacks and pain points. In the next few series of posts I’m going to try and help walk you through the process of getting your game up and off the ground, from what you’re envisioning in your head to an actual working version. So, let’s get started.

1. Get It Out Of Your Head

It’s time you pull out a pencil, pen, or open your laptop to a writing program. First thing’s first, you have to get your game out of your head. Write it down and put it somewhere you can reference it later.

2. Writer’s Block

So if you’ve opened a text editor or you have a pen in your hand you’ve successfully completed step one. Now, what do you write? I like to start with the five W’s:

Whom?

  • Does your game appeal to a specific age range or interest group or gender or even ethnic background?
  • Will you have a large audience your game will appeal to or a small audience?
  • What are the benefits and downsides of the audience you’ve identified?

What?

  • What kind of game are you trying to make?
  • What programming language best suits this kind of game?
  • Does it fit into a specific genre of game or does it span multiple genres?
  • Does it embody a completely new genre?
  • Can you find other games that are similar to the game you are trying to make? If so, what do these games do well and where do fall short?
  • Are there lots of other games on the market similar to the type of game you’re trying to make?
  • What will your charge for your game?
  • What do other, similar games of this type charge?
  • What are the benefits and downsides of the type of game you’re trying to make?

Where?

  • Where does your game take place?
  • What kind of maps or features or environment are unique to your game?
  • What are the benefits and downsides of where your game takes place?

When?

  • When will you have time to work on this game?
  • When can you start this game?
  • When can you fund the development of this game?
  • What are the benefits and downsides of developing this game?

Why?

  • Why are you making this game?
  • Why is your game unique?
  • Why will your game stand out from the crowd?
  • Why will people choose to play your game over other similar games?
  • Why will people pay for your game?
  • What are the benefits and downsides of making this game?

3. Make A Design Document

Your design document is a refined version of everything you’ve written down in step 2. Go back and really analyze what your goals for the game are and if what you’ve written down makes sense in the larger picture. Sometimes a good idea you have for one area of the game will conflict or make another part of the game tedious, uninspired or downright frustrating. For a game design document I like to use the following format:

  1. Intro
    • What is the vision for your game and a short description of how the game is played
  2. Audience, Platform & Marketing Strategies
    • Who the game is for, what platforms you’re making it for and what sets your game apart that will make it marketable and different from others
  3. Core Gameplay & Mechanics
    • How the game is played including physics, rules and limitations
  4. Characters
    • What characters are in your game including what they look like, their names and backgrounds and personalities
  5. Story, Themes & Twists
    • If your game has an overarching story then you’ll outline your plot and how the game progresses with the story line
  6. World
    • Describe the world your game is set in, including maps and locations and their purpose or importance
  7. Assets
    • All the different images, music, animations, etc that you will need to have a fully functional game
  8. Technical Specs
    • What language you’re using, how games are loaded/saved, where games are stored, the number of servers you’ll need and anything else relating to the technical setup of your game
  9. Interface
    • What the game interface looks like and how the player will interact with it
  10. Outside References
    • Articles, links, design inspriations, or anything else that you’re using as a reference for the game you’re making
  11. Appendix
    • Code style guidelines, dictionary of terms, and anything else that is important for understanding your design document that may not necessarily relate to your game directly

Once you’ve fully fleshed out your game design by going into depth about the features, physics, economy, weapons, characters and how the game works it’s time to break it down. Start by creating lots of of small, easy tasks you can accomplish in order to see your core game mechanics to completion enough that you could play a simple version of your game without any extra bells and whistles. Set yourself up to do as little as you have to but as much as you need to in order to get a really simplified, yet completed, version of your game.

How To Get People To Play Your Game

Comments 2 Standard

I’ve learned a lot in the almost 15 years I’ve been running online games. Sure, I can tell you all the different marketing strategies you usually see articles for that show you how to spam your game in every social network and paid advertising service known to man, but that’s not what this post is all about. There’s a difference between getting people to KNOW about your game and getting people to PLAY your game.

Know Your Target Audience

First and foremost you need to know your audience. Who does your game appeal to? If you’re advertising your game for 30+ year old men but the only people who’ve played it so far are young  teenage girls then advertising it on a Cars Automotive Forum is just a waste of your time. If your game is brand new and you’re not sure of your target audience then you can do some playtesting to get feedback on who it appeals to the most. You can also try asking a variety of friend and family to play if playtesting isn’t an option for you — this will give you a varied pool of ages and computer skill levels to draw some basic conclusions from.

Advertise To Your Target Audience

If you’re looking for children to play your game and all of your advertisements/branding/banners/phrases use large vocabulary words and dense/visually busy/highly realistic/dark images then you’re already setting yourself up for increased headaches and hair pulling. If you don’t know much about your target audience then it’s time to stop and do some research. What appeals to children is completely different from what appeals to adults or teenages just like what appeals to women is different from what appeals to men.

Add Lots Of Variety

If you go the pay for advertising route, or even if you self-promote your game in forums/social networks you need to vary how you advertise. By this I mean use both different graphics and wording and in what you’re posting. You’ll quickly find out which advertisements and wording works better than others. If you always have one static saying and image that you’re spamming around the internet it will fade into the background noise. Try animated banners and static banners, bright colors and dull colors, varying text sizes and text amounts. If you post just one banner/phrase and it doesn’t attract people then don’t keep posting the same banner/phrase. One thing I like to tell people is the definition of stupidity — doing the same thing over and over again and expecting a different result. If you don’t mix things up you won’t get a different outcome.

Make It Easy

By this I mean you want your game to be easy to find, install, run and start playing. If someone clicks on your website and they now have to wade through 15 different links that are randomly dispersed through an already text-heavy blog post to find the link to get to your game download page then you’ve already lost customers before they’ve even started. Have your download or embedded game front and center. Make it easy to download or join — the fewer fields and steps they have to complete to start playing the faster they’ll become engaged and access to the experience they were looking for.

Teach Them How To Play

It’s hard to play if you can’t figure out how the game works or which buttons you need to press to get things started. Make access to instructions or a tutorial just as easy as it was to find and launch your game and keep your instructions appropriate for your target audience. Children need instructions with fewer, easier to follow with less text than adults do. Don’t shoot yourself in the foot by writing instructions or a tutorial that they can’t follow or don’t understand.

Start Playing As Soon As Possible

Instructions and a tutorial are great but they can also be tedious and time consuming. Keep them short and to the point, or intersperse brief tutorials/instructions that are introduced progressively throughout gameplay. The longer your target audience has to wade through learning how to play the less likely they are to start playing and stick with it.

Control, Control, Control

If your target audience has made it past your tutorial or instructions and they’re playing there’s one other thing that can really bring everything to an abrupt stop and that’s having difficulty interacting with the game. If your controls are too sensitive or your combinations are too tricky or are too fast for them to accomplish in the amount of time you’re giving them you’ll find that their interest drops off like an air-conditioner falling out of a window. I’m not saying your controls can’t have a learning curve, just that it should be a fairly short one or even a progressive one where you start off simple and add more and more complexity as you go.

Make It Fun

So you can do all of these things I’ve mentioned and people still don’t play your game because they don’t think it’s fun. I could go on and on about this topic and in fact I already have if you’re interested in reading about it so I won’t drag on about it here and now. If people don’t think your game is fun then it doesn’t matter if you’ve hit the mark on all the other points you’ll still find yourself back to the drawing board. So I hope this helps you in your endeavors to get people playing your game because in my experience if you can master these points here you’re well on your way down the path to success.

 

Why Making A Game Takes the Fun Out of It (and how to fix this)

Comments 4 Standard

I see it all the time, people coming into forums and online communities for games and game developers asking how to make a game or how to get their ultra cool idea that everyone will love and has never been done before off the ground and make it a tangible reality. Let’s get things straight, we love games because they’re fun and entertaining. It drives our creative vision and imagination and offers an escape from the mundane and the boring reality that is our lives. This passion, this drive to express ourselves and have fun is often what leads people to try their hand at making their own games. Many will start this journey but very few will finish it and even fewer will finish it with a successful and positive outcome (and let’s face it, money in your pockets). So why does this happen? Why do so many people start down this path of learning and creativity and adventure for fun that ends up leaving them broken, frustrated and depressed? The reality is that games are a lot of work and the very nature of making a game isn’t even a little bit fun. In many ways it’s the exact opposite of what we’re trying to achieve. So how does this happen and what can we do to fix it? Let’s break it down from the point of view of an Indie game developer whose a one man shop (or small shop) trying to make a game.

Lack of skills

You want to make a game but you’ve never programmed before, you don’t know anything about what’s required to make the type of game you want to create and even if you have those things covered you may not have all the skills you need to make it happen. Just because you can program doesn’t mean you can draw or compose artwork or market your finished product if you ever get that far. As an indie game developer you really have to be a jack of all trades. Think about trying to build a house if you’ve never built a house before. What happens if you only know how to frame the house but not how to do plumbing and electrical and tile work and all the other things that are required to finish the house? You end up with just the shell of a house that is lacking in so many ways you can hardly call it a house. This is one of the biggest problems I see with indie game devs — they lack the skills to accomplish what they’ve set out to do and they’re not prepared to outsource when they need to, which brings me to my next point.

Budget constraints

Making games is inherently expensive. Even if you create your own game framework and develop your own models/artwork, sounds and music you still have to — at a minimum — invest in a computer and dedicate hundreds of hours towards the development of your game. Those hours add up and while you’re developing your game you’re not earning a living that you need to support yourself and/or your family. Yes, that’s right, you still need to eat and buy necessities and support yourself and/or your family which is why even if you do have the funds outsource some of the work you lack the skills for you’re still fighting a losing battle towards my next point.

Time constraints and distractions

Supporting yourself and your family means that you’ll still need a full time job even as you chase the ethereal dream of creating your own game. Your time is precious and what little of it you have left after your regular day job has to be split between your other financial and personal commitments. Your kids need their parents and your house and car need to be maintained and you’ll struggle to find the proper work/life balance amidst all of the chaos that you juggle on a daily basis without adding the complexities of your game into the mix.

Technical problems, bugs, new frameworks and advances

So even if you can overcome all these odds so far you’ll still find yourself stuck hitting roadblocks as your game progresses. Technical problems you didn’t predict or forsee early on (and how could you, you’re still just learning yourself) end up being the bane of your game’s existence. Now you have to go back and re-write and re-factor and debug until you’re so frustrated you could pull all of your hair out and go bald. New frameworks and technological advances will make your second guess yourself or roll back to square one because you really do want to upgrade your SDK and add in the new dynamic system and better bump map texturing because who doesn’t want their game to be using the newest, latest and greatest technology available? No one wants to play a game that doesn’t have the same bells and whistles that their competition does because they took the the extra time/budget/testing cycle hits to go with the greater tech.

Slow progress and scope creep

Ultimately these things combined will drag your game down. What may have started off well and progressing quickly has suddenly slowed to a snail’s pace. Things suddenly feel like they’re never getting done or you have so many issues on your plate that it feels like there’s never an end in sight. Your game has hit a standstill and isn’t advancing like it was in the beginning and this is awfully discouraging and frustrating. The scope of your project has suddenly tripled and your todo list is a never-ending tally of bug fixes and re-factors and speed optimizations that need to be addressed for any chances of your game seeming like it’s something worth playing.

Early demo failures and monotonous repetition

If you’ve made it far enough to put together early demos and alpha access then pat yourself on the back — most people will never make it this far and you’ve just become a member of an elite club that deserves a badge of honor. The only problem is your demo gets horrible reviews, you realize your controls are too hard to use and this puts you into a crazy monotonous cycle of playing a particular part of your game over and over again as you attempt to fine tune it and make it more playable and more fun.

Never good enough

Unfortunately the truth is that your game will never be good enough. Someone will always find something to complain about even if you see some great feedback and helpful critiques that, if implemented, could really take your game to the next level and set you apart from your competition. Your controls will never be 100% perfect, your menu system may be too hard to read or too complex to navigate and you’ll never quash all the bugs that have been reported partly because you can’t re-create them all because your game is being run and tested under hundreds of different environments and hardware and operating systems that you didn’t have access to (and probably never will) as you were developing. If you’ve made it here this might just be the time for you to throw in the towel and say goodbye to all the blood, sweat and tears you succumbed to in order to make it this far.

Overcoming It All

If this has discouraged you against making your own game — good. Making a game isn’t easy and it’s not something for everyone so don’t waste your time early on if you’re not prepared to go through everything I’ve already mentioned and be able to walk away without anything to show for it. However that doesn’t mean you shouldn’t make a game or that it’s impossible to do it either. Where there is a will there’s a way and let me show you how.

  • Map out your game design, features, characters and how the game works. Now create lots of small, easy tasks you can accomplish in order to see your core game mechanics to completion enough that you could play a simple version of your game without any extra bells and whistles. Set yourself up to do as little as you have to but as much as you need to in order to get a completed version of your game.
  • If you lack the skill to do something you have two options. The first is that you resign yourself to taking the time to learn this new skill and the next is that you can outsource the skill to someone who’s already achieved it. You don’t have to be an expert programmer to make a game, just an adequate one. If you’re going to invest time into learning a new skill don’t dwell on it for too long, learn enough that you feel confident you can accomplish the task at hand and then move on. Investing too much time in learning a skill will start you down a path that walks further and further away from working on your game.
  • Sit down and map out all of the expenses you foresee as being necessary to complete your game. Now triple it. If you can’t afford to spend this amount of money into your game then you need to go back to your concept and re-work it until you get a budget that you can work with. If you’re really determined you can look for some outside investors but don’t count on this — ever. Most investors want to see a fully working demo before they’ll even consider opening their pocketbooks and investors will demand more than 50% of whatever profits you make from your game when it’s done.
  • Your time is precious when you have so little of it to devote to your game. Start by mapping out a timeline of your game features/assets and how long you think it will take you to accomplish them. Now double that. Now compare that to how much free time you really have to devote to your game. Will this game take you more than a year to complete? Do you have the dedication to spend more than a year working on a single project? If the answer is no then you need to go back to the drawing board until you’ve come up with a reasonable timeline that you can work with. Keep your game as small as you possibly can by focusing on the core mechanics and leaving out any fluff that you could add at a later date. Now stick to your timeline. If you budget 2 weeks to work on a character and by the end of the second week the character isn’t done don’t dwell on it — either move on to the next item in your list. Don’t adjust your timeline and don’t spend more time that you budgeted on this part of it. Sure, your ultimate goal is to have a working character with great animation but if you can’t ever get a game working with a broken character then who cares if your character’s animation is jerky or unrealistic? Think about the big picture because you can always circle back later.
  • Invest in a good debugger and testing tools. Do whatever you can to automate this process as much as possible because it will give you more time to work on trivial issues when you can quickly address and fix the larger ones. If you run into a bug that makes your game do something funky but it doesn’t prevent the gameplay from continuing table it and work on something else. Try not to get caught up in the more minute issues and focus more on the big picture. You can always circle back and fix bugs later but if you spend all your time bug quashing you’ll end up with a pretty interface or character or scene that doesn’t let interact and play with it. Pick a version of a framework and stick with it, don’t upgrade it unless you absolutely have to. The more you upgrade and update to the latest and greatest the more issues you’ll run into and the more refactoring and scope creep you’ll run into. It’s okay to build a game that isn’t using the latest and greatest version of your frameworks or 3rd party integrations. This will also give you a chance to work with and around the quirks in the version of the framework/software you chose to use instead of having to re-work around these every time you upgrade and re-factor.
  • Get the core mechanics working version of your game finished as early as possible no matter what it looks like or how bad it is. A crappy, ugly, glitching yet working version of your game is better than a pretty, perfectionist, bug free version of your game that isn’t at all playable. Don’t wait until the last minute or the week before it opens to get feedback on what you’re doing. Feedback is a great way to find issues you hadn’t considered and it will give you an idea of what other people think about your game. After all, no one wants to play a game they don’t think is fun. Don’t ignore constructive criticism even if it’s not what you want to hear. That doesn’t mean you have to change or add anything anyone has ever asked you for — it means that you need to take those things into consideration going forward. See past the reviews that focus on your aesthetics — at least initially — because you can always change and fix those later, core mechanics and gameplay are much harder to tackle once you’ve invested lots of time and energy into them.
  • Your game will NEVER be perfect. You will always be tweaking, adding, adjusting and fine tuning it. Instead of wasting your time doing this early on and ending up with something that isn’t a viable product devote that time to your game after you have something you can put out there. Don’t be a perfectionist, no matter how many bugs you quash and features you add or tweak there will always be another bug or problem coming down the pipeline. Try to prioritize the most important ones and tackle those first. Ultimately you want to get something up and working no matter how good or bad it is and then build upon it from there. Rome wasn’t built in a day so don’t expect your game to be. Get a working version up first and foremost and then add on to it and enhance it over time, your customer base won’t hate you for that, rather the opposite — they’ll appreciate your continued efforts to improve upon what you’ve done so far.

PHP Tutorial: Run Multiple Tic-Tac-Toe Game Instances (no database required)

Leave a comment Standard

Someone asked me about this in a comment recently so this post is specifically for you but I’m sure there are other people who will benefit from it as well. If you haven’t read the tic-tac-toe game tutorial yet then you’ll need to start there. This tutorial assumes you’ve already completed that and now you want to run two or more tic-tac-toe boards on the page simultaneously.

Or if you want to skip this tutorial you can
download the source code or try the working example

Concepts

The neat thing about classes is that you can use them to create multiple instances with varying states and data even though they all have the same methods and properties. Think about a monster RPG game. Each monster has a different name and breed and picture and strength — but they all have those things in common even though the values are different. Our tic tac toe class works the same way, we can create multiple instances of the game and they’ll each have different states — whose turn it is, which places on the board are filled — but they’ll all work the same way. In order to run multiple instances of our tic tac toe games we’re going to have to update our games so they can be uniquely identified by an instance number. The reason for this is so that when you play the game on instance 1 we know you want to update the state of instance 1 when you submit the form. If we didn’t give each game it’s own instance identifier then every time you made a move on one board it would reflect that move on all instances of the board at the same time.

Creating The Instance Form

Let’s change our index file so that we’re allowing the user to choose how many instances of the game they want to play. We start by removing where we created a new game from the top of the file. Since we want multiple instances we need to create the new game for every instance we have and since we don’t know how many instances we have at this point it needs to move down in our code base. Now once the user has selected how many instances of the game they want to play we need to dynamically generate that many. Using a for loop we loop through the number of instances they selected and create a game for each of those instances in our new $_SESSION[‘game’] array. Before this was only a single game, making it an array means we now have multiple games in our game session variable. Finally we create a new game instance and tell it to start playing. This is what our new index file looks like.

<?php
/***
* File: index.php
* Author: design1online.com, LLC
* Created: 4.6.2015
* License: Public GNU
* Description: PHP/MySQL Version of 2 Player Tic Tac Toe
* that allows playing multiple instances of the game at the same time
***/
require_once('oop/class.game.php');
require_once('oop/class.tictactoe.php');

//this will store their information as they refresh the page
session_start();

define('MAX_INSTANCES', 5); //the maximum number of games they can play at the same time

//trying to set number of instances to play
if (isset($_POST['instances'])) {
 if (is_numeric($_POST['instances']) && $_POST['instances'] > 0) {
 $_SESSION['instances'] = $_POST['instances'];
 }
}

?>
<html>
 <head>
 <title>Tic Tac Toe - Multiple Instances</title>
 <link rel="stylesheet" type="text/css" href="inc/style.css" />
 </head>
 <body>
 <div id="content">
 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
 <h2>Let's Play Tic Tac Toe!</h2>
 <?php
 //we need to know how many instances to create
 if (!isset($_SESSION['instances'])) {
 ?>
 <p>How many games would you like to instantiate?</p>
 <select name="instances">
 <?php
 for ($i = 1; $i <= MAX_INSTANCES; $i++) {
 echo "<option value=\"$i\">$i</option>";
 }
 ?>
 </select>
 <input type="submit" name="submit" value="Let Me Play!" />
 <?php
 } else {
 echo "<table width=\"100%\">
 <tr>";
 
 for ($i = 1; $i <= $_SESSION['instances']; $i++) {
 
 //if they haven't started a game yet let's load one
 if (!isset($_SESSION['game'][$i]['tictactoe'])) {
 $_SESSION['game'][$i]['tictactoe'] = new tictactoe($i);
 }
 
 echo "<td>";
 
 //play the game passing it the game data for that instance
 $_SESSION['game'][$i]['tictactoe']->playGame($_POST);
 
 echo "</td>";
 }
 
 echo "</tr>
 </table>";
 }
 ?>
 </form>
 </div>
 </body>
</html>

Adding Instances To The Class

The first thing we need to do is add an instance identifier to our tictactoe class. Since we need to know which game the player is trying to play adding a $this->instance value to our class will let us keep track of which game is which. Once that’s done we update our checks for $_POST data to make sure we’re using the correct data for the correct instance. Voila! Our games now only update when they see $_POST data that pertains to them. Our new tictactoe class file looks like this:

<?php
/***
* File: oop/class.tictactoe.php
* Author: design1online.com, LLC
* Created: 1.31.2012
* License: Public GNU
* Description: tic tac toe game
***/

class tictactoe extends game
{
 var $instance = 0; //the instance of this game
 var $player = "X"; //whose turn is
 var $board = array(); //the tic tac toe board
 var $totalMoves = 0; //how many moves have been made so far 

 /**
 * Purpose: default constructor
 * Preconditions: none
 * Postconditions: parent object started
 **/
 function tictactoe($instance)
 {
 /**
 * instantiate the parent game class so this class
 * inherits all of the game class's attributes 
 * and methods
 **/
 $this->instance = $instance;
 game::start();
 
 $this->newBoard();
 }
 
 /**
 * Purpose: start a new tic tac toe game
 * Preconditions: none
 * Postconditions: game is ready to be displayed
 **/
 function newGame()
 {
 //setup the game
 $this->start();
 
 //reset the player
 $this->player = "X";
 $this->totalMoves = 0;
 
 //reset the board
 $this->newBoard();
 }
 
 function newBoard() {
 
 //clear out the board
 $this->board = array();
 
 //create the board
 for ($x = 0; $x <= 2; $x++)
 {
 for ($y = 0; $y <= 2; $y++)
 {
 $this->board[$x][$y] = null;
 }
 }
 }
 
 /**
 * Purpose: run the game until it's tied or someone has won
 * Preconditions: all $_POST content for this game
 * Postconditions: game is in play
 **/
 function playGame($gamedata)
 {
 if (!$this->isOver() && isset($gamedata[$this->instance . 'move'])) {
 $this->move($gamedata);
 }
 
 //player pressed the button to start a new game
 if (isset($gamedata[$this->instance . 'newgame'])) {
 $this->newGame();
 }
 
 //display the game
 $this->displayGame();
 }
 
 /**
 * Purpose: display the game interface
 * Preconditions: none
 * Postconditions: start a game or keep playing the current game
 **/
 function displayGame()
 {
 
 //while the game isn't over
 if (!$this->isOver())
 {
 echo "<div id=\"board\">";
 
 for ($x = 0; $x < 3; $x++)
 {
 for ($y = 0; $y < 3; $y++)
 {
 echo "<div class=\"board_cell\">";
 
 //check to see if that position is already filled
 if ($this->board[$x][$y])
 echo "<img src=\"images/{$this->board[$x][$y]}.jpg\" alt=\"{$this->board[$x][$y]}\" title=\"{$this->board[$x][$y]}\" />";
 else
 {
 //let them choose to put an x or o there
 echo "<select name=\"{$this->instance}_{$x}_{$y}\">
 <option value=\"\"></option>
 <option value=\"{$this->player}\">{$this->player}</option>
 </select>";
 }
 
 echo "</div>";
 }
 
 echo "<div class=\"break\"></div>";
 }
 
 echo "
 <p align=\"center\">
 <input type=\"submit\" name=\"{$this->instance}move\" value=\"Take Turn\" /><br/>
 <b>It's player {$this->player}'s turn.</b></p>
 </div>";
 }
 else
 {
 
 //someone won the game or there was a tie
 if ($this->isOver() != "Tie")
 echo successMsg("Congratulations player " . $this->isOver() . ", you've won the game!");
 else if ($this->isOver() == "Tie")
 echo errorMsg("Whoops! Looks like you've had a tie game. Want to try again?");
 
 echo "<p align=\"center\"><input type=\"submit\" name=\"{$this->instance}newgame\" value=\"New Game\" /></p>";
 }
 }
 
 /**
 * Purpose: trying to place an X or O on the board
 * Preconditions: the position they want to make their move
 * Postconditions: the game data is updated
 **/
 function move($gamedata)
 { 

 if ($this->isOver())
 return;

 //remove duplicate entries on the board 
 $gamedata = array_unique($gamedata);
 
 foreach ($gamedata as $key => $value)
 {
 if ($value == $this->player)
 { 
 //update the board in that position with the player's X or O 
 $coords = explode("_", $key);
 
 //make sure we use the data from the right instance
 if ($coords[0] == $this->instance) {
 $this->board[$coords[1]][$coords[2]] = $this->player;

 //change the turn to the next player
 if ($this->player == "X")
 $this->player = "O";
 else
 $this->player = "X";
 
 $this->totalMoves++;
 }
 }
 }
 
 if ($this->isOver())
 return;
 }
 
 /**
 * Purpose: check for a winner
 * Preconditions: none
 * Postconditions: return the winner if found
 **/
 function isOver()
 {
 //top row
 if ($this->board[0][0] && $this->board[0][0] == $this->board[0][1] && $this->board[0][1] == $this->board[0][2])
 return $this->board[0][0];
 
 //middle row
 if ($this->board[1][0] && $this->board[1][0] == $this->board[1][1] && $this->board[1][1] == $this->board[1][2])
 return $this->board[1][0];
 
 //bottom row
 if ($this->board[2][0] && $this->board[2][0] == $this->board[2][1] && $this->board[2][1] == $this->board[2][2])
 return $this->board[2][0];
 
 //first column
 if ($this->board[0][0] && $this->board[0][0] == $this->board[1][0] && $this->board[1][0] == $this->board[2][0])
 return $this->board[0][0];
 
 //second column
 if ($this->board[0][1] && $this->board[0][1] == $this->board[1][1] && $this->board[1][1] == $this->board[2][1])
 return $this->board[0][1];
 
 //third column
 if ($this->board[0][2] && $this->board[0][2] == $this->board[1][2] && $this->board[1][2] == $this->board[2][2])
 return $this->board[0][2];
 
 //diagonal 1
 if ($this->board[0][0] && $this->board[0][0] == $this->board[1][1] && $this->board[1][1] == $this->board[2][2])
 return $this->board[0][0];
 
 //diagonal 2
 if ($this->board[0][2] && $this->board[0][2] == $this->board[1][1] && $this->board[1][1] == $this->board[2][0])
 return $this->board[0][2];
 
 if ($this->totalMoves >= 9)
 return "Tie";
 }
}

Conclusion

Try the working example! In this tutorial we talked about instances and how you can use a class to dynamically create multiple instances each of which keep track of their own state and values. If you’ve been following my game tutorials then I hope you’re starting to see how powerful classes are and how iterative improvements can be used to enhance your gameplay, functionality and user experience.

How Do I Get Started Making An Online Game?

Leave a comment Standard

This is something I’ve been asked fairly often. If you’re interested in starting your own online game here’s a few things to get you moving in the right direction.

What game are you going to make?

Let’s not put the cart before the horse. Before you can even consider making an online game you need to decide what kind of game you’re going to make. I don’t care if it’s as simple as tic-tac-toe or hangman or as complex as world of warcraft, you’ll need to sit down and put some serious thought into what you want to accomplish before you set yourself to the task. Take some time to write out all of the things you want your game to do (or not do) and create a design document with an easy to follow checklist — this will allow you to check off all the things features and functionality in your game as you work on it.

What programming language are you going to use?

Take a day or two to look at several different programming languages. Which one will make it easiest for you to accomplish all of the goals and tasks you set down in your design document? Choosing the language you’re most familiar with won’t always be the best choice in the grand scheme of things. If you’re not sure which programming language your game is best suited for then try joining a programming forum and getting some honest feedback from senior programmers and developers who can help steer you in the right direction.

Can you afford an online game?

Now that you have a design document and you know what programming language you’re going to use it’s time to get down to facts and figures. How many servers will you need to get your game up and running and what will that cost you? How will you pay for your domain name or any specific software or artwork you’ll need to get your game where you want it to be? Pull up some kind of spreadsheet software and track down the prices for everything you need and add it all up. What will it cost you monthly and yearly? If you’re short on cash you can try to develop via a local machine however this won’t always give you the same experience, environment and the same range of problems as a live setup will. In addition, some programming languages/games require multiple servers in order to work properly so developing locally isn’t always an option.

How long will it take you to develop your online game?

Once you’ve figure out prices it’s time to consider how long it will take you to create your game. This will help you understand what your development costs are before your game is even up and running. There’s no easy way to figure out how long it will take you to make your game, however, you can break up your game design document with estimates (and DEADLINES!!!) on how much time you want to spend on each feature. Try to stick to those and you’ll be more successful in getting your game up and running on a timeline you can afford.

Do you have enough time and money available to dedicate to an online game?

Now you know what it will cost you and you have an idea of how long it will take you to complete your game. This is the make it or break it point. Can you afford the financial burden of getting your game developed and open to the public? What happens if it doesn’t bring in any money? Can you afford sustaining your game (or sadly closing it) if it doesn’t live up to it’s expectations? What happens if you go past your deadline and your game isn’t done yet? What will you do? Do you have enough time to set aside for the development of your game and stick to your deadlines? Will you have time to devote to your game after it’s done to answer emails, manage content, fix bugs and add new features? If the answer to any of these questions is no then you’re not ready to make this game. Shove it in a file — please don’t throw it away and waste your hard work or time — and come back to it again in the future. Go back to the first step and start over again. You can design a new game or the same game over and over again until you can answer every single one of these question with a yes. That means you’re ready to start.

Get setup and start, don’t procrastinate.

When I say you’re ready to start I mean it. Don’t put it aside another second, pull out your wallet to rent some server space or build your local development environment and get started. No excuses. The longer you wait and the more you put it off again and again the less of a chance there is of anything ever getting done. It might be hard and it may take a whole lot of blood, sweat and tears but your efforts will be rewarded with a finished product — whatever that may be.

Start small and simple.

There’s nothing wrong with starting small and keeping things simple. Most working, successful ideas and concepts start out that way. Over time you can refine and re-work the idea until it becomes larger and more complex. Let your game follow the same example. Start with anything on your list that’s simple and you can finish quickly. As you finish these small, simple tasks and features of the game you’ll get a greater feeling of accomplishment and it will encourage you continue to working towards the larger and more complex parts of your game. It will also help you stay focused and stick to your deadlines.

Push through the pain!

When all hope seems lost keep going, don’t stop. Even if your code is horrible or your have hundreds of bugs that you can’t fix don’t let it prevent you from completing your game. Nothing is or ever will be perfect. Instead strive to do a little bit better next time, and a little bit better the time after that. Rome wasn’t built in a day and neither will your game or your programming skills.

If at first you don’t succeed… don’t be afraid to close the game and try again.

So at this point your game should be finished and open to the public. Even if you advertise the heck out of it not every game will be a success or work out quite the way you wanted it to. Some people may laugh at it, criticize the graphics, or even tell you it’s repetitive, boring or it’s all been done before. Don’t let anything stop you from taking everything you’ve learned so far from going back to step one to try, try, try again. Whether you close your game or go through a few more iterations to add new features, fix problems and make it better, it will be GUARANTEED to fail in some way, shape or form. Nothing in life is set in stone — if something doesn’t work change it over and over again until it gets the job done and then exceeds your expectations. Every time you make a game or improve upon an existing one you’ll learn more, become a better programmer and game designer, and take another further step down the path of having the next big hit game on the Internet.