war simulation
TRANSCRIPT
University of PalestineSoftware Engineering
Concurrent and Real Time Programming
Simulates a Virtual Battle
By:Issam
AlshamalyShady
AlshareefMohammad
Abaas
:SupervisorEng. Mohammad Alshareef
Introduction
Project Interface
Project Explaining
Code
?
Index
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
Project Interface
Project Explaining
Symbols:
House
Solider
Tank
Plane
House “Peace Force”
Blast “injustice Force”
Project Explaining
Symbols:
Under Attack House
Destroyed Solider
Destroyed Tank
Destroyed Plane
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.
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.
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("");
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");
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.
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.
Any Question?
Thank you