first commit
This commit is contained in:
commit
4240366c52
30 changed files with 2581 additions and 0 deletions
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/BomberCoso4.0.iml" filepath="$PROJECT_DIR$/BomberCoso4.0.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
11
BomberCoso4.0.iml
Normal file
11
BomberCoso4.0.iml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
0
BugBomberCoso.txt
Normal file
0
BugBomberCoso.txt
Normal file
26
LICENSE
Normal file
26
LICENSE
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# DON'T BE A DICK PUBLIC LICENSE
|
||||||
|
|
||||||
|
> Version 1.1, December 2016
|
||||||
|
|
||||||
|
> Copyright (C) 2024 Rossi Stefano
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim or modified
|
||||||
|
copies of this license document.
|
||||||
|
|
||||||
|
> DON'T BE A DICK PUBLIC LICENSE
|
||||||
|
> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
1. Do whatever you like with the original work, just don't be a dick.
|
||||||
|
|
||||||
|
Being a dick includes - but is not limited to - the following instances:
|
||||||
|
|
||||||
|
1a. Outright copyright infringement - Don't just copy this and change the name.
|
||||||
|
1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
|
||||||
|
1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.
|
||||||
|
|
||||||
|
2. If you become rich through modifications, related works/services, or supporting the original work,
|
||||||
|
share the love. Only a dick would make loads off this work and not buy the original work's
|
||||||
|
creator(s) a pint.
|
||||||
|
|
||||||
|
3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
|
||||||
|
you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.
|
45
README.md
Normal file
45
README.md
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
# Bomber Coso
|
||||||
|
|
||||||
|
This is a simple 2D game developed in Java Applet.
|
||||||
|
|
||||||
|
Just a small projet to learn threading and mouse events in Java.
|
||||||
|
|
||||||
|
Bombs will spam randomly on the screen. Faster with time.
|
||||||
|
You need to click on them to pause them before they explode.
|
||||||
|
But if you click them again. The y will restart to consume.
|
||||||
|
|
||||||
|
You can group them together to free up the space.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Java (6 to) 8 (max, recommended)
|
||||||
|
- NetBeans (highly recommended)
|
||||||
|
|
||||||
|
Java Applets have been dropped with Java 9. So you need an older versione to run this project.
|
||||||
|
Java 8 is the preferred version. Until Java 6 should be ok.
|
||||||
|
|
||||||
|
Problems running the project are expected, applets are deprecated and not supported by modern browsers.**
|
||||||
|
|
||||||
|
This is a NetBeans Project. Using NetBeans isn't mandatory but recommended for the built-in applet runner.
|
||||||
|
You can run the GrigliaApplet.java class with netbeans.
|
||||||
|
|
||||||
|
[NetBeans Instructions](https://netbeans.apache.org/tutorial/main/kb/docs/java/javase-jdk8/)
|
||||||
|
|
||||||
|
Alternatively, you can use IntellijJ IDEA with the [Applet runner plugin](https://plugins.jetbrains.com/plugin/16682-applet-runner) (not tested).
|
||||||
|
|
||||||
|
## Installation and run
|
||||||
|
|
||||||
|
Clone the repo:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://gitlab.com/stefanorossiti/bomber-coso
|
||||||
|
```
|
||||||
|
|
||||||
|
Run `AppletBomberCoso` with your preferred IDE (NetBeans is recommended) using
|
||||||
|
java 8.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
All my work is released under [DBAD](https://www.dbad-license.org/) license.
|
3
applet.policy
Normal file
3
applet.policy
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
grant {
|
||||||
|
permission java.security.AllPermission;
|
||||||
|
};
|
73
build.xml
Normal file
73
build.xml
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- You may freely edit this file. See commented blocks below for -->
|
||||||
|
<!-- some examples of how to customize the build. -->
|
||||||
|
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||||
|
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||||
|
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||||
|
<!-- the Compile on Save feature is turned off for the project. -->
|
||||||
|
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||||
|
<!-- in the project's Project Properties dialog box.-->
|
||||||
|
<project name="BomberCoso" default="default" basedir=".">
|
||||||
|
<description>Builds, tests, and runs the project BomberCoso.</description>
|
||||||
|
<import file="nbproject/build-impl.xml"/>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
There exist several targets which are by default empty and which can be
|
||||||
|
used for execution of your tasks. These targets are usually executed
|
||||||
|
before and after some main targets. They are:
|
||||||
|
|
||||||
|
-pre-init: called before initialization of project properties
|
||||||
|
-post-init: called after initialization of project properties
|
||||||
|
-pre-compile: called before javac compilation
|
||||||
|
-post-compile: called after javac compilation
|
||||||
|
-pre-compile-single: called before javac compilation of single file
|
||||||
|
-post-compile-single: called after javac compilation of single file
|
||||||
|
-pre-compile-test: called before javac compilation of JUnit tests
|
||||||
|
-post-compile-test: called after javac compilation of JUnit tests
|
||||||
|
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||||
|
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||||
|
-pre-jar: called before JAR building
|
||||||
|
-post-jar: called after JAR building
|
||||||
|
-post-clean: called after cleaning build products
|
||||||
|
|
||||||
|
(Targets beginning with '-' are not intended to be called on their own.)
|
||||||
|
|
||||||
|
Example of inserting an obfuscator after compilation could look like this:
|
||||||
|
|
||||||
|
<target name="-post-compile">
|
||||||
|
<obfuscate>
|
||||||
|
<fileset dir="${build.classes.dir}"/>
|
||||||
|
</obfuscate>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
For list of available properties check the imported
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
|
||||||
|
Another way to customize the build is by overriding existing main targets.
|
||||||
|
The targets of interest are:
|
||||||
|
|
||||||
|
-init-macrodef-javac: defines macro for javac compilation
|
||||||
|
-init-macrodef-junit: defines macro for junit execution
|
||||||
|
-init-macrodef-debug: defines macro for class debugging
|
||||||
|
-init-macrodef-java: defines macro for class execution
|
||||||
|
-do-jar: JAR building
|
||||||
|
run: execution of project
|
||||||
|
-javadoc-build: Javadoc generation
|
||||||
|
test-report: JUnit report generation
|
||||||
|
|
||||||
|
An example of overriding the target for project execution could look like this:
|
||||||
|
|
||||||
|
<target name="run" depends="BomberCoso-impl.jar">
|
||||||
|
<exec dir="bin" executable="launcher.exe">
|
||||||
|
<arg file="${dist.jar}"/>
|
||||||
|
</exec>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
Notice that the overridden target depends on the jar target and not only on
|
||||||
|
the compile target as the regular run target does. Again, for a list of available
|
||||||
|
properties which you can use, check the target you are overriding in the
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
-->
|
||||||
|
</project>
|
28
build/AppletBomberCoso.html
Normal file
28
build/AppletBomberCoso.html
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<TITLE>Applet HTML Page</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
<BODY>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
*** GENERATED applet HTML launcher - DO NOT EDIT IN 'BUILD' FOLDER ***
|
||||||
|
|
||||||
|
If you need to modify this HTML launcher file (e.g., to add applet parameters),
|
||||||
|
copy it to where your applet class is found in the SRC folder. If you do this,
|
||||||
|
the IDE will use it when you run or debug the applet.
|
||||||
|
|
||||||
|
Tip: To exclude an HTML launcher from the JAR file, use exclusion filters in
|
||||||
|
the Packaging page in the Project Properties dialog.
|
||||||
|
|
||||||
|
For more information see the online help.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
|
||||||
|
|
||||||
|
<P>
|
||||||
|
<APPLET codebase="classes" code="bombercoso/AppletBomberCoso.class" width=350 height=200></APPLET>
|
||||||
|
</P>
|
||||||
|
|
||||||
|
<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
0
build/classes/.netbeans_automatic_build
Normal file
0
build/classes/.netbeans_automatic_build
Normal file
0
build/classes/.netbeans_update_resources
Normal file
0
build/classes/.netbeans_update_resources
Normal file
BIN
build/classes/bombercoso/AppletBomberCoso.class
Normal file
BIN
build/classes/bombercoso/AppletBomberCoso.class
Normal file
Binary file not shown.
BIN
build/classes/bombercoso/Bomba.class
Normal file
BIN
build/classes/bombercoso/Bomba.class
Normal file
Binary file not shown.
BIN
build/classes/bombercoso/BomberListener.class
Normal file
BIN
build/classes/bombercoso/BomberListener.class
Normal file
Binary file not shown.
BIN
build/classes/bombercoso/ScoreController.class
Normal file
BIN
build/classes/bombercoso/ScoreController.class
Normal file
Binary file not shown.
BIN
images/ezgif-2-79fd62cf59.gif
Normal file
BIN
images/ezgif-2-79fd62cf59.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 158 KiB |
3
manifest.mf
Normal file
3
manifest.mf
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
X-COMMENT: Main-Class will be added automatically by build
|
||||||
|
|
1799
nbproject/build-impl.xml
Normal file
1799
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
build.xml.data.CRC32=89ed4b64
|
||||||
|
build.xml.script.CRC32=b5e4e199
|
||||||
|
build.xml.stylesheet.CRC32=f85dc8f2@1.111.0.48
|
||||||
|
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||||
|
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||||
|
nbproject/build-impl.xml.data.CRC32=89ed4b64
|
||||||
|
nbproject/build-impl.xml.script.CRC32=a18113d2
|
||||||
|
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.111.0.48
|
0
nbproject/private/config.properties
Normal file
0
nbproject/private/config.properties
Normal file
8
nbproject/private/private.properties
Normal file
8
nbproject/private/private.properties
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
compile.on.save=true
|
||||||
|
do.depend=false
|
||||||
|
do.jar=true
|
||||||
|
do.jlink=false
|
||||||
|
javac.debug=true
|
||||||
|
javadoc.preview=true
|
||||||
|
jlink.strip=false
|
||||||
|
user.properties.file=C:\\Users\\Administrator\\AppData\\Roaming\\NetBeans\\22\\build.properties
|
4
nbproject/private/private.xml
Normal file
4
nbproject/private/private.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||||
|
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||||
|
</project-private>
|
89
nbproject/project.properties
Normal file
89
nbproject/project.properties
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
annotation.processing.enabled=true
|
||||||
|
annotation.processing.enabled.in.editor=false
|
||||||
|
annotation.processing.processors.list=
|
||||||
|
annotation.processing.run.all.processors=true
|
||||||
|
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||||
|
application.title=BomberCoso
|
||||||
|
application.vendor=Administrator
|
||||||
|
build.classes.dir=${build.dir}/classes
|
||||||
|
build.classes.excludes=**/*.java,**/*.form
|
||||||
|
# This directory is removed when the project is cleaned:
|
||||||
|
build.dir=build
|
||||||
|
build.generated.dir=${build.dir}/generated
|
||||||
|
build.generated.sources.dir=${build.dir}/generated-sources
|
||||||
|
# Only compile against the classpath explicitly listed here:
|
||||||
|
build.sysclasspath=ignore
|
||||||
|
build.test.classes.dir=${build.dir}/test/classes
|
||||||
|
build.test.results.dir=${build.dir}/test/results
|
||||||
|
# Uncomment to specify the preferred debugger connection transport:
|
||||||
|
#debug.transport=dt_socket
|
||||||
|
debug.classpath=\
|
||||||
|
${run.classpath}
|
||||||
|
debug.modulepath=\
|
||||||
|
${run.modulepath}
|
||||||
|
debug.test.classpath=\
|
||||||
|
${run.test.classpath}
|
||||||
|
debug.test.modulepath=\
|
||||||
|
${run.test.modulepath}
|
||||||
|
# This directory is removed when the project is cleaned:
|
||||||
|
dist.dir=dist
|
||||||
|
dist.jar=${dist.dir}/BomberCoso.jar
|
||||||
|
dist.javadoc.dir=${dist.dir}/javadoc
|
||||||
|
endorsed.classpath=
|
||||||
|
excludes=
|
||||||
|
includes=**
|
||||||
|
jar.compress=false
|
||||||
|
javac.classpath=
|
||||||
|
# Space-separated list of extra javac options
|
||||||
|
javac.compilerargs=
|
||||||
|
javac.deprecation=false
|
||||||
|
javac.external.vm=false
|
||||||
|
javac.modulepath=
|
||||||
|
javac.processormodulepath=
|
||||||
|
javac.processorpath=\
|
||||||
|
${javac.classpath}
|
||||||
|
javac.source=1.7
|
||||||
|
javac.target=1.7
|
||||||
|
javac.test.classpath=\
|
||||||
|
${javac.classpath}:\
|
||||||
|
${build.classes.dir}
|
||||||
|
javac.test.modulepath=\
|
||||||
|
${javac.modulepath}
|
||||||
|
javac.test.processorpath=\
|
||||||
|
${javac.test.classpath}
|
||||||
|
javadoc.additionalparam=
|
||||||
|
javadoc.author=false
|
||||||
|
javadoc.encoding=${source.encoding}
|
||||||
|
javadoc.html5=false
|
||||||
|
javadoc.noindex=false
|
||||||
|
javadoc.nonavbar=false
|
||||||
|
javadoc.notree=false
|
||||||
|
javadoc.private=false
|
||||||
|
javadoc.splitindex=true
|
||||||
|
javadoc.use=true
|
||||||
|
javadoc.version=false
|
||||||
|
javadoc.windowtitle=
|
||||||
|
jlink.launcher=false
|
||||||
|
jlink.launcher.name=BomberCoso
|
||||||
|
main.class=bombercoso.Bomba
|
||||||
|
manifest.file=manifest.mf
|
||||||
|
meta.inf.dir=${src.dir}/META-INF
|
||||||
|
mkdist.disabled=false
|
||||||
|
platform.active=Zulu_8.0.412_8
|
||||||
|
run.classpath=\
|
||||||
|
${javac.classpath}:\
|
||||||
|
${build.classes.dir}
|
||||||
|
# Space-separated list of JVM arguments used when running the project.
|
||||||
|
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||||
|
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||||
|
run.jvmargs=-Djava.security.policy=applet.policy
|
||||||
|
run.modulepath=\
|
||||||
|
${javac.modulepath}
|
||||||
|
run.test.classpath=\
|
||||||
|
${javac.test.classpath}:\
|
||||||
|
${build.test.classes.dir}
|
||||||
|
run.test.modulepath=\
|
||||||
|
${javac.test.modulepath}
|
||||||
|
source.encoding=UTF-8
|
||||||
|
src.dir=src
|
||||||
|
test.src.dir=test
|
16
nbproject/project.xml
Normal file
16
nbproject/project.xml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||||
|
<type>org.netbeans.modules.java.j2seproject</type>
|
||||||
|
<configuration>
|
||||||
|
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||||
|
<name>BomberCoso</name>
|
||||||
|
<explicit-platform explicit-source-supported="true"/>
|
||||||
|
<source-roots>
|
||||||
|
<root id="src.dir"/>
|
||||||
|
</source-roots>
|
||||||
|
<test-roots>
|
||||||
|
<root id="test.src.dir"/>
|
||||||
|
</test-roots>
|
||||||
|
</data>
|
||||||
|
</configuration>
|
||||||
|
</project>
|
193
src/bombercoso/AppletBomberCoso.java
Normal file
193
src/bombercoso/AppletBomberCoso.java
Normal file
|
@ -0,0 +1,193 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package bombercoso;
|
||||||
|
|
||||||
|
import java.applet.Applet;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author BBC
|
||||||
|
*/
|
||||||
|
public class AppletBomberCoso extends Applet implements MouseListener, MouseMotionListener, Runnable, BomberListener{
|
||||||
|
//DOUBLE BUFFERING
|
||||||
|
Graphics bufferGraphics;
|
||||||
|
Image offscreen;
|
||||||
|
|
||||||
|
//array di bombe, inserire il num max di bombe
|
||||||
|
Bomba[] b = new Bomba[500];
|
||||||
|
private int bombCnt = 0;
|
||||||
|
//inserire ogni quanto spawnare una nuova bomba in ms
|
||||||
|
private int msToNextBomb = 2000;
|
||||||
|
private int msAggContext = 20;
|
||||||
|
//istanzio lo scorecontroller
|
||||||
|
private ScoreController sc = new ScoreController();
|
||||||
|
|
||||||
|
Thread thAggContext = new Thread(this);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(){
|
||||||
|
this.setSize(600,600);
|
||||||
|
//System.out.println("Start");
|
||||||
|
|
||||||
|
thAggContext.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Graphics g)
|
||||||
|
{
|
||||||
|
paint(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g){
|
||||||
|
//gewstione offscreen
|
||||||
|
offscreen = createImage(this.getWidth() ,this.getHeight());
|
||||||
|
bufferGraphics = offscreen.getGraphics();
|
||||||
|
//cancello il contenuto
|
||||||
|
bufferGraphics.clearRect(0,0,this.getWidth() ,this.getHeight());
|
||||||
|
|
||||||
|
//disegno la bomba con eventualmente il tempo rimanente prima di scoppiare,
|
||||||
|
//se la bomba è gia scoppiata disegno un cerchio rosso pieno
|
||||||
|
|
||||||
|
for(int i = 0; i < bombCnt && i < b.length; i++){
|
||||||
|
if(b[i].getTimeToBoom() <= 0.01){
|
||||||
|
//disegno il contorno della bomba
|
||||||
|
bufferGraphics.setColor(Color.BLACK);
|
||||||
|
bufferGraphics.drawOval((int)b[i].getUpperLeftCorner().getX(), (int)b[i].getUpperLeftCorner().getY(), b[i].getRaggio()*2, b[i].getRaggio()*2);
|
||||||
|
|
||||||
|
//cerchio rosso
|
||||||
|
bufferGraphics.setColor(Color.BLACK);
|
||||||
|
bufferGraphics.fillOval((int)b[i].getUpperLeftCorner().getX(), (int)b[i].getUpperLeftCorner().getY(), b[i].getRaggio()*2, b[i].getRaggio()*2);
|
||||||
|
}else{
|
||||||
|
//disegno il background delal bomba
|
||||||
|
bufferGraphics.setColor(Color.WHITE);
|
||||||
|
bufferGraphics.fillOval((int)b[i].getUpperLeftCorner().getX(), (int)b[i].getUpperLeftCorner().getY(), b[i].getRaggio()*2, b[i].getRaggio()*2);
|
||||||
|
|
||||||
|
//disegno il riempimento della bomba che indica il tempo allo scoppio
|
||||||
|
//a dipendenza di quanto tempo rimane il colore del riempimento cambia
|
||||||
|
if(b[i].getTimeToBoom() <= 3){
|
||||||
|
bufferGraphics.setColor(Color.RED);
|
||||||
|
}else if(b[i].getTimeToBoom() <= 7){
|
||||||
|
bufferGraphics.setColor(Color.ORANGE);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
bufferGraphics.setColor(Color.GREEN);
|
||||||
|
}
|
||||||
|
bufferGraphics.fillArc((int)b[i].getUpperLeftCorner().getX(), (int)b[i].getUpperLeftCorner().getY(), b[i].getRaggio()*2, b[i].getRaggio()*2, -90, (int)((360/b[i].getBegginningTimeToBoom())* b[i].getTimeToBoom()));
|
||||||
|
|
||||||
|
//disegno la miccia della bomba
|
||||||
|
bufferGraphics.drawArc((int)b[i].getUpperLeftCorner().getX() + b[i].getRaggio(), (int)b[i].getUpperLeftCorner().getY() - b[i].getRaggio(), b[i].getRaggio()*2, b[i].getRaggio()*2, 180, (int)((-1)*(180/b[i].getBegginningTimeToBoom())* b[i].getTimeToBoom()));
|
||||||
|
|
||||||
|
//disegno il contorno della bomba
|
||||||
|
bufferGraphics.setColor(Color.BLACK);
|
||||||
|
bufferGraphics.drawOval((int)b[i].getUpperLeftCorner().getX(), (int)b[i].getUpperLeftCorner().getY(), b[i].getRaggio()*2, b[i].getRaggio()*2);
|
||||||
|
|
||||||
|
//scrivo il timer della bomba, se è minore uguale a 3 lo scrive in rosso
|
||||||
|
if(b[i].getTimeToBoom() <= 3){
|
||||||
|
bufferGraphics.setColor(Color.RED);
|
||||||
|
}else{
|
||||||
|
bufferGraphics.setColor(Color.BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
//scrivo il numero di conteggio allo scoppio
|
||||||
|
//bufferGraphics.drawString(String.valueOf(b[i].getTimeToBoom()),(int)b[i].getCentro().getX()-3, (int)b[i].getCentro().getY() + 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//stampo il punteggio del gioco
|
||||||
|
bufferGraphics.setColor(Color.LIGHT_GRAY);
|
||||||
|
bufferGraphics.fillRect(0, 0, 100, 20);
|
||||||
|
bufferGraphics.setColor(Color.BLACK);
|
||||||
|
bufferGraphics.drawString("Punteggio: " + sc.getScore(), 10, 15);
|
||||||
|
|
||||||
|
g.drawImage(offscreen,0,0,this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
int i = msToNextBomb/msAggContext-1;
|
||||||
|
while(thAggContext.isAlive()){
|
||||||
|
//ogni secondo (40 volte il ciclo con pausa di 25 ms) viene istanziana una nuova bomba
|
||||||
|
i++;
|
||||||
|
if(i == msToNextBomb/msAggContext){
|
||||||
|
//System.out.println("nuovabomber");
|
||||||
|
//istanzio una nuova bomba alla posizione dell array di bombe iche conta quante bombe ci sono gia e aggiungo i listener
|
||||||
|
if (bombCnt < b.length){
|
||||||
|
b[bombCnt] = new Bomba(this);
|
||||||
|
this.addMouseListener(b[bombCnt]);
|
||||||
|
this.addMouseMotionListener(b[bombCnt]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bombCnt++;
|
||||||
|
i=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
//repaint ogni 25 ms
|
||||||
|
repaint();
|
||||||
|
Thread.sleep(msAggContext); //l'occhio vede a max 30hz --> 1000/30 = 33.3
|
||||||
|
//System.out.println("agg");
|
||||||
|
|
||||||
|
}catch(InterruptedException e){
|
||||||
|
System.out.println("InterruptedExceptionContextAgg");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////
|
||||||
|
// BOMBER INTERFACE
|
||||||
|
/////////////////////////
|
||||||
|
@Override
|
||||||
|
public void boom(int ID){
|
||||||
|
System.out.println("bomba " + ID + " esplosa");
|
||||||
|
//thAggContext.stop();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disabled(int ID) {
|
||||||
|
System.out.println("bomba " + ID + " disabilitata");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rehabilitated(int ID) {
|
||||||
|
System.out.println("bomba " + ID + " riabilitata");
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////
|
||||||
|
// MOUSE LISTENER
|
||||||
|
/////////////////////////
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
}
|
||||||
|
}
|
208
src/bombercoso/Bomba.java
Normal file
208
src/bombercoso/Bomba.java
Normal file
|
@ -0,0 +1,208 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package bombercoso;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author BBC
|
||||||
|
*/
|
||||||
|
//la bomba è un oggetto circolare dotata di timer interno che parte o si
|
||||||
|
//ferma in base ai click dell utente
|
||||||
|
public class Bomba implements Runnable, MouseListener, MouseMotionListener{
|
||||||
|
//grandezza del contesto grafico
|
||||||
|
private static final int wGC = 600, hGC = 600;
|
||||||
|
private int ID; //id della bomba
|
||||||
|
private boolean activated;
|
||||||
|
private static int countID = 0; //variabile per il conteggio delle bombe per l assegnazione dell ID
|
||||||
|
private Point centro; //punto del centro della bomba
|
||||||
|
private int raggio; //raggio della bomba
|
||||||
|
private float timeToBoom;
|
||||||
|
private final float beginningTimeToBoom;
|
||||||
|
private Point upperLeftCorner; // angolo alto sinistro del quadrato in cui e inscritto il cerchio della bomba
|
||||||
|
private Thread timer = new Thread(this);
|
||||||
|
|
||||||
|
private BomberListener bInt;
|
||||||
|
|
||||||
|
//costrittore di default, quqando istanzio un oggetto bomba dovro passare
|
||||||
|
//come paramentro chi riceve i "segnali" di BomberListener
|
||||||
|
//poi devo far combaciare i 2 oggetti tramite il costruttore
|
||||||
|
public Bomba(BomberListener bInt){
|
||||||
|
//faccio combaciare la classe istanziante con l oggetto istanziato
|
||||||
|
this.bInt = bInt;
|
||||||
|
|
||||||
|
this.ID = Bomba.countID;
|
||||||
|
Bomba.countID++;
|
||||||
|
|
||||||
|
//genero misure della bomba
|
||||||
|
randomBombMeasures();
|
||||||
|
this.beginningTimeToBoom = this.timeToBoom;
|
||||||
|
|
||||||
|
//calcolo upperLeftCorner
|
||||||
|
upperLeftCornerCompute();
|
||||||
|
|
||||||
|
//inizio il decremento di timeToBoom tramite il thread timer
|
||||||
|
this.activated = true;
|
||||||
|
beginCountdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
// public Bomba(int ID, Point centro, int raggio, int timeToBoom){
|
||||||
|
// this.ID = this.countID;
|
||||||
|
// this.countID++;
|
||||||
|
// }
|
||||||
|
|
||||||
|
private void upperLeftCornerCompute(){
|
||||||
|
this.upperLeftCorner = new Point((int)centro.getX() - raggio, (int)centro.getY() - raggio);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void randomBombMeasures(){
|
||||||
|
//genero una misura casuale del raggio che da da 20 a 40 px
|
||||||
|
this.raggio = (int)((Math.random()*100)/5)+20;
|
||||||
|
|
||||||
|
//genero una misura casuale del centro, controlla che la bomba non esce dai bordi (0,0) e (wGC,hGC)
|
||||||
|
do{
|
||||||
|
this.centro = new Point((int)(Math.random()*wGC)-this.raggio, (int)(Math.random()*hGC)-this.raggio);
|
||||||
|
}while(centro.getX()-raggio < 0 || centro.getY()-raggio < 0);
|
||||||
|
|
||||||
|
//genero un timing casuale per la bomba da 5 a 15 che poi saranno secondi
|
||||||
|
this.timeToBoom = (int)(Math.random()*10 + 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void beginCountdown(){
|
||||||
|
if(this.activated && this.timeToBoom > 0){
|
||||||
|
this.timer.start();
|
||||||
|
this.activated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void resumeCountdown(){
|
||||||
|
if(!this.activated && this.timeToBoom > 0){
|
||||||
|
this.timer.resume();
|
||||||
|
this.activated = true;
|
||||||
|
this.bInt.rehabilitated(this.ID);
|
||||||
|
|
||||||
|
//System.out.println("Bomba: " + this.ID + " Reactivated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void pauseCountdown(){
|
||||||
|
if(this.activated){
|
||||||
|
this.timer.suspend();
|
||||||
|
this.activated = false;
|
||||||
|
this.bInt.disabled(this.ID);
|
||||||
|
//System.out.println("Bomba: " + this.ID + " Neutralized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void stopCountdown(){
|
||||||
|
if(this.timer.isAlive()){
|
||||||
|
this.timer.stop();
|
||||||
|
this.activated = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
while(this.timer.isAlive()){
|
||||||
|
try {
|
||||||
|
//System.out.println("Bomba: " + this.ID + " Explods in: " + this.timeToBoom);
|
||||||
|
Thread.sleep(100);
|
||||||
|
this.timeToBoom = (float)(this.timeToBoom - 0.1);
|
||||||
|
}catch (InterruptedException e){
|
||||||
|
System.out.println("InterruptedExceptionBomb" + this.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.timeToBoom <= 0.01){
|
||||||
|
//System.out.println("Bomba: " + this.ID + " BOOOM");
|
||||||
|
bInt.boom(this.ID);
|
||||||
|
stopCountdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////
|
||||||
|
// SETTER E GETTER
|
||||||
|
/////////////////////////
|
||||||
|
public Point getUpperLeftCorner(){
|
||||||
|
return this.upperLeftCorner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRaggio(){
|
||||||
|
return this.raggio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getCentro(){
|
||||||
|
return this.centro;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float getTimeToBoom(){
|
||||||
|
return this.timeToBoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getBegginningTimeToBoom(){
|
||||||
|
return this.beginningTimeToBoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////
|
||||||
|
// MOUSE LISTENER
|
||||||
|
/////////////////////////
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
//controllo se ho cliccato nella area del duadrato in cui e circoncritta la bomba
|
||||||
|
if(e.getX() > upperLeftCorner.getX() && e.getY() > upperLeftCorner.getY() && e.getX() < upperLeftCorner.getX() + 2*raggio && e.getY() < upperLeftCorner.getY() + 2*raggio){
|
||||||
|
if(this.activated){
|
||||||
|
pauseCountdown();
|
||||||
|
}else{
|
||||||
|
resumeCountdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
//con il talso sx le bombe vengono prese
|
||||||
|
if(e.getX() > upperLeftCorner.getX() && e.getY() > upperLeftCorner.getY() && e.getX() < upperLeftCorner.getX() + 2*raggio && e.getY() < upperLeftCorner.getY() + 2*raggio){
|
||||||
|
//System.out.println("mov");
|
||||||
|
if (e.getModifiers() == MouseEvent.BUTTON1_MASK) {
|
||||||
|
Point click = new Point(e.getX(), e.getY());
|
||||||
|
|
||||||
|
centro.setLocation(click);
|
||||||
|
|
||||||
|
upperLeftCornerCompute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//con il talso dx le bombe vengono spinte
|
||||||
|
if(e.getX() > upperLeftCorner.getX() && e.getY() > upperLeftCorner.getY() && e.getX() < upperLeftCorner.getX() + 2*raggio && e.getY() < upperLeftCorner.getY() + 2*raggio){
|
||||||
|
//System.out.println("mov");
|
||||||
|
if (e.getModifiers() == MouseEvent.BUTTON3_MASK) {
|
||||||
|
Point click = new Point(e.getX(), e.getY());
|
||||||
|
|
||||||
|
centro.setLocation(centro.getX() - (click.getX() - centro.getX()), centro.getY() - (click.getY() - centro.getY()));
|
||||||
|
|
||||||
|
upperLeftCornerCompute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
18
src/bombercoso/BomberListener.java
Normal file
18
src/bombercoso/BomberListener.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package bombercoso;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author BBC
|
||||||
|
*/
|
||||||
|
public interface BomberListener {
|
||||||
|
//si attiva quando viene cliccata la bomba e restituisce le la bomba è attiva o no
|
||||||
|
public void boom(int ID);
|
||||||
|
|
||||||
|
public void disabled(int ID);
|
||||||
|
|
||||||
|
public void rehabilitated(int ID);
|
||||||
|
}
|
21
src/bombercoso/ScoreController.java
Normal file
21
src/bombercoso/ScoreController.java
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package bombercoso;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author SAMT
|
||||||
|
*/
|
||||||
|
public class ScoreController {
|
||||||
|
private int Score;
|
||||||
|
|
||||||
|
public ScoreController(){
|
||||||
|
this.Score = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScore(){
|
||||||
|
return String.valueOf(this.Score);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue