Вы находитесь на странице: 1из 34

Android game (snake & ladder) for android Based

operating system

University of Azad Jammu and Kashmir


Department of CS & IT
Muzaffarabad

Israr

Hussain
Nasir Abbasi

39
33

Sir Zaki Hassan Kazmi

Snakes

and Ladders is an ancient Indian board game


regarded today as a worldwide classic.

It

is played between two or more players on a


gameboard having numbered, gridded squares.

number of "ladders" and "snakes" are pictured on


the board, each connecting two specific board squares.

The

object of the game is to navigate one's game


piece, according to die rolls, from the start (bottom
square) to the finish (top square), helped or hindered
by ladders and snakes respectively.

The

historic version had root in morality lessons,


where a player's progression up the board
represented a life journey complicated by virtues
(ladders) and vices (snakes).

Android
(JDK

Studio

7,8)

Android

SDK Tools

In

the beginning of the game, the players pieces are


placed in the start area.

Every

player will be given a chance and they have to


go about it turn wise.

Players

position is at the bottom of the ladder then


he can climb it and reach to the top of the ladder.

If

the player encounters a snake he has to retrace his


steps back by coming to the square where the tail of
the snake is there.

The

game is won when the button of the player


reaches the finish point first.

The

Application is basically consist of 36 squares,


Two User's can play this game, First of all player one
roll the dice, we get the random values from a java
function called random(); It basically generates
random numbers from up to infinity, but we bound
this function into 6 number which are not decimal,
(without .point)

We

then create a layout using Android XML and


create 36 boxes having numbers on it.

Create

two coins red for player one and orange for


player two.

These

two coins stays at point 1 at the bottom when


game starts.

This

class provides methods that return random


values.

java.util.Timer

is a facility for threads to schedule


tasks for future execution in a background thread.
Tasks may be scheduled for one-time execution, or
for repeated execution at regular intervals.

java.util.TimerTask

is a task that can be scheduled


for one-time or repeated execution by a Timer.

When

an application component starts and the


application does not have any other components
running, the Android system starts a new Linux
process for the application with a single thread of
execution.

By

default, all components of the same application


run in the same process and thread (called the
"main" thread).

an application component starts and there already


exists a process for that application (because another
component from the application exists), then the
component is started within that process and uses
the same thread of execution.

If

However,

you can arrange for different components


in your application to run in separate processes, and
you can create additional threads for any process.

Its

the ability of the operating system to run


different parts of a program simultaneously.

These

processes do not interfere with each other (in


a well written program or application) and each is
referred to as a thread. Think of it as making a
sandwich: you cut the bread and meats side by side
and then place them on slices of bread.

These

processes dont interfere with each other in


fact, they complement each other, and they are all
part of the same program, which is making a
sandwich.

In

Android, multithreading is implemented through


the Handler class.

Multithreading

uses your system resources


efficiently to get a task done.

It also allows the operating system to juggle several


tasks at the same time.

The

handler class lets you process and send message


objects, which contain descriptions and data, and
runnable objects that refer to a MessageQueue
belonging to a thread.

A handler will let you execute message objects and


runnable objects at a specified time in the future.

Each

instance of a handler will belong to a single


thread only when declared.

Runnable

objects are those objects that contain


commands that will be executed to obtain results in
your program.

Callback

interface you can use when instantiating a


Handler to avoid having to implement your own
subclass of Handler

setCompoundDrawablesWithIntrinsicBounds

(int

left, int top, int right, int bottom)


Sets the Drawables (if any) to appear to the left of,
above, to the right of, and below the text. Use 0 if
you do not want a Drawable there. The Drawables'
bounds will be set to their intrinsic bounds

First

of All the application checks for whom turn is,


we use a flag variable for checking the turns,

i.

ii.

if flag variable has a integer value of 0 then its


player one turn
if the flag value is 1 then its player 2nd turn, Then
we work with UI Threads.

Every

application has its own special thread that runs UI


objects such as View objects; this thread is called the UI
thread.

Only

objects running on the UI thread have access to


other objects on that thread.

Because

tasks that you run on a thread from a thread


pool aren't running on your UI thread, they don't have
access to UI objects.

To

move data from a background thread to the UI


thread, use a Handler that's running on the UI
thread.

The

project described above supports various


resolution schemes.

The

save and exit feature in the game give it an extra


flexibility.

provision for storing the high memory of the


players is provided.

Вам также может понравиться