diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard.class b/bin/dk/wiegand/games/pong/ScoreBoard.class
new file mode 100644
index 0000000..172a18c
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard.class b/bin/dk/wiegand/games/pong/ScoreBoard.class
new file mode 100644
index 0000000..172a18c
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/TennisCourt.class b/bin/dk/wiegand/games/pong/TennisCourt.class
new file mode 100644
index 0000000..119ee76
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/TennisCourt.class
Binary files differ
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard.class b/bin/dk/wiegand/games/pong/ScoreBoard.class
new file mode 100644
index 0000000..172a18c
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/TennisCourt.class b/bin/dk/wiegand/games/pong/TennisCourt.class
new file mode 100644
index 0000000..119ee76
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/TennisCourt.class
Binary files differ
diff --git a/src/dk/wiegand/games/pong/Ball.java b/src/dk/wiegand/games/pong/Ball.java
new file mode 100644
index 0000000..2841ed8
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Ball.java
@@ -0,0 +1,59 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class Ball {
+ public Game game;
+ public double x;
+ public static final double X_SPEED_DEFAULT = 10;
+ public double xSpeed = X_SPEED_DEFAULT;
+ public double y;
+ public double ySpeed = 0.7;
+ public static final int SIZE = 20;
+
+ public Ball(Game game) {
+ this.game = game;
+ x = game.playerA.x + Player.WIDTH;
+ }
+
+ public void tick() {
+ x += xSpeed;
+ y += ySpeed;
+ // Bounce on top/button
+ if (y > game.getTennisCourt().HEIGHT - Ball.SIZE || y < 0) {
+ ySpeed *= -1;
+ return;
+ }
+ // Out right
+ if (x > game.getTennisCourt().WIDTH - Ball.SIZE) {
+ game.score(game.playerB);
+ return;
+ }
+ // Out left
+ if (x < 0) {
+ game.score(game.playerA);
+ return;
+ }
+ }
+
+ public void toPlayer(Player player) {
+ switch (player.getPlayerId()) {
+ case A:
+ x = game.playerA.x + Player.WIDTH;
+ xSpeed = Ball.X_SPEED_DEFAULT;
+ break;
+ case B:
+ x = game.playerB.x - Ball.SIZE;
+ xSpeed = Ball.X_SPEED_DEFAULT * -1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillOval((int) x, (int) y, Ball.SIZE, Ball.SIZE);
+ }
+}
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard.class b/bin/dk/wiegand/games/pong/ScoreBoard.class
new file mode 100644
index 0000000..172a18c
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/TennisCourt.class b/bin/dk/wiegand/games/pong/TennisCourt.class
new file mode 100644
index 0000000..119ee76
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/TennisCourt.class
Binary files differ
diff --git a/src/dk/wiegand/games/pong/Ball.java b/src/dk/wiegand/games/pong/Ball.java
new file mode 100644
index 0000000..2841ed8
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Ball.java
@@ -0,0 +1,59 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class Ball {
+ public Game game;
+ public double x;
+ public static final double X_SPEED_DEFAULT = 10;
+ public double xSpeed = X_SPEED_DEFAULT;
+ public double y;
+ public double ySpeed = 0.7;
+ public static final int SIZE = 20;
+
+ public Ball(Game game) {
+ this.game = game;
+ x = game.playerA.x + Player.WIDTH;
+ }
+
+ public void tick() {
+ x += xSpeed;
+ y += ySpeed;
+ // Bounce on top/button
+ if (y > game.getTennisCourt().HEIGHT - Ball.SIZE || y < 0) {
+ ySpeed *= -1;
+ return;
+ }
+ // Out right
+ if (x > game.getTennisCourt().WIDTH - Ball.SIZE) {
+ game.score(game.playerB);
+ return;
+ }
+ // Out left
+ if (x < 0) {
+ game.score(game.playerA);
+ return;
+ }
+ }
+
+ public void toPlayer(Player player) {
+ switch (player.getPlayerId()) {
+ case A:
+ x = game.playerA.x + Player.WIDTH;
+ xSpeed = Ball.X_SPEED_DEFAULT;
+ break;
+ case B:
+ x = game.playerB.x - Ball.SIZE;
+ xSpeed = Ball.X_SPEED_DEFAULT * -1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillOval((int) x, (int) y, Ball.SIZE, Ball.SIZE);
+ }
+}
diff --git a/src/dk/wiegand/games/pong/Game.java b/src/dk/wiegand/games/pong/Game.java
new file mode 100644
index 0000000..27c7714
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Game.java
@@ -0,0 +1,159 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Font;
+import java.awt.Graphics;
+
+public class Game {
+ private final TennisCourt tennisCourt;
+ private ScoreBoard scoreBoard;
+
+ public int touchCount = 0;
+ public static final int TOUCH_CHANGE = 10;
+ public static final double TOUCH_CHANGE_FACTOR = 2;
+ public Player serve;
+ public static final int GAME_GOLS = 5;
+ private GameState gameState;
+
+ public Player playerA;
+ public Player playerB;
+ private Ball ball;
+
+ public Game(final TennisCourt tennisCourt) {
+ this.tennisCourt = tennisCourt;
+ changeGameState(GameState.START);
+ }
+
+ public TennisCourt getTennisCourt() {
+ return tennisCourt;
+ }
+
+ public Ball getBall() {
+ return ball;
+ }
+
+ public void score(Player player) {
+ ball.toPlayer(player);
+ this.serve = player;
+ switch (player.getPlayerId()) {
+ case A:
+ playerB.score();
+ playerA.init();
+ break;
+ case B:
+ playerA.score();
+ playerB.init();
+ break;
+ }
+ }
+
+ public void tick() {
+ tennisCourt.tick();
+ if (gameState == GameState.START) {
+ PlayerId playerSelected = tennisCourt.getKeyboardHandler().playerSelected();
+ if (playerSelected != null) {
+ switch (playerSelected) {
+ case A:
+ ball.toPlayer(serve = playerA);
+ break;
+ case B:
+ ball.toPlayer(serve = playerB);
+ break;
+ default:
+ break;
+ }
+ }
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ changeGameState(GameState.RUN);
+ }
+ }
+ playerA.tick();
+ playerB.tick();
+ if (gameState == GameState.RUN) {
+ // Ball
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ serve = null;
+ }
+ // Ball
+ if (serve == null) {
+ ball.tick();
+ if (Player.WIDTH * 2 >= ball.x && playerA.y <= ball.y && playerA.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ if (tennisCourt.WIDTH - Player.WIDTH * 2 <= ball.x + Ball.SIZE && playerB.y <= ball.y && playerB.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ }
+ }
+ if (gameState == GameState.END) {
+ if (tennisCourt.getKeyboardHandler().esc()) {
+ changeGameState(GameState.START);
+ }
+ }
+ }
+
+ public void render(Graphics graphics) {
+ scoreBoard.render(graphics);
+ playerA.render(graphics);
+ playerB.render(graphics);
+ if (gameState == GameState.START || gameState == GameState.RUN) {
+ ball.render(graphics);
+ }
+ if (gameState == GameState.START) {
+ renderText(graphics, "Pong - the game", tennisCourt.HEIGHT/2 - 50, 50);
+ renderText(graphics, "Select player to server by [left] and [right] arrow", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Player A: Up [a] Down [z]", tennisCourt.HEIGHT/2 + 50, 25);
+ renderText(graphics, "Player B: Up [up] Down [down]", tennisCourt.HEIGHT/2 + 100, 25);
+ renderText(graphics, "Press [space] to serve", tennisCourt.HEIGHT/2 + 150, 25);
+ renderText(graphics, GAME_GOLS + " goals to win", tennisCourt.HEIGHT/2 + 200, 25);
+ }
+ if (gameState == GameState.END) {
+ renderText(graphics, "GAME OVER", tennisCourt.HEIGHT/2 - 50, 50);
+ if (serve != null) renderText(graphics, "Player "+ serve.getPlayerId() +" won!", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Press [escape] to continue", tennisCourt.HEIGHT/2 + 50, 25);
+ }
+ }
+
+ public void renderText(Graphics graphics, String text, int y, double fontsize) {
+ graphics.setFont(new Font("Courier New", Font.PLAIN, (int) fontsize));
+ graphics.drawString(text, (int) (tennisCourt.WIDTH / 2 - (((double) text.length()) / 2 * fontsize / 100 * 120 / 2)), y);
+ }
+
+ public void changeGameState(GameState gameState) {
+ this.gameState = gameState;
+ switch (gameState) {
+ case START:
+ playerA = new Player(this, PlayerId.A);
+ playerB = new Player(this, PlayerId.B);
+ serve = playerA;
+ ball = new Ball(this);
+ scoreBoard = new ScoreBoard(tennisCourt, this);
+ break;
+ case RUN:
+ break;
+ case END:
+ break;
+ default:
+ break;
+ }
+ }
+
+ public GameState getGameState() {
+ return gameState;
+ }
+
+ public enum PlayerId {
+ A, B;
+ }
+
+ public enum GameState {
+ START, RUN, END
+ }
+}
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard.class b/bin/dk/wiegand/games/pong/ScoreBoard.class
new file mode 100644
index 0000000..172a18c
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/TennisCourt.class b/bin/dk/wiegand/games/pong/TennisCourt.class
new file mode 100644
index 0000000..119ee76
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/TennisCourt.class
Binary files differ
diff --git a/src/dk/wiegand/games/pong/Ball.java b/src/dk/wiegand/games/pong/Ball.java
new file mode 100644
index 0000000..2841ed8
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Ball.java
@@ -0,0 +1,59 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class Ball {
+ public Game game;
+ public double x;
+ public static final double X_SPEED_DEFAULT = 10;
+ public double xSpeed = X_SPEED_DEFAULT;
+ public double y;
+ public double ySpeed = 0.7;
+ public static final int SIZE = 20;
+
+ public Ball(Game game) {
+ this.game = game;
+ x = game.playerA.x + Player.WIDTH;
+ }
+
+ public void tick() {
+ x += xSpeed;
+ y += ySpeed;
+ // Bounce on top/button
+ if (y > game.getTennisCourt().HEIGHT - Ball.SIZE || y < 0) {
+ ySpeed *= -1;
+ return;
+ }
+ // Out right
+ if (x > game.getTennisCourt().WIDTH - Ball.SIZE) {
+ game.score(game.playerB);
+ return;
+ }
+ // Out left
+ if (x < 0) {
+ game.score(game.playerA);
+ return;
+ }
+ }
+
+ public void toPlayer(Player player) {
+ switch (player.getPlayerId()) {
+ case A:
+ x = game.playerA.x + Player.WIDTH;
+ xSpeed = Ball.X_SPEED_DEFAULT;
+ break;
+ case B:
+ x = game.playerB.x - Ball.SIZE;
+ xSpeed = Ball.X_SPEED_DEFAULT * -1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillOval((int) x, (int) y, Ball.SIZE, Ball.SIZE);
+ }
+}
diff --git a/src/dk/wiegand/games/pong/Game.java b/src/dk/wiegand/games/pong/Game.java
new file mode 100644
index 0000000..27c7714
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Game.java
@@ -0,0 +1,159 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Font;
+import java.awt.Graphics;
+
+public class Game {
+ private final TennisCourt tennisCourt;
+ private ScoreBoard scoreBoard;
+
+ public int touchCount = 0;
+ public static final int TOUCH_CHANGE = 10;
+ public static final double TOUCH_CHANGE_FACTOR = 2;
+ public Player serve;
+ public static final int GAME_GOLS = 5;
+ private GameState gameState;
+
+ public Player playerA;
+ public Player playerB;
+ private Ball ball;
+
+ public Game(final TennisCourt tennisCourt) {
+ this.tennisCourt = tennisCourt;
+ changeGameState(GameState.START);
+ }
+
+ public TennisCourt getTennisCourt() {
+ return tennisCourt;
+ }
+
+ public Ball getBall() {
+ return ball;
+ }
+
+ public void score(Player player) {
+ ball.toPlayer(player);
+ this.serve = player;
+ switch (player.getPlayerId()) {
+ case A:
+ playerB.score();
+ playerA.init();
+ break;
+ case B:
+ playerA.score();
+ playerB.init();
+ break;
+ }
+ }
+
+ public void tick() {
+ tennisCourt.tick();
+ if (gameState == GameState.START) {
+ PlayerId playerSelected = tennisCourt.getKeyboardHandler().playerSelected();
+ if (playerSelected != null) {
+ switch (playerSelected) {
+ case A:
+ ball.toPlayer(serve = playerA);
+ break;
+ case B:
+ ball.toPlayer(serve = playerB);
+ break;
+ default:
+ break;
+ }
+ }
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ changeGameState(GameState.RUN);
+ }
+ }
+ playerA.tick();
+ playerB.tick();
+ if (gameState == GameState.RUN) {
+ // Ball
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ serve = null;
+ }
+ // Ball
+ if (serve == null) {
+ ball.tick();
+ if (Player.WIDTH * 2 >= ball.x && playerA.y <= ball.y && playerA.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ if (tennisCourt.WIDTH - Player.WIDTH * 2 <= ball.x + Ball.SIZE && playerB.y <= ball.y && playerB.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ }
+ }
+ if (gameState == GameState.END) {
+ if (tennisCourt.getKeyboardHandler().esc()) {
+ changeGameState(GameState.START);
+ }
+ }
+ }
+
+ public void render(Graphics graphics) {
+ scoreBoard.render(graphics);
+ playerA.render(graphics);
+ playerB.render(graphics);
+ if (gameState == GameState.START || gameState == GameState.RUN) {
+ ball.render(graphics);
+ }
+ if (gameState == GameState.START) {
+ renderText(graphics, "Pong - the game", tennisCourt.HEIGHT/2 - 50, 50);
+ renderText(graphics, "Select player to server by [left] and [right] arrow", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Player A: Up [a] Down [z]", tennisCourt.HEIGHT/2 + 50, 25);
+ renderText(graphics, "Player B: Up [up] Down [down]", tennisCourt.HEIGHT/2 + 100, 25);
+ renderText(graphics, "Press [space] to serve", tennisCourt.HEIGHT/2 + 150, 25);
+ renderText(graphics, GAME_GOLS + " goals to win", tennisCourt.HEIGHT/2 + 200, 25);
+ }
+ if (gameState == GameState.END) {
+ renderText(graphics, "GAME OVER", tennisCourt.HEIGHT/2 - 50, 50);
+ if (serve != null) renderText(graphics, "Player "+ serve.getPlayerId() +" won!", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Press [escape] to continue", tennisCourt.HEIGHT/2 + 50, 25);
+ }
+ }
+
+ public void renderText(Graphics graphics, String text, int y, double fontsize) {
+ graphics.setFont(new Font("Courier New", Font.PLAIN, (int) fontsize));
+ graphics.drawString(text, (int) (tennisCourt.WIDTH / 2 - (((double) text.length()) / 2 * fontsize / 100 * 120 / 2)), y);
+ }
+
+ public void changeGameState(GameState gameState) {
+ this.gameState = gameState;
+ switch (gameState) {
+ case START:
+ playerA = new Player(this, PlayerId.A);
+ playerB = new Player(this, PlayerId.B);
+ serve = playerA;
+ ball = new Ball(this);
+ scoreBoard = new ScoreBoard(tennisCourt, this);
+ break;
+ case RUN:
+ break;
+ case END:
+ break;
+ default:
+ break;
+ }
+ }
+
+ public GameState getGameState() {
+ return gameState;
+ }
+
+ public enum PlayerId {
+ A, B;
+ }
+
+ public enum GameState {
+ START, RUN, END
+ }
+}
diff --git a/src/dk/wiegand/games/pong/GameEngine.java b/src/dk/wiegand/games/pong/GameEngine.java
new file mode 100644
index 0000000..fb964d9
--- /dev/null
+++ b/src/dk/wiegand/games/pong/GameEngine.java
@@ -0,0 +1,47 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Canvas;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.image.BufferStrategy;
+
+import javax.swing.JFrame;
+
+public abstract class GameEngine {
+ private final int width;
+ private final int height;
+ private final Canvas canvas;
+ private final BufferStrategy bufferStrategy;
+
+ public GameEngine(final int width, final int height) {
+ this.width = width;
+ this.height = height;
+
+ JFrame frame = new JFrame("Pong");
+ // Place frame in center of screen
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ frame.setBounds(screenSize.width / 2 - width / 2, screenSize.height / 2 - height / 2, width, height);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setResizable(false);
+ frame.setVisible(true);
+ // Canvas
+ canvas = new Canvas();
+ canvas.setPreferredSize(new Dimension(width, height));
+ canvas.setMinimumSize(new Dimension(width, height));
+ canvas.setMaximumSize(new Dimension(width, height));
+ canvas.setFocusable(false);
+ frame.add(canvas);
+ frame.pack();
+ canvas.createBufferStrategy(3);
+ bufferStrategy = canvas.getBufferStrategy();
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+}
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard.class b/bin/dk/wiegand/games/pong/ScoreBoard.class
new file mode 100644
index 0000000..172a18c
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/TennisCourt.class b/bin/dk/wiegand/games/pong/TennisCourt.class
new file mode 100644
index 0000000..119ee76
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/TennisCourt.class
Binary files differ
diff --git a/src/dk/wiegand/games/pong/Ball.java b/src/dk/wiegand/games/pong/Ball.java
new file mode 100644
index 0000000..2841ed8
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Ball.java
@@ -0,0 +1,59 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class Ball {
+ public Game game;
+ public double x;
+ public static final double X_SPEED_DEFAULT = 10;
+ public double xSpeed = X_SPEED_DEFAULT;
+ public double y;
+ public double ySpeed = 0.7;
+ public static final int SIZE = 20;
+
+ public Ball(Game game) {
+ this.game = game;
+ x = game.playerA.x + Player.WIDTH;
+ }
+
+ public void tick() {
+ x += xSpeed;
+ y += ySpeed;
+ // Bounce on top/button
+ if (y > game.getTennisCourt().HEIGHT - Ball.SIZE || y < 0) {
+ ySpeed *= -1;
+ return;
+ }
+ // Out right
+ if (x > game.getTennisCourt().WIDTH - Ball.SIZE) {
+ game.score(game.playerB);
+ return;
+ }
+ // Out left
+ if (x < 0) {
+ game.score(game.playerA);
+ return;
+ }
+ }
+
+ public void toPlayer(Player player) {
+ switch (player.getPlayerId()) {
+ case A:
+ x = game.playerA.x + Player.WIDTH;
+ xSpeed = Ball.X_SPEED_DEFAULT;
+ break;
+ case B:
+ x = game.playerB.x - Ball.SIZE;
+ xSpeed = Ball.X_SPEED_DEFAULT * -1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillOval((int) x, (int) y, Ball.SIZE, Ball.SIZE);
+ }
+}
diff --git a/src/dk/wiegand/games/pong/Game.java b/src/dk/wiegand/games/pong/Game.java
new file mode 100644
index 0000000..27c7714
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Game.java
@@ -0,0 +1,159 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Font;
+import java.awt.Graphics;
+
+public class Game {
+ private final TennisCourt tennisCourt;
+ private ScoreBoard scoreBoard;
+
+ public int touchCount = 0;
+ public static final int TOUCH_CHANGE = 10;
+ public static final double TOUCH_CHANGE_FACTOR = 2;
+ public Player serve;
+ public static final int GAME_GOLS = 5;
+ private GameState gameState;
+
+ public Player playerA;
+ public Player playerB;
+ private Ball ball;
+
+ public Game(final TennisCourt tennisCourt) {
+ this.tennisCourt = tennisCourt;
+ changeGameState(GameState.START);
+ }
+
+ public TennisCourt getTennisCourt() {
+ return tennisCourt;
+ }
+
+ public Ball getBall() {
+ return ball;
+ }
+
+ public void score(Player player) {
+ ball.toPlayer(player);
+ this.serve = player;
+ switch (player.getPlayerId()) {
+ case A:
+ playerB.score();
+ playerA.init();
+ break;
+ case B:
+ playerA.score();
+ playerB.init();
+ break;
+ }
+ }
+
+ public void tick() {
+ tennisCourt.tick();
+ if (gameState == GameState.START) {
+ PlayerId playerSelected = tennisCourt.getKeyboardHandler().playerSelected();
+ if (playerSelected != null) {
+ switch (playerSelected) {
+ case A:
+ ball.toPlayer(serve = playerA);
+ break;
+ case B:
+ ball.toPlayer(serve = playerB);
+ break;
+ default:
+ break;
+ }
+ }
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ changeGameState(GameState.RUN);
+ }
+ }
+ playerA.tick();
+ playerB.tick();
+ if (gameState == GameState.RUN) {
+ // Ball
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ serve = null;
+ }
+ // Ball
+ if (serve == null) {
+ ball.tick();
+ if (Player.WIDTH * 2 >= ball.x && playerA.y <= ball.y && playerA.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ if (tennisCourt.WIDTH - Player.WIDTH * 2 <= ball.x + Ball.SIZE && playerB.y <= ball.y && playerB.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ }
+ }
+ if (gameState == GameState.END) {
+ if (tennisCourt.getKeyboardHandler().esc()) {
+ changeGameState(GameState.START);
+ }
+ }
+ }
+
+ public void render(Graphics graphics) {
+ scoreBoard.render(graphics);
+ playerA.render(graphics);
+ playerB.render(graphics);
+ if (gameState == GameState.START || gameState == GameState.RUN) {
+ ball.render(graphics);
+ }
+ if (gameState == GameState.START) {
+ renderText(graphics, "Pong - the game", tennisCourt.HEIGHT/2 - 50, 50);
+ renderText(graphics, "Select player to server by [left] and [right] arrow", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Player A: Up [a] Down [z]", tennisCourt.HEIGHT/2 + 50, 25);
+ renderText(graphics, "Player B: Up [up] Down [down]", tennisCourt.HEIGHT/2 + 100, 25);
+ renderText(graphics, "Press [space] to serve", tennisCourt.HEIGHT/2 + 150, 25);
+ renderText(graphics, GAME_GOLS + " goals to win", tennisCourt.HEIGHT/2 + 200, 25);
+ }
+ if (gameState == GameState.END) {
+ renderText(graphics, "GAME OVER", tennisCourt.HEIGHT/2 - 50, 50);
+ if (serve != null) renderText(graphics, "Player "+ serve.getPlayerId() +" won!", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Press [escape] to continue", tennisCourt.HEIGHT/2 + 50, 25);
+ }
+ }
+
+ public void renderText(Graphics graphics, String text, int y, double fontsize) {
+ graphics.setFont(new Font("Courier New", Font.PLAIN, (int) fontsize));
+ graphics.drawString(text, (int) (tennisCourt.WIDTH / 2 - (((double) text.length()) / 2 * fontsize / 100 * 120 / 2)), y);
+ }
+
+ public void changeGameState(GameState gameState) {
+ this.gameState = gameState;
+ switch (gameState) {
+ case START:
+ playerA = new Player(this, PlayerId.A);
+ playerB = new Player(this, PlayerId.B);
+ serve = playerA;
+ ball = new Ball(this);
+ scoreBoard = new ScoreBoard(tennisCourt, this);
+ break;
+ case RUN:
+ break;
+ case END:
+ break;
+ default:
+ break;
+ }
+ }
+
+ public GameState getGameState() {
+ return gameState;
+ }
+
+ public enum PlayerId {
+ A, B;
+ }
+
+ public enum GameState {
+ START, RUN, END
+ }
+}
diff --git a/src/dk/wiegand/games/pong/GameEngine.java b/src/dk/wiegand/games/pong/GameEngine.java
new file mode 100644
index 0000000..fb964d9
--- /dev/null
+++ b/src/dk/wiegand/games/pong/GameEngine.java
@@ -0,0 +1,47 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Canvas;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.image.BufferStrategy;
+
+import javax.swing.JFrame;
+
+public abstract class GameEngine {
+ private final int width;
+ private final int height;
+ private final Canvas canvas;
+ private final BufferStrategy bufferStrategy;
+
+ public GameEngine(final int width, final int height) {
+ this.width = width;
+ this.height = height;
+
+ JFrame frame = new JFrame("Pong");
+ // Place frame in center of screen
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ frame.setBounds(screenSize.width / 2 - width / 2, screenSize.height / 2 - height / 2, width, height);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setResizable(false);
+ frame.setVisible(true);
+ // Canvas
+ canvas = new Canvas();
+ canvas.setPreferredSize(new Dimension(width, height));
+ canvas.setMinimumSize(new Dimension(width, height));
+ canvas.setMaximumSize(new Dimension(width, height));
+ canvas.setFocusable(false);
+ frame.add(canvas);
+ frame.pack();
+ canvas.createBufferStrategy(3);
+ bufferStrategy = canvas.getBufferStrategy();
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/KeyboardHandler.java b/src/dk/wiegand/games/pong/KeyboardHandler.java
new file mode 100644
index 0000000..38f6e88
--- /dev/null
+++ b/src/dk/wiegand/games/pong/KeyboardHandler.java
@@ -0,0 +1,81 @@
+package dk.wiegand.games.pong;
+
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import dk.wiegand.games.pong.Game.PlayerId;
+
+public class KeyboardHandler implements KeyListener {
+
+ private boolean playerAUp, playerADown, playerBUp, playerBDown, serve, playerA, playerB, esc;
+ private boolean keys[] = new boolean[256];
+
+ public boolean up(PlayerId playerId) {
+ switch (playerId) {
+ case A:
+ return playerAUp;
+ case B:
+ return playerBUp;
+ default:
+ return false;
+ }
+ }
+
+ public boolean down(PlayerId playerId) {
+ switch (playerId) {
+ case A:
+ return playerADown;
+ case B:
+ return playerBDown;
+ default:
+ return false;
+ }
+ }
+
+ public PlayerId playerSelected() {
+ if (playerA) {
+ return Game.PlayerId.A;
+ }
+ if (playerB) {
+ return Game.PlayerId.B;
+ }
+ return null;
+ }
+
+ public boolean serve() {
+ return serve;
+ }
+
+ public boolean esc() {
+ return esc;
+ }
+
+ public void tick() {
+ playerA = keys[KeyEvent.VK_LEFT];
+ playerAUp = keys[KeyEvent.VK_A];
+ playerADown = keys[KeyEvent.VK_Z];
+
+ playerB = keys[KeyEvent.VK_RIGHT];
+ playerBUp = keys[KeyEvent.VK_UP];
+ playerBDown = keys[KeyEvent.VK_DOWN];
+
+ serve = keys[KeyEvent.VK_SPACE];
+
+ esc = keys[KeyEvent.VK_ESCAPE];
+ }
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ keys[e.getKeyCode()] = true;
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ keys[e.getKeyCode()] = false;
+ }
+
+}
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard.class b/bin/dk/wiegand/games/pong/ScoreBoard.class
new file mode 100644
index 0000000..172a18c
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/TennisCourt.class b/bin/dk/wiegand/games/pong/TennisCourt.class
new file mode 100644
index 0000000..119ee76
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/TennisCourt.class
Binary files differ
diff --git a/src/dk/wiegand/games/pong/Ball.java b/src/dk/wiegand/games/pong/Ball.java
new file mode 100644
index 0000000..2841ed8
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Ball.java
@@ -0,0 +1,59 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class Ball {
+ public Game game;
+ public double x;
+ public static final double X_SPEED_DEFAULT = 10;
+ public double xSpeed = X_SPEED_DEFAULT;
+ public double y;
+ public double ySpeed = 0.7;
+ public static final int SIZE = 20;
+
+ public Ball(Game game) {
+ this.game = game;
+ x = game.playerA.x + Player.WIDTH;
+ }
+
+ public void tick() {
+ x += xSpeed;
+ y += ySpeed;
+ // Bounce on top/button
+ if (y > game.getTennisCourt().HEIGHT - Ball.SIZE || y < 0) {
+ ySpeed *= -1;
+ return;
+ }
+ // Out right
+ if (x > game.getTennisCourt().WIDTH - Ball.SIZE) {
+ game.score(game.playerB);
+ return;
+ }
+ // Out left
+ if (x < 0) {
+ game.score(game.playerA);
+ return;
+ }
+ }
+
+ public void toPlayer(Player player) {
+ switch (player.getPlayerId()) {
+ case A:
+ x = game.playerA.x + Player.WIDTH;
+ xSpeed = Ball.X_SPEED_DEFAULT;
+ break;
+ case B:
+ x = game.playerB.x - Ball.SIZE;
+ xSpeed = Ball.X_SPEED_DEFAULT * -1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillOval((int) x, (int) y, Ball.SIZE, Ball.SIZE);
+ }
+}
diff --git a/src/dk/wiegand/games/pong/Game.java b/src/dk/wiegand/games/pong/Game.java
new file mode 100644
index 0000000..27c7714
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Game.java
@@ -0,0 +1,159 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Font;
+import java.awt.Graphics;
+
+public class Game {
+ private final TennisCourt tennisCourt;
+ private ScoreBoard scoreBoard;
+
+ public int touchCount = 0;
+ public static final int TOUCH_CHANGE = 10;
+ public static final double TOUCH_CHANGE_FACTOR = 2;
+ public Player serve;
+ public static final int GAME_GOLS = 5;
+ private GameState gameState;
+
+ public Player playerA;
+ public Player playerB;
+ private Ball ball;
+
+ public Game(final TennisCourt tennisCourt) {
+ this.tennisCourt = tennisCourt;
+ changeGameState(GameState.START);
+ }
+
+ public TennisCourt getTennisCourt() {
+ return tennisCourt;
+ }
+
+ public Ball getBall() {
+ return ball;
+ }
+
+ public void score(Player player) {
+ ball.toPlayer(player);
+ this.serve = player;
+ switch (player.getPlayerId()) {
+ case A:
+ playerB.score();
+ playerA.init();
+ break;
+ case B:
+ playerA.score();
+ playerB.init();
+ break;
+ }
+ }
+
+ public void tick() {
+ tennisCourt.tick();
+ if (gameState == GameState.START) {
+ PlayerId playerSelected = tennisCourt.getKeyboardHandler().playerSelected();
+ if (playerSelected != null) {
+ switch (playerSelected) {
+ case A:
+ ball.toPlayer(serve = playerA);
+ break;
+ case B:
+ ball.toPlayer(serve = playerB);
+ break;
+ default:
+ break;
+ }
+ }
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ changeGameState(GameState.RUN);
+ }
+ }
+ playerA.tick();
+ playerB.tick();
+ if (gameState == GameState.RUN) {
+ // Ball
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ serve = null;
+ }
+ // Ball
+ if (serve == null) {
+ ball.tick();
+ if (Player.WIDTH * 2 >= ball.x && playerA.y <= ball.y && playerA.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ if (tennisCourt.WIDTH - Player.WIDTH * 2 <= ball.x + Ball.SIZE && playerB.y <= ball.y && playerB.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ }
+ }
+ if (gameState == GameState.END) {
+ if (tennisCourt.getKeyboardHandler().esc()) {
+ changeGameState(GameState.START);
+ }
+ }
+ }
+
+ public void render(Graphics graphics) {
+ scoreBoard.render(graphics);
+ playerA.render(graphics);
+ playerB.render(graphics);
+ if (gameState == GameState.START || gameState == GameState.RUN) {
+ ball.render(graphics);
+ }
+ if (gameState == GameState.START) {
+ renderText(graphics, "Pong - the game", tennisCourt.HEIGHT/2 - 50, 50);
+ renderText(graphics, "Select player to server by [left] and [right] arrow", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Player A: Up [a] Down [z]", tennisCourt.HEIGHT/2 + 50, 25);
+ renderText(graphics, "Player B: Up [up] Down [down]", tennisCourt.HEIGHT/2 + 100, 25);
+ renderText(graphics, "Press [space] to serve", tennisCourt.HEIGHT/2 + 150, 25);
+ renderText(graphics, GAME_GOLS + " goals to win", tennisCourt.HEIGHT/2 + 200, 25);
+ }
+ if (gameState == GameState.END) {
+ renderText(graphics, "GAME OVER", tennisCourt.HEIGHT/2 - 50, 50);
+ if (serve != null) renderText(graphics, "Player "+ serve.getPlayerId() +" won!", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Press [escape] to continue", tennisCourt.HEIGHT/2 + 50, 25);
+ }
+ }
+
+ public void renderText(Graphics graphics, String text, int y, double fontsize) {
+ graphics.setFont(new Font("Courier New", Font.PLAIN, (int) fontsize));
+ graphics.drawString(text, (int) (tennisCourt.WIDTH / 2 - (((double) text.length()) / 2 * fontsize / 100 * 120 / 2)), y);
+ }
+
+ public void changeGameState(GameState gameState) {
+ this.gameState = gameState;
+ switch (gameState) {
+ case START:
+ playerA = new Player(this, PlayerId.A);
+ playerB = new Player(this, PlayerId.B);
+ serve = playerA;
+ ball = new Ball(this);
+ scoreBoard = new ScoreBoard(tennisCourt, this);
+ break;
+ case RUN:
+ break;
+ case END:
+ break;
+ default:
+ break;
+ }
+ }
+
+ public GameState getGameState() {
+ return gameState;
+ }
+
+ public enum PlayerId {
+ A, B;
+ }
+
+ public enum GameState {
+ START, RUN, END
+ }
+}
diff --git a/src/dk/wiegand/games/pong/GameEngine.java b/src/dk/wiegand/games/pong/GameEngine.java
new file mode 100644
index 0000000..fb964d9
--- /dev/null
+++ b/src/dk/wiegand/games/pong/GameEngine.java
@@ -0,0 +1,47 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Canvas;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.image.BufferStrategy;
+
+import javax.swing.JFrame;
+
+public abstract class GameEngine {
+ private final int width;
+ private final int height;
+ private final Canvas canvas;
+ private final BufferStrategy bufferStrategy;
+
+ public GameEngine(final int width, final int height) {
+ this.width = width;
+ this.height = height;
+
+ JFrame frame = new JFrame("Pong");
+ // Place frame in center of screen
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ frame.setBounds(screenSize.width / 2 - width / 2, screenSize.height / 2 - height / 2, width, height);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setResizable(false);
+ frame.setVisible(true);
+ // Canvas
+ canvas = new Canvas();
+ canvas.setPreferredSize(new Dimension(width, height));
+ canvas.setMinimumSize(new Dimension(width, height));
+ canvas.setMaximumSize(new Dimension(width, height));
+ canvas.setFocusable(false);
+ frame.add(canvas);
+ frame.pack();
+ canvas.createBufferStrategy(3);
+ bufferStrategy = canvas.getBufferStrategy();
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/KeyboardHandler.java b/src/dk/wiegand/games/pong/KeyboardHandler.java
new file mode 100644
index 0000000..38f6e88
--- /dev/null
+++ b/src/dk/wiegand/games/pong/KeyboardHandler.java
@@ -0,0 +1,81 @@
+package dk.wiegand.games.pong;
+
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import dk.wiegand.games.pong.Game.PlayerId;
+
+public class KeyboardHandler implements KeyListener {
+
+ private boolean playerAUp, playerADown, playerBUp, playerBDown, serve, playerA, playerB, esc;
+ private boolean keys[] = new boolean[256];
+
+ public boolean up(PlayerId playerId) {
+ switch (playerId) {
+ case A:
+ return playerAUp;
+ case B:
+ return playerBUp;
+ default:
+ return false;
+ }
+ }
+
+ public boolean down(PlayerId playerId) {
+ switch (playerId) {
+ case A:
+ return playerADown;
+ case B:
+ return playerBDown;
+ default:
+ return false;
+ }
+ }
+
+ public PlayerId playerSelected() {
+ if (playerA) {
+ return Game.PlayerId.A;
+ }
+ if (playerB) {
+ return Game.PlayerId.B;
+ }
+ return null;
+ }
+
+ public boolean serve() {
+ return serve;
+ }
+
+ public boolean esc() {
+ return esc;
+ }
+
+ public void tick() {
+ playerA = keys[KeyEvent.VK_LEFT];
+ playerAUp = keys[KeyEvent.VK_A];
+ playerADown = keys[KeyEvent.VK_Z];
+
+ playerB = keys[KeyEvent.VK_RIGHT];
+ playerBUp = keys[KeyEvent.VK_UP];
+ playerBDown = keys[KeyEvent.VK_DOWN];
+
+ serve = keys[KeyEvent.VK_SPACE];
+
+ esc = keys[KeyEvent.VK_ESCAPE];
+ }
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ keys[e.getKeyCode()] = true;
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ keys[e.getKeyCode()] = false;
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/Player.java b/src/dk/wiegand/games/pong/Player.java
new file mode 100644
index 0000000..0cbbc67
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Player.java
@@ -0,0 +1,74 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+import dk.wiegand.games.pong.Game.GameState;
+import dk.wiegand.games.pong.Game.PlayerId;
+
+public class Player {
+ private static final int INDENT = 10;
+ private final Game game;
+ private final PlayerId playerId;
+ public double x;
+ public static final int WIDTH = 10;
+ public static final int HEIGHT = 90;
+ public double y;
+ public static final double SPEED = 10;
+ public int score;
+
+ public Player(final Game game, final PlayerId playerId) {
+ this.game = game;
+ this.playerId = playerId;
+ score = 0;
+ init();
+ }
+
+ public void init() {
+ switch (playerId) {
+ case A:
+ x = INDENT;
+ break;
+ case B:
+ x = game.getTennisCourt().WIDTH - INDENT - WIDTH;
+ break;
+ }
+ this.y = game.getTennisCourt().HEIGHT / 2 - HEIGHT / 2;
+ }
+
+ public PlayerId getPlayerId() {
+ return playerId;
+ }
+
+ public void score() {
+ score++;
+ init();
+ if (score >= Game.GAME_GOLS) {
+ game.changeGameState(GameState.END);
+ game.serve = this;
+ }
+ }
+
+ public void tick() {
+ if (game.getGameState() == GameState.START || game.getGameState() == GameState.RUN) {
+ // Up
+ if (game.getTennisCourt().getKeyboardHandler().up(playerId) && y > 0) {
+ y -= Player.SPEED;
+ }
+ // Down
+ if (game.getTennisCourt().getKeyboardHandler().down(playerId) && y < (game.getTennisCourt().HEIGHT - Player.HEIGHT)) {
+ y += Player.SPEED;
+ }
+ }
+ // Ball follow if serve
+ if (game.serve != null && game.serve.getPlayerId() == playerId) {
+ game.getBall().y = y + Player.HEIGHT / 2 - Ball.SIZE / 2;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillRect((int) x, (int) y, WIDTH, HEIGHT);
+ }
+
+}
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard.class b/bin/dk/wiegand/games/pong/ScoreBoard.class
new file mode 100644
index 0000000..172a18c
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/TennisCourt.class b/bin/dk/wiegand/games/pong/TennisCourt.class
new file mode 100644
index 0000000..119ee76
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/TennisCourt.class
Binary files differ
diff --git a/src/dk/wiegand/games/pong/Ball.java b/src/dk/wiegand/games/pong/Ball.java
new file mode 100644
index 0000000..2841ed8
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Ball.java
@@ -0,0 +1,59 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class Ball {
+ public Game game;
+ public double x;
+ public static final double X_SPEED_DEFAULT = 10;
+ public double xSpeed = X_SPEED_DEFAULT;
+ public double y;
+ public double ySpeed = 0.7;
+ public static final int SIZE = 20;
+
+ public Ball(Game game) {
+ this.game = game;
+ x = game.playerA.x + Player.WIDTH;
+ }
+
+ public void tick() {
+ x += xSpeed;
+ y += ySpeed;
+ // Bounce on top/button
+ if (y > game.getTennisCourt().HEIGHT - Ball.SIZE || y < 0) {
+ ySpeed *= -1;
+ return;
+ }
+ // Out right
+ if (x > game.getTennisCourt().WIDTH - Ball.SIZE) {
+ game.score(game.playerB);
+ return;
+ }
+ // Out left
+ if (x < 0) {
+ game.score(game.playerA);
+ return;
+ }
+ }
+
+ public void toPlayer(Player player) {
+ switch (player.getPlayerId()) {
+ case A:
+ x = game.playerA.x + Player.WIDTH;
+ xSpeed = Ball.X_SPEED_DEFAULT;
+ break;
+ case B:
+ x = game.playerB.x - Ball.SIZE;
+ xSpeed = Ball.X_SPEED_DEFAULT * -1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillOval((int) x, (int) y, Ball.SIZE, Ball.SIZE);
+ }
+}
diff --git a/src/dk/wiegand/games/pong/Game.java b/src/dk/wiegand/games/pong/Game.java
new file mode 100644
index 0000000..27c7714
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Game.java
@@ -0,0 +1,159 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Font;
+import java.awt.Graphics;
+
+public class Game {
+ private final TennisCourt tennisCourt;
+ private ScoreBoard scoreBoard;
+
+ public int touchCount = 0;
+ public static final int TOUCH_CHANGE = 10;
+ public static final double TOUCH_CHANGE_FACTOR = 2;
+ public Player serve;
+ public static final int GAME_GOLS = 5;
+ private GameState gameState;
+
+ public Player playerA;
+ public Player playerB;
+ private Ball ball;
+
+ public Game(final TennisCourt tennisCourt) {
+ this.tennisCourt = tennisCourt;
+ changeGameState(GameState.START);
+ }
+
+ public TennisCourt getTennisCourt() {
+ return tennisCourt;
+ }
+
+ public Ball getBall() {
+ return ball;
+ }
+
+ public void score(Player player) {
+ ball.toPlayer(player);
+ this.serve = player;
+ switch (player.getPlayerId()) {
+ case A:
+ playerB.score();
+ playerA.init();
+ break;
+ case B:
+ playerA.score();
+ playerB.init();
+ break;
+ }
+ }
+
+ public void tick() {
+ tennisCourt.tick();
+ if (gameState == GameState.START) {
+ PlayerId playerSelected = tennisCourt.getKeyboardHandler().playerSelected();
+ if (playerSelected != null) {
+ switch (playerSelected) {
+ case A:
+ ball.toPlayer(serve = playerA);
+ break;
+ case B:
+ ball.toPlayer(serve = playerB);
+ break;
+ default:
+ break;
+ }
+ }
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ changeGameState(GameState.RUN);
+ }
+ }
+ playerA.tick();
+ playerB.tick();
+ if (gameState == GameState.RUN) {
+ // Ball
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ serve = null;
+ }
+ // Ball
+ if (serve == null) {
+ ball.tick();
+ if (Player.WIDTH * 2 >= ball.x && playerA.y <= ball.y && playerA.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ if (tennisCourt.WIDTH - Player.WIDTH * 2 <= ball.x + Ball.SIZE && playerB.y <= ball.y && playerB.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ }
+ }
+ if (gameState == GameState.END) {
+ if (tennisCourt.getKeyboardHandler().esc()) {
+ changeGameState(GameState.START);
+ }
+ }
+ }
+
+ public void render(Graphics graphics) {
+ scoreBoard.render(graphics);
+ playerA.render(graphics);
+ playerB.render(graphics);
+ if (gameState == GameState.START || gameState == GameState.RUN) {
+ ball.render(graphics);
+ }
+ if (gameState == GameState.START) {
+ renderText(graphics, "Pong - the game", tennisCourt.HEIGHT/2 - 50, 50);
+ renderText(graphics, "Select player to server by [left] and [right] arrow", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Player A: Up [a] Down [z]", tennisCourt.HEIGHT/2 + 50, 25);
+ renderText(graphics, "Player B: Up [up] Down [down]", tennisCourt.HEIGHT/2 + 100, 25);
+ renderText(graphics, "Press [space] to serve", tennisCourt.HEIGHT/2 + 150, 25);
+ renderText(graphics, GAME_GOLS + " goals to win", tennisCourt.HEIGHT/2 + 200, 25);
+ }
+ if (gameState == GameState.END) {
+ renderText(graphics, "GAME OVER", tennisCourt.HEIGHT/2 - 50, 50);
+ if (serve != null) renderText(graphics, "Player "+ serve.getPlayerId() +" won!", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Press [escape] to continue", tennisCourt.HEIGHT/2 + 50, 25);
+ }
+ }
+
+ public void renderText(Graphics graphics, String text, int y, double fontsize) {
+ graphics.setFont(new Font("Courier New", Font.PLAIN, (int) fontsize));
+ graphics.drawString(text, (int) (tennisCourt.WIDTH / 2 - (((double) text.length()) / 2 * fontsize / 100 * 120 / 2)), y);
+ }
+
+ public void changeGameState(GameState gameState) {
+ this.gameState = gameState;
+ switch (gameState) {
+ case START:
+ playerA = new Player(this, PlayerId.A);
+ playerB = new Player(this, PlayerId.B);
+ serve = playerA;
+ ball = new Ball(this);
+ scoreBoard = new ScoreBoard(tennisCourt, this);
+ break;
+ case RUN:
+ break;
+ case END:
+ break;
+ default:
+ break;
+ }
+ }
+
+ public GameState getGameState() {
+ return gameState;
+ }
+
+ public enum PlayerId {
+ A, B;
+ }
+
+ public enum GameState {
+ START, RUN, END
+ }
+}
diff --git a/src/dk/wiegand/games/pong/GameEngine.java b/src/dk/wiegand/games/pong/GameEngine.java
new file mode 100644
index 0000000..fb964d9
--- /dev/null
+++ b/src/dk/wiegand/games/pong/GameEngine.java
@@ -0,0 +1,47 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Canvas;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.image.BufferStrategy;
+
+import javax.swing.JFrame;
+
+public abstract class GameEngine {
+ private final int width;
+ private final int height;
+ private final Canvas canvas;
+ private final BufferStrategy bufferStrategy;
+
+ public GameEngine(final int width, final int height) {
+ this.width = width;
+ this.height = height;
+
+ JFrame frame = new JFrame("Pong");
+ // Place frame in center of screen
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ frame.setBounds(screenSize.width / 2 - width / 2, screenSize.height / 2 - height / 2, width, height);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setResizable(false);
+ frame.setVisible(true);
+ // Canvas
+ canvas = new Canvas();
+ canvas.setPreferredSize(new Dimension(width, height));
+ canvas.setMinimumSize(new Dimension(width, height));
+ canvas.setMaximumSize(new Dimension(width, height));
+ canvas.setFocusable(false);
+ frame.add(canvas);
+ frame.pack();
+ canvas.createBufferStrategy(3);
+ bufferStrategy = canvas.getBufferStrategy();
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/KeyboardHandler.java b/src/dk/wiegand/games/pong/KeyboardHandler.java
new file mode 100644
index 0000000..38f6e88
--- /dev/null
+++ b/src/dk/wiegand/games/pong/KeyboardHandler.java
@@ -0,0 +1,81 @@
+package dk.wiegand.games.pong;
+
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import dk.wiegand.games.pong.Game.PlayerId;
+
+public class KeyboardHandler implements KeyListener {
+
+ private boolean playerAUp, playerADown, playerBUp, playerBDown, serve, playerA, playerB, esc;
+ private boolean keys[] = new boolean[256];
+
+ public boolean up(PlayerId playerId) {
+ switch (playerId) {
+ case A:
+ return playerAUp;
+ case B:
+ return playerBUp;
+ default:
+ return false;
+ }
+ }
+
+ public boolean down(PlayerId playerId) {
+ switch (playerId) {
+ case A:
+ return playerADown;
+ case B:
+ return playerBDown;
+ default:
+ return false;
+ }
+ }
+
+ public PlayerId playerSelected() {
+ if (playerA) {
+ return Game.PlayerId.A;
+ }
+ if (playerB) {
+ return Game.PlayerId.B;
+ }
+ return null;
+ }
+
+ public boolean serve() {
+ return serve;
+ }
+
+ public boolean esc() {
+ return esc;
+ }
+
+ public void tick() {
+ playerA = keys[KeyEvent.VK_LEFT];
+ playerAUp = keys[KeyEvent.VK_A];
+ playerADown = keys[KeyEvent.VK_Z];
+
+ playerB = keys[KeyEvent.VK_RIGHT];
+ playerBUp = keys[KeyEvent.VK_UP];
+ playerBDown = keys[KeyEvent.VK_DOWN];
+
+ serve = keys[KeyEvent.VK_SPACE];
+
+ esc = keys[KeyEvent.VK_ESCAPE];
+ }
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ keys[e.getKeyCode()] = true;
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ keys[e.getKeyCode()] = false;
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/Player.java b/src/dk/wiegand/games/pong/Player.java
new file mode 100644
index 0000000..0cbbc67
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Player.java
@@ -0,0 +1,74 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+import dk.wiegand.games.pong.Game.GameState;
+import dk.wiegand.games.pong.Game.PlayerId;
+
+public class Player {
+ private static final int INDENT = 10;
+ private final Game game;
+ private final PlayerId playerId;
+ public double x;
+ public static final int WIDTH = 10;
+ public static final int HEIGHT = 90;
+ public double y;
+ public static final double SPEED = 10;
+ public int score;
+
+ public Player(final Game game, final PlayerId playerId) {
+ this.game = game;
+ this.playerId = playerId;
+ score = 0;
+ init();
+ }
+
+ public void init() {
+ switch (playerId) {
+ case A:
+ x = INDENT;
+ break;
+ case B:
+ x = game.getTennisCourt().WIDTH - INDENT - WIDTH;
+ break;
+ }
+ this.y = game.getTennisCourt().HEIGHT / 2 - HEIGHT / 2;
+ }
+
+ public PlayerId getPlayerId() {
+ return playerId;
+ }
+
+ public void score() {
+ score++;
+ init();
+ if (score >= Game.GAME_GOLS) {
+ game.changeGameState(GameState.END);
+ game.serve = this;
+ }
+ }
+
+ public void tick() {
+ if (game.getGameState() == GameState.START || game.getGameState() == GameState.RUN) {
+ // Up
+ if (game.getTennisCourt().getKeyboardHandler().up(playerId) && y > 0) {
+ y -= Player.SPEED;
+ }
+ // Down
+ if (game.getTennisCourt().getKeyboardHandler().down(playerId) && y < (game.getTennisCourt().HEIGHT - Player.HEIGHT)) {
+ y += Player.SPEED;
+ }
+ }
+ // Ball follow if serve
+ if (game.serve != null && game.serve.getPlayerId() == playerId) {
+ game.getBall().y = y + Player.HEIGHT / 2 - Ball.SIZE / 2;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillRect((int) x, (int) y, WIDTH, HEIGHT);
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/Pong.java b/src/dk/wiegand/games/pong/Pong.java
new file mode 100644
index 0000000..00132a6
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Pong.java
@@ -0,0 +1,65 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Graphics;
+
+public class Pong implements Runnable {
+ private static final long FRAMES_PER_SECOND = 1000 / 30;
+
+ private TennisCourt tennisCourt;
+
+ private boolean running = false;
+
+ private Game game;
+
+ public static void main(String[] args) {
+ Pong pong = new Pong();
+ pong.start();
+ }
+
+ private void init() {
+ tennisCourt = new TennisCourt(1024, 768);
+ game = new Game(tennisCourt);
+ }
+
+ private void tick() {
+ game.tick();
+ }
+
+ private void render() {
+ Graphics graphics = tennisCourt.getGraphics();
+
+ tennisCourt.render(graphics);
+ game.render(graphics);
+
+ tennisCourt.showGraphics();
+ graphics.dispose();
+ }
+
+ @Override
+ public void run() {
+ init();
+ long delta;
+ while (running) {
+ long start = System.currentTimeMillis();
+ tick();
+ render();
+ if ((delta = (FRAMES_PER_SECOND - (System.currentTimeMillis() - start))) > 0) {
+ try {
+ Thread.sleep(delta);
+ } catch (InterruptedException e) {
+ System.out.println("Can't sleep!");
+ }
+ }
+ }
+ }
+
+ public synchronized void start() {
+ if (running) {
+ return;
+ }
+ running = true;
+ Thread thread = new Thread(this);
+ thread.start();
+ }
+
+}
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard.class b/bin/dk/wiegand/games/pong/ScoreBoard.class
new file mode 100644
index 0000000..172a18c
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/TennisCourt.class b/bin/dk/wiegand/games/pong/TennisCourt.class
new file mode 100644
index 0000000..119ee76
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/TennisCourt.class
Binary files differ
diff --git a/src/dk/wiegand/games/pong/Ball.java b/src/dk/wiegand/games/pong/Ball.java
new file mode 100644
index 0000000..2841ed8
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Ball.java
@@ -0,0 +1,59 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class Ball {
+ public Game game;
+ public double x;
+ public static final double X_SPEED_DEFAULT = 10;
+ public double xSpeed = X_SPEED_DEFAULT;
+ public double y;
+ public double ySpeed = 0.7;
+ public static final int SIZE = 20;
+
+ public Ball(Game game) {
+ this.game = game;
+ x = game.playerA.x + Player.WIDTH;
+ }
+
+ public void tick() {
+ x += xSpeed;
+ y += ySpeed;
+ // Bounce on top/button
+ if (y > game.getTennisCourt().HEIGHT - Ball.SIZE || y < 0) {
+ ySpeed *= -1;
+ return;
+ }
+ // Out right
+ if (x > game.getTennisCourt().WIDTH - Ball.SIZE) {
+ game.score(game.playerB);
+ return;
+ }
+ // Out left
+ if (x < 0) {
+ game.score(game.playerA);
+ return;
+ }
+ }
+
+ public void toPlayer(Player player) {
+ switch (player.getPlayerId()) {
+ case A:
+ x = game.playerA.x + Player.WIDTH;
+ xSpeed = Ball.X_SPEED_DEFAULT;
+ break;
+ case B:
+ x = game.playerB.x - Ball.SIZE;
+ xSpeed = Ball.X_SPEED_DEFAULT * -1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillOval((int) x, (int) y, Ball.SIZE, Ball.SIZE);
+ }
+}
diff --git a/src/dk/wiegand/games/pong/Game.java b/src/dk/wiegand/games/pong/Game.java
new file mode 100644
index 0000000..27c7714
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Game.java
@@ -0,0 +1,159 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Font;
+import java.awt.Graphics;
+
+public class Game {
+ private final TennisCourt tennisCourt;
+ private ScoreBoard scoreBoard;
+
+ public int touchCount = 0;
+ public static final int TOUCH_CHANGE = 10;
+ public static final double TOUCH_CHANGE_FACTOR = 2;
+ public Player serve;
+ public static final int GAME_GOLS = 5;
+ private GameState gameState;
+
+ public Player playerA;
+ public Player playerB;
+ private Ball ball;
+
+ public Game(final TennisCourt tennisCourt) {
+ this.tennisCourt = tennisCourt;
+ changeGameState(GameState.START);
+ }
+
+ public TennisCourt getTennisCourt() {
+ return tennisCourt;
+ }
+
+ public Ball getBall() {
+ return ball;
+ }
+
+ public void score(Player player) {
+ ball.toPlayer(player);
+ this.serve = player;
+ switch (player.getPlayerId()) {
+ case A:
+ playerB.score();
+ playerA.init();
+ break;
+ case B:
+ playerA.score();
+ playerB.init();
+ break;
+ }
+ }
+
+ public void tick() {
+ tennisCourt.tick();
+ if (gameState == GameState.START) {
+ PlayerId playerSelected = tennisCourt.getKeyboardHandler().playerSelected();
+ if (playerSelected != null) {
+ switch (playerSelected) {
+ case A:
+ ball.toPlayer(serve = playerA);
+ break;
+ case B:
+ ball.toPlayer(serve = playerB);
+ break;
+ default:
+ break;
+ }
+ }
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ changeGameState(GameState.RUN);
+ }
+ }
+ playerA.tick();
+ playerB.tick();
+ if (gameState == GameState.RUN) {
+ // Ball
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ serve = null;
+ }
+ // Ball
+ if (serve == null) {
+ ball.tick();
+ if (Player.WIDTH * 2 >= ball.x && playerA.y <= ball.y && playerA.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ if (tennisCourt.WIDTH - Player.WIDTH * 2 <= ball.x + Ball.SIZE && playerB.y <= ball.y && playerB.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ }
+ }
+ if (gameState == GameState.END) {
+ if (tennisCourt.getKeyboardHandler().esc()) {
+ changeGameState(GameState.START);
+ }
+ }
+ }
+
+ public void render(Graphics graphics) {
+ scoreBoard.render(graphics);
+ playerA.render(graphics);
+ playerB.render(graphics);
+ if (gameState == GameState.START || gameState == GameState.RUN) {
+ ball.render(graphics);
+ }
+ if (gameState == GameState.START) {
+ renderText(graphics, "Pong - the game", tennisCourt.HEIGHT/2 - 50, 50);
+ renderText(graphics, "Select player to server by [left] and [right] arrow", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Player A: Up [a] Down [z]", tennisCourt.HEIGHT/2 + 50, 25);
+ renderText(graphics, "Player B: Up [up] Down [down]", tennisCourt.HEIGHT/2 + 100, 25);
+ renderText(graphics, "Press [space] to serve", tennisCourt.HEIGHT/2 + 150, 25);
+ renderText(graphics, GAME_GOLS + " goals to win", tennisCourt.HEIGHT/2 + 200, 25);
+ }
+ if (gameState == GameState.END) {
+ renderText(graphics, "GAME OVER", tennisCourt.HEIGHT/2 - 50, 50);
+ if (serve != null) renderText(graphics, "Player "+ serve.getPlayerId() +" won!", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Press [escape] to continue", tennisCourt.HEIGHT/2 + 50, 25);
+ }
+ }
+
+ public void renderText(Graphics graphics, String text, int y, double fontsize) {
+ graphics.setFont(new Font("Courier New", Font.PLAIN, (int) fontsize));
+ graphics.drawString(text, (int) (tennisCourt.WIDTH / 2 - (((double) text.length()) / 2 * fontsize / 100 * 120 / 2)), y);
+ }
+
+ public void changeGameState(GameState gameState) {
+ this.gameState = gameState;
+ switch (gameState) {
+ case START:
+ playerA = new Player(this, PlayerId.A);
+ playerB = new Player(this, PlayerId.B);
+ serve = playerA;
+ ball = new Ball(this);
+ scoreBoard = new ScoreBoard(tennisCourt, this);
+ break;
+ case RUN:
+ break;
+ case END:
+ break;
+ default:
+ break;
+ }
+ }
+
+ public GameState getGameState() {
+ return gameState;
+ }
+
+ public enum PlayerId {
+ A, B;
+ }
+
+ public enum GameState {
+ START, RUN, END
+ }
+}
diff --git a/src/dk/wiegand/games/pong/GameEngine.java b/src/dk/wiegand/games/pong/GameEngine.java
new file mode 100644
index 0000000..fb964d9
--- /dev/null
+++ b/src/dk/wiegand/games/pong/GameEngine.java
@@ -0,0 +1,47 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Canvas;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.image.BufferStrategy;
+
+import javax.swing.JFrame;
+
+public abstract class GameEngine {
+ private final int width;
+ private final int height;
+ private final Canvas canvas;
+ private final BufferStrategy bufferStrategy;
+
+ public GameEngine(final int width, final int height) {
+ this.width = width;
+ this.height = height;
+
+ JFrame frame = new JFrame("Pong");
+ // Place frame in center of screen
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ frame.setBounds(screenSize.width / 2 - width / 2, screenSize.height / 2 - height / 2, width, height);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setResizable(false);
+ frame.setVisible(true);
+ // Canvas
+ canvas = new Canvas();
+ canvas.setPreferredSize(new Dimension(width, height));
+ canvas.setMinimumSize(new Dimension(width, height));
+ canvas.setMaximumSize(new Dimension(width, height));
+ canvas.setFocusable(false);
+ frame.add(canvas);
+ frame.pack();
+ canvas.createBufferStrategy(3);
+ bufferStrategy = canvas.getBufferStrategy();
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/KeyboardHandler.java b/src/dk/wiegand/games/pong/KeyboardHandler.java
new file mode 100644
index 0000000..38f6e88
--- /dev/null
+++ b/src/dk/wiegand/games/pong/KeyboardHandler.java
@@ -0,0 +1,81 @@
+package dk.wiegand.games.pong;
+
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import dk.wiegand.games.pong.Game.PlayerId;
+
+public class KeyboardHandler implements KeyListener {
+
+ private boolean playerAUp, playerADown, playerBUp, playerBDown, serve, playerA, playerB, esc;
+ private boolean keys[] = new boolean[256];
+
+ public boolean up(PlayerId playerId) {
+ switch (playerId) {
+ case A:
+ return playerAUp;
+ case B:
+ return playerBUp;
+ default:
+ return false;
+ }
+ }
+
+ public boolean down(PlayerId playerId) {
+ switch (playerId) {
+ case A:
+ return playerADown;
+ case B:
+ return playerBDown;
+ default:
+ return false;
+ }
+ }
+
+ public PlayerId playerSelected() {
+ if (playerA) {
+ return Game.PlayerId.A;
+ }
+ if (playerB) {
+ return Game.PlayerId.B;
+ }
+ return null;
+ }
+
+ public boolean serve() {
+ return serve;
+ }
+
+ public boolean esc() {
+ return esc;
+ }
+
+ public void tick() {
+ playerA = keys[KeyEvent.VK_LEFT];
+ playerAUp = keys[KeyEvent.VK_A];
+ playerADown = keys[KeyEvent.VK_Z];
+
+ playerB = keys[KeyEvent.VK_RIGHT];
+ playerBUp = keys[KeyEvent.VK_UP];
+ playerBDown = keys[KeyEvent.VK_DOWN];
+
+ serve = keys[KeyEvent.VK_SPACE];
+
+ esc = keys[KeyEvent.VK_ESCAPE];
+ }
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ keys[e.getKeyCode()] = true;
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ keys[e.getKeyCode()] = false;
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/Player.java b/src/dk/wiegand/games/pong/Player.java
new file mode 100644
index 0000000..0cbbc67
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Player.java
@@ -0,0 +1,74 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+import dk.wiegand.games.pong.Game.GameState;
+import dk.wiegand.games.pong.Game.PlayerId;
+
+public class Player {
+ private static final int INDENT = 10;
+ private final Game game;
+ private final PlayerId playerId;
+ public double x;
+ public static final int WIDTH = 10;
+ public static final int HEIGHT = 90;
+ public double y;
+ public static final double SPEED = 10;
+ public int score;
+
+ public Player(final Game game, final PlayerId playerId) {
+ this.game = game;
+ this.playerId = playerId;
+ score = 0;
+ init();
+ }
+
+ public void init() {
+ switch (playerId) {
+ case A:
+ x = INDENT;
+ break;
+ case B:
+ x = game.getTennisCourt().WIDTH - INDENT - WIDTH;
+ break;
+ }
+ this.y = game.getTennisCourt().HEIGHT / 2 - HEIGHT / 2;
+ }
+
+ public PlayerId getPlayerId() {
+ return playerId;
+ }
+
+ public void score() {
+ score++;
+ init();
+ if (score >= Game.GAME_GOLS) {
+ game.changeGameState(GameState.END);
+ game.serve = this;
+ }
+ }
+
+ public void tick() {
+ if (game.getGameState() == GameState.START || game.getGameState() == GameState.RUN) {
+ // Up
+ if (game.getTennisCourt().getKeyboardHandler().up(playerId) && y > 0) {
+ y -= Player.SPEED;
+ }
+ // Down
+ if (game.getTennisCourt().getKeyboardHandler().down(playerId) && y < (game.getTennisCourt().HEIGHT - Player.HEIGHT)) {
+ y += Player.SPEED;
+ }
+ }
+ // Ball follow if serve
+ if (game.serve != null && game.serve.getPlayerId() == playerId) {
+ game.getBall().y = y + Player.HEIGHT / 2 - Ball.SIZE / 2;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillRect((int) x, (int) y, WIDTH, HEIGHT);
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/Pong.java b/src/dk/wiegand/games/pong/Pong.java
new file mode 100644
index 0000000..00132a6
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Pong.java
@@ -0,0 +1,65 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Graphics;
+
+public class Pong implements Runnable {
+ private static final long FRAMES_PER_SECOND = 1000 / 30;
+
+ private TennisCourt tennisCourt;
+
+ private boolean running = false;
+
+ private Game game;
+
+ public static void main(String[] args) {
+ Pong pong = new Pong();
+ pong.start();
+ }
+
+ private void init() {
+ tennisCourt = new TennisCourt(1024, 768);
+ game = new Game(tennisCourt);
+ }
+
+ private void tick() {
+ game.tick();
+ }
+
+ private void render() {
+ Graphics graphics = tennisCourt.getGraphics();
+
+ tennisCourt.render(graphics);
+ game.render(graphics);
+
+ tennisCourt.showGraphics();
+ graphics.dispose();
+ }
+
+ @Override
+ public void run() {
+ init();
+ long delta;
+ while (running) {
+ long start = System.currentTimeMillis();
+ tick();
+ render();
+ if ((delta = (FRAMES_PER_SECOND - (System.currentTimeMillis() - start))) > 0) {
+ try {
+ Thread.sleep(delta);
+ } catch (InterruptedException e) {
+ System.out.println("Can't sleep!");
+ }
+ }
+ }
+ }
+
+ public synchronized void start() {
+ if (running) {
+ return;
+ }
+ running = true;
+ Thread thread = new Thread(this);
+ thread.start();
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/ScoreBoard.java b/src/dk/wiegand/games/pong/ScoreBoard.java
new file mode 100644
index 0000000..fd9ea39
--- /dev/null
+++ b/src/dk/wiegand/games/pong/ScoreBoard.java
@@ -0,0 +1,80 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class ScoreBoard {
+ private static final int THIKNESS = 11;
+ private static final int FONT_SIZE = 110;
+
+ private final TennisCourt tennisCourt;
+ private final Game game;
+
+ public ScoreBoard(final TennisCourt tennisCourt, final Game game) {
+ this.tennisCourt = tennisCourt;
+ this.game = game;
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ Segment7 segment7 = new Segment7(FONT_SIZE, THIKNESS);
+ segment7.render(graphics, tennisCourt.WIDTH/2 - (FONT_SIZE/2+THIKNESS), THIKNESS, game.playerA.score);
+ segment7.render(graphics, tennisCourt.WIDTH/2 + THIKNESS, THIKNESS, game.playerB.score);
+ }
+
+ private class Segment7 {
+
+ private final Segment[] s7 = new Segment[7];
+
+ public Segment7(int fontSize, int thikness) {
+ s7[0] = new Segment(0, 0, fontSize/2, thikness);
+ s7[1] = new Segment(fontSize/2-thikness, 0, thikness, fontSize/2);
+ s7[2] = new Segment(fontSize/2-thikness, fontSize/2, thikness, fontSize/2);
+ s7[3] = new Segment(0, fontSize-thikness, fontSize/2, thikness);
+ s7[4] = new Segment(0, fontSize/2, thikness, fontSize/2);
+ s7[5] = new Segment(0, 0, thikness, fontSize/2);
+ s7[6] = new Segment(0, fontSize/2-(thikness/2), fontSize/2, thikness);
+ }
+
+ private boolean[][] numbers = {
+ { true, true, true, true, true, true, false },
+ { false, true, true, false, false, false, false },
+ { true, true, false, true, true, false, true },
+ { true, true, true, true, false, false, true },
+ { false, true, true, false, false, true, true },
+ { true, false, true, true, false, true, true },
+ { true, false, true, true, true, true, true },
+ { true, true, true, false, false, false, false },
+ { true, true, true, true, true, true, true },
+ { true, true, true, false, false, true, true }
+ };
+
+ public void render(Graphics graphics, int offsetX, int offsetY, int score) {
+ boolean[] number = numbers[score];
+ for (int i = 0; i < 7; i++) {
+ if (number[i]) {
+ s7[i].render(graphics, offsetX, offsetY);
+ }
+ }
+ }
+ }
+
+ private class Segment {
+ private int x;
+ private int y;
+ private int width;
+ private int height;
+
+ public Segment(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+ public void render(Graphics graphics, int offsetX, int offsetY) {
+ graphics.fillRect(offsetX + x, offsetY + y, width, height);
+ }
+ }
+
+}
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..930a957
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ pong-game
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bin/dk/wiegand/games/pong/Ball.class b/bin/dk/wiegand/games/pong/Ball.class
new file mode 100644
index 0000000..1a85c99
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Ball.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$GameState.class b/bin/dk/wiegand/games/pong/Game$GameState.class
new file mode 100644
index 0000000..8d0ce8e
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$GameState.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game$PlayerId.class b/bin/dk/wiegand/games/pong/Game$PlayerId.class
new file mode 100644
index 0000000..e8b45ae
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game$PlayerId.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Game.class b/bin/dk/wiegand/games/pong/Game.class
new file mode 100644
index 0000000..9399dbd
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Game.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/GameEngine.class b/bin/dk/wiegand/games/pong/GameEngine.class
new file mode 100644
index 0000000..bb44bcf
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/GameEngine.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/KeyboardHandler.class b/bin/dk/wiegand/games/pong/KeyboardHandler.class
new file mode 100644
index 0000000..17c98ec
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/KeyboardHandler.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Player.class b/bin/dk/wiegand/games/pong/Player.class
new file mode 100644
index 0000000..a532b7a
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Player.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/Pong.class b/bin/dk/wiegand/games/pong/Pong.class
new file mode 100644
index 0000000..4eab229
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/Pong.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
new file mode 100644
index 0000000..0f5d29d
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
new file mode 100644
index 0000000..8c0c831
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard$Segment7.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/ScoreBoard.class b/bin/dk/wiegand/games/pong/ScoreBoard.class
new file mode 100644
index 0000000..172a18c
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/ScoreBoard.class
Binary files differ
diff --git a/bin/dk/wiegand/games/pong/TennisCourt.class b/bin/dk/wiegand/games/pong/TennisCourt.class
new file mode 100644
index 0000000..119ee76
--- /dev/null
+++ b/bin/dk/wiegand/games/pong/TennisCourt.class
Binary files differ
diff --git a/src/dk/wiegand/games/pong/Ball.java b/src/dk/wiegand/games/pong/Ball.java
new file mode 100644
index 0000000..2841ed8
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Ball.java
@@ -0,0 +1,59 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class Ball {
+ public Game game;
+ public double x;
+ public static final double X_SPEED_DEFAULT = 10;
+ public double xSpeed = X_SPEED_DEFAULT;
+ public double y;
+ public double ySpeed = 0.7;
+ public static final int SIZE = 20;
+
+ public Ball(Game game) {
+ this.game = game;
+ x = game.playerA.x + Player.WIDTH;
+ }
+
+ public void tick() {
+ x += xSpeed;
+ y += ySpeed;
+ // Bounce on top/button
+ if (y > game.getTennisCourt().HEIGHT - Ball.SIZE || y < 0) {
+ ySpeed *= -1;
+ return;
+ }
+ // Out right
+ if (x > game.getTennisCourt().WIDTH - Ball.SIZE) {
+ game.score(game.playerB);
+ return;
+ }
+ // Out left
+ if (x < 0) {
+ game.score(game.playerA);
+ return;
+ }
+ }
+
+ public void toPlayer(Player player) {
+ switch (player.getPlayerId()) {
+ case A:
+ x = game.playerA.x + Player.WIDTH;
+ xSpeed = Ball.X_SPEED_DEFAULT;
+ break;
+ case B:
+ x = game.playerB.x - Ball.SIZE;
+ xSpeed = Ball.X_SPEED_DEFAULT * -1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillOval((int) x, (int) y, Ball.SIZE, Ball.SIZE);
+ }
+}
diff --git a/src/dk/wiegand/games/pong/Game.java b/src/dk/wiegand/games/pong/Game.java
new file mode 100644
index 0000000..27c7714
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Game.java
@@ -0,0 +1,159 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Font;
+import java.awt.Graphics;
+
+public class Game {
+ private final TennisCourt tennisCourt;
+ private ScoreBoard scoreBoard;
+
+ public int touchCount = 0;
+ public static final int TOUCH_CHANGE = 10;
+ public static final double TOUCH_CHANGE_FACTOR = 2;
+ public Player serve;
+ public static final int GAME_GOLS = 5;
+ private GameState gameState;
+
+ public Player playerA;
+ public Player playerB;
+ private Ball ball;
+
+ public Game(final TennisCourt tennisCourt) {
+ this.tennisCourt = tennisCourt;
+ changeGameState(GameState.START);
+ }
+
+ public TennisCourt getTennisCourt() {
+ return tennisCourt;
+ }
+
+ public Ball getBall() {
+ return ball;
+ }
+
+ public void score(Player player) {
+ ball.toPlayer(player);
+ this.serve = player;
+ switch (player.getPlayerId()) {
+ case A:
+ playerB.score();
+ playerA.init();
+ break;
+ case B:
+ playerA.score();
+ playerB.init();
+ break;
+ }
+ }
+
+ public void tick() {
+ tennisCourt.tick();
+ if (gameState == GameState.START) {
+ PlayerId playerSelected = tennisCourt.getKeyboardHandler().playerSelected();
+ if (playerSelected != null) {
+ switch (playerSelected) {
+ case A:
+ ball.toPlayer(serve = playerA);
+ break;
+ case B:
+ ball.toPlayer(serve = playerB);
+ break;
+ default:
+ break;
+ }
+ }
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ changeGameState(GameState.RUN);
+ }
+ }
+ playerA.tick();
+ playerB.tick();
+ if (gameState == GameState.RUN) {
+ // Ball
+ if (tennisCourt.getKeyboardHandler().serve()) {
+ serve = null;
+ }
+ // Ball
+ if (serve == null) {
+ ball.tick();
+ if (Player.WIDTH * 2 >= ball.x && playerA.y <= ball.y && playerA.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ if (tennisCourt.WIDTH - Player.WIDTH * 2 <= ball.x + Ball.SIZE && playerB.y <= ball.y && playerB.y + Player.HEIGHT >= ball.y) {
+ ball.xSpeed *= -1;
+ touchCount++;
+ if (touchCount > 0 && touchCount % Game.TOUCH_CHANGE == 0) {
+ ball.xSpeed *= Game.TOUCH_CHANGE_FACTOR;
+ }
+ }
+ }
+ }
+ if (gameState == GameState.END) {
+ if (tennisCourt.getKeyboardHandler().esc()) {
+ changeGameState(GameState.START);
+ }
+ }
+ }
+
+ public void render(Graphics graphics) {
+ scoreBoard.render(graphics);
+ playerA.render(graphics);
+ playerB.render(graphics);
+ if (gameState == GameState.START || gameState == GameState.RUN) {
+ ball.render(graphics);
+ }
+ if (gameState == GameState.START) {
+ renderText(graphics, "Pong - the game", tennisCourt.HEIGHT/2 - 50, 50);
+ renderText(graphics, "Select player to server by [left] and [right] arrow", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Player A: Up [a] Down [z]", tennisCourt.HEIGHT/2 + 50, 25);
+ renderText(graphics, "Player B: Up [up] Down [down]", tennisCourt.HEIGHT/2 + 100, 25);
+ renderText(graphics, "Press [space] to serve", tennisCourt.HEIGHT/2 + 150, 25);
+ renderText(graphics, GAME_GOLS + " goals to win", tennisCourt.HEIGHT/2 + 200, 25);
+ }
+ if (gameState == GameState.END) {
+ renderText(graphics, "GAME OVER", tennisCourt.HEIGHT/2 - 50, 50);
+ if (serve != null) renderText(graphics, "Player "+ serve.getPlayerId() +" won!", tennisCourt.HEIGHT/2, 25);
+ renderText(graphics, "Press [escape] to continue", tennisCourt.HEIGHT/2 + 50, 25);
+ }
+ }
+
+ public void renderText(Graphics graphics, String text, int y, double fontsize) {
+ graphics.setFont(new Font("Courier New", Font.PLAIN, (int) fontsize));
+ graphics.drawString(text, (int) (tennisCourt.WIDTH / 2 - (((double) text.length()) / 2 * fontsize / 100 * 120 / 2)), y);
+ }
+
+ public void changeGameState(GameState gameState) {
+ this.gameState = gameState;
+ switch (gameState) {
+ case START:
+ playerA = new Player(this, PlayerId.A);
+ playerB = new Player(this, PlayerId.B);
+ serve = playerA;
+ ball = new Ball(this);
+ scoreBoard = new ScoreBoard(tennisCourt, this);
+ break;
+ case RUN:
+ break;
+ case END:
+ break;
+ default:
+ break;
+ }
+ }
+
+ public GameState getGameState() {
+ return gameState;
+ }
+
+ public enum PlayerId {
+ A, B;
+ }
+
+ public enum GameState {
+ START, RUN, END
+ }
+}
diff --git a/src/dk/wiegand/games/pong/GameEngine.java b/src/dk/wiegand/games/pong/GameEngine.java
new file mode 100644
index 0000000..fb964d9
--- /dev/null
+++ b/src/dk/wiegand/games/pong/GameEngine.java
@@ -0,0 +1,47 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Canvas;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.image.BufferStrategy;
+
+import javax.swing.JFrame;
+
+public abstract class GameEngine {
+ private final int width;
+ private final int height;
+ private final Canvas canvas;
+ private final BufferStrategy bufferStrategy;
+
+ public GameEngine(final int width, final int height) {
+ this.width = width;
+ this.height = height;
+
+ JFrame frame = new JFrame("Pong");
+ // Place frame in center of screen
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ frame.setBounds(screenSize.width / 2 - width / 2, screenSize.height / 2 - height / 2, width, height);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setResizable(false);
+ frame.setVisible(true);
+ // Canvas
+ canvas = new Canvas();
+ canvas.setPreferredSize(new Dimension(width, height));
+ canvas.setMinimumSize(new Dimension(width, height));
+ canvas.setMaximumSize(new Dimension(width, height));
+ canvas.setFocusable(false);
+ frame.add(canvas);
+ frame.pack();
+ canvas.createBufferStrategy(3);
+ bufferStrategy = canvas.getBufferStrategy();
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/KeyboardHandler.java b/src/dk/wiegand/games/pong/KeyboardHandler.java
new file mode 100644
index 0000000..38f6e88
--- /dev/null
+++ b/src/dk/wiegand/games/pong/KeyboardHandler.java
@@ -0,0 +1,81 @@
+package dk.wiegand.games.pong;
+
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import dk.wiegand.games.pong.Game.PlayerId;
+
+public class KeyboardHandler implements KeyListener {
+
+ private boolean playerAUp, playerADown, playerBUp, playerBDown, serve, playerA, playerB, esc;
+ private boolean keys[] = new boolean[256];
+
+ public boolean up(PlayerId playerId) {
+ switch (playerId) {
+ case A:
+ return playerAUp;
+ case B:
+ return playerBUp;
+ default:
+ return false;
+ }
+ }
+
+ public boolean down(PlayerId playerId) {
+ switch (playerId) {
+ case A:
+ return playerADown;
+ case B:
+ return playerBDown;
+ default:
+ return false;
+ }
+ }
+
+ public PlayerId playerSelected() {
+ if (playerA) {
+ return Game.PlayerId.A;
+ }
+ if (playerB) {
+ return Game.PlayerId.B;
+ }
+ return null;
+ }
+
+ public boolean serve() {
+ return serve;
+ }
+
+ public boolean esc() {
+ return esc;
+ }
+
+ public void tick() {
+ playerA = keys[KeyEvent.VK_LEFT];
+ playerAUp = keys[KeyEvent.VK_A];
+ playerADown = keys[KeyEvent.VK_Z];
+
+ playerB = keys[KeyEvent.VK_RIGHT];
+ playerBUp = keys[KeyEvent.VK_UP];
+ playerBDown = keys[KeyEvent.VK_DOWN];
+
+ serve = keys[KeyEvent.VK_SPACE];
+
+ esc = keys[KeyEvent.VK_ESCAPE];
+ }
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ keys[e.getKeyCode()] = true;
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ keys[e.getKeyCode()] = false;
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/Player.java b/src/dk/wiegand/games/pong/Player.java
new file mode 100644
index 0000000..0cbbc67
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Player.java
@@ -0,0 +1,74 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+import dk.wiegand.games.pong.Game.GameState;
+import dk.wiegand.games.pong.Game.PlayerId;
+
+public class Player {
+ private static final int INDENT = 10;
+ private final Game game;
+ private final PlayerId playerId;
+ public double x;
+ public static final int WIDTH = 10;
+ public static final int HEIGHT = 90;
+ public double y;
+ public static final double SPEED = 10;
+ public int score;
+
+ public Player(final Game game, final PlayerId playerId) {
+ this.game = game;
+ this.playerId = playerId;
+ score = 0;
+ init();
+ }
+
+ public void init() {
+ switch (playerId) {
+ case A:
+ x = INDENT;
+ break;
+ case B:
+ x = game.getTennisCourt().WIDTH - INDENT - WIDTH;
+ break;
+ }
+ this.y = game.getTennisCourt().HEIGHT / 2 - HEIGHT / 2;
+ }
+
+ public PlayerId getPlayerId() {
+ return playerId;
+ }
+
+ public void score() {
+ score++;
+ init();
+ if (score >= Game.GAME_GOLS) {
+ game.changeGameState(GameState.END);
+ game.serve = this;
+ }
+ }
+
+ public void tick() {
+ if (game.getGameState() == GameState.START || game.getGameState() == GameState.RUN) {
+ // Up
+ if (game.getTennisCourt().getKeyboardHandler().up(playerId) && y > 0) {
+ y -= Player.SPEED;
+ }
+ // Down
+ if (game.getTennisCourt().getKeyboardHandler().down(playerId) && y < (game.getTennisCourt().HEIGHT - Player.HEIGHT)) {
+ y += Player.SPEED;
+ }
+ }
+ // Ball follow if serve
+ if (game.serve != null && game.serve.getPlayerId() == playerId) {
+ game.getBall().y = y + Player.HEIGHT / 2 - Ball.SIZE / 2;
+ }
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ graphics.fillRect((int) x, (int) y, WIDTH, HEIGHT);
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/Pong.java b/src/dk/wiegand/games/pong/Pong.java
new file mode 100644
index 0000000..00132a6
--- /dev/null
+++ b/src/dk/wiegand/games/pong/Pong.java
@@ -0,0 +1,65 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Graphics;
+
+public class Pong implements Runnable {
+ private static final long FRAMES_PER_SECOND = 1000 / 30;
+
+ private TennisCourt tennisCourt;
+
+ private boolean running = false;
+
+ private Game game;
+
+ public static void main(String[] args) {
+ Pong pong = new Pong();
+ pong.start();
+ }
+
+ private void init() {
+ tennisCourt = new TennisCourt(1024, 768);
+ game = new Game(tennisCourt);
+ }
+
+ private void tick() {
+ game.tick();
+ }
+
+ private void render() {
+ Graphics graphics = tennisCourt.getGraphics();
+
+ tennisCourt.render(graphics);
+ game.render(graphics);
+
+ tennisCourt.showGraphics();
+ graphics.dispose();
+ }
+
+ @Override
+ public void run() {
+ init();
+ long delta;
+ while (running) {
+ long start = System.currentTimeMillis();
+ tick();
+ render();
+ if ((delta = (FRAMES_PER_SECOND - (System.currentTimeMillis() - start))) > 0) {
+ try {
+ Thread.sleep(delta);
+ } catch (InterruptedException e) {
+ System.out.println("Can't sleep!");
+ }
+ }
+ }
+ }
+
+ public synchronized void start() {
+ if (running) {
+ return;
+ }
+ running = true;
+ Thread thread = new Thread(this);
+ thread.start();
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/ScoreBoard.java b/src/dk/wiegand/games/pong/ScoreBoard.java
new file mode 100644
index 0000000..fd9ea39
--- /dev/null
+++ b/src/dk/wiegand/games/pong/ScoreBoard.java
@@ -0,0 +1,80 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class ScoreBoard {
+ private static final int THIKNESS = 11;
+ private static final int FONT_SIZE = 110;
+
+ private final TennisCourt tennisCourt;
+ private final Game game;
+
+ public ScoreBoard(final TennisCourt tennisCourt, final Game game) {
+ this.tennisCourt = tennisCourt;
+ this.game = game;
+ }
+
+ public void render(Graphics graphics) {
+ graphics.setColor(Color.WHITE);
+ Segment7 segment7 = new Segment7(FONT_SIZE, THIKNESS);
+ segment7.render(graphics, tennisCourt.WIDTH/2 - (FONT_SIZE/2+THIKNESS), THIKNESS, game.playerA.score);
+ segment7.render(graphics, tennisCourt.WIDTH/2 + THIKNESS, THIKNESS, game.playerB.score);
+ }
+
+ private class Segment7 {
+
+ private final Segment[] s7 = new Segment[7];
+
+ public Segment7(int fontSize, int thikness) {
+ s7[0] = new Segment(0, 0, fontSize/2, thikness);
+ s7[1] = new Segment(fontSize/2-thikness, 0, thikness, fontSize/2);
+ s7[2] = new Segment(fontSize/2-thikness, fontSize/2, thikness, fontSize/2);
+ s7[3] = new Segment(0, fontSize-thikness, fontSize/2, thikness);
+ s7[4] = new Segment(0, fontSize/2, thikness, fontSize/2);
+ s7[5] = new Segment(0, 0, thikness, fontSize/2);
+ s7[6] = new Segment(0, fontSize/2-(thikness/2), fontSize/2, thikness);
+ }
+
+ private boolean[][] numbers = {
+ { true, true, true, true, true, true, false },
+ { false, true, true, false, false, false, false },
+ { true, true, false, true, true, false, true },
+ { true, true, true, true, false, false, true },
+ { false, true, true, false, false, true, true },
+ { true, false, true, true, false, true, true },
+ { true, false, true, true, true, true, true },
+ { true, true, true, false, false, false, false },
+ { true, true, true, true, true, true, true },
+ { true, true, true, false, false, true, true }
+ };
+
+ public void render(Graphics graphics, int offsetX, int offsetY, int score) {
+ boolean[] number = numbers[score];
+ for (int i = 0; i < 7; i++) {
+ if (number[i]) {
+ s7[i].render(graphics, offsetX, offsetY);
+ }
+ }
+ }
+ }
+
+ private class Segment {
+ private int x;
+ private int y;
+ private int width;
+ private int height;
+
+ public Segment(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+ public void render(Graphics graphics, int offsetX, int offsetY) {
+ graphics.fillRect(offsetX + x, offsetY + y, width, height);
+ }
+ }
+
+}
diff --git a/src/dk/wiegand/games/pong/TennisCourt.java b/src/dk/wiegand/games/pong/TennisCourt.java
new file mode 100644
index 0000000..25fbf4f
--- /dev/null
+++ b/src/dk/wiegand/games/pong/TennisCourt.java
@@ -0,0 +1,69 @@
+package dk.wiegand.games.pong;
+
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Toolkit;
+import java.awt.image.BufferStrategy;
+
+import javax.swing.JFrame;
+
+public class TennisCourt {
+ public final int WIDTH;
+ public final int HEIGHT;
+ private final Canvas canvas;
+ private final BufferStrategy bufferStrategy;
+ private final KeyboardHandler keyboardHandler;
+
+ public TennisCourt(int width, int height) {
+ this.WIDTH = width;
+ this.HEIGHT = height;
+
+ JFrame frame = new JFrame("Pong");
+ // Place frame in center of screen
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ frame.setBounds(screenSize.width / 2 - WIDTH / 2, screenSize.height / 2 - HEIGHT / 2, WIDTH, HEIGHT);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setResizable(false);
+ frame.setVisible(true);
+ // Keyboard listener
+ frame.addKeyListener(keyboardHandler = new KeyboardHandler());
+ // Canvas
+ canvas = new Canvas();
+ canvas.setPreferredSize(new Dimension(WIDTH, HEIGHT));
+ canvas.setMinimumSize(new Dimension(WIDTH, HEIGHT));
+ canvas.setMaximumSize(new Dimension(WIDTH, HEIGHT));
+ canvas.setFocusable(false);
+ frame.add(canvas);
+ frame.pack();
+ canvas.createBufferStrategy(3);
+ bufferStrategy = canvas.getBufferStrategy();
+ }
+
+ public KeyboardHandler getKeyboardHandler() {
+ return keyboardHandler;
+ }
+
+ public Graphics getGraphics() {
+ return bufferStrategy.getDrawGraphics();
+ }
+
+ public void showGraphics() {
+ bufferStrategy.show();
+ }
+
+ public void tick() {
+ keyboardHandler.tick();
+ }
+
+ public void render(Graphics graphics) {
+ graphics.clearRect(0, 0, WIDTH, HEIGHT);
+ graphics.setColor(Color.BLACK);
+ graphics.fillRect(0, 0, WIDTH, HEIGHT);
+ // Net
+ graphics.setColor(Color.WHITE);
+ graphics.drawLine(WIDTH / 2, 0, WIDTH / 2, HEIGHT);
+ }
+
+}