This is the second installment of the Minesweeper game mini-series. In this , you will learn how to fully implement the client side of the application. We will use a native iOS application that connects to the web servers, parses the data, and displays the user interface interaction.


Project Overview

Minesweeper Flag is a multi-player board game that is played between two opponents. Commonly, blue or red is assigned to each player. The board is composed by 256 equal squares, and each board has 51 mines placed in entirely random positions.

1x1.trans Build a Multiplayer Minesweeper Game: Client Side Creation
Preview of the Final Effect

Review of Part 1

Before you start the second part of the series make sure you have the first part fully tested and implemented.


Step 1: Installing Cocos 2D

The first step is to download and install the Cocos 2D game engine. For this tutorial, we used Cocos 2D version 2.

Once downloaded, you need to install it and integrate it with Xcode. Unpack the file downloaded before and you will notice a file called install-templates.sh. Open a terminal window and run that file using the following command


 


Step 2: Create a New Project

Using Xcode, create a new project: File -> New -> Project.

1x1.trans Build a Multiplayer Minesweeper Game: Client Side Creation

Choose the Cocos2d v2.x on the left side menu and Cocos2d iOS on the right one.


Step 3: Configure Project Settings

Give your project a name and a company identifier. For this tutorial, we use the iPad device family option.

1x1.trans Build a Multiplayer Minesweeper Game: Client Side Creation

Step 4: Verify the Setup

If everything is correct you should see a window similar to the following one:

1x1.trans Build a Multiplayer Minesweeper Game: Client Side Creation

Step 5: Add New Classes

Now you should add two new Objective-c classes. To do this, access the menu option File -> New -> File.

Add the following classes:

  • LoadingScene: This class will serve as a loading screen for the user while he / she is waiting for another player to join the game.
  • GameScene: This is the core class of the game; is where the main logic is programmed.

Step 6: Add Resource Files

In order to correctly run the game you should add the resource files to your project. Here you can download the resource files used. Next, copy them to the resources folder.


Step 7: Create the HelloWorldLayer Class

Change your HelloWorldLayer header file to the following:


 

Change the HelloWorldLayer implementation file to the following:


 


Step 8: Create the LoadingScene Class

Change your LoadingScene header file to the following:


 

Change your LoadingScene implementation file to the following:


 


Step 9: Create the GameScene Class

Change your GameScene header file to the following:

Tagged with →  

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>