Skip to content

Commit b2e9fde

Browse files
committed
#22 Dropped Gradle for Maven
1 parent e9f9f67 commit b2e9fde

File tree

10 files changed

+169
-85
lines changed

10 files changed

+169
-85
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,5 @@ out/
190190
.log.txt
191191
/.gradle/
192192
Package game.png
193+
target/*
194+
.PrintType-TEST.txt

build.gradle

Lines changed: 0 additions & 54 deletions
This file was deleted.

gradle/wrapper/gradle-wrapper.jar

-57.3 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 0 additions & 5 deletions
This file was deleted.

pom.xml

Lines changed: 115 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
45
<modelVersion>4.0.0</modelVersion>
56
<groupId>com.redomar.game</groupId>
67
<artifactId>javagame</artifactId>
7-
<version>Alpha 1.8.5</version>
8+
<version>Alpha 1.8.6</version>
89
<inceptionYear>2013</inceptionYear>
910
<licenses>
1011
<license>
@@ -13,30 +14,136 @@
1314
<distribution>repo</distribution>
1415
</license>
1516
</licenses>
17+
<repositories>
18+
<repository>
19+
<id>local-maven-repo</id>
20+
<url>file://${project.basedir}/res/jars</url>
21+
</repository>
22+
</repositories>
1623
<dependencies>
1724
<dependency>
1825
<groupId>org.apache.commons</groupId>
1926
<artifactId>commons-text</artifactId>
2027
<version>1.10.0</version>
21-
<scope>runtime</scope>
2228
</dependency>
2329
<dependency>
2430
<groupId>org.apache.commons</groupId>
2531
<artifactId>commons-lang3</artifactId>
2632
<version>3.12.0</version>
27-
<scope>runtime</scope>
2833
</dependency>
2934
<dependency>
3035
<groupId>org.jetbrains</groupId>
3136
<artifactId>annotations</artifactId>
32-
<version>23.0.0</version>
33-
<scope>runtime</scope>
37+
<version>23.1.0</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.thehowtotutorial.splashscreen</groupId>
41+
<artifactId>JSplashScreen</artifactId>
42+
<version>1.0</version>
3443
</dependency>
3544
<dependency>
3645
<groupId>junit</groupId>
3746
<artifactId>junit</artifactId>
38-
<version>4.13.1</version>
47+
<version>4.13.2</version>
3948
<scope>test</scope>
4049
</dependency>
4150
</dependencies>
51+
<properties>
52+
<maven.compiler.source>8</maven.compiler.source>
53+
<maven.compiler.target>8</maven.compiler.target>
54+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
55+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
56+
</properties>
57+
<build>
58+
<sourceDirectory>src</sourceDirectory>
59+
<resources>
60+
<resource>
61+
<directory>res</directory>
62+
</resource>
63+
</resources>
64+
<testSourceDirectory>
65+
test
66+
</testSourceDirectory>
67+
<plugins>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-resources-plugin</artifactId>
71+
<version>2.6</version>
72+
<configuration>
73+
<useDefaultDelimiters>false</useDefaultDelimiters>
74+
<delimiters>
75+
<delimiter>${*}</delimiter>
76+
<delimiter>@</delimiter>
77+
</delimiters>
78+
<encoding>UTF-8</encoding>
79+
</configuration>
80+
</plugin>
81+
<plugin>
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-dependency-plugin</artifactId>
84+
<version>3.3.0</version>
85+
<executions>
86+
<execution>
87+
<id>copy-dependencies</id>
88+
<phase>prepare-package</phase>
89+
<goals>
90+
<goal>copy-dependencies</goal>
91+
</goals>
92+
<configuration>
93+
<outputDirectory>${project.build.directory}/lib</outputDirectory>
94+
<overWriteReleases>false</overWriteReleases>
95+
<overWriteSnapshots>false</overWriteSnapshots>
96+
<overWriteIfNewer>true</overWriteIfNewer>
97+
</configuration>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
<plugin>
102+
<!-- Build an executable JAR -->
103+
<groupId>org.apache.maven.plugins</groupId>
104+
<artifactId>maven-jar-plugin</artifactId>
105+
<version>2.4</version>
106+
<configuration>
107+
108+
<archive>
109+
<manifest>
110+
<addClasspath>true</addClasspath>
111+
<classpathPrefix>lib/</classpathPrefix>
112+
<mainClass>com.redomar.game.Launcher</mainClass>
113+
</manifest>
114+
</archive>
115+
</configuration>
116+
<dependencies>
117+
<dependency>
118+
<groupId>com.thehowtotutorial.splashscreen</groupId>
119+
<artifactId>JSplashScreen</artifactId>
120+
<version>1.0</version>
121+
</dependency>
122+
</dependencies>
123+
</plugin>
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-install-plugin</artifactId>
127+
<version>2.4</version>
128+
<executions>
129+
<execution>
130+
<id>install-external-non-maven-jar-MWS-Client-into-local-maven-repo</id>
131+
<phase>clean</phase>
132+
<configuration>
133+
<repositoryLayout>default</repositoryLayout>
134+
<groupId>com.thehowtotutorial.splashscreen</groupId>
135+
<artifactId>JSplashScreen</artifactId>
136+
<version>1.0</version>
137+
<file>${project.basedir}/res/jars/JSplashScreen.jar</file>
138+
<packaging>jar</packaging>
139+
<generatePom>true</generatePom>
140+
</configuration>
141+
<goals>
142+
<goal>install-file</goal>
143+
</goals>
144+
</execution>
145+
</executions>
146+
</plugin>
147+
</plugins>
148+
</build>
42149
</project>

src/com/redomar/game/Game.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Game extends Canvas implements Runnable {
3434

3535
// Setting the size and name of the frame/canvas
3636
private static final long serialVersionUID = 1L;
37-
private static final String game_Version = "v1.8.5 Alpha";
37+
private static final String game_Version = "v1.8.6 Alpha";
3838
private static final int WIDTH = 160;
3939
private static final int HEIGHT = (WIDTH / 3 * 2);
4040
private static final int SCALE = 3;

src/com/redomar/game/audio/AudioHandler.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
import org.jetbrains.annotations.NotNull;
66

77
import javax.sound.sampled.*;
8+
import java.io.BufferedInputStream;
89
import java.io.File;
9-
import java.util.Arrays;
10+
import java.io.IOException;
11+
import java.io.InputStream;
1012
import java.util.Objects;
1113

12-
1314
public class AudioHandler {
1415

15-
public final Printer musicPrinter = new Printer(PrintTypes.MUSIC);
16+
public static final Printer musicPrinter = new Printer(PrintTypes.MUSIC);
1617
private Clip clip;
1718
private boolean active = false;
1819
private boolean music = false;
@@ -43,20 +44,32 @@ private void check(String path) {
4344
}
4445
}
4546

47+
/**
48+
* Initialises an audio clip from the specified file path.
49+
*
50+
* @param path the file path of the audio clip
51+
*/
4652
private void initiate(String path) {
4753
try {
48-
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(Objects.requireNonNull(AudioHandler.class.getResourceAsStream(path)));
54+
InputStream inputStream = new BufferedInputStream(Objects.requireNonNull(AudioHandler.class.getResourceAsStream(path)));
55+
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);
56+
audioInputStream.mark(Integer.MAX_VALUE);
4957
AudioFormat baseFormat = audioInputStream.getFormat();
5058
AudioFormat decodeFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
5159
AudioInputStream decodedAudioInputStream = AudioSystem.getAudioInputStream(decodeFormat, audioInputStream);
5260
clip = AudioSystem.getClip();
5361
clip.open(decodedAudioInputStream);
62+
} catch (IOException e) {
63+
musicPrinter.cast().exception("Audio file not found " + path);
64+
musicPrinter.cast().exception(e.getMessage());
65+
5466
} catch (Exception e) {
55-
System.err.println(Arrays.toString(e.getStackTrace()));
5667
musicPrinter.print("Audio Failed to initiate", PrintTypes.ERROR);
68+
musicPrinter.cast().exception(e.getMessage());
5769
}
5870
}
5971

72+
6073
public void play() {
6174
try {
6275
if (clip == null) return;

src/com/redomar/game/log/Printer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class Printer {
1212
private PrintTypes type;
1313
private String message;
1414
private boolean evalTypeAsException = false;
15+
private boolean mute = false;
1516

1617
public Printer() {
1718
this.type = PrintTypes.GAME;
@@ -53,6 +54,7 @@ private void printOut() {
5354
}
5455
logFile.log(String.format("%s%s\t%s", msgTime, msgType, message));
5556

57+
if (mute) return;
5658
String formattedStringForConsole = String.format("%s%s %s%n", msgType, msgTime, message);
5759

5860
if (type.equals(PrintTypes.ERROR) || evalTypeAsException) {
@@ -79,6 +81,15 @@ public String getMessage() {
7981
return message;
8082
}
8183

84+
public void mute() {
85+
this.mute = true;
86+
}
87+
88+
@SuppressWarnings("unused")
89+
public void unmute() {
90+
this.mute = false;
91+
}
92+
8293
/**
8394
* Error that keeps the current {@link PrintTypes PrintType } instead of using {@link PrintTypes PrintTypes.ERROR}
8495
*

src/com/redomar/game/menu/Menu.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.redomar.game.audio.AudioHandler;
55
import com.redomar.game.event.Mouse;
66
import com.redomar.game.lib.Font;
7+
import com.redomar.game.log.Printer;
78
import com.thehowtotutorial.splashscreen.JSplash;
89

910
import javax.swing.*;
@@ -44,8 +45,13 @@ public static void play() {
4445
splash.splashOn();
4546

4647
// Background tasks
47-
Game.setBackgroundMusic(new AudioHandler("/music/Towards The End.wav", true));
48-
Game.getBackgroundMusic().setVolume(VOLUME_IN_DB);
48+
try {
49+
Game.setBackgroundMusic(new AudioHandler("/music/Towards The End.wav", true));
50+
Game.getBackgroundMusic().setVolume(VOLUME_IN_DB);
51+
} catch (Exception e) {
52+
Printer printer = new Printer();
53+
printer.exception(e.getMessage());
54+
}
4955
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
5056
Game.setAlternateColsR(true);
5157
Game.setAlternateColsS(true);

test/com/redomar/game/audio/AudioHandlerTest.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,39 @@
55

66
import java.io.File;
77

8-
import static org.junit.Assert.*;
8+
import static org.junit.Assert.assertTrue;
99

1010
/**
1111
* Created by Mohamed on 28/08/2016.
1212
* This file tests the com.redomar.game.audio.AudioHandler class
1313
*/
1414
public class AudioHandlerTest {
1515

16+
@Before
17+
public void before() {
18+
AudioHandler.musicPrinter.mute();
19+
}
20+
1621
@Test
17-
public void bgMusicExists() throws Exception {
22+
public void bgMusicExists() {
1823
File sfx = new File("res/music/Towards The End.mp3");
1924
assertTrue(sfx.exists());
2025
}
2126

2227
@Test(expected = NullPointerException.class)
23-
public void expectReturnExceptionFileEmptyDir(){
28+
public void expectReturnExceptionFileEmptyDir() {
2429
File empty = new File("");
25-
AudioHandler audio = new AudioHandler(empty);
30+
new AudioHandler(empty);
2631
}
2732

2833
@Test(expected = NullPointerException.class)
29-
public void expectReturnExceptionFileEmptyPath(){
30-
AudioHandler audio = new AudioHandler("");
34+
public void expectReturnExceptionFileEmptyPath() {
35+
new AudioHandler("");
3136
}
3237

33-
@Test
34-
public void tryInitiatingAndPlayingNonExistingFile(){
35-
AudioHandler audio = new AudioHandler("//");
36-
audio.play();
38+
@Test()
39+
public void tryInitiatingAndPlayingNonExistingFile() {
40+
new AudioHandler("//").play();
3741
}
3842

3943
}

0 commit comments

Comments
 (0)