S60 5th Edition SDK v0.9
Example Applications Guide

Naughts and Crosses Example

1. About this Example
2. Architecture
3. Prerequisites
4. Design and Implementation
5. Running the Example


1. About this Example

Noughts and Crosses is one of the C++ example applications which support the scalable UI using either bitmaps or SVG-T icons. The original purpose of this example is to demonstrate scalability and the usage of bitmaps and svg-t graphics in differet versions. This version supports svg-t.

2. Architecture

NoughtsAndCrosses follows traditional MVC architecture.

3. Prerequisites

This example exists as a complete application, and has the standard Symbian OS application architecture employing the Application, Document, UI, and View classes. The example makes use of several other Symbian OS concepts which the reader should be aware of before attempting to understand this example.

4. Design and Implementation

The application was designed with three main components: This design ensures that the UI and Engine are kept separate.

4.1 Application framework

The following framework classes produce the skeleton application:

4.2 The model

The model provides the functionality to play a game of Noughts and Crosses. It provides for the following:

4.3 Configuration and statistical data

This component of the application is responsible for accessing and updating the configuration and statistical data. The configuration information stored is used to determine which player starts the game (human or CPU), what symbol the human player will use (O or X), and the player’s name. The statistical information contains the number of times the human player wins and loses.

4.4 MMP files

The MMP file for S60 5.0 is: nac_S60_5th_ed.mmp

4.5 Touch UI Support

To implement HandlePointerEvent function in the container (to provide Touch UI support for the CCoeControl derived control).
 void CNoughtsAndCrossesContainer::HandlePointerEventL (const TPointerEvent& aPointerEvent)
    {
    // Check if touch is enabled or not
    if ( !AknLayoutUtils::PenEnabled() )
        {
        return;
        }
    
    if (aPointerEvent.iType == TPointerEvent::EButton1Up)
        {
        CNoughtsAndCrossesDocument* document = static_cast<
        CNoughtsAndCrossesDocument*> (iView.AppUi () ->Document ());

        TRect boardRect = Rect ();
        TInt verticalTileSize = boardRect.Size ().iWidth / BOARD_SIZE;
        TInt horisontalTileSize = boardRect.Size ().iHeight / BOARD_SIZE;
        
        ICursorRow = aPointerEvent.iPosition.iY / horisontalTileSize;
        ICursorColumn = aPointerEvent.iPosition.iX / verticalTileSize;
        
        if (!document->CanMove())
            {
            return;
            }
        
        if (document->MakeHumanMoveL(iCursorRow, iCursorColumn))
            {
            if (document->CanMove())
                {
                document->MakeComputerMove();
                }
            }    
        }

    // Call base class HandlePointerEventL ()
    CCoeControl::HandlePointerEventL (aPointerEvent);
    }

Otherwise it derives its views from CAknView and CCoeControl classes. Also AknLayoutUtils (UI Metrics API) is used for scalability. The original purpose of this example is to demonstrate scalability and the usage of bitmaps and svg-t graphics in different versions. This version supports svg-t.

5. Running the Example

When the application starts up and the user presses the Select softkey, the following screen appears:

Startupview.JPG
Figure1: Start up view

Pressing the option Settings the below screen appears.

  1. Player’s Name: In this we can give the name of the player who is going to play.
  2. Who plays first: The player should select it whether it can be Human or computer.
  3. Player type: The player can select the type whether it can be nought or cross.
Settingsview.JPG
Figure2:Settings view

When the player fails to finish the game in a row ar column ar diagonal the below screen appears and the game is said to be draw.

Drawview.JPG
Figure3:Draw view


When the player finishes the game with cross in a row the below screen appears and the player is won.

Winview1.JPG
Figure4:Win view1


When the opposite player finishes the noughts in the diagonal view then that player is said to won the match and it is shown in the below screen:

Winview2.JPG
Figure5:Win view2


For viewing the statics of the game played goto Options - > Stats, the below screen appears.


Statisticalinformation.JPG
Figure5:Statistical Information



© Nokia 2008

Back to top