Games Programming

GAMES PROGRAMMING

Task – 1

Pseudo Codes

Direction Control Method

PROCEDURE DirectionGenerate

USE VARIABLES : tempDirection As INTEGER

BEGIN

IF direction = -1 THEN

tempDirection := Random Value Between 0.0 and 1.0 * directionsite

ELSE

tempDirection := direction

direction := -1

END IF

RETURN tempDirection

END

Key Control Method

PROCEDURE DirectionDefine(evt As KeyEvent)

BEGIN

IF KeyCode = Left Arrow Key THEN

userDirection := 1

ELSE IF KeyCode = Right Arrow Key THEN

userDirection := 0

END IF

END

Time Control Method

PROCEDURE RunningTime(jtxt As JTextField)

BEGIN

REPEAT

timeElapsed += timeElapsed

DISPLAY timeElapsed in jtxt

wait for 1000 As millisecond

UNTIL timeElapsed <> 100 AND running

END

1.2 – Implementation

Direction Control Method

Key Control Method

Time Control Method

1.3 – Testing

1.3.1 – Testing for movement

When Play MenuItem is clicked, the block will move left or right direction randomly.

Task – 2

2.1 – Design

Pseudo Codes

Movement of the block

PROCEDURE Movement(jpl As JPanel, direction As Integer)

USE VARIABLES : a of TYPE integer, running of TYPE boolean

BEGIN

a:=0

WHILE(a<30 And running=True)

IF direction=0 THEN

move jpl to right 1 pixel

ELSE IF

move jpl to left 1 pixel

END IF

wait for speed As millisecond

CALL checkCollision(jpl)

a++

END WHILE

END

Three Level Control

PROCEDURE jmnuitemPlayActionPerformed

BEGIN

IF jmnuitemchkEasy is Selected THEN

speed:=25

levelFactor:=3

ELSE IF jmnuitemchkMedium is Selected THEN

speed:=18

levelFactor:=4

ELSE

speed:=8

levelFactor:=5

END IF

credit:=10

timeElapsed:=0

DISPLAY credit

DISPLAY timeElapsed

make jmnuitemPlay enabled false

running:=true

make jp1 visible

set focus on jp1

mb1:=new MovingBlock(jp1)

START mb1

CALL RunningTime(jtxtTime)

END

2.2 – Implementation

Main Method

Class BLOCK2

Movement of the block

Three Level Control

2.3 – Testing

2.3.1 – Testing for movement with Easy

When Easy Menu Item is checked and Play Menu Item is clicked, the Block will move slowly.

2.3.2 – Testing for movement with Medium

When Medium Menu Item is checked and Play Menu Item is clicked, the Block will move a little faster.

2.3.3 – Testing for Movement with Hard

When Hard Menu Item is checked and Play Menu Item is clicked, the Block will move very fast.

Task – 3
3.1 – Design

Pseudo Codes

Scoring Method

PROCEDURE GameOver()

USE VARIABLES : ElapsedTime, Cred, TotScore, score of TYPE INTEGER

BEGIN

ElapsedTime:=100

Cred:=jtxtCredits

TotScore:=jtxtScore

IF timeElapsed = 100 AND Cred<>0 THEN

DISPLAY "You Win!"

score:=ElapsedTime*Cred*levelFactor

DISPLAY (TotScore+score)

ELSE

DISPLAY "Game Over!"

END IF

ENABLE jmnuitemPlay

END

Collision Control Method

PROCEDURE CollisionCheck(JPanel jpl)

BEGIN

IF (x Location of jpl + width of jpl)=gameareaWidth OR x Location of jpl=0 THEN

Set the location of jpl(blockX,blockY)

IF speed>=2 THEN

speed-=speed*10f/100

END IF

credit--

DISPLAY credit in jtxtCredits

IF credit=0 THEN

running:=false

CALL GameOver()

END IF

END IF

IF timeElapsed==100 AND running THEN

running:=false

CALL GameOver()

END IF

END

3.2 – Implementation

Scoring Method

Collision Control Method

3.3 – Testing
3.3.1 – Testing for Scoring System

When a player wins the game, a message box “You Win!” will appear and the score will be calculated.

3.3.2 – Testing for Collision

When the block reach the edge of the area, the block return to the center of the area, the movement speed of the block increased about 10% and lose 1 credit.

Task – 4

4.1 – Design

Pseudo Codes

Class BLOCK4

CLASS BLOCK4 INHERIT BLOCK2

PROCEDURE BLOCK4()

directionsite:=4

END PROCEDURE

END CLASS

4.2 – Implementation

Class BLOCK4

4.3 – Testing

Task – 5

5.1 – Design

Pseudo Codes

Override CollisionCheck

PROCEDURE CollisionCheck(JPanel jpl)

BEGIN

IF (x Location of jpl + width of jpl)=gameareaWidth OR x Location of jpl=0 OR (y Location of jpl + height of jpl)=gameareaHeight OR y Location of jpl=0 THEN

Set the location of jpl(blockX,blockY)

IF speed>=2 THEN

speed-=speed*10f/100

END IF

credit--

DISPLAY credit in jtxtCredits

IF credit=0 THEN

running:=false

CALL GameOver()

END IF

END IF

IF timeElapsed==100 AND running THEN

running:=false

CALL GameOver()

END IF

END

Override Key Control Method

PROCEDURE DirectionDefine(evt As KeyEvent)

BEGIN

IF KeyCode = Left Arrow Key THEN

userDirection := 1

ELSE IF KeyCode = Right Arrow Key THEN

userDirection := 0

ELSE IF KeyCode = Down Arrow Key THEN

userDirection := 2

ELSE IF KeyCode = Up Arrow Key THEN

userDirection :=3

END IF

END

Override Movement

PROCEDURE Movement(jpl As JPanel, direction As INTEGER)

USE VARIABLES : a of TYPE Integer

BEGIN

a:=0;

while a<30 AND running

IF direction=0 THEN

move jpl to right 1 pixel

ELSE IF direction=1 THEN

move jpl to left 1 pixel

ELSE IF direction=2 THEN

move jpl to up 1 pixel

ELSE IF direction==3 THEN

move jpl to down 1 pixel

END IF

wait for speed As millisecond

CALL checkCollision(jpl)

a++

END WHILE

END

5.2 – Implementation

Override CollisionCheck

Override Key Control Method

Override Movement

5.3 – Testing
5.3.1 – Testing for BLOCK4 Movement

When Play MenuItem is clicked, the block will move left, right, up, and down direction randomly.

Task – 6
6.1 – Design

Pseudo Codes

GameOver Method

PROCEDURE GameOver()

USE VARIABLES : ElapsedTime, Cred, TotScore, score of TYPE INTEGER

BEGIN

ElapsedTime:=100

Cred:=jtxtCredits

TotScore:=jtxtScore

IF timeElapsed = 100 AND Cred<>0 THEN

DISPLAY "You Win!"

score:=ElapsedTime*Cred*levelFactor

DISPLAY (TotScore+score)

ELSE

DISPLAY "Game Over!"

END IF

ENABLE jmnuitemPlay

Set the Location of jp1(blockX,blockY)

Set the Location of jp2(blockX,blockY)

Set the Location of jp3(blockX,blockY)

Set the Location of jp4(blockX,blockY)

CALL RecordScore()

END

PlayActionPerformed

PROCEDURE jmnuitemPlayActionPerformed

BEGIN

IF jmnuitemchkEasy is Selected THEN

speed:=25

levelFactor:=3

ELSE IF jmnuitemchkMedium is Selected THEN

speed:=18

levelFactor:=4

ELSE

speed:=8

levelFactor:=5

END IF

credit:=10

timeElapsed:=0

DISPLAY credit

DISPLAY timeElapsed

make jmnuitemPlay enabled false

running:=true

IF jmnuitemchkOneBlock is Selected THEN

make jp1 visible

set focus on jp1

mb1:=new MovingBlock(jp1)

START mb1

Block := "1 Block"

ELSE IF jmnuitemchkTwoBlocks is Selected THEN

make jp1 visible

make jp2 visible

set focus on jp1

mb1:=new MovingBlock(jp1)

mb2:=new MovingBlock(jp2)

START mb1

START mb2

Block := "2 Blocks"

ELSE IF jmnuitemchkThreeBlocks is Selected THEN

make jp1 visible

make jp2 visible

make jp3 visible

set focus on jp1

mb1:=new MovingBlock(jp1)

mb2:=new MovingBlock(jp2)

mb3:=new MovingBlock(jp3)

START mb1

START mb2

START mb3

Block := "3 Blocks"

ELSE IF jmnuitemchkThreeBlocks is Selected THEN

make jp1 visible

make jp2 visible

make jp3 visible

make jp4 visible

set focus on jp1

mb1:=new MovingBlock(jp1)

mb2:=new MovingBlock(jp2)

mb3:=new MovingBlock(jp3)

mb4:=new MovingBlock(jp4)

START mb1

START mb2

START mb3

START mb4

Block := "4 Blocks"

END IF

CALL RunningTime(jtxtTime)

END

6.2 – Implementation

Class BLOCK2

GameOver Method

PlayActionPerformed

6.3 – Testing

6.3.1 – Testing for BLOCK4 Movement with four moving blocks

When 4 Blocks Menu Item is checked and Play Menu Item is clicked, four moving blocks will move randomly in all directions.

Task – 7
7.1 – Design

1. Player name

Pseudo Codes

Save Score Method

PROCEDURE RecordScore

USE VARIABLES : FileDir As File

gc As GregorianCalendar

datetime, scoredata, temp As String

fr As FileReader

br As BufferedReader

fw As FileWriter

pw As PrintWriter

BEGIN

FileDir := new File("Score/" + jtxtPlayerName + ".txt")

gc := new GregorianCalendar()

datetime := gc.DAY_OF_MONTH + "/" + (gc.MONTH)+1) + "/" + gc.YEAR + " " + gc.HOUR_OF_DAY + ":" + gc.MINUTE + ":" + gc.SECOND

scoredata := ""

IF FileDir is exist THEN

fr := OPEN FileReader(FileDir)

br := OPEN BufferedReader(fr)

temp := READ br

WHILE temp <> null

scoredata += temp + ONE ENTER KEY

temp := READ br

END WHILE

CLOSE br

CLOSE fr

END IF

fw := OPEN FileWriter(FileDir)

pw := OPEN PrintWriter(fw)

scoredata += datetime + ONE TAB KEY + Level + ONE TAB KEY + Block + ONE TAB KEY + Score + ONE ENTER KEY

WRITE scoredata

CLOSE pw

CLOSE fw

END

Read Score Method

PROCEDURE ScoreRead()

USE VARIABLES : fr As FileReader

br As BufferedReader

temp As String

BEGIN

fr := OPEN FileReader(FileDir)

br := OPEN BufferedReader(fr)

temp := READ br

WHILE temp <> null

DISPLAY Play History

temp := READ br

END WHILE

CLOSE br

CLOSE fr

END

7.2 – Implementation

7.3 – Testing

When the player clicked the menu item Scores, a dialog box will appear that showing the play history of that player.

Task – 8

8.1 – Design

Pseudo Codes

jmnuHelpActionPerformed

PROCEDURE : jmnuHelpActionPerformed

USE VARIABLES : filepath As File

helpfile As String Array

BEGIN

filepath := OPEN FILE("Help/UserManual.mht")

helpfile[] := {"hh.exe",filepath}

RUN helpfile

END

8.2 – Implementation

8.3 – Testing

When a user clicks on the Help Menu Item, a user manual dialog will appear.

Please be aware that the free essay that you were just reading was not written by us. This essay, and all of the others available to view on the website, were provided to us by students in exchange for services that we offer. This relationship helps our students to get an even better deal while also contributing to the biggest free essay resource in the UK!