Home - Computing - Speedy Mouse - Technical Disscussion

 

Table of Contents

Introduction

Interpretation of the problem

Features

User Friendly GUI

Ambience

Enhanced game play

Customisation

Hi Scores Table

Cheats

How to play

Object-oriented and Algorithmic Design

Game

SpeedyMouse

Player

Block

Hi Score

Music

Timer

Time Container

Coding

GUI construction

How to use

The start up screen

The options screen

The game screen

Discussion of layout

Technical discussion

The setup screen

The Options screen

The game Screen

Other Screens

Functionality

Object Orientated Design

Enhanced GUI

Sound

Level progression

Hi scores

Options

Cheat

Game play

Minor enhancements

Appendix one Technical Issues

Known Bugs

Screen Size

Compilation details

 


 

Introduction

 

Interpretation of the problem

 

Speedy mouse from its specification is a simple game, however games in the past like Tetris and Ribbon (on the Playstation) while popular have also been extremely simple. Therefore a game this is relaxing and subtly challenging has been developed.

 

The relaxation has been created through soothing music and repetition in the levels, the user clearly knows what is expected of them at each point through the difficulty varies dramatically.

 

The subtle challenge comes from the increase in the number of blocks and less time available at each level, what begins as a very easy game gets progressively difficult to the point of undoable. Noting that speedy mouse has no final level (it can in theory keep going and going), the increased number of blocks and decreased time add to an inevitable failure on the users behalf (a trait similar to Tetris).

 

Should the user lose a life they have the extra blocks they missed added to the game play area, but they get the advantage of an extra five seconds, this mean quite literally torturous persistence will nearly always pay off.

 

The blocks in this game do not move and are placed in grid the ultimate dividend of this is that more blocks can appear on the screen. The style of play would favour a hi number of blocks over animated graphics.

 

In attempting to replicate this impending doom, it is hoped that Speedy Mouse is both enjoyable and addictive.

 

Features

 

User Friendly GUI

 

Just as all other applications follow a pre-defined formula so do games i.e. a setup screen from which you can start the game or access options and other added features and a main game screen. Starting the game is literally as simple as clicking start and clicking the blocks, the other functions are build around this with a methodology (fully discussed in the GUI section) that does not detract from this simplicity.

 

Ambience

 

A great deal of effort was given to give the game personality. Indeed given the finite development period this has been at the cost of some more traditional enhancements that pervious students had taken (as outlined in the specification). This decision was made by looking at the problem.

 

Speedymouse will never compete with quake, speedymouse to me is a quick but fun game that someone could play for a minute or so and put away, it is a concept that would suit the idea of online web page games . Hence both these concepts of being quick but fun strongly relay on the game offering personality.

 

Java has powerful multi media functionality and this was taken advantage of, it is hoped the fun graphics placed together with the jazzy entertainer sound track create a game that both looks and plays fun.

 

Whilst such a project is not a graphical design project the author has constructed many of the graphics and sound himself.

 

Enhanced game play

 

The game play has been enhanced in a number of ways. For example the blocks no longer overlap (see the algorithms section for details). In addition to this a more recognisable progressive structure has been added in the form of levels and lives which the player will now progress through.

 

Customisation

 

Due to the high level of graphic design in the game, this game may not be as customable as most but the player can both change their name and set the colour of the game play area background.

 

Hi Scores Table

 

The idea of addictiveness / longevity is extended with a hi score table, it is hoped that user will find this presents a challenge to themselves and invokes a desire to come back to the game.

 

Cheats

 

Sticking closely to the game formula a cheat has been provided in that if the user specifies their name as “slow mouse” the will get 1000 lives. This idea has been favoured over turning the timer off, as it still will present a challenge (inevitably SpeedyMouse will level off at 99 blocks to be click in 10 seconds, which is clearly impossible).

 

How to play

 

This version of speedy mouse is simple to play, click on start, and click the blocks before time runs out. A great deal of effort has been taken to ensure the menus provide a system where by the additional functionality has not subtracted from the games inherent simplicity. The reader can learn about these additional functions in the GUI section which explores the games functionality in exhaustive detail.

 

 

 


 

Object-oriented and Algorithmic Design

 

Object-oriented Design

 

A class diagram is inserted below; it goes some length in illustrating the high level of encapsulation in the program. This has the end advantage of not only producing readable, manageable code, but significantly aiding extensibility. For example if we decided to make the game a two player game, whilst we would have to produce code in the controlling class, SpeedyMouse, we would, in addition to that, only have to create a second instance of player. A discussion of each class follows.

 

 

Game

 

Java can not create executable files (*.exe) like C++, therefore having this as a separate class may seem somewhat redundant, however abstracting this from the main body of the program draws a clear line for the reader between static classes (of which this is the only one) and non-static classes and methods (of which the rest are). Whilst it could be argued this could easily be incorporated in the main body of the class SpeedyMouse , it is seen as aesthetically better to have it separate.

 

SpeedyMouse

 

This is quite literally the control class, it is responsible for running the game and GUI. Consequently it is unsurprising that it contains the largest number of methods and is threaded.

 

Amongst these methods is one to ensure blocks do not overlap, shown below. The method which calls this method ensures that it does not iterate more than 99 times. The reason for this is essentially the game play area is grid of 50 px squares, there are only 100 of these squares available.

 

public int [] placeBlockAt()

{

/*

*

*/

int proposed [] = new int [2]; // [x][y]

int coOrdinates [] = new int [2]; //[x][y]

boolean placed = false;

while (placed == false)

{

//get random number between 0 and 10

proposed [0] = 0 + (int)(Math.random()*10);

proposed [1] = 0 + (int)(Math.random()*10);

//if that postion is empty it will == 0

if (positions [proposed[0]] [proposed[1]] == 0)

{

//place it in there

coOrdinates [0] = proposed [0] *50;

coOrdinates [1] = proposed [1] *50;

positions [proposed[0]] [proposed[1]] = 1;

placed = true;

}

 

 

}

return coOrdinates; //the xy values of that block

}

The method proposes a random position and searches the global 2d array to see if that postion is free, if it is it marks the place as taken and returns the co ordinates of the location. If the postion is not free is proposes another random postion.

Player

 

Abstracting the player allows for extendibility, for example if a two player game was to be create apart from modifying the controlling class (speedymouse.java) only a second instance of this object would need to be created, it also allows for single store location of player statistics, lead to less global variables and neater code.

 

Block

 

Whilst this block is largely an information container an idea that there was not time to implement was having different blocks for example you would have your standard block, however in addition to this you would have another block than when click provides the player with an extra life. The diagram below shows how inheritance could be used with this class to implement such an idea.

 

 

Hi Score

 

Whilst initially an obvious extraction, given the complexity of the algorithms in the class, if proves to be a much needed abstraction. Whilst it's method to take and output an array are straight forward it employs insertion sort, see below, to find which values should be outputted and in which order.

 

public void insertSort()

{

//sort scores

int insert;

String insertString;

for ( int next = 1; next<hiScores.length; next++ )

{

insert = hiScores[next];

insertString = hiScoresNames[next];

int moveItem = next;

while ( moveItem>0 && hiScores[moveItem-1] > insert )

{

hiScores[moveItem] = hiScores[moveItem-1];

hiScoresNames[moveItem] = hiScoresNames[moveItem-1];

moveItem--;

}

hiScores[moveItem] = insert;

hiScoresNames[moveItem] = insertString;

}

}

 

Insertion sort is a very efficient algorithm and works out at O(n 2 ), whilst merge sort may be more efficient algorithm given there is only six items to sort, the simpler insert sort was opted form.

 

The algorithms works by iterating through each element in the array, for example if our array was 10,9,4,5,3 and 2 it would compare 9 with 10 finding 10 to be the greater it would place this at the beginning of the list, this will cause all the element (right from the newly found location) to shit one position right, When we are to make a transfer, first we store the element at its current postion in a temporary variable, so that when the entire list is shuffled the element is not lost. This operating iterate until the list is sort for example:

 

Iteration 1: 9 10 4 5 3 2

Iteration 2: 4 9 10 5 3 2

Iteration 3: 4 5 9 10 3 2

Iteration 4: 3 4 5 9 10 2

Iteration 5: 2 3 4 5 9 10

 

Music

 

Having an object which we can call on to handle the games sound leaves us in position for easy extension of the idea presented here, for example we may want to add a game over sound, or if we implement the idea discussed earlier in blocks have different sound effects for each block. The introduction of appropriate method (and sound files) to this class would make this a very easy extension.

 

Timer

 

The timer whilst again an obvious abstraction, is also a necessary one, as it must run independently of the game. Whilst the timer thread ends between levels the game thread must keep running, a game will consume many timer threads, have this as an object means that initiation of the repetitive task is straight forward and painless for the programmer. This would illustrate a benefit of object orientated languages over more procedural ones such a C.

 

Time Container

 

This class is literally a buffer class that provides the ability for the timer and speedymouse class to exchange information, with such a class the complexity of dynamic objects would have to entered into.


 

Coding

 

A great deal of effort has been taken to make the code as straight forward and comprehendible as possible. The program is approximately 2000, lines of code this could easily be condensed into less, however as this is mainly white space it does not have the disadvantage of weighing the program down but has the added advantage of making it more understandable.

 

The code is also quite liberally commented and I would refer the reader to it for more technical discussion of the algorithms (again another element removed when the program is complied).


 

GUI construction

How to use

 

The start up screen

 

Speedy mouse is simple to use, on start up you have choice of options, you can start playing the game straight away, change you name in options, view the high scores, get help, find out about the game and ultimately quit. Notably the last function can be preformed at a time by simply exiting the window.

 

 

The options screen

 

The Options screen allows you customise the game somewhat, by clicking the change name button you can change you name to anything you desire . You can also change the game play area background simply by clicking the change colour button and the colour on display and in game will be changed to you choosing. Static information is white an dynamic information light orange.

 

 

The game screen

 

To start the game simple press the status button and the game will begin, but as the game doesn't begin instantly this allows time for the new user to familiarise themselves with new uncultured display panel.

 

 

 

The labels coloured orange do not change where as the black labels display the games curial and changing statistics. Any time you want to know what level your on, your score, how much time you have left, or the number of lives you have just glance over at this panel.

 

Discussion of layout

 

There is always a standard layout in any software program, for this reason all word processors look similar, all spread sheet packages look similar and it is no different with games. Platform independent they start with a start screen, provide options or direct play on this screen. Speedy mouse incorporates this functionality and follows this user recognisable design. Consequently it is hoped that from the start the user will initiatively know what to do.

 

In games the in game screen usually displays some statistics along with the actual game, similarly so does speedy mouse, it incorporates all the players statistics, on the in game panel on the right. Including an irregular status “button” that shows the state of the game, it is hoped this will draw the user attention so they recognised the periods where the game is paused.

 

Technical discussion

 

The “main” object extends JFrame within this JFrame all the activities take place. The JFrame is very intentionally set to 700 by 500 a size that will allow the games use on all but the oldest computers.

 

The three main game panels, the setup screen (with the options start game, view hi-scores, etc.), the options screen and the game screen are all separate JPanels. Though these are all created on start up they are controlled so only one is visible at a time.

 

All images in the game represent JLabels that have been set on top of these JPanels, transparency and layering achieve the over all look. The methodology is document and explained in the code (“speedymouse.java”).

 

The setup screen

 

It is hoped that the custom rollover buttons instantly identify what is clickable and what is not.

 

Each button in itself is a JPanel to this panel is added and image and a listener, when the mouse enters the JPanel the image is change, when the mouse leaves the JPanel the image is changed back again. The listener also listens for clicks and upon one executes the relevant code.

 

The Options screen

 

This screen is similar to the start-up screen but uses JButtons instead, labels are white and changeable information is light orange. The user has two options they can change their name by click the adjacent button (also labelled) change name or the can change the background colour in the in game display. The later function also display the currently selected colour and is changeable through the JColorChooser interface which is invoked by clicked the adjacent button (also labelled as) change colour.

 

The game Screen

 

The game screen is composed of two JPanels the controls and the actual play area, the controls contains a JButton for starting the game, this feature was added to give a new user time to familiarise themselves with the interface before the action begins.

 

The controls is composed mainly of labels, static ones being colour orange and the dynamic ones being coloured black it is hoped that this is not only more aesthetically pleasing but also always the user to quickly find the needed information.

 

The game play area is JPanels in it's to this the game pieces (essentially the blocks) are add at each level, removed by the player with method to remove and left over being called at the end of each level, this stop the blocks remaining in a situation where the game has been completed and the user want to play the game again.

 

Other Screens

 

The help, about and hi score screen are all simple JOptionPanes that simply display strings. In the case of hi-scores however this information is dynamic and therefore is calculate by the class hi-scores and then passed as string, more information on it's method can be found in the algorithms section.

 

In the case of selecting the colour this uses java's JColorChooser, and apart for checking for null content the program does not change this method.

 


Functionality

 

In addition to the original requirements this section outlines additional functionality added.

 

Object Orientated Design

 

The current development of speedy mouse employs a number of objects. The abstraction of these objects allows further extensibility, this is illustrated in previous sections.

 

Enhanced GUI

 

The GUI has now been organised into three screens, start up, options and game. A large amount of graphics have been added, including blocks, backgrounds and logos with the additional extension of custom button on the start up screen.

 

Sound

 

Sound has been added in the form of in game music a sound effects.

 

Level progression

 

The difficulty level has been significantly altered, instead of selecting a difficulty level the user is now present with a series of level which get increasingly difficult. They now have a number of ‘lives' in which to get as high a score as possible.

 

Hi scores

 

The idea of having scores has been extended further in allowing the user to have hi score table for that session. This presents the user with a refreshed and sorted table of high scores.

 

Options

 

The user now has additional options in the form of the ability to change their name and the background colour of the game play area.

 

Cheat

 

A cheat has been added to game, where by if the users specifies their name as “slow mouse” they will receive 1000 lives.

 

Game play

 

An algorithm has been implemented that stop the blocks from overlapping, the game will handle want more than the original 10 blocks outlined in the specification in the course of the game.

 

Minor enhancements

 

The is now a help and about text, that let the user know in nutshell how to play the game and refer him to web site for more information.


 

 

Appendix one Technical Issues

 

Known Bugs

 

Screen Size

 

There is a known issue with screen size on some computers. The game will display below the 700, 500 specified on line 130 of speedymouse.java a possible solution is to allow the user to resize the window (by removing line 129 “setResizable(false);”) but given the invariable use of absolute positioning this solution has not been opted for.

 

Compilation details

 

This version of speedy mouse is complied under j2se development kit 5.0 update 1 and employs some the newest java techniques (for example in threads).

Speedymouse has not been developed as an applet the reason for this was both a consequent of time and the language it was to be programmed in. Flash is now arguably more portable than java, with a version now released for mobile phones Actionscript (also an object orientated language and similar in syntax) may better suit such a development.

This would encompass a simple copy and paste of the main method into speedymouse

For the more thoughtful entering the right name will enter you into cheat mode.

 

 

Home - Computing - Speedy Mouse - Technical Disscussion
 
 
Discuss in our forum