Coding a Simple Slot Machine Game

Guest Post

In this article, let’s use PHP in creating this simple browser-based game.

A lot of gaming companies such as Gameforge and Goodgame Studios use PHP because the language is very easy to use.

You can learn the basics of PHP coding on Learn To Code London. You really don’t need a formal education to learn how to code, as the tutorials are straightforward. Whether you want to create a basic game such as a slot machine or a complex one such as web-based RPGs, you can use the PHP language.

For this article, let’s create a very simple code for a slot machine.

Slot machines have been around for quite a while now. The first ever slot machine was created by Sittman and Pitt in Brooklyn, New York, which was based on a drum mechanism instead of reels. Fast forward to today, slot machines are now digitized and run completely on random-generated numbers instead of gears. What makes slot machines popular is not only the way they are played but the themes, designs, and sounds they carry. All slot machines are controlled using a single spin button but each one is designed uniquely. Apart from the classic slot titles such as the Liberty Bell slots, there are now modern ones that carry with them commercially-licensed titles such as Dracula and Star Trek. There are also new ones now like Slingo: Deal or No Deal, which is a combination of a slot machine and bingo. There are many other different slot machine themes but for now, let’s focus on creating a simple one, which can be used as a backbone for coding more complex ones.

Making a 3-reel slot machine

Let’s start by making the face of a three-reel slot machine game with just one payout line. You may add more payout lines once you’re done with this tutorial.

$faces = array ('Image1', 'Image2', 'Image 3', 'Image4', 'Image5', 'Image6');

You can use any image for your slot machine. You can use images of the same concept or go crazy by using a variety of pictures. You can change them later on anyway if you’re not satisfied with the outcome.

Next, you must declare the winning payouts. In this case, all three images must match the payout line.

$payouts = array (
 'Image1|Image1|Image1' => '10',
 'Image2|Image2|Image2' => '20',
 'Image3|Image3|Image3' => '25',
 'Image4|Image4|Image4' => '35',
 'Image5|Image5|Image5' => '50',
 'Image6|Image6|Image6' => '200',
 );
if (isset($payouts[$result1.'|'.$result2.'|'.$result3])) {
 // give the payout
 }

Then, when spinning the reels, you must make the first and third reels spin in the same direction, while the second one goes in another direction. This is how the old slot machines roll.

$wheel1 = array();
 foreach ($faces as $face) {
 $wheel1[] = $face;
 }
 $wheel2 = array_reverse($wheel1);
 $wheel3 = $wheel1;

That’s it! It’s that simple. With this code, you will be able to create the backbone of any slot machine you want. You can add more payouts and wheels for the game by modifying the payout codes and adding wheels 4 and 5.

This is a guest article

Super Game Kit – An Awesome iOS Game Starter Kit – Coming Soon

Wall West Studio

Finally an awesome iOS Game Starter Kit for a great price!

After creating and publishing my 4th iOS game to Apple App Store I decided to create an iOS game starter kit! I felt that there was a lot of “boiler plate” code that I had to write for each game. This was super time consuming, tedious and at times error prone.

I also remember when I was creating my first game how long it took to get something basic up and running. It probably took me 2 weeks just to get a square bouncing around on the screen! The learning curve was steep!

How can we make it easier, simpler and faster for aspiring game developers to create, publish and start generating revenue from games?

So I decided to create a new iOS game starter kit to help anyone get started with creating game apps for Apple App Store fast and easy!

Key Features of Super Game Kit

  • Generic light-weight game development kit for iOS
  • Easy to get started making games for Apple App Store
  • Pre-defined launch, menu and game scenes
  • User-interface (UI) transitions, buttons and flow
  • Special effects!
  • Layout management functions
  • Save game data storage with encryption
  • Game Center integration – leaderboards and achievements
  • In-app purchase processing
  • In-game analytics
  • Publisher-side advertising integration
  • Social sharing integration
  • Documentation and examples
  • Start making income with your game in no time!

The Super Game Kit will provide a one-stop-shop solution allowing game developers to create and bring games to the market super fast!

Interested? Learn more about Super Game Kit!