war simulation

14
University of Palestine Software Engineering Concurrent and Real Time Programming Simulates a Virtual Battle By : Issam Alshamaly Shady Alshareef Mohammad Abaas : Supervisor Eng. Mohammad Alshareef

Upload: issam-ahmad

Post on 12-Apr-2017

103 views

Category:

Software


1 download

TRANSCRIPT

Page 1: War Simulation

University of PalestineSoftware Engineering

Concurrent and Real Time Programming 

Simulates a Virtual Battle

By:Issam

AlshamalyShady

AlshareefMohammad

Abaas

:SupervisorEng. Mohammad Alshareef

Page 2: War Simulation

Introduction

Project Interface

Project Explaining

Code

?

Index

Page 3: War Simulation

Simulates a Virtual Battle is a project simulates battle or war; we all know that the world doesn’t empty from wars because always the forces of good and evil are exist, but in the end even the evil forces were reached to highest level of the power, the good forces will be win.

This is a project to explain how the Concurrent Systems work, in it there four threads ( Man, Tank, Plane and Radar) and also fifth thread as main class.

Man, Tank and Plane are attack threads, and Radar thread for defender.

Introduction

Page 4: War Simulation

Project Interface

Page 5: War Simulation

Project Explaining

Symbols:

House

Solider

Tank

Plane

House “Peace Force”

Blast “injustice Force”

Page 6: War Simulation

Project Explaining

Symbols:

Under Attack House

Destroyed Solider

Destroyed Tank

Destroyed Plane

Page 7: War Simulation

Project Explaining

In the begin of the project all houses are safety as the normal case and immediately the attacker threads and the defender thread start.

Attacker units attack houses and we can see the explosions in the interface, Radar which is the only defender unit searches about the houses which were attacked and when found anyone of them, it identifies the type of attack and destroys it as we as show symbols of three attack types.

Page 8: War Simulation

Project Explaining

But we can help the defender unit through pressing on the blast places.

And we can control in the speed of threads from decrease or increase delay time.

In addition to all that we can use the peace force which protects all houses or the injustice force which destroys all houses.

Battle statistical shows the number of Attack units and the units that were destroyed.

Again button makes restart to the project.

Page 9: War Simulation

Code

We used array of buttons to print the battlefield and every button is as house, also we control with buttons through their coordinates.• public static javax.swing.JButton[][] multi = new JButton[10][10];• for (x = 0; x <= multi.length - 1; x++) { for (y = 0; y <= multi.length - 1; y++) { //code}}

• multi[x][y] = new JButton("");

Page 10: War Simulation

Code

We used this function to get the a reference of the source that has fired the event.

• ((JButton) e.getSource()).getName();

• setName("save");

We used “setName” function to identify the statues of home and attacker type.

• setName("Foot soldiers attack");

Page 11: War Simulation

Code

We used “setIcon();” function to appear an image describes the status of house. • setIcon(PrintArray.Iplan);

• Random r = new Random(); int rx = r.nextInt(10); int ry = r.nextInt(10);

We used “Random();” function to generate a new coordinate.

Page 12: War Simulation

Code

We used “isSelected()” function as a key for buttons to prevent more than one attacking at the same time.

• setSelected(true);

• War.stop.unlock();

We used “ReentrantLock” function to lock and unlock in some cases.

Page 13: War Simulation

Any Question?

Page 14: War Simulation

Thank you