snowboard report

45
Design & Implementation Of Snowboard Game SEC, Sikar Page 1 CHAPTER  1 SYSTEM REQUIREMENT SPECIFICATION 1. 1 Introduction 1.1.a:- Purpose: This document provides concrete details concerning the software goals as identified by Snowboard Game. The intended audience of the SRS is primarily the other parties that might have an interest in the software under development. 1.1.b:- Scope:  Create different gaming str ategies.  Manage all the details regarding snowboarding.  Track all the necessary moves of the skiers.  Group the objects of the game together.  Confirmation given to the end user for play.  View instruction and scoring in the game.  Activities like jumping, skiing, sliding, etc. 1.1.c:- Technology:  EditPlus ----- Java Editor  SmartDraw ----- DFDs Developing Tool 

Upload: payal-agrawal

Post on 06-Apr-2018

232 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 1/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 1

CHAPTER – 1

SYSTEM REQUIREMENT SPECIFICATION

1. 1 Introduction 

1.1.a:- Purpose:

This document provides concrete details concerning the software goals as identified by

Snowboard Game. The intended audience of the SRS is primarily the other parties that

might have an interest in the software under development.

1.1.b:- Scope:

  Create different gaming strategies.

  Manage all the details regarding snowboarding.

  Track all the necessary moves of the skiers.

 Group the objects of the game together.

  Confirmation given to the end user for play.

  View instruction and scoring in the game.

  Activities like jumping, skiing, sliding, etc.

1.1.c:- Technology:

  EditPlus ----- Java Editor

  SmartDraw ----- DFD‟s Developing Tool 

Page 2: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 2/45

Page 3: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 3/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 3

1.3 External Interface Requirements

1.3.a:- User Interface:

There are some user interfaces that are being implemented in this software, these are:

  ActionListener:

This interface is used to implement the methods related to action like number

press etc. it connect all the actions to the dedicated tasks.

  Runnable:

It is mainly used for threading purpose, whereby we can run various threadsin a synchronized manner.

1.3.b:- Hardware Interfaces:

As such there is no specific hardware requirement to run this software. A working system

would do the job.

1.3.c:- Software Interfaces:

No specific software is required. Only a java enabled browser like firefox, chrome, etc. is

required to run the game.

Page 4: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 4/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 4

1.4 Analysis Models:

A Data Flow diagram is represented here for the software analysis, as shown in

Player

View

Scoring

View

Instructions

End

Play

Pause

Change

Window

Browser

Game

Screen

Pause

Screen

End

Game

Pause The

Game

Instruction

Scores

Page 5: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 5/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 5

1.5 Model Used:

A Spiral Model of Software

Development and Enhancement

Evolution of process models. Before concentrating in depth on the spiral model, we

should take a look at a number of others: the code-and-fix model, the stagewise model and

the waterfall model, the evolutionary development model, and the transform model.

The code-and-fix model. The basic model used in the earliest days of software

development contained two steps:

(1)Write some code.

(2) Fix the problems in the code

Thus, the order of the steps was to do some coding first and to think about the

requirements, design, test, and maintenance later. This model has three pri mary difficulties:

(a) After a number of fixes, the code became so poorly structured that subsequent fixes were

very expensive. This underscored the need for a design phase prior to coding.

(b) Frequently, even well-designed software was such a poor match to users‟ needs that it

was either rejected outright or expensively redeveloped .This made the need for a

requirements phase prior to design evident.

(c) Code was expensive to fix because of poor preparation for testing and modification. This

made it clear that explicit recognition of these phases, as well as test-and-evolution planning

and preparation tasks in the early phases, were needed.

Page 6: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 6/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 6

Page 7: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 7/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 7

The evolutionary development model. The above concerns led to the formulation of 

the evolutionary development model,4 whose stages consist of expanding increments of an

Page 8: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 8/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 8

operational software product, with the directions of evolution being determined by

operational experience. The evolutionary development model is ideally matched to a fourth-

generation language application and well matched to situations in which users say, “I can‟t

tell you what 1 want, but 1‟11k now it when I see it.” It gives users a rapid i nitialoperational capability and provides a realistic operational basis .for determining subsequent

product improvements. Nonetheless, evolutionary development also has its difficulties. It is

generally difficult to distinguish it from the old codeand- fix model, whose spaghetti code

and lack of planning were the initial motivation for the waterfall model. It is also based on

the often unrealistic assumption that the user‟s operational system will be flexible enough to

accommodate unplanned evolution paths. This assumption is unjustified in three primary

circumstances:

(1) Circumstances in which several independently evolved applications must subsequently

be closely integrated.

(2) “Information-sclerosis” cases, in which temporary work -arounds for software

deficiencies increasingly solidify into unchangeable constraints on evolution.

The following comment is a typical example: “It‟s nice that you could change those

equipment codes to make them more intelligible

for us, but the Codes Committee just met and established the current codes as company

standards.” 

(3) Bridging situations, in which the new software is incrementally replacing a large

existing system. If the existing system is poorly modularized, it is difficult to provide a

good sequence of “bridges” between the old software and the expanding increments of new

software.

Under such conditions, evolutionary development projects have come to grief by pursuing

stages in the wrong order: evolving a lot of hard-to-change code before addressing long-

range architectural and usage considerations.

advantageous. The primary advantage of the spiral model is that its range of options

accommodates the good features of existing software process models, while its risk driven

approach avoids many of their difficulties. In appropriate situations, the spiral model

becomes equivalent to one of the existing process models. In other situations, it provides

guidance on the best mix of existing approaches to a given project; for example, its

application to the TRWSPS provided a risk-driven mix of specifying, prototyping, and

Page 9: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 9/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 9

evolutionary development. The primary conditions under which the spiral model becomes

equivalent to other main process models are summarized as follows:

l If a project has a low risk in such areas as getting the wrong user interface or not meeting

stringent performance requirements, and if it has a high risk in budget and schedulepredictability and control, then these risk considerations drive the spiral model into an

equivalence to the waterfall model.

  If a software product‟s requirements are very stable (implying a low risk of 

expensive design and code breakage due to requirements changes during

development), and if the presence of errors in the software product constitutes a

high risk to the mission it serves, then these risk considerations drive the spiral

model to resemble the two-leg model of precise specification and normal deductive

program development.

  If a project has a low risk in such areas as losing budget and schedule predictability

and control, encountering large-system integration problems, or coping with

information sclerosis, and if it has a high risk in such areas as getting the wrong

user interface or user decision support requirements, then these risk considerations

drive the spiral model into an equivalence to the evolutionary development model.

  If automated software generation capabilities are available, then the spiral model

accommodates them either as options for rapid prototyping or for application of the

transform model, depending on the risk considerations involved.

  If the high-risk elements of a project involve a mix of the risk items listed above,

then the spiral approach will reflect an appropriate mix of the process models

above.

In doing so, its risk avoidance features will generally avoid the difficulties of the other

models. The spiral model has a number of additional advantages, summarized as follows:

It focuses early attention on options involving the reuse of existing software.The steps

involving the identification and evaluation of alternatives encourage these options.

  Difficulties. The full spiral model can be successfully applied in many situations, but

some difficulties must be addressed before it can be called a mature, universally

applicable model. The three primary challenges involve matching to contract

software, relying on risk-assessment expertise, and the need for further elaboration

of spiral model steps.

Page 10: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 10/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 10

1.6 A prioritized top list of software risk items:- 

Risk item Risk management

techniques

1. Personnelshortfalls

Staffing with top talent, job matching; teambuilding;morale building; cross-training; pre-scheduling key

people

2. Unrealistic

schedules and

budgets

Detailed, multisource cost and schedule estimation;

design to cost; incremental development; software

reuse; requirements scrubbing

3. Developing the

wrong software

functions

Organization analysis; mission analysis; ops-concept

formulation; user surveys; prototyping; early users‟ 

manuals

4. Developing the

wrong user

interface

Task analysis; prototyping; scenarios; user

characterization (functionality, style, workload)

5. Gold plating Requirements scrubbing; prototyping; cost-benefit

analysis; design to cost

6. Continuing stream

of requirement

changes

High change threshold; information hiding; incremental

development (defer changes to later increments)

7. Shortfalls in;

externally furnished

components

Benchmarking; inspections; reference checking compatibility

analysis

1.7 The Risk Management Plan:

Even if an organization is not ready to adopt the entire spiral approach, one

characteristic technique that can easily be adapted to any life-cycle model provides many of 

the benefits of the spiral approach. This is the Risk Management Plan summarized in Table

This plan basically ensures that each project makes an early identification of its top risk 

items (the number 10 is not an absolute equirement), develops a strategy for resolving the

risk items, identifies and sets down an agenda to resolve new risk items as they

Page 11: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 11/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 11

surface, and highlights progress versus plans in monthly reviews.

Table: Software Risk Management Plan.

  The Player

  Uses a Frame

  Layout.

  Buttons.

o  Delays.

  Score Area.o  Non-Editable.

  Permits multiple instances of Random moves of skiers.

Page 12: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 12/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 12

CHAPTER – 2

A BRIEF ABOUT JAVA

2.1 Introduction

Why Java Technology is so important? 

This high-level powerful programming language provides a powerful software

platform as the JVM installed on different platform understand the same byte code. This is

ideal for server side web programming and runs in a secured manner over internet. It

enhance the computing power of the users by taking merely from desktop to the resource of 

the web. It contains JVM and Java Application Programming Interface (API) that are kinds

of readymade software components, and for using any component, the need is just to import

a related package in your program use the functionality. It offers development tools that can

be used in compiling, running, debugging and documenting the application, making the Java

programming fun and easy. The automatic garbage collection mechanism helps in avoiding

memory leaks and its coding takes less development time than other programming

languages like C++.

Different Editions of Java Technology 

a) Java SE - Java SE or Java Standard Edition provides tools and API's that you can use to

create server applications, desktop applications, and even applets. 

b) JEE - Based on the foundation framework of the standard edition, Java EnterpriseEdition helps in web application service, component model and enterprise class service

oriented architecture (SOA).

c) JME - Java Micro Edition or JME for short is an accumulation of Java APIs that are used

for the development of software for devices like mobile phones, PDAs, TV set-top boxes,

game programming.

Page 13: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 13/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 13

Advantages of Java

Java is simple, easy to design , easy to write, and therefore easy to compile, debug, and

learn than any other programming languages.

  Java is object-oriented, that is used to build modular programs and reusable code in

other application.

  Java is platform-independent and flexible in nature. The most significant feature of 

Java is to run a program easily from one computer system to another.

  Java works on distributed environment. It is designed to work on distributed

computing , Any network programs in Java is same as sending and receiving data to

and from a file.  Java is secure. The Java language, compiler, interpreter and runtime environment

are securable .

  Java is robust. Robust means reliability. Java emphasis on checking for possible

errors, as Java compilers are able to detect many error problem in program during

the execution of respective program code.

  Java supports multithreaded. Multithreaded is the path of execution for a program to

perform several tasks simultaneously within a program. The java come with the

concept of Multithreaded Program. In other languages, operating system-specific

procedures have to be called in order to work on multithreading.

Page 14: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 14/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 14

2.2 AWT

2.2.a Introduction:

The Abstract Window Toolkit (AWT) contains numerous classes andmethods that allow you to create and manage windows. The main purpose of the

AWT is to support applet windows, it can also be used to create stand-alone

windows that run in a GUI environment, such as Windows.

2.2.b AWT Classes: 

The AWT classes are contained in the java.awt package. It is one of Java's largest

packages. some of the AWT classes.

AWT Classes:

Class  Description

AWTEvent Encapsulates AWT events.

AWTEventMulticaster Dispatches events to multiple listeners.

BorderLayout The border layout manager. Border

layouts use five components: North,

South, East, West, and Center.

Button Creates a push button control.

Canvas A blank, semantics-free window.

CardLayout The card layout manager. Card layouts

emulate index cards. Only the one on

top is showing.

Page 15: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 15/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 15

Checkbox Creates a check box control.

CheckboxGroup Creates a group of check box controls.

CheckboxMenuItem Creates an on/off menu item.

Choice Creates a pop-up list.

Color Manages colors in a portable, platform-

independent fashion.

Component An abstract superclass for various

AWT components.

Container A subclass of Component that can hold

other components.

Cursor Encapsulates a bitmapped cursor.

Dialog Creates a dialog window.

Dimension Specifies the dimensions of an object.

The width is stored in width, and the

height is stored in height.

Event Encapsulates events.

EventQueue Queues events.

FileDialog Creates a window from which a file can

be selected.

Page 16: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 16/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 16

FlowLayout The flow layout manager. Flow layout

positions components left to right, top

to bottom.

Font Encapsulates a type font.

FontMetrics Encapsulates various information

related to a font. This information helps

you display text in a window.

Frame Creates a standard window that has a

title bar, resize corners, and a menu bar.

Graphics Encapsulates the graphics context. This

context is used by the various output

methods to display output in a window.

GraphicsDevice Describes a graphics device such as a

screen or printer.

GraphicsEnvironment Describes the collection of available

Font and GraphicsDevice objects.

GridBagConstraints Defines various constraints relating to

the GridBagLayout class.

GridBagLayout The grid bag layout manager. Grid bag

layout displays components subject to

the constraints specified by

GridBagConstraints.

Page 17: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 17/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 17

GridLayout The grid layout manager. Grid layout

displays components in a two-

dimensional grid.

Image Encapsulates graphical images.

Insets Encapsulates the borders of a container.

Label Creates a label that displays a string.

List Creates a list from which the user can

choose. Similar to the standard

Windows list box.

MediaTracker Manages media objects.

Menu Creates a pull-down menu.

MenuBar Creates a menu bar.

MenuComponent An abstract class implemented by

various menu classes.

MenuItem Creates a menu item.

MenuShortcut Encapsulates a keyboard shortcut for a

menu item.

Panel The simplest concrete subclass of 

Container.

Point Encapsulates a Cartesian coordinate

pair, stored in x and y.

Page 18: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 18/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 18

Polygon Encapsulates a polygon.

PopupMenu Encapsulates a pop-up menu.

PrintJob An abstract class that represents a print

 job.

Rectangle Encapsulates a rectangle.

Scrollbar Creates a scroll bar control.

ScrollPane A container that provides horizontal

and/or vertical scroll bars for another

component.

SystemColor Contains the colors of GUI widgets

such as windows, scroll bars, text, and

others.

TextArea Creates a multiline edit control.

TextComponent A superclass for TextArea and

TextField.

TextField Creates a single-line edit control.

Toolkit Abstract class implemented by the

AWT.

Window Creates a window with no frame, no

menu bar, and no title.

Page 19: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 19/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 19

CHAPTER – 3

CODING

Code For Snowboard

import java.applet.Applet; // This imports our native Java applet class for us to use

import java.applet.AudioClip; //class for playing sounds in an applet

import java.awt.*; //It imports the awt package

import java.awt.event.FocusEvent; //Component has gained or lost the input focus

import java.awt.event.FocusListener; // for receiving keyboard focus events on a component

import java.awt.event.KeyEvent; //Generated event when a key is pressedimport

  java.awt.event.KeyListener; //for receiving keyboard events

import java.util.Random; //generate a stream of pseudorandom numbers.

public class Snowboard extends Applet implements Runnable, KeyListener, FocusListener

{

private int x = 250; //Starting horizontal position of snowboarderprivate int armWave = 0; //Tracks arm wave of snowboarder

Random Generate1 = new Random();

Thread t; //for only one user

private String direction = "start1"; //Shows startup screen on load.

Image start; //Image for startup screen.

Image exit; //Image for exit game screen.

Image end; //Image for end game screen.

private String tempDirection = ""; //Stores direction when paused.

Image mySkier; //Image for snowboarder.

Image paused[] = new Image[6]; //Images for animated paused display.

private int pausedCounter = 0; //Counter for animating paused display.

Image offImage; //drawing off screen & then copying it

Graphics offGraphics; // to prevent white flashing.

Page 20: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 20/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 20

private boolean crashed = false; //Variables,images,& audio files for crashes.

private int crashedCounter = 0, crashedCounter2 = 0;

Image ow;AudioClip crashed1, crashed2, crashed3;

private boolean jumped = false, jumpedSlow = false; //images & audio

private int jumpedCounter = 0; //files for jumps.

AudioClip jump;

private boolean muted = false;

private int score = 0; //Variables for tracking score

private int highScore = 0; //High Score, Distance

private int distance = 0;

private int numMoguls = 5; //Number of moguls generated.

private Moguls myMoguls[] = new Moguls[5]; //Array of mogul objects.

private int numRocks = 10; //Number of rocks generated.

private Rocks myRocks[] = new Rocks[10]; //Array of rock objects.

private int numTrees = 20; //Number of trees generated.

private Trees myTrees[] = new Trees[20]; //Array of tree objects.

private int numSantas = 3; //Number of santas generated.

private Santas mySantas[] = new Santas[3]; //Array of santa objects.

private int numSkiers = 4; //Number of skiers generated.

private Skiers mySkiers[] = new Skiers[4]; //Array of skier objects.

public void init()

{

addKeyListener(this); //Implements the key & focus listeners.

addFocusListener(this);

enableEvents(AWTEvent.WINDOW_EVENT_MASK);

Page 21: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 21/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 21

for(int i = 0; i < numMoguls; i++) //Generates initial mogul locations.

{ //similarly of rock,tree,santa & skiers

myMoguls[i] = new Moguls();

myMoguls[i].newMogul(Generate1);}

for (int i = 0; i < 6 ; i++) //Sticks the proper images into the

{ //array of paused images.

paused[i] = getImage(getCodeBase(), "paused" + (i + 1) + ".gif");

}

ow = getImage(getCodeBase(), "ouch.gif"); //Sets up the crashed image.

crashed1 = getAudioClip(getCodeBase(), "splat.wav"); //Set up various

crashed2 = getAudioClip(getCodeBase(), "hithard.wav"); //audio files.

crashed3 = getAudioClip(getCodeBase(), "dullthump.wav");

 jump = getAudioClip(getCodeBase(), "boing2.wav");

repaint();

}

public void keyPressed(KeyEvent e)

{

int key = e.getKeyCode(); //Stores keys that are pressed.

if(direction.equals("start1")) //Allows keys from the start screen.

{

if(key == KeyEvent.VK_NUMPAD8)

direction = "stop";

if(key == KeyEvent.VK_NUMPAD6)

direction = "start2";

}

else if(direction.equals("start2")) //Allows keys from instruction screen.

{

Page 22: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 22/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 22

if(key == KeyEvent.VK_NUMPAD8)

direction = "stop";

if(key == KeyEvent.VK_NUMPAD4)

direction = "start1";if(key == KeyEvent.VK_NUMPAD6)

direction = "start3";

}

else if(direction.equals("start3")) //Allows keys from Scoring screen.

{

if(key == KeyEvent.VK_NUMPAD8)

direction = "stop";

if(key == KeyEvent.VK_NUMPAD4)

direction = "start2";

}

else if(direction.equals("exit")) //Allows only 8 after exiting a game.

{

if(key == KeyEvent.VK_NUMPAD8)

newGame();

}

else if(direction.equals("end")) //Allows only 8 after the game ends.

{

if(key == KeyEvent.VK_NUMPAD8)

newGame();

}

else if(direction.equals("paused")) //Allows only 5 when paused.

{

if(key == KeyEvent.VK_NUMPAD0)

direction = "exit";

if(key == KeyEvent.VK_NUMPAD5) //Sets direction to the

{ // value it held prior to being paused.

direction = tempDirection;

if(direction.equals("upleft") || direction.equals("upright"))

direction = "stop"; //Sets direction to stop if 7 or 9

Page 23: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 23/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 23

} //were held down when paused.

}

else if(jumped == true) //Allows only some keys when jumped is set to true.

{ //similar code for key pressed

}

else if(jumpedSlow == true) //Allows only some keys when jumpedSlow

{ //is true

 //Similar as above

}

else if(crashed == true) //Disables all commands when crashed is true

{ //(approx. .5 seconds).

}

else if(direction.equals("crashed")) //Allows only some keys to be pressed

{ //after crashed is set to false but while

 //same as above

}

else //Keys allowed when not crashed, jumped, paused,

{ //or on the start screens.

 //same as above

}

if(key == KeyEvent.VK_DECIMAL) //Mutes sound.

muted = !muted;

e.consume();

}

public void keyReleased(KeyEvent e)

{

int key = e.getKeyCode();

Page 24: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 24/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 24

if(!(direction.equals("start1") || direction.equals("start2") ||

direction.equals("start3")

|| direction.equals("paused") || jumped == true || jumpedSlow == true

|| direction.equals("crashed")|| direction.equals("exit") || direction.equals("end")))

{ //Stops movement after 7 and 9 are released.

if(key == KeyEvent.VK_NUMPAD7)

direction = "stop";

if(key == KeyEvent.VK_NUMPAD9)

direction = "stop";

}

e.consume();

}

public void keyTyped(KeyEvent e)

{

e.consume();

}

public void start()

{

t = new Thread(this);

t.start();

}

public void run()

{

long tm = System.currentTimeMillis(); //Stores system time

 //when program starts.return unit of time of the return value is a millisecond

while(Thread.currentThread() == t)

{

moveSkier(); //Function that moves all objects.

repaint(); //Repaints the component.

Page 25: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 25/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 25

try

{

tm += 33; //33 milliseconds.

Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));} //Delay for drawing the animation every 33

 //milliseconds, calculated from

catch(InterruptedException e) //the start times stored earlier.

{

break;

}

}

}

public void stop()

{ t = null;

offImage = null;

offGraphics = null;

}

public void moveSkier()

{

if(direction.equals("paused")) //Increments pausedCounter

{ // for animating the paused display.

pausedCounter++;

if(pausedCounter == 54)

pausedCounter = 0;

}

else if(direction.equals("end") || direction.equals("exit"))

{

if(score > highScore) //Moves score into highScore if it is larger.

highScore = score;

}

else

{

Page 26: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 26/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 26

if(direction.equals("downleft")) //Snowboarder moves

{ //quickly down and left.

x = x - 4; //Moves the snowboarder to the left.

distance = distance + 2; //Increments distancefor(int i = 0; i < numMoguls; i++ ) //Functions for moving

myMoguls[i].moveMogul(7, Generate1);// the objects

for(int i = 0; i < numRocks; i++ )

myRocks[i].moveRock(7, Generate1);

for(int i = 0; i < numTrees; i++ )

myTrees[i].moveTree(7, Generate1);

for(int i = 0; i < numSantas; i++ )

mySantas[i].moveSanta(6, Generate1);

for(int i = 0; i < numSkiers; i++ )

mySkiers[i].moveSkier(4, Generate1);

if(x < 2) //Moves the snowboarder back if he

{ // crashes into the side of the screen.

direction = "downright";

x = x + 8;

}

}

if(direction.equals("downright")) //Snowboarder moves quickly

{ //down and right.

x = x + 4; //Moves the snowboarder to the right.

distance = distance + 2; //Increments distance.

 //Same as in downright

if(x > 481) //Moves the snowboarder back if he

{ // crashes into the side of the screen.

direction = "downleft";

x = x - 8;

}

}

if(direction.equals("down")) //Snowboarder moves quickly down.

{

Page 27: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 27/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 27

distance = distance + 2; //Increments distance.

armWave++; //Increments armWave.

 //same as above

}if(direction.equals("left")) //Snowboarder moves slowly

{ //down and left.

x = x - 4; //Moves the snowboarder to the left.

distance = distance + 1; //Increments distance.

 //same as above

if(x < 2) //Moves the snowboarder back if he

{ // crashed into the side of the screen

direction = "right";

x = x + 8;

}

}

if(direction.equals("right")) //Snowboarder moves slowly

{ // down and right.

x = x + 4; //Moves the snowboarder to the right.

distance = distance + 1; //Increments distance.

 //same as above

if(x > 481) //Moves the snowboarder back if he

{ // crashes into the side of the screen.

direction = "left";

x = x - 8;

}

}

if(direction.equals("upleft")) //Snowboarder moves one step left.

{

x = x - 2; //Moves the snowboarder to the left.

 //Functions for moving the objects

for(int i = 0; i < numSantas; i++ )

mySantas[i].moveSanta(-3, Generate1);

Page 28: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 28/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 28

 //that continue to move when

for(int i = 0; i < numSkiers; i++ ) //the snowboarder does not.

mySkiers[i].moveSkier(-5, Generate1);

if(x < 2) //Moves the snowboarder back if hex = x + 2; // crashes into the side of the screen.

}

if(direction.equals("upright")) //Snowboarder moves one step

{ //right.

x = x + 2; //Moves the snowboarder to the right.

for(int i = 0; i < numSantas; i++ ) //Functions for moving the

mySantas[i].moveSanta(-1, Generate1); // objects that

for(int i = 0; i < numSkiers; i++ ) // continue to move when

mySkiers[i].moveSkier(-3, Generate1);

 // the snowboarder does not.

if(x > 481) //Moves the snowboarder back if he

x = x - 2; // crashes into the side of the screen.

}

if(direction.equals("stop")) //Snowboarder does not move.

{ //Functions for moving objects

 //same as above

}

if(direction.equals("slowdown")) //Used for slower jumps only.

{

distance = distance + 1; //Increments distance.

for(int i = 0; i < numMoguls; i++ ) //Functions for moving

myMoguls[i].moveMogul(4, Generate1);// the objects.

for(int i = 0; i < numRocks; i++ )

myRocks[i].moveRock(4, Generate1);

for(int i = 0; i < numTrees; i++ )

myTrees[i].moveTree(4, Generate1);

for(int i = 0; i < numSantas; i++ )

mySantas[i].moveSanta(3, Generate1);

for(int i = 0; i < numSkiers; i++ )

Page 29: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 29/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 29

mySkiers[i].moveSkier(1, Generate1);

if(jumpedSlow == false) //Sets direction to down if the

{ // snowboarder is moving straight down at the end

direction = "down"; // of a slow jump.}

}

if(direction.equals("crashed")) //Moves objects that continue to

{ // move when the snowboarder is crashed.

for(int i = 0; i < numSantas; i++ )

mySantas[i].moveSanta(-1, Generate1);

for(int i = 0; i < numSkiers; i++ )

mySkiers[i].moveSkier(-3, Generate1);

}

if(!direction.equals("exit") && !direction.equals("end"))

{

if(jumped == false && jumpedSlow == false)

detectJump(); //Detects jumps when the

if(jumped == true) // snowboarder is not already jumped.

{

  jumpedCounter++; //Increments the jumpCounter.

  jumpedScore(); //Calculates score if the

if(jumpedCounter == 75) //snowboarder passes

{ // over anything while jumped.

 jumped = false; //Ends the jump after a

 jumpedCounter = 0; // set amount of time.

}

}

else if(jumpedSlow == true)

{

  jumpedCounter++; //Increments the jumpCounter.

  jumpedSlowScore(); //Calculates score if the

if(jumpedCounter == 75) // snowboarder passes

Page 30: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 30/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 30

{ // over anything while jumped.

 jumpedSlow = false; //Ends the jump after

 jumpedCounter = 0; // a set amount of time.

}}

else if(crashed == true)

{

crashedCounter++; //Increments crashedCounter.

if(crashedCounter == 15)

{

crashed = false; //Unlocks controls after a set

crashedCounter = 0; // amount of time.

}

}

else

detectCrash();

if(distance > 3000 && !direction.equals("crashed"))

direction = "end";//Ends game if distance reaches 3000.

}

}

}

public void detectJump() //Detects the snowboarder passing over moguls.

{

for(int i = 0; i < numMoguls; i++ )

{

if(myMoguls[i].x < x + 10 && myMoguls[i].x > x - 10 &&

myMoguls[i].y < 185 && myMoguls[i].y > 165)

{

if(direction.equals("down") || direction.equals("downleft") ||

direction.equals("downright"))

{

 jumped = true; //Jumped state for faster downward

Page 31: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 31/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 31

if(muted == false) // movement.

 jump.play(); //Plays jump sound.

score = score + 50; //Adds to score.

}else if(direction.equals("left") || direction.equals("right"))

{

 jumpedSlow = true; //Jumped state for slower

if(muted == false) // downward movement.

 jump.play(); //Plays jump sound.

score = score + 25; //Adds to score.

}

}

}

}

public void jumpedScore() //Detects the snowboarder passing over objects during

{ //a faster jump.

for(int i = 0; i < numRocks; i++ )

{

if(myRocks[i].x < x + 10 && myRocks[i].x > x - 10 &&

myRocks[i].y < 185 && myRocks[i].y > 165)

{

score = score + 100; //Increments score for jumping rocks.

}

}//similar for trees, santa, skiers

}

public void jumpedSlowScore() //Detects the snowboarder passing over objects

during

{ //a slower jump.

for(int i = 0; i < numRocks; i++ )

{

Page 32: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 32/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 32

if(myRocks[i].x < x + 10 && myRocks[i].x > x - 10 &&

myRocks[i].y < 185 && myRocks[i].y > 165)

{

score = score + 50; //Increments score for jumping rocks.}

}//similar for other objects

}

public void detectCrash() //Function that detects collisions.

{

if(crashedCounter2 == 0)

{

for(int i = 0; i < numRocks; i++ )

{

if(myRocks[i].x < x + 10 && myRocks[i].x > x - 10 &&

myRocks[i].y < 185 && myRocks[i].y > 165)

{

direction = "crashed"; //Sets crashed states.

crashed = true;

crashedCounter++; //Increments the crashed counters.

crashedCounter2++;

if(muted == false)

crashed2.play(); //Plays rock crash sound.

score = score - 200;//Decreases score for hitting rocks.

}

}//similar for other

} }

else if(!direction.equals("crashed")) //Disables crash detection for the first

{ //few movements after a crash to keep from hitting the same object more

crashedCounter2++; // than once.

if(crashedCounter2 == 3)

crashedCounter2 = 0;

}

}

Page 33: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 33/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 33

public void newGame() //Function for starting a new game.

{

x = 250; //Resets the snowboarder.

crashed = false; //Clears crashed and jumped states.crashedCounter = 0;

crashedCounter2 = 0;

 jumped = false;

 jumpedSlow = false;

 jumpedCounter = 0;

for(int i = 0; i < numMoguls; i++) //Generates new mogul locations.

myMoguls[i].newMogul(Generate1);

 //similar for other objects

distance = 0; //Resets distance and score.

score = 0;

direction = "stop"; //Sets snowboarder to the stopped direction.

}

public void paint(Graphics g)

{

if (offImage != null) //Makes the offImage if it doesn't exist.

{

g.drawImage(offImage, 0, 0, null);

} }

public void update(Graphics g)

{

if(offGraphics == null)

{

offImage = createImage(500, 500);

offGraphics = offImage.getGraphics();

}

Page 34: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 34/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 34

offGraphics.setColor(getBackground());

offGraphics.fillRect(0, 0, 500, 500); //Fills offImage with a white

offGraphics.setColor(Color.black); // background.

paintFrame(offGraphics); //Function that draws everything to offGraphics.g.drawImage(offImage, 0, 0, null); //Draws offImage to the main screen.

}

public void paintFrame(Graphics g)

{

resize(500, 500);

g.setColor(Color.black);

requestFocusInWindow(); //Requests that this Component get input focus,

if(direction.equals("start1"))

{

start = getImage(getCodeBase(), "start1.gif");

g.drawImage(start, 0, 0, this); //Draws start image.

}

 //similar for start 2 & 3

else if(direction.equals("exit"))

{

exit = getImage(getCodeBase(), "exit.gif");

g.drawImage(exit, 0, 0, this); //Draws exit image.

g.drawString("Your Score", 185, 315); //Draws Scores

g.drawString("= " + score, 253, 315);

g.drawString("High Score", 185, 335);

g.drawString("= " + highScore, 253, 335);

}//same for end

else

{

if(jumped == true || jumpedSlow == true) //Sets jumped image.

mySkier = getImage(getCodeBase(), "snowboardjump.gif");

else

{

Page 35: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 35/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 35

if(direction.equals("crashed")) //Sets other skiers images.

mySkier = getImage(getCodeBase(), "snowboardcrash1.gif");

if(direction.equals("stop") || direction.equals("upleft") ||

direction.equals("upright"))mySkier = getImage(getCodeBase(), "snowboardside.gif");

if(direction.equals("left"))

mySkier = getImage(getCodeBase(), "snowboard45.gif");

 //similar for right, down left & right,

if(direction.equals("down"))

{

if(armWave < 8) //Sets down images based on armWave.

mySkier = getImage(getCodeBase(), "snowboard0a.gif");

else

{

mySkier = getImage(getCodeBase(), "snowboard0b.gif");

if(armWave >= 16)

armWave = 0;

}

}

}

for(int i = 0; i < numMoguls; i++) //Draws moguls

{

myMoguls[i].mogulImage=getImage(getCodeBase(), "snowboardmogul.gif");

g.drawImage(myMoguls[i].mogulImage,myMoguls[i].x, myMoguls[i].y,this);

}//similar for rocks, santa & trees

for(int i = 0; i < numSkiers; i++) //Draws skiers

{

if(mySkiers[i].skiersDirection == "left")

mySkiers[i].skierImage = getImage(getCodeBase(), "skier2.gif");

else //Image is set based on skiers current direction.

mySkiers[i].skierImage = getImage(getCodeBase(), "skier1.gif");

g.drawImage(mySkiers[i].skierImage, mySkiers[i].x, mySkiers[i].y, this);

}

Page 36: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 36/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 36

g.drawImage(mySkier, x, 175, this); //Draws snowboarder.

if(crashedCounter2 == 1)

{g.drawImage(ow, x + 9, 165, this); //Draws ouch image if crashed.

}

if(direction.equals("paused")) //Draws paused image, cycling through

{ //images based on pausedCounter.

g.drawImage(paused[(pausedCounter / 9)], 175, 212, this);

g.drawRect(175, 212, 150, 75);

}

g.setColor(getBackground());

g.fillRect(350, 0, 150, 73); //Draws score box.

g.setColor(Color.black);

g.drawRect(350, 1, 149, 72);

g.drawString("Distance", 363, 20);

g.drawString("= " + distance + " ft.", 431, 20);

g.drawString("Score", 363, 40);

g.drawString("= " + score, 431, 40);

g.drawString("High Score", 363, 60);

if(score > highScore)//Makes current score show up as high score if it

{ //is higher

g.drawString("=", 431, 60);

g.setColor(Color.RED);

g.drawString("" + score, 451, 60);

g.setColor(Color.black);

}

else

g.drawString("= " + highScore, 431, 60);

}

g.drawRect(1, 1, 498, 498); //Draws a box around the game.

Page 37: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 37/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 37

g.setColor(getBackground()); //Sets color to white.

g.fillRect(0, 0, 85, 30); //Fills in a box for sound on/off display.

g.setColor(Color.black);

g.drawRect(1, 1, 84, 29); //Draws a box for sound on/off display.if(muted == true) //Displays whether sound is on or off.

g.drawString("Sound: Off", 15, 20);

else

g.drawString("Sound: On", 15, 20);

}

public void focusGained(FocusEvent e)

{

e.getComponent();

}

public void focusLost(FocusEvent e) //Pauses the game if focus is moved away.

{

if(!(direction.equals("start1") || direction.equals("start2") ||

direction.equals("start3")

||

direction.equals("exit") || direction.equals("end")))

direction = "paused";

}

}

class Moguls //similar for other classes

{

public int x; //x and y coordinates for moguls.

public int y;

Image mogulImage;

public Moguls()

{

Page 38: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 38/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 38

}

public void newMogul(Random g1) //Function for generating a new mogul.

{do //Loop regenerates the mogul if it appears on top of the snowboarder.

{

x = (int)(g1.nextDouble() * 480) + 2;

y = (int)(g1.nextDouble() * 480) + 2;

}

while(x < 265 && x > 235 && y < 190 && y > 160);

}

public void moveMogul(int y1, Random g1) //Function for moving moguls.

{

y = y - y1;

if(y < 2) //New mogul at bottom of screen if one leaves the top of the screen.

{

y = 498;

x = (int)(g1.nextDouble() * 480) + 2;

}

}

}

class Skiers

{

public int x; //x and y coordinates for skiers.

public int y;

public int speed; //Speed and direction variables for skiers.

public String skiersDirection;

public int skiersCounter;

public int skiersChange;

Image skierImage;

Page 39: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 39/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 39

public Skiers()

{

}

public void newSkier(Random g1) //Function for generating new skiers.{

do

{

x = (int)(g1.nextDouble() * 480) + 2;

y = (int)(g1.nextDouble() * 480) + 2;

}

while(x < 265 && x > 235 && y < 190 && y > 160);

if(((int)(g1.nextDouble()*2)+1)==1) //Randomly generates direction of skier.

skiersDirection = "left";

else

skiersDirection = "right";

skiersCounter = 0;

skiersChange = (int)(g1.nextDouble() * 20) + 1; //Sets how often the skier

speed = (int)(g1.nextDouble() * 3) - 1; //change direction & variable speed.

}

public void moveSkier(int y1, Random g1) //Function for moving skiers.

{

skiersCounter++;

if(skiersCounter > skiersChange) //Chance to change direction after

{ // a random amount of time.

if(((int)(g1.nextDouble() * 2) + 1) == 1)

skiersDirection = "left";

else

skiersDirection = "right";

skiersCounter = 0;

skiersChange = (int)(g1.nextDouble() * 20) + 1;

}

y = y - y1 - speed;

Page 40: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 40/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 40

if(skiersDirection == "left")

x = x - 3 + speed;

elsex = x + 3 - speed;

if(y < 2) //Generate new skier at the bottom if one leaves top of the screen.

{ y = 498;

x = (int)(g1.nextDouble() * 480) + 2;

if(((int)(g1.nextDouble() * 2) + 1) == 1)

skiersDirection = "left";

else

skiersDirection = "right";

speed = (int)(g1.nextDouble() * 3) - 1;

}

if(y > 498) //Generates new skier at top if one leaves bottom of the screen.

{ y = 2;

x = (int)(g1.nextDouble() * 480) + 2;

if(((int)(g1.nextDouble() * 2) + 1) == 1)

skiersDirection = "left";

else

skiersDirection = "right";

speed = (int)(g1.nextDouble() * 3) - 1;

}

if(x > 481) //Pushes skiers back if they collide with the right side.

{ x = x - 6 + speed;

skiersDirection = "left";

}

if(x < 2) //Pushes skiers back if they collide with the left side.

{ x = x + 6 - speed;

skiersDirection = "right";

}

}  //END OF CODE

}

Page 41: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 41/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 41

CHAPTER – 4

SCREEN SHOTS

Start

Page 42: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 42/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 42

Gameplay

Page 43: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 43/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 43

End Game

Page 44: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 44/45

Design & Implementation Of Snowboard Game

SEC, Sikar Page 44

CHAPTER – 5

CONCLUSION

Computer Programming is an art, a way of explaining how a specific task is to be

performed by a given computer. Contrary to popular belief computer programming can be

both fun and excellent opportunity to exercise your mind, creativity and imagination. It

gives you the power to instruct computers according to your will. With highly powerful

workhorses at your disposal there is no limit what you can do with the help of programming

languages. the only limit being your imagination.

This project is GUI based which uses applets and event handling. Overall it is a

simple Snowboard game which will be further modified that it may conatain all the new

features..

Page 45: Snowboard Report

8/2/2019 Snowboard Report

http://slidepdf.com/reader/full/snowboard-report 45/45

Design & Implementation Of Snowboard Game

REFERENCES 

BOOKS 

[1] Herbert Schildt „Java Complete Reference‟ Tata McGrow Hill 

[2] Kathy Sierra „Head First Java‟ O‟Reilly 

[3] John Zukowski ‟Master in Java2‟ BPB Publications.

ONLINE REFERENCE

[1] www.java.sun.com

[2] www.roseindia.net

[3] www.codeguru.com