Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 23:18, 12 August 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Click and hit : A simple game using WRT

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia 5230
Created: girishpadia (05 Mar 2011)
Last edited: hamishwillee (12 Aug 2012)



This game is very simple. It is intended to show the basic use of nested < div > tag and moving its position on the screen using Javascript. It also describes how the CSS (Cascading Style Sheet) can be more effective using each < div > tag's ID attribute. In this game the screen is divided into three parts as follow:

  1. Container : The area which is colored Red.
  2. ClickMe  : The small area within the container with black color.
  3. Counter  : The area with Green color which counts Hits on "ClickMe" area and if not then the Miss.

You can see the initial screen as shown in the following figure.

You can see the initial screen as shown in the following figure.

The Game Logic

You can see the above screen when you start the game. Now you have to touch the black area on screen. If you are successful to touch the black area then the black area will move onto a random position. Your successful Hit will be incremented by 1. If you cannot touch the black area properly then the "Miss" will be incremented by 1. This way the game will count each Hit and Miss on the black area on the screen. The black area will keep moving on the screen at random position.

How to create project

Please download and install the Nokia Web SDK. Create a new project in it. Replace the files, index.html,basic.css and basic.js with the code below.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="">
<title>Click and Hit Gane</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script language="javascript" type="text/javascript" src="basic.js"></script>
<link rel="stylesheet" href="basic.css" type="text/css" />
<meta name="Generator" content="Nokia WDE 3.0.0" />
<body onclick="MissCount();">
<h2>Click and Hit</h2>
<div id="container" align="center">
<div id="clickme" align="center" onclick="HitCount();"></div>
<br />
<div id="counter" align="center">
Hit : 0 Miss : 0


/* Defining style sheet for container id */
width:300px; /* Defining width */
height:400px; /* Defining height */
border:1; /* Border is defined with value 1 */
background-color:Red; /* Setting background color */
/* Defining style sheet for clickme id */
width:20px; /* Defining width */
height:20px; /* Defining height */
border=1; /* Border is defined with value 1 */
background-color:Black; /* Setting background color */
position:absolute; /* The clicking object postion is defined as absolute. */
/* Defining style sheet for counter id */
width:300px; /* Defining width */
height:30px; /* Defining height */
border=1; /* Border is defined with value 1 */
background-color:Green; /* Setting background color */
font-size:16px; /* Font size is 16px */
font-weight:300; /* font weight is set 300 */
vertical-align:middle; /* Vertical alignment is set to middle */


/* Defining Glabla variable starts */ 
var hit=0;
var miss=0;
var x=0;
var y=0;
/* Defining Glabla variable ends here */
function init()
// Add your code stpes here
/* Function getXY is to get random value of x position and y position.
* The value of x is assigned to left position of clickme div object.
* The value of y is assigned to top position of clickme div object.

function getXY()
x = Math.floor(Math.random()* 250)+20 ; // Random number will be generated between (0 to 250)+20
y = Math.floor(Math.random()* 350)+20 ;// Random number will be generated between (0 to 350)+20
document.getElementById('clickme').style.left = x+"px"; // Value of x assigned to left position.
document.getElementById('clickme') = y+"px"; // Value of y assigned to top position.
/* Function HitCount is called whenever user successfully clicks on the clickme div object */
function HitCount()
hit++; // Variable hit is incremented by 1.
if(miss >=0)
/* Function HitCount is called whenever user unsuccessful to click on the clickme div object */
function MissCount()
miss++; // Variable miss is incremented by 1.
printVal(); // Function printVal is called.
function printVal()
// Values of conter div tag is set by Hit and Miss variables.
document.getElementById('counter').innerHTML = "Hit : "+hit+" Miss : "+miss;

Tested On device

The game is tested on Nokie 5230

File Download

Another Image

Article 8 image2.PNG

This page was last modified on 12 August 2012, at 23:18.
34 page views in the last 30 days.