diff --git a/.gitignore b/.gitignore
index c617ee7..8ee4e6b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,4 @@
# Created by .gitignore support plugin (hsz.mobi)
serverTime.iml
.idea
-junit-4.7.jar
-jbox2d-library-2.2.1.1.jar
-jbox2d-testbed-2.2.1.1.jar
-jbox2d-serialization-1.1.0.jar
\ No newline at end of file
+src/collector/src/tileMapStuff/codeNameMetalMayhem.java
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..37f45b3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,9 @@
+serverTime
+==========
+
+server exploration
+this is a group project for our Software enginering class
+building a game that will allow two users to compete in different games by havging common variables representing
+different objects in the individual games.
+run the game class to run the currnet collector game
+
diff --git a/out/production/serverTime/Color.txt b/out/production/serverTime/Color.txt
new file mode 100644
index 0000000..f23ba4b
--- /dev/null
+++ b/out/production/serverTime/Color.txt
@@ -0,0 +1 @@
+BLACK
\ No newline at end of file
diff --git a/out/production/serverTime/DBOps.class b/out/production/serverTime/DBOps.class
deleted file mode 100644
index a208432..0000000
Binary files a/out/production/serverTime/DBOps.class and /dev/null differ
diff --git a/src/Snake/.classpath b/out/production/serverTime/Snake/.classpath
similarity index 100%
rename from src/Snake/.classpath
rename to out/production/serverTime/Snake/.classpath
diff --git a/src/Snake/.project b/out/production/serverTime/Snake/.project
similarity index 100%
rename from src/Snake/.project
rename to out/production/serverTime/Snake/.project
diff --git a/src/Snake/.settings/org.eclipse.jdt.core.prefs b/out/production/serverTime/Snake/.settings/org.eclipse.jdt.core.prefs
similarity index 100%
rename from src/Snake/.settings/org.eclipse.jdt.core.prefs
rename to out/production/serverTime/Snake/.settings/org.eclipse.jdt.core.prefs
diff --git a/out/production/serverTime/Snake/GameApplet$1.class b/out/production/serverTime/Snake/GameApplet$1.class
new file mode 100644
index 0000000..eaa61ce
Binary files /dev/null and b/out/production/serverTime/Snake/GameApplet$1.class differ
diff --git a/out/production/serverTime/Snake/GameApplet$Block.class b/out/production/serverTime/Snake/GameApplet$Block.class
new file mode 100644
index 0000000..3327bcf
Binary files /dev/null and b/out/production/serverTime/Snake/GameApplet$Block.class differ
diff --git a/out/production/serverTime/Snake/GameApplet$Snake.class b/out/production/serverTime/Snake/GameApplet$Snake.class
new file mode 100644
index 0000000..fef721e
Binary files /dev/null and b/out/production/serverTime/Snake/GameApplet$Snake.class differ
diff --git a/out/production/serverTime/Snake/GameApplet$UpdateScore.class b/out/production/serverTime/Snake/GameApplet$UpdateScore.class
new file mode 100644
index 0000000..c16ddac
Binary files /dev/null and b/out/production/serverTime/Snake/GameApplet$UpdateScore.class differ
diff --git a/out/production/serverTime/Snake/GameApplet.class b/out/production/serverTime/Snake/GameApplet.class
new file mode 100644
index 0000000..d492808
Binary files /dev/null and b/out/production/serverTime/Snake/GameApplet.class differ
diff --git a/out/production/serverTime/collector/CollectObject.class b/out/production/serverTime/collector/CollectObject.class
new file mode 100644
index 0000000..59d4c89
Binary files /dev/null and b/out/production/serverTime/collector/CollectObject.class differ
diff --git a/out/production/serverTime/collector/CollectPlayer.class b/out/production/serverTime/collector/CollectPlayer.class
new file mode 100644
index 0000000..68c22eb
Binary files /dev/null and b/out/production/serverTime/collector/CollectPlayer.class differ
diff --git a/out/production/serverTime/collector/PhysicsSprite$1.class b/out/production/serverTime/collector/PhysicsSprite$1.class
new file mode 100644
index 0000000..860d259
Binary files /dev/null and b/out/production/serverTime/collector/PhysicsSprite$1.class differ
diff --git a/out/production/serverTime/collector/PhysicsSprite$2.class b/out/production/serverTime/collector/PhysicsSprite$2.class
new file mode 100644
index 0000000..9d67713
Binary files /dev/null and b/out/production/serverTime/collector/PhysicsSprite$2.class differ
diff --git a/out/production/serverTime/collector/PhysicsSprite$3.class b/out/production/serverTime/collector/PhysicsSprite$3.class
new file mode 100644
index 0000000..8fb16d1
Binary files /dev/null and b/out/production/serverTime/collector/PhysicsSprite$3.class differ
diff --git a/out/production/serverTime/collector/PhysicsSprite.class b/out/production/serverTime/collector/PhysicsSprite.class
new file mode 100644
index 0000000..4a980eb
Binary files /dev/null and b/out/production/serverTime/collector/PhysicsSprite.class differ
diff --git a/out/production/serverTime/collector/ball.png b/out/production/serverTime/collector/ball.png
new file mode 100644
index 0000000..09b836b
Binary files /dev/null and b/out/production/serverTime/collector/ball.png differ
diff --git a/out/production/serverTime/collector/box.png b/out/production/serverTime/collector/box.png
new file mode 100644
index 0000000..3457a3b
Binary files /dev/null and b/out/production/serverTime/collector/box.png differ
diff --git a/out/production/serverTime/collector/characterSprite$1.class b/out/production/serverTime/collector/characterSprite$1.class
new file mode 100644
index 0000000..41603e3
Binary files /dev/null and b/out/production/serverTime/collector/characterSprite$1.class differ
diff --git a/out/production/serverTime/collector/characterSprite$2.class b/out/production/serverTime/collector/characterSprite$2.class
new file mode 100644
index 0000000..a37ce8f
Binary files /dev/null and b/out/production/serverTime/collector/characterSprite$2.class differ
diff --git a/out/production/serverTime/collector/characterSprite$3.class b/out/production/serverTime/collector/characterSprite$3.class
new file mode 100644
index 0000000..9b95268
Binary files /dev/null and b/out/production/serverTime/collector/characterSprite$3.class differ
diff --git a/out/production/serverTime/collector/characterSprite.class b/out/production/serverTime/collector/characterSprite.class
new file mode 100644
index 0000000..2b5dac8
Binary files /dev/null and b/out/production/serverTime/collector/characterSprite.class differ
diff --git a/out/production/serverTime/collector/collectPanel$1.class b/out/production/serverTime/collector/collectPanel$1.class
new file mode 100644
index 0000000..a52661c
Binary files /dev/null and b/out/production/serverTime/collector/collectPanel$1.class differ
diff --git a/out/production/serverTime/collector/collectPanel.class b/out/production/serverTime/collector/collectPanel.class
new file mode 100644
index 0000000..a113c3d
Binary files /dev/null and b/out/production/serverTime/collector/collectPanel.class differ
diff --git a/out/production/serverTime/collector/src/PNG/backGround.png b/out/production/serverTime/collector/src/PNG/backGround.png
new file mode 100644
index 0000000..fd100c0
Binary files /dev/null and b/out/production/serverTime/collector/src/PNG/backGround.png differ
diff --git a/out/production/serverTime/collector/src/PNG/coin.png b/out/production/serverTime/collector/src/PNG/coin.png
new file mode 100644
index 0000000..e4bb9f7
Binary files /dev/null and b/out/production/serverTime/collector/src/PNG/coin.png differ
diff --git a/out/production/serverTime/collector/src/PNG/fireBall.gif b/out/production/serverTime/collector/src/PNG/fireBall.gif
new file mode 100644
index 0000000..c1b5d13
Binary files /dev/null and b/out/production/serverTime/collector/src/PNG/fireBall.gif differ
diff --git a/out/production/serverTime/collector/src/PNG/fireBallRight.gif b/out/production/serverTime/collector/src/PNG/fireBallRight.gif
new file mode 100644
index 0000000..01120b4
Binary files /dev/null and b/out/production/serverTime/collector/src/PNG/fireBallRight.gif differ
diff --git a/out/production/serverTime/collector/src/PNG/ground.png b/out/production/serverTime/collector/src/PNG/ground.png
new file mode 100644
index 0000000..4f66843
Binary files /dev/null and b/out/production/serverTime/collector/src/PNG/ground.png differ
diff --git a/out/production/serverTime/collector/src/PNG/heroLeft.png b/out/production/serverTime/collector/src/PNG/heroLeft.png
new file mode 100644
index 0000000..f7f09da
Binary files /dev/null and b/out/production/serverTime/collector/src/PNG/heroLeft.png differ
diff --git a/out/production/serverTime/collector/src/PNG/prince.class b/out/production/serverTime/collector/src/PNG/prince.class
new file mode 100644
index 0000000..f438541
Binary files /dev/null and b/out/production/serverTime/collector/src/PNG/prince.class differ
diff --git a/out/production/serverTime/collector/src/PNG/spaceShip.png b/out/production/serverTime/collector/src/PNG/spaceShip.png
new file mode 100644
index 0000000..4a23a76
Binary files /dev/null and b/out/production/serverTime/collector/src/PNG/spaceShip.png differ
diff --git a/out/production/serverTime/collector/src/PNG/zombie.png b/out/production/serverTime/collector/src/PNG/zombie.png
new file mode 100644
index 0000000..7a34b03
Binary files /dev/null and b/out/production/serverTime/collector/src/PNG/zombie.png differ
diff --git a/out/production/serverTime/collector/src/dbStuff/collectListener.class b/out/production/serverTime/collector/src/dbStuff/collectListener.class
new file mode 100644
index 0000000..a79f7b8
Binary files /dev/null and b/out/production/serverTime/collector/src/dbStuff/collectListener.class differ
diff --git a/out/production/serverTime/collector/src/dbStuff/dbCollectConnect.class b/out/production/serverTime/collector/src/dbStuff/dbCollectConnect.class
new file mode 100644
index 0000000..b8a3b13
Binary files /dev/null and b/out/production/serverTime/collector/src/dbStuff/dbCollectConnect.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Coin.class b/out/production/serverTime/collector/src/tileMapStuff/Coin.class
new file mode 100644
index 0000000..ea0321c
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Coin.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Entity$1.class b/out/production/serverTime/collector/src/tileMapStuff/Entity$1.class
new file mode 100644
index 0000000..da65fc2
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Entity$1.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Entity$UpdateScore.class b/out/production/serverTime/collector/src/tileMapStuff/Entity$UpdateScore.class
new file mode 100644
index 0000000..604b68b
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Entity$UpdateScore.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Entity.class b/out/production/serverTime/collector/src/tileMapStuff/Entity.class
new file mode 100644
index 0000000..5fba5db
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Entity.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Game$1.class b/out/production/serverTime/collector/src/tileMapStuff/Game$1.class
new file mode 100644
index 0000000..64c3db2
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Game$1.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Game$DirectionListener.class b/out/production/serverTime/collector/src/tileMapStuff/Game$DirectionListener.class
new file mode 100644
index 0000000..daefe78
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Game$DirectionListener.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Game$GameLoop.class b/out/production/serverTime/collector/src/tileMapStuff/Game$GameLoop.class
new file mode 100644
index 0000000..6218640
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Game$GameLoop.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Game$dbStuff.class b/out/production/serverTime/collector/src/tileMapStuff/Game$dbStuff.class
new file mode 100644
index 0000000..28ad258
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Game$dbStuff.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Game.class b/out/production/serverTime/collector/src/tileMapStuff/Game.class
new file mode 100644
index 0000000..4eb5267
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Game.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Map.class b/out/production/serverTime/collector/src/tileMapStuff/Map.class
new file mode 100644
index 0000000..4495649
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Map.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/Zombie.class b/out/production/serverTime/collector/src/tileMapStuff/Zombie.class
new file mode 100644
index 0000000..35d604d
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/Zombie.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/codeNameMetalMayhem.class b/out/production/serverTime/collector/src/tileMapStuff/codeNameMetalMayhem.class
new file mode 100644
index 0000000..4a3cfe4
Binary files /dev/null and b/out/production/serverTime/collector/src/tileMapStuff/codeNameMetalMayhem.class differ
diff --git a/out/production/serverTime/collector/src/tileMapStuff/levelOne.txt b/out/production/serverTime/collector/src/tileMapStuff/levelOne.txt
new file mode 100644
index 0000000..b8e0b24
--- /dev/null
+++ b/out/production/serverTime/collector/src/tileMapStuff/levelOne.txt
@@ -0,0 +1,17 @@
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
+1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1
+1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
+1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1
+1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
+1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
+
+
diff --git a/out/production/serverTime/collector/workingHero.png b/out/production/serverTime/collector/workingHero.png
new file mode 100644
index 0000000..d56d57a
Binary files /dev/null and b/out/production/serverTime/collector/workingHero.png differ
diff --git a/out/production/serverTime/gui/ChatPanel$1.class b/out/production/serverTime/gui/ChatPanel$1.class
new file mode 100644
index 0000000..6a2aa0b
Binary files /dev/null and b/out/production/serverTime/gui/ChatPanel$1.class differ
diff --git a/out/production/serverTime/gui/ChatPanel$EnterListener.class b/out/production/serverTime/gui/ChatPanel$EnterListener.class
new file mode 100644
index 0000000..3580bd8
Binary files /dev/null and b/out/production/serverTime/gui/ChatPanel$EnterListener.class differ
diff --git a/out/production/serverTime/gui/ChatPanel$SendListener.class b/out/production/serverTime/gui/ChatPanel$SendListener.class
new file mode 100644
index 0000000..7d443a1
Binary files /dev/null and b/out/production/serverTime/gui/ChatPanel$SendListener.class differ
diff --git a/out/production/serverTime/gui/ChatPanel$ServerTime.class b/out/production/serverTime/gui/ChatPanel$ServerTime.class
new file mode 100644
index 0000000..4c7d2ff
Binary files /dev/null and b/out/production/serverTime/gui/ChatPanel$ServerTime.class differ
diff --git a/out/production/serverTime/gui/ChatPanel$TimerListener.class b/out/production/serverTime/gui/ChatPanel$TimerListener.class
new file mode 100644
index 0000000..97adbac
Binary files /dev/null and b/out/production/serverTime/gui/ChatPanel$TimerListener.class differ
diff --git a/out/production/serverTime/gui/ChatPanel$UpdateChatThread.class b/out/production/serverTime/gui/ChatPanel$UpdateChatThread.class
new file mode 100644
index 0000000..ca642ac
Binary files /dev/null and b/out/production/serverTime/gui/ChatPanel$UpdateChatThread.class differ
diff --git a/out/production/serverTime/gui/ChatPanel.class b/out/production/serverTime/gui/ChatPanel.class
new file mode 100644
index 0000000..191f7db
Binary files /dev/null and b/out/production/serverTime/gui/ChatPanel.class differ
diff --git a/out/production/serverTime/gui/GUI.class b/out/production/serverTime/gui/GUI.class
new file mode 100644
index 0000000..335eda1
Binary files /dev/null and b/out/production/serverTime/gui/GUI.class differ
diff --git a/out/production/serverTime/gui/LoginPanel$1.class b/out/production/serverTime/gui/LoginPanel$1.class
new file mode 100644
index 0000000..9587906
Binary files /dev/null and b/out/production/serverTime/gui/LoginPanel$1.class differ
diff --git a/out/production/serverTime/gui/LoginPanel$ButtonListener.class b/out/production/serverTime/gui/LoginPanel$ButtonListener.class
new file mode 100644
index 0000000..84fff56
Binary files /dev/null and b/out/production/serverTime/gui/LoginPanel$ButtonListener.class differ
diff --git a/out/production/serverTime/gui/LoginPanel$SubmitListener.class b/out/production/serverTime/gui/LoginPanel$SubmitListener.class
new file mode 100644
index 0000000..73b90c7
Binary files /dev/null and b/out/production/serverTime/gui/LoginPanel$SubmitListener.class differ
diff --git a/out/production/serverTime/gui/LoginPanel.class b/out/production/serverTime/gui/LoginPanel.class
new file mode 100644
index 0000000..a0f41b2
Binary files /dev/null and b/out/production/serverTime/gui/LoginPanel.class differ
diff --git a/out/production/serverTime/gui/MenuPanel$1.class b/out/production/serverTime/gui/MenuPanel$1.class
new file mode 100644
index 0000000..9de0fc9
Binary files /dev/null and b/out/production/serverTime/gui/MenuPanel$1.class differ
diff --git a/out/production/serverTime/gui/MenuPanel$EnableButton.class b/out/production/serverTime/gui/MenuPanel$EnableButton.class
new file mode 100644
index 0000000..8bea426
Binary files /dev/null and b/out/production/serverTime/gui/MenuPanel$EnableButton.class differ
diff --git a/out/production/serverTime/gui/MenuPanel$MenuButton.class b/out/production/serverTime/gui/MenuPanel$MenuButton.class
new file mode 100644
index 0000000..5148400
Binary files /dev/null and b/out/production/serverTime/gui/MenuPanel$MenuButton.class differ
diff --git a/out/production/serverTime/gui/MenuPanel.class b/out/production/serverTime/gui/MenuPanel.class
new file mode 100644
index 0000000..9d28ace
Binary files /dev/null and b/out/production/serverTime/gui/MenuPanel.class differ
diff --git a/out/production/serverTime/main.class b/out/production/serverTime/main.class
deleted file mode 100644
index 404d0c2..0000000
Binary files a/out/production/serverTime/main.class and /dev/null differ
diff --git a/out/production/serverTime/main/DBOps.class b/out/production/serverTime/main/DBOps.class
new file mode 100644
index 0000000..aa82486
Binary files /dev/null and b/out/production/serverTime/main/DBOps.class differ
diff --git a/out/production/serverTime/main/Driver$1.class b/out/production/serverTime/main/Driver$1.class
new file mode 100644
index 0000000..1935517
Binary files /dev/null and b/out/production/serverTime/main/Driver$1.class differ
diff --git a/out/production/serverTime/main/Driver.class b/out/production/serverTime/main/Driver.class
new file mode 100644
index 0000000..7dd2dbd
Binary files /dev/null and b/out/production/serverTime/main/Driver.class differ
diff --git a/out/production/serverTime/main/Listener.class b/out/production/serverTime/main/Listener.class
new file mode 100644
index 0000000..65d6c1b
Binary files /dev/null and b/out/production/serverTime/main/Listener.class differ
diff --git a/out/production/serverTime/main/TestPanel$ButtonListener.class b/out/production/serverTime/main/TestPanel$ButtonListener.class
new file mode 100644
index 0000000..16107ca
Binary files /dev/null and b/out/production/serverTime/main/TestPanel$ButtonListener.class differ
diff --git a/out/production/serverTime/main/TestPanel.class b/out/production/serverTime/main/TestPanel.class
new file mode 100644
index 0000000..edcf13a
Binary files /dev/null and b/out/production/serverTime/main/TestPanel.class differ
diff --git a/out/production/serverTime/main/User.class b/out/production/serverTime/main/User.class
new file mode 100644
index 0000000..453588f
Binary files /dev/null and b/out/production/serverTime/main/User.class differ
diff --git a/out/production/serverTime/space/data/enemyships.jpg b/out/production/serverTime/space/data/enemyships.jpg
new file mode 100644
index 0000000..c7917a3
Binary files /dev/null and b/out/production/serverTime/space/data/enemyships.jpg differ
diff --git a/out/production/serverTime/space/data/ship-animated.gif b/out/production/serverTime/space/data/ship-animated.gif
new file mode 100644
index 0000000..83f89d2
Binary files /dev/null and b/out/production/serverTime/space/data/ship-animated.gif differ
diff --git a/out/production/serverTime/space/src/test/SetupClass.class b/out/production/serverTime/space/src/test/SetupClass.class
new file mode 100644
index 0000000..3fab91e
Binary files /dev/null and b/out/production/serverTime/space/src/test/SetupClass.class differ
diff --git a/out/test/serverTime/DBOpsTest$TestJunit.class b/out/test/serverTime/DBOpsTest$TestJunit.class
index 49dc01d..3f8401a 100644
Binary files a/out/test/serverTime/DBOpsTest$TestJunit.class and b/out/test/serverTime/DBOpsTest$TestJunit.class differ
diff --git a/out/test/serverTime/DBOpsTest.class b/out/test/serverTime/DBOpsTest.class
index f32df70..0eec65f 100644
Binary files a/out/test/serverTime/DBOpsTest.class and b/out/test/serverTime/DBOpsTest.class differ
diff --git a/out/test/serverTime/JunitTestSuite.class b/out/test/serverTime/JunitTestSuite.class
index c1d3fb1..69fd22d 100644
Binary files a/out/test/serverTime/JunitTestSuite.class and b/out/test/serverTime/JunitTestSuite.class differ
diff --git a/out/test/serverTime/testRunner.class b/out/test/serverTime/testRunner.class
index cf12995..a298e3f 100644
Binary files a/out/test/serverTime/testRunner.class and b/out/test/serverTime/testRunner.class differ
diff --git a/out/test/test.iml b/out/test/test.iml
new file mode 100644
index 0000000..39257af
--- /dev/null
+++ b/out/test/test.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Driver.java b/src/Driver.java
deleted file mode 100644
index 01f5d98..0000000
--- a/src/Driver.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/* *************************************************************
- File Name: Driver.java
- Last Changed Date: October 27th, 2014
- Purpose: Displays the TestPanel showing inter-user connectivity
- Author: Adam Clemons
- ************************************************************* */
-
-import java.awt.BorderLayout;
-import java.io.IOException;
-
-import javax.swing.JFrame;
-
-public class Driver {
-
- public static TestPanel newPanel;
-
- public static void main(String[] args) throws IOException {
- DBOps.connect();
-
- // Creates the JFrame, sets what happens when we close it, and makes it a fixed size (dependent on JPanel sizes)
- JFrame displayFrame = new JFrame("View Connectivity!");
- displayFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- displayFrame.setResizable(false);
- displayFrame.setLayout(new BorderLayout());
-
- newPanel = new TestPanel();
-
- displayFrame.getContentPane().add(newPanel);
-
- // Packs the Frame up for delivery to the console
- displayFrame.pack();
- displayFrame.setLocationRelativeTo(null);
- displayFrame.setVisible(true); // Allows us to see the Frame
-
- }
-}
diff --git a/src/Snake/SnakeApplet.html b/src/Snake/SnakeApplet.html
deleted file mode 100644
index b6a4544..0000000
--- a/src/Snake/SnakeApplet.html
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
- JavaApplet named SnakeApplet
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Snake/bin/GameApplet$Block.class b/src/Snake/bin/GameApplet$Block.class
deleted file mode 100644
index 3622a05..0000000
Binary files a/src/Snake/bin/GameApplet$Block.class and /dev/null differ
diff --git a/src/Snake/bin/GameApplet$Snake.class b/src/Snake/bin/GameApplet$Snake.class
deleted file mode 100644
index dcc55ea..0000000
Binary files a/src/Snake/bin/GameApplet$Snake.class and /dev/null differ
diff --git a/src/Snake/bin/GameApplet.class b/src/Snake/bin/GameApplet.class
deleted file mode 100644
index bf0e58f..0000000
Binary files a/src/Snake/bin/GameApplet.class and /dev/null differ
diff --git a/src/Snake/bin/java.policy.applet b/src/Snake/bin/java.policy.applet
deleted file mode 100644
index ba9f51d..0000000
--- a/src/Snake/bin/java.policy.applet
+++ /dev/null
@@ -1,7 +0,0 @@
-/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
-/* DO NOT EDIT */
-
-grant {
- permission java.security.AllPermission;
-};
-
diff --git a/src/Snake/core.jar b/src/Snake/core.jar
deleted file mode 100644
index c21c0c0..0000000
Binary files a/src/Snake/core.jar and /dev/null differ
diff --git a/src/View.java b/src/View.java
deleted file mode 100644
index 3261b9b..0000000
--- a/src/View.java
+++ /dev/null
@@ -1,8 +0,0 @@
-/**
- * Created by Spencer on 10/24/2014.
- */
-public class View {
-
- //creates a User for the view to be attached to?
- User user = new User();
-}
diff --git a/src/collector/src/tileMapStuff/Coin.java b/src/collector/src/tileMapStuff/Coin.java
new file mode 100644
index 0000000..e28109c
--- /dev/null
+++ b/src/collector/src/tileMapStuff/Coin.java
@@ -0,0 +1,40 @@
+package collector.src.tileMapStuff;
+
+import java.awt.*;
+
+/**
+ * Created by newScanTron on 11/11/2014.
+ */
+public class Coin extends Entity
+{
+ /**
+ * Create a new entity in the game
+ * @param map The map this entity is going to wander around
+ * @param x The initial x position of this entity in grid cells
+ * @param y The initial y position of this entity in grid cells
+ */
+ Map map = new Map();
+ public Coin(Map map, float x, float y)
+ {
+ super(map, x, y);
+ }
+
+ public void paint(Graphics g) {
+ // work out the screen position of the entity based on the
+ // x/y position and the size that tiles are being rendered at. So
+ // if we're at 1.5,1.5 and the tile size is 10 we'd render on screen
+ // at 15,15.
+ int xp = (int) (Map.TILE_SIZE * x);
+ int yp = (int) (Map.TILE_SIZE * y);
+ g.setColor(new Color(222, 104, 244));
+ g.drawRect (xp ,yp , Map.TILE_SIZE, Map.TILE_SIZE);
+
+ }
+ //proximity detection
+ public float proximity(float x, float y)
+ {
+ float distance = 0;
+ distance = (float) Math.sqrt(Math.pow((this.x - x), 2)+Math.pow((this.y -y), 2));
+ return distance;
+ }
+}
diff --git a/src/collector/src/tileMapStuff/Entity.java b/src/collector/src/tileMapStuff/Entity.java
new file mode 100644
index 0000000..d8dd894
--- /dev/null
+++ b/src/collector/src/tileMapStuff/Entity.java
@@ -0,0 +1,119 @@
+package collector.src.tileMapStuff;
+
+import main.DBOps;
+import main.Driver;
+
+import java.awt.*;
+
+public class Entity {
+ /** The x and y position of this entity in terms of grid cells
+ * that make up the map object*/
+ protected float x;
+ protected float y;
+ protected Map map;
+ /** The size of this entity, this is used to calculate collisions with walls */
+ private float size = 0.4f;
+ private boolean grounded = false;
+ protected int score = 0;
+ protected Color playColor = new Color(203, 200, 106);
+ private Thread scoreThread = new Thread(new UpdateScore());
+
+ public Entity(Map map, float x, float y)
+ {
+ this.map = map;
+ this.x = x;
+ this.y = y;
+ }
+ public float getX()
+ {
+ return x;
+ }
+
+ public float getY()
+ {
+ return y;
+ }
+
+ public void setScore(int add)
+ {
+ this.score += add;
+ }
+
+ public boolean move(float dx, float dy)
+ {
+ float nx = x + dx;
+ float ny = y + dy;
+ // check if the new position of the entity collides with
+ // anything
+ if (validLocation(nx, ny)) {
+ // if it doesn't then change our position to the new position
+ x = nx;
+ y = ny;
+ if (map.isCoin(x, y, 1))
+ {
+ map.setClear((int)x, (int)y);
+ setScore(1);
+ scoreThread = new Thread(new UpdateScore());
+ scoreThread.start();
+ System.out.println(score);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public boolean validLocation(float nx, float ny)
+ {
+
+ grounded = false;
+ if (map.isBlocked(nx, ny))
+ {
+ return false;
+ }
+ if (map.isBlocked(nx + size, ny))
+ {
+ return false;
+ }
+ if (map.isBlocked(nx, ny + size))
+ {
+ grounded = true;
+ return false;
+ }
+ if (map.isBlocked(nx + size, ny + size))
+ {
+ grounded = true;
+ return false;
+ }
+ return true;
+ }
+
+ // check to see if Entity is grounded
+ public boolean isGrounded()
+ {
+ grounded = true;
+ if (map.isBlocked(x, y +size))
+ {
+ grounded = true;
+ }
+ return grounded;
+ }
+
+ public void paint(Graphics g) {
+ int xp = (int) (Map.TILE_SIZE * x);
+ int yp = (int) (Map.TILE_SIZE * y);
+ g.setColor(playColor);
+ g.fillRect(xp, yp, 10, 10);
+ }
+
+ private class UpdateScore implements Runnable {
+
+ public void run() {
+ int DBscore = Integer.parseInt((DBOps.getData("scores", "1", "id", "Collector")).get(0)) + 5;
+ DBOps.updateData("scores", "Collector", "" + DBscore, "id", "1");
+ DBscore = Integer.parseInt((DBOps.getData("users", Driver.currentUser.getName(), "user", "scoredCollector")).get(0)) + 5;
+ DBOps.updateData("users", "scoredCollector", "" + DBscore, "user", Driver.currentUser.getName() );
+ return;
+ }
+
+ }
+}
diff --git a/src/collector/src/tileMapStuff/Game.java b/src/collector/src/tileMapStuff/Game.java
new file mode 100644
index 0000000..b643802
--- /dev/null
+++ b/src/collector/src/tileMapStuff/Game.java
@@ -0,0 +1,180 @@
+package collector.src.tileMapStuff;//Chris Murphy
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.util.ArrayList;
+
+//sept 2013
+//purpose: a main panel for the player and prince to do battle
+
+public class Game extends JPanel
+{
+ private static final long serialVersionUID = 1L;
+ private final int height = 270;
+ private final int length = 450;
+ private Color myPurp = new Color(150, 0, 220);
+ //booleas for which key is pressed
+ boolean up = false;
+ boolean down = false;
+ boolean right = false;
+ boolean left = false;
+ //some more stuff that im adding from the game canvas
+ Map map = new Map();
+ private ArrayList coins;
+
+ private float gravity = 0.055f;
+ Entity player;
+ public Timer myTimer;
+
+ //constructor
+ public Game()
+ {
+ player = new Entity(map, 3f, 2f);
+ coins = new ArrayList();
+
+ addKeyListener(new DirectionListener());
+ setBackground(Color.black);
+ setPreferredSize(new Dimension(length, height));
+ setFocusable(true);
+ myTimer = new Timer(12, new GameLoop());
+ myTimer.start();
+ }
+
+ private class GameLoop implements ActionListener
+ {
+
+ public void actionPerformed(ActionEvent arg0)
+ {
+ requestFocus();
+ player.move(0, gravity);
+ coins = map.getCoinList();
+ float currlow = 1000;
+ float currX = 0;
+ float currY = 0;
+ for (Coin c : coins)
+ {
+ float currDist = c.proximity(player.getX(), player.getY());
+ if (currDist < currlow)
+ {
+ currlow = currDist;
+ currX = c.getX();
+ currY = c.getY();
+ }
+ }
+ map.setClosest((int) currX, (int) currY);
+ //begin to connect to the database
+ /* String userName = "chris";
+ String userIdString = DBOps.getData("users", userName, userName, "id").get(0);
+ int userId = Integer.parseInt(userIdString);
+ DBOps.getData("player", "", "id", "string_colour").get(0);*/
+
+ repaint();
+ logic();
+ }
+ }
+
+ //logic does some stuff to move our player this will become mor complicated
+ //shortly
+ public void logic()
+ {
+ float dx = 0;
+ float dy = 0;
+ float speed = 3.5f;
+ float jump = 9.0f;
+ float downPound = 2f;
+ float smoothing = 0.03f;
+ if (map.isBlocked(dx, dy) )
+ {
+ if (right)
+ {
+ right = false;
+ }
+ else if (!right)
+ {
+ right = true;
+ }
+ }
+ if (left)
+ {
+ dx -= speed;
+ }
+ if (right)
+ {
+ dx += speed;
+ }
+ if (up && player.isGrounded())
+ {
+ dy -= jump;
+ }
+ if (down)
+ {
+ dy += downPound;
+ }
+ player.move(dx * smoothing, dy * smoothing);
+ }
+
+ public void paintComponent(Graphics page)
+ {
+ super.paintComponent(page);
+ page.setColor(myPurp);
+ page.fillRect(0, 0, 450, 270);
+ map.paint(page);
+ player.paint(page);
+ }
+
+ public class DirectionListener implements KeyListener
+ {
+ public void keyPressed(KeyEvent e)
+ {
+ // check the keyboard and record which keys are pressed
+ if (e.getKeyCode() == KeyEvent.VK_LEFT)
+ {
+ left = true;
+ }
+ if (e.getKeyCode() == KeyEvent.VK_RIGHT)
+ {
+ right = true;
+ }
+ if (e.getKeyCode() == KeyEvent.VK_DOWN)
+ {
+ down = true;
+ }
+ if (e.getKeyCode() == KeyEvent.VK_UP)
+ {
+ up = true;
+ }
+ }
+
+ public void keyReleased(KeyEvent e)
+ {
+ // check the keyboard and record which keys are released
+ if (e.getKeyCode() == KeyEvent.VK_LEFT)
+ {
+ left = false;
+ }
+ if (e.getKeyCode() == KeyEvent.VK_RIGHT)
+ {
+ right = false;
+ }
+ if (e.getKeyCode() == KeyEvent.VK_DOWN)
+ {
+ down = false;
+ }
+ if (e.getKeyCode() == KeyEvent.VK_UP)
+ {
+ up = false;
+ }
+ }
+
+ public void keyTyped(KeyEvent event)
+ {
+ }
+ }
+}
+
+
+
diff --git a/src/collector/src/tileMapStuff/Map.java b/src/collector/src/tileMapStuff/Map.java
new file mode 100644
index 0000000..fee3a24
--- /dev/null
+++ b/src/collector/src/tileMapStuff/Map.java
@@ -0,0 +1,224 @@
+package collector.src.tileMapStuff;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Random;
+
+public class Map
+{
+ /**
+ * The value indicating a each type of cell
+ */
+ private static final int CLEAR = 0;
+ private static final int BLOCKED = 1;
+ private static final int COIN = 2;
+ private static final int CLOSEST = 5;
+ /**
+ * The width and height in grid cells of our map
+ */
+ public static final int WIDTH = 25;
+ public static final int HEIGHT = 15;
+ /**
+ * The rendered size of the tile (in pixels)
+ */
+ public static final int TILE_SIZE = 18;
+ /**
+ * The actual data for our map
+ */
+ private Color coinColor = new Color(204, 100, 100);
+ private int[][] data;
+ public ArrayList coinList = new ArrayList();
+
+ public Map()
+ {
+// will get this to work so we can impliment a level editor
+
+// BufferedReader br = new BufferedReader(new FileReader("collector/src/tileMapStuff/levelOne.txt"));
+// try {
+// StringBuilder sb = new StringBuilder();
+// String line = br.readLine();
+//
+// while (line != null) {
+// sb.append(line);
+// sb.append(System.lineSeparator());
+// line = br.readLine();
+// System.out.println(line);
+// }
+// String everything = sb.toString();
+// } finally {
+// br.close();
+// }
+ data = new int[][]
+
+ {
+
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+ {1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1},
+ {1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1},
+ {1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 1},
+ {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1},
+ {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
+ {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1},
+ {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1},
+ {1, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1},
+ {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1},
+ {1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1},
+ {1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1},
+ {1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1},
+ {1, 0, 0, 0, 2, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1},
+ {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1},
+ {1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1},
+ {1, 0, 2, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1},
+ {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1},
+ {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1},
+ {1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1},
+ {1, 0, 0, 2, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1},
+ {1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1},
+ {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
+ {1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1},
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
+ };
+ }
+
+
+ public ArrayList getCoinList()
+ {
+ return coinList;
+ }
+
+ /**
+ * Render the map to the graphics context provided. The rendering
+ * is just simple fill rectangles
+ *
+ * @param g The graphics context on which to draw the map
+ */
+
+ public void paint(Graphics g)
+ {
+ // loop through all the tiles in the map rendering them
+ // based on whether they block or not
+ coinList = new ArrayList();
+ for (int x = 0; x < WIDTH; x++)
+ {
+ for (int y = 0; y < HEIGHT; y++)
+ {
+
+ // so if the cell is blocks, draw a light grey block
+ // otherwise use a dark gray
+ if (data[x][y] == BLOCKED)
+ {
+ g.setColor(new Color(13,140,200));
+ g.fillRect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
+ }
+ if (data[x][y] == COIN)
+ {
+
+ if (coinList.size() < 5)
+ coinList.add(new Coin(this, x, y));
+ g.setColor(Color.GREEN);
+ g.fillRect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE/2 , TILE_SIZE/2 );
+ data[x][y] = CLEAR;
+
+ }
+ if (data[x][y] == CLOSEST)
+ {
+ g.setColor(coinColor);
+ g.fillRect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE/2 , TILE_SIZE/2 );
+
+ }
+ }
+ }
+ int count = 0;
+ while (coinList.size() > count)
+ {
+ data[(int) coinList.get(count).getX()][(int) coinList.get(count).getY()] = COIN;
+ count ++;
+ }
+ }
+
+ /**
+ * @param x The x position to check for blocking
+ * @param y The y position to check for blocking
+ * @return True if the location is isBlocked
+ * is a coin and a method to reset the coin if
+ * it is gathered
+ */
+ public boolean isBlocked(float x, float y)
+ {
+ return data[(int) x][(int) y] == BLOCKED;
+ }
+
+ public boolean isCoin(float x, float y, int size)
+ {
+
+ if (data[(int) x][(int) y] == COIN || data[(int) x][(int) y] == CLOSEST)
+ {
+ return true;
+ }
+// if (data[(int) x+ (int)size][(int) y] == COIN || data[(int) x + (int)size][(int) y] == CLOSEST)
+// {
+// return true;
+// }
+// if (data[(int) x][(int) y + (int) size] == COIN || data[(int) x][(int) y + (int) size] == CLOSEST)
+// {
+//
+// return true;
+// }
+// if (data[(int) x + (int)size ][(int) y + (int)size] == COIN || data[(int) x + (int)size][(int) y + (int)size] == CLOSEST)
+// {
+//
+// return true;
+// }
+ return false;
+ }
+
+ public void setClear(int x, int y)
+ {
+ data[x][y] = CLEAR;
+ resetCoin();
+ }
+
+ public void setClosest(int x, int y)
+ {
+ for (int xCount = 0; xCount < WIDTH; xCount++)
+ {
+ for (int yCount = 0; yCount < HEIGHT; yCount++)
+ {
+//hoping this will reset what was the closest coin to a regular coin
+ if (data[xCount][yCount] == CLOSEST)
+ {
+ data[xCount][yCount] = COIN;
+ }
+ }
+ }
+ data[x][y] = CLOSEST;
+ }
+
+ //method to replace the coin in a new and random space
+ public void resetCoin()
+ {
+ Random rand = new Random();
+ int x = rand.nextInt(WIDTH);
+ int y = rand.nextInt(HEIGHT);
+ if (data[x][y] == CLEAR)
+ {
+ data[x][y] = COIN;
+ }
+ else if (data[x][y] == BLOCKED)
+ {
+ resetCoin();
+ }
+ else
+ {
+ //data[x][y] = CLEAR;
+
+ }
+ if (coinList.size() < 5)
+ {
+ x = rand.nextInt(WIDTH);
+ y = rand.nextInt(HEIGHT);
+
+ }
+ System.out.println(data);
+ }
+}
diff --git a/src/collector/src/tileMapStuff/codeNameMetalMayhem.java b/src/collector/src/tileMapStuff/codeNameMetalMayhem.java
new file mode 100644
index 0000000..e461356
--- /dev/null
+++ b/src/collector/src/tileMapStuff/codeNameMetalMayhem.java
@@ -0,0 +1,34 @@
+package collector.src.tileMapStuff;
+
+import main.DBOps;
+
+import javax.swing.*;
+import java.io.FileNotFoundException;
+
+
+public class codeNameMetalMayhem extends JFrame
+{
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param args
+ * this class only exists so that i can test the game without signing in
+ * everytime
+ *
+ */
+
+ public static void main(String[] args) throws FileNotFoundException
+ {
+ DBOps.connect();
+ Game zombiePanel = new Game();
+ //ZombiePanel zombiePanel = new ZombiePanel();
+ JFrame codeNameMetalMayhem = new JFrame ("The Mayhem is Metal...ah!");
+ codeNameMetalMayhem.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ codeNameMetalMayhem.getContentPane().add(zombiePanel);
+ codeNameMetalMayhem.pack();
+ codeNameMetalMayhem.setVisible(true);
+
+ }
+
+}
diff --git a/src/collector/src/tileMapStuff/levelOne.txt b/src/collector/src/tileMapStuff/levelOne.txt
new file mode 100644
index 0000000..b8e0b24
--- /dev/null
+++ b/src/collector/src/tileMapStuff/levelOne.txt
@@ -0,0 +1,17 @@
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
+1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1
+1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
+1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1
+1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1
+1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
+1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
+
+
diff --git a/src/gui/ChatPanel.java b/src/gui/ChatPanel.java
new file mode 100644
index 0000000..db512ab
--- /dev/null
+++ b/src/gui/ChatPanel.java
@@ -0,0 +1,371 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.text.ParseException;
+import java.util.ArrayList;
+
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+import javax.swing.Timer;
+import javax.swing.JButton;
+import javax.swing.JFormattedTextField;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultCaret;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+
+import main.DBOps;
+import main.Driver;
+
+/* *************************************************************
+File Name: ChatPanel.java
+Last Changed Date: November 10th, 2014
+Purpose: Layout for chatting
+Author: Adam Clemons
+************************************************************* */
+
+public class ChatPanel extends JPanel {
+
+ private static final long serialVersionUID = 1L;
+ public ArrayList messages;
+ public JTextPane messageArea;
+ public JScrollPane messagePane;
+ public JFormattedTextField messageField;
+ public JButton send;
+ public GridBagLayout gLayout;
+ public GridBagConstraints c;
+ public long lastSent;
+ public SimpleAttributeSet keyWord;
+ public Thread myTimer, updateThread;
+ public Timer newTimer;
+ public int time;
+ private Thread checkThread = new Thread(new ChatChecker());
+
+
+ public ChatPanel() throws ParseException, BadLocationException {
+ messages = new ArrayList();
+ messageField = new JFormattedTextField();
+ messageField.setColumns(20);
+ messageField.setText("You must log in to chat.");
+ messageField.addKeyListener(new EnterListener());
+ messageField.setEditable(false);
+ send = new JButton("Send");
+ send.addActionListener(new SendListener());
+ send.setEnabled(false);
+ send.setMultiClickThreshhold(1000);
+ messageArea = new JTextPane();
+ messageArea.setEditable(false);
+ DefaultCaret caret = (DefaultCaret)messageArea.getCaret();
+ caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
+ messagePane = new JScrollPane(messageArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ messagePane.setPreferredSize(new Dimension(450, 80));
+
+ messages.add("SkyNet: Welcome to Server Time Chat! Available commands: /users, /start");
+
+ keyWord = new SimpleAttributeSet();
+
+ gLayout = new GridBagLayout();
+ c = new GridBagConstraints();
+ setLayout(gLayout);
+
+ c.fill = GridBagConstraints.BOTH;
+ c.gridwidth = 2;
+ c.weightx = 1;
+ c.weighty = .7;
+ c.gridx = 0;
+ c.gridy = 0;
+ add(messagePane,c);
+
+ c.fill = GridBagConstraints.BOTH;
+ c.gridwidth = 1;
+ c.weightx = .8;
+ c.weighty = .3;
+ c.gridx = 0;
+ c.gridy = 1;
+ add(messageField,c);
+
+ c.weightx = .2;
+ c.gridx = 1;
+ c.gridy = 1;
+ add(send,c);
+
+ checkThread.start();
+ }
+
+ public void updateChat() throws BadLocationException {
+ Driver.displayFrame.toFront();
+ updateThread = new Thread(new UpdateChatThread());
+ updateThread.start();
+ }
+
+ public long getTimeStamp() throws ParseException {
+ return System.currentTimeMillis();
+ }
+
+ private class SendListener implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+ if (messageField.getText().equals("/users")) {
+ DBOps.updateData("info", "string_colour", "SkyNet" + ": " + " Online users: " + Driver.onlineUsers(), "id", "2");
+ try {
+ DBOps.updateData("info", "time_stamp", "" + getTimeStamp(), "id", "2");
+ } catch (ParseException e1) {
+ e1.printStackTrace();
+ }
+ }
+
+ else if (messageField.getText().equals("/start")) {
+ if (Driver.returnRunning() == false) {
+
+ DBOps.updateData("info", "time_stamp", "True", "id", "3");
+ DBOps.updateData("scores", "Collector", "" + 0, "id", "1");
+ DBOps.updateData("scores", "Snake", "" + 0, "id", "1");
+
+ DBOps.updateData("info", "string_colour", "SkyNet" + ": " + "New match started! Teams have 60 seconds. Good luck!", "id", "2");
+ try {
+ DBOps.updateData("info", "time_stamp", "" + getTimeStamp(), "id", "2");
+ DBOps.updateData("info", "time_stamp", "" + getTimeStamp(), "id", "5");
+ } catch (ParseException e1) {
+ e1.printStackTrace();
+ }
+
+ DBOps.updateData("info", "time_stamp", "60", "id", "4");
+ }
+ else {
+ DBOps.updateData("info", "string_colour", "SkyNet" + ": " + "Game is currently in progress.", "id", "2");
+ try {
+ DBOps.updateData("info", "time_stamp", "" + getTimeStamp(), "id", "2");
+ } catch (ParseException e1) {
+ e1.printStackTrace();
+ }
+ }
+ }
+
+ else {
+ DBOps.updateData("info", "string_colour", Driver.currentUser.getName() + ": " + messageField.getText().replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\""), "id", "2");
+ int DBscore = Integer.parseInt((DBOps.getData("users", Driver.currentUser.getName(), "user", "messages")).get(0)) + 1;
+ DBOps.updateData("users", "messages", "" + DBscore, "user", Driver.currentUser.getName() );
+ try {
+ DBOps.updateData("info", "time_stamp", "" + getTimeStamp(), "id", "2");
+ } catch (ParseException e1) {
+ e1.printStackTrace();
+ }
+ }
+ messageField.setText("");
+ }
+ }
+
+ private class EnterListener implements KeyListener {
+
+ public void keyPressed(KeyEvent e) {
+
+ }
+
+ public void keyReleased(KeyEvent e) {
+ if (e.getKeyCode() == KeyEvent.VK_ENTER)
+ send.doClick();
+ }
+
+ public void keyTyped(KeyEvent arg0) {
+ }
+
+ }
+
+
+ class ServerTime implements Runnable {
+ private volatile boolean isRunning;
+ private volatile String winner;
+
+ public void run() {
+ if (Driver.currentUser != null)
+ isRunning = true;
+ while(isRunning) {
+ try {
+ int tempTime = Integer.parseInt((DBOps.getData("info", "4", "id", "time_stamp")).get(0)) - 10;
+ if (getTimeStamp() - Long.parseLong(DBOps.getData("info", "5", "id", "time_stamp").get(0)) >= 10 && Driver.returnRunning()) {
+ if (tempTime >= 0)
+ time = tempTime;
+ DBOps.updateData("info", "time_stamp", "" + time, "id", "4");
+ String s = (DBOps.getData("scores", "1", "id", "Snake")).get(0);
+ String c = (DBOps.getData("scores", "1", "id", "Collector")).get(0);
+
+ if (time > 0) {
+ DBOps.updateData("info", "string_colour", "SkyNet" + ": " + "Teams have " + time + " seconds. S: " + s + " C: " + c, "id", "2");
+ try {
+ DBOps.updateData("info", "time_stamp", "" + getTimeStamp(), "id", "5");
+ DBOps.updateData("info", "time_stamp", "" + getTimeStamp(), "id", "2");
+ } catch (ParseException e1) {
+ e1.printStackTrace();
+ }
+ }
+ else {
+ DBOps.updateData("info", "time_stamp", "False", "id", "3");
+ if (Integer.parseInt(s) > Integer.parseInt(c)) {
+ winner = "Snakes win!";
+ if (Driver.playingSnake) {
+ int DBscore = Integer.parseInt((DBOps.getData("users", Driver.currentUser.getName(), "user", "wonSnake")).get(0)) + 1;
+ DBOps.updateData("users", "wonSnake", "" + DBscore, "user", Driver.currentUser.getName() );
+ }
+ }
+ else if (Integer.parseInt(c) > Integer.parseInt(s)) {
+ winner = "Collectors win!";
+ if (Driver.playingCollector) {
+ int DBscore = Integer.parseInt((DBOps.getData("users", Driver.currentUser.getName(), "user", "wonCollector")).get(0)) + 1;
+ DBOps.updateData("users", "wonCollector", "" + DBscore, "user", Driver.currentUser.getName() );
+ }
+ }
+ else
+ winner = "It's a tie!";
+ DBOps.updateData("info", "string_colour", "SkyNet" + ": " + "Game Over! " + winner + " S: " + s + " C: " + c, "id", "2");
+ try {
+ DBOps.updateData("info", "time_stamp", "" + getTimeStamp(), "id", "2");
+ } catch (ParseException e1) {
+ e1.printStackTrace();
+ }
+ isRunning = false;
+
+ Driver.newPanel.mainPanel.setLayout(new FlowLayout());
+ Driver.newPanel.mainPanel.removeAll();
+ Driver.newPanel.mainPanel.setPreferredSize(null);
+
+ Driver.newPanel.mainPanel.add(new MenuPanel());
+ Driver.newPanel.chatPanel.setFocusable(true);
+
+ Driver.newPanel.chatPanel.messageField.setText("");
+ Driver.newPanel.chatPanel.messageField.setEditable(true);
+ Driver.newPanel.chatPanel.send.setEnabled(true);
+
+ Driver.newPanel.revalidate(); Driver.newPanel.repaint();
+
+ return;
+ }
+ }
+ else {
+ if (Driver.returnRunning() == false) {
+ isRunning = false;
+
+ String s = (DBOps.getData("scores", "1", "id", "Snake")).get(0);
+ String c = (DBOps.getData("scores", "1", "id", "Collector")).get(0);
+
+ if (Integer.parseInt(s) > Integer.parseInt(c)) {
+ if (Driver.playingSnake) {
+ int DBscore = Integer.parseInt((DBOps.getData("users", Driver.currentUser.getName(), "user", "wonSnake")).get(0)) + 1;
+ DBOps.updateData("users", "wonSnake", "" + DBscore, "user", Driver.currentUser.getName() );
+ }
+ }
+ else if (Integer.parseInt(c) > Integer.parseInt(s)) {
+ if (Driver.playingCollector) {
+ int DBscore = Integer.parseInt((DBOps.getData("users", Driver.currentUser.getName(), "user", "wonCollector")).get(0)) + 1;
+ DBOps.updateData("users", "wonCollector", "" + DBscore, "user", Driver.currentUser.getName() );
+ }
+ }
+
+ Driver.newPanel.mainPanel.setLayout(new FlowLayout());
+ Driver.newPanel.mainPanel.removeAll();
+ Driver.newPanel.mainPanel.setPreferredSize(null);
+
+ Driver.newPanel.mainPanel.add(new MenuPanel());
+ Driver.newPanel.chatPanel.setFocusable(true);
+
+ Driver.newPanel.chatPanel.messageField.setText("");
+ Driver.newPanel.chatPanel.messageField.setEditable(true);
+ Driver.newPanel.chatPanel.send.setEnabled(true);
+
+ Driver.newPanel.revalidate(); Driver.newPanel.repaint();
+
+ return;
+ }
+ }
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+
+
+ private class UpdateChatThread implements Runnable {
+
+ public void run() {
+ messageArea.setText("\u200B");
+ messageArea.setLayout(new GridLayout(messages.size(),1));
+
+ for (String m:messages) {
+ String[] textWords = m.split(" ");
+ String username = textWords[0].substring(0, textWords[0].length());
+ String message = m.substring(username.length(), m.length());
+
+ StyleConstants.setForeground(keyWord, Color.RED);
+ try {
+ messageArea.getStyledDocument().insertString(messageArea.getText().length(),username, keyWord);
+ StyleConstants.setForeground(keyWord, Color.BLACK);
+ messageArea.getStyledDocument().insertString(messageArea.getText().length(),message + "\n", keyWord);
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ };
+
+ if ((messages.get(messages.size()-1).split(": ")[1].equals("Fantastic.")))
+ playSound("Fantastic.wav");
+
+ messageArea.revalidate(); messageArea.repaint();
+
+ }
+ }
+
+ public void restartThread() {
+ myTimer = new Thread(new ServerTime());
+ myTimer.start();
+ }
+
+ private class ChatChecker implements Runnable {
+
+ private volatile boolean isRunning = true;
+
+ public void run() {
+ while(isRunning) {
+ long tempLastSent = Long.parseLong(DBOps.getData("info", "2", "id", "time_stamp").get(0));
+ String tempMessage = (String) DBOps.getData("info", "2", "id","string_colour").get(0);
+ if ((tempLastSent == lastSent) == false) {
+ lastSent = tempLastSent;
+ messages.add(tempMessage);
+ try {
+ updateChat();
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ public void playSound(String soundName) {
+
+ try {
+ AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(getClass().getResource(soundName));
+ Clip clip = AudioSystem.getClip();
+ clip.open(audioInputStream);
+ clip.start();
+ }
+ catch (Exception ex) {
+ System.out.println("Error with playing sound.");
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/src/gui/Fantastic.wav b/src/gui/Fantastic.wav
new file mode 100644
index 0000000..372f65f
Binary files /dev/null and b/src/gui/Fantastic.wav differ
diff --git a/src/gui/GUI.java b/src/gui/GUI.java
new file mode 100644
index 0000000..859103a
--- /dev/null
+++ b/src/gui/GUI.java
@@ -0,0 +1,85 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+import java.text.ParseException;
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingConstants;
+import javax.swing.border.MatteBorder;
+import javax.swing.text.BadLocationException;
+
+
+/* *************************************************************
+ File Name: GUI.java
+ Last Changed Date: November 10th, 2014
+ Purpose: Main GUI handling
+ Author: Adam Clemons
+ ************************************************************* */
+
+public class GUI extends JPanel{
+
+ private static final long serialVersionUID = 1L;
+ public JPanel mainPanel;
+ public ChatPanel chatPanel;
+ public JLabel credits, title;
+ public GridBagLayout gLayout;
+ public GridBagConstraints c;
+
+
+ public GUI() throws ParseException, BadLocationException {
+
+ // Initialize components
+ title = new JLabel("Server Time");
+ title.setFont(new Font("Arial Black", Font.PLAIN, 72));
+ title.setHorizontalAlignment(SwingConstants.CENTER);
+ title.setBorder(new MatteBorder(0,0,2,0,Color.MAGENTA));
+ title.setForeground(Color.WHITE);
+ title.setBackground(Color.BLACK);
+ title.setOpaque(true);
+
+ gLayout = new GridBagLayout();
+ c = new GridBagConstraints();
+
+ mainPanel = new LoginPanel();
+ mainPanel.setBackground(Color.BLACK);
+
+ chatPanel = new ChatPanel();
+ chatPanel.setBackground(Color.BLACK);
+ chatPanel.setBorder(new MatteBorder(2,0,0,0,Color.MAGENTA));
+
+ setPreferredSize(new Dimension(500, 600));
+
+ setLayout(gLayout);
+ setBorder(BorderFactory.createLineBorder(Color.MAGENTA, 2));
+ setBackground(Color.BLACK);
+
+ // Add components
+ c.fill = GridBagConstraints.BOTH;
+ c.weightx = 0;
+ c.weighty = 0;
+ c.gridx = 0;
+ c.gridy = 0;
+ add(title,c);
+
+ c.fill = GridBagConstraints.CENTER;
+ c.weighty = .6;
+ c.gridx = 0;
+ c.gridy = 1;
+
+ add(mainPanel,c);
+
+
+ c.fill = GridBagConstraints.BOTH;
+ c.weighty = 0;
+ c.gridx = 0;
+ c.gridy = 2;
+ add(chatPanel,c);
+ }
+
+}
diff --git a/src/gui/LoginPanel.java b/src/gui/LoginPanel.java
new file mode 100644
index 0000000..65aa7e1
--- /dev/null
+++ b/src/gui/LoginPanel.java
@@ -0,0 +1,237 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.text.ParseException;
+
+import javax.swing.JButton;
+import javax.swing.JFormattedTextField;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.text.JTextComponent;
+
+import main.DBOps;
+import main.Driver;
+import main.User;
+
+
+
+/* *************************************************************
+File Name: LoginPanel.java
+Last Changed Date: November 10th, 2014
+Purpose: Layout for logging in
+Author: Adam Clemons
+************************************************************* */
+
+public class LoginPanel extends JPanel {
+
+ private static final long serialVersionUID = 1L;
+ public JButton login, register;
+ public GridBagLayout gLayout;
+ public GridBagConstraints c;
+ public JLabel username, password;
+ public JFormattedTextField usernameField, passwordField;
+ public JButton submit;
+ private boolean loggingin;
+ public RegexOnly myRegex;
+
+ public LoginPanel() {
+ login = new JButton("Login!");
+ login.addActionListener(new ButtonListener());
+ register = new JButton("Register!");
+ register.addActionListener(new ButtonListener());
+ setLayout(new GridLayout(1, 2));
+
+ add(login);
+ add(register);
+ }
+
+ private class ButtonListener implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+
+ if (e.getSource() == login)
+ loggingin = true;
+ else
+ loggingin = false;
+
+ // Log in components
+ gLayout= new GridBagLayout();
+ c = new GridBagConstraints();
+
+ myRegex = new RegexOnly();
+
+ username = new JLabel("Username:");
+ username.setForeground(Color.WHITE);
+ password = new JLabel("Password:");
+ password.setForeground(Color.WHITE);
+ usernameField = new JFormattedTextField();
+ usernameField.setColumns(10);
+ usernameField.addKeyListener(myRegex);
+ passwordField = new JFormattedTextField();
+ passwordField.setColumns(10);
+ passwordField.addKeyListener(myRegex);
+ submit = new JButton("Submit");
+ submit.addActionListener(new SubmitListener());
+
+ setLayout(gLayout);
+ removeAll();
+
+ // Add components
+ c.fill = GridBagConstraints.BOTH;
+ c.weighty = (double) 1/3;
+ c.weightx = .5;
+ c.gridx = 0;
+ c.gridy = 0;
+ add(username,c);
+
+ c.gridx = 1;
+ c.gridy = 0;
+ add(usernameField,c);
+
+ c.gridx = 0;
+ c.gridy = 1;
+ add(password,c);
+
+ c.gridx = 1;
+ c.gridy = 1;
+ add(passwordField,c);
+
+ c.gridwidth = 2;
+ c.weightx = 1;
+ c.gridx = 0;
+ c.gridy = 2;
+ add(submit,c);
+
+ Driver.newPanel.revalidate();
+
+ }
+ }
+
+ private class SubmitListener implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+
+ boolean success = true;
+ boolean found = false;
+
+ usernameField.setText(usernameField.getText().replaceAll("[^A-Za-z0-9]", ""));
+ passwordField.setText(passwordField.getText().replaceAll("[^A-Za-z0-9]", ""));
+
+ if (usernameField.getText().length() > 20)
+ usernameField.setText(usernameField.getText().substring(0, 20));
+ if (passwordField.getText().length() > 15)
+ passwordField.setText(passwordField.getText().substring(0, 20));
+
+ // Log in check
+ if (loggingin) {
+ Driver.updateUsers();
+ String attemptName = usernameField.getText();
+ for (User u:Driver.users) {
+ if (attemptName.toLowerCase().trim().equals(u.getName().toLowerCase().trim())) {
+ found = true;
+
+ if (passwordField.getText().equals(u.getPassword())) {
+ if ((Integer.parseInt((DBOps.getData("users", u.getName(), "user", "connected")).get(0))) == 0) {
+ JOptionPane.showMessageDialog(null, "You are now logged in!");
+ Driver.currentUser = new User(u.getName(), passwordField.getText());
+ DBOps.updateData("users", "connected", "1", "user", u.getName());
+ DBOps.updateData("info", "string_colour", "SkyNet" + ": " + u.getName() + " has entered the fray.", "id", "2");
+ int DBscore = Integer.parseInt((DBOps.getData("users", Driver.currentUser.getName(), "user", "loggedIn")).get(0)) + 1;
+ DBOps.updateData("users", "loggedIn", "" + DBscore, "user", Driver.currentUser.getName() );
+ try {
+ DBOps.updateData("info", "time_stamp", "" + Driver.newPanel.chatPanel.getTimeStamp(), "id", "2");
+ } catch (ParseException e1) {
+ e1.printStackTrace();
+ }
+ success = true;
+ }
+ else {
+ JOptionPane.showMessageDialog(null, "User is already logged in!");
+ success = false;
+ break;
+ }
+ }
+ else {
+ JOptionPane.showMessageDialog(null, "Invalid password!");
+ success = false;
+ break;
+ }
+ }
+ }
+ if (!found){
+ JOptionPane.showMessageDialog(null, "Username not registered!");
+ success = false;
+ }
+ }
+ // Registration check
+ else {
+ Driver.updateUsers();
+ String attemptName = usernameField.getText();
+ if (attemptName.toLowerCase().equals("skynet") || attemptName.toLowerCase().equals("adam")) {
+ JOptionPane.showMessageDialog(null, "Hide.");
+ return;
+ }
+
+ for (User u:Driver.users) {
+ if (attemptName.toLowerCase().trim().equals(u.getName().toLowerCase().trim())) {
+ JOptionPane.showMessageDialog(null, "This username has already been taken");
+ success = false;
+ }
+ }
+ if (success) {
+ JOptionPane.showMessageDialog(null, "Username registered!");
+ Driver.currentUser = new User(attemptName.trim(), passwordField.getText());
+ DBOps.insertData("users", "user`, `password`, `connected",
+ attemptName + "\", \"" + passwordField.getText() + "\", \"1");
+ DBOps.updateData("info", "string_colour", "SkyNet" + ": " + Driver.currentUser.getName() + " has become one of us.", "id", "2");
+ try {
+ DBOps.updateData("info", "time_stamp", "" + Driver.newPanel.chatPanel.getTimeStamp(), "id", "2");
+ } catch (ParseException e1) {
+ }
+
+ }
+ }
+
+ if (success) {
+ Driver.newPanel.mainPanel.setLayout(new FlowLayout());
+ Driver.newPanel.mainPanel.removeAll();
+ Driver.newPanel.mainPanel.setPreferredSize(null);
+ Driver.newPanel.mainPanel.setBackground(Color.MAGENTA);
+
+ Driver.newPanel.mainPanel.add(new MenuPanel());
+
+ Driver.newPanel.chatPanel.messageField.setText("");
+ Driver.newPanel.chatPanel.messageField.setEditable(true);
+ Driver.newPanel.chatPanel.send.setEnabled(true);
+
+ Driver.newPanel.revalidate(); Driver.newPanel.repaint();
+ }
+
+ }
+ }
+
+ public class RegexOnly extends KeyAdapter {
+
+ private int MAXSIZE = 20;
+ private String allowedRegex = "[^A-Za-z0-9]";
+
+ public void keyReleased(KeyEvent e) {
+ String curText = ((JTextComponent) e.getSource()).getText();
+ curText = curText.replaceAll(allowedRegex, "");
+
+ if (curText.length() > MAXSIZE)
+ curText = curText.substring(0, MAXSIZE);
+
+ ((JTextComponent) e.getSource()).setText(curText);
+ }
+ }
+}
diff --git a/src/gui/MenuPanel.java b/src/gui/MenuPanel.java
new file mode 100644
index 0000000..b461e9b
--- /dev/null
+++ b/src/gui/MenuPanel.java
@@ -0,0 +1,162 @@
+package gui;
+
+import collector.src.tileMapStuff.Game;
+import javax.swing.*;
+
+import processing.core.PApplet;
+import snake.GameApplet;
+import main.DBOps;
+import main.Driver;
+
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+
+/* *************************************************************
+File Name: MenuPanel.java
+Last Changed Date: November 10th, 2014
+Purpose: Layout for game access
+Author: Adam Clemons
+************************************************************* */
+
+
+public class MenuPanel extends JPanel {
+
+
+ private static final long serialVersionUID = 1L;
+ public JButton snake, collector, stats;
+ public GridBagLayout gLayout;
+ public GridBagConstraints c;
+ public Game collectorGame;
+ public Timer enabler = new Timer(1000, new EnableButton());
+
+ public MenuPanel() {
+ snake = new JButton("Snake");
+ snake.addActionListener(new MenuButton());
+ snake.setFocusPainted(false);
+ snake.setBackground(Color.RED);
+ collector = new JButton("Collector");
+ collector.addActionListener(new MenuButton());
+ collector.setFocusPainted(false);
+ collector.setBackground(Color.GREEN);
+ stats = new JButton("Stats");
+ stats.addActionListener(new MenuButton());
+ stats.setFocusPainted(false);
+ stats.setBackground(Color.CYAN);
+
+ if (Driver.returnRunning() == false) {
+ snake.setEnabled(false);
+ collector.setEnabled(false);
+ if (collectorGame != null)
+ collectorGame.myTimer.stop();
+ }
+
+ gLayout = new GridBagLayout();
+ c = new GridBagConstraints();
+ setBackground(Color.BLACK);
+
+ c.fill = GridBagConstraints.BOTH;
+ c.gridx = 0;
+ c.gridy = 0;
+ add(snake,c);
+
+ c.gridx = 0;
+ c.gridy = 1;
+ add(collector,c);
+
+ c.gridx = 0;
+ c.gridy = 2;
+ add(stats,c);
+
+ enabler.start();
+ }
+
+
+ private class MenuButton implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+ enabler.stop();
+ if (e.getSource() == collector)
+ {
+ Driver.playingCollector = true;
+ int DBscore = Integer.parseInt((DBOps.getData("users", Driver.currentUser.getName(), "user", "playedCollector")).get(0)) + 1;
+ DBOps.updateData("users", "playedCollector", "" + DBscore, "user", Driver.currentUser.getName() );
+
+ Driver.newPanel.mainPanel.setLayout(new FlowLayout());
+ Driver.newPanel.mainPanel.removeAll();
+ Driver.newPanel.mainPanel.setPreferredSize(null);
+ collectorGame = new Game();
+ JPanel gamePanel = new JPanel();
+ gamePanel.setPreferredSize(new Dimension(450,270));
+ gamePanel.setLayout(new BorderLayout());
+ gamePanel.add(collectorGame, BorderLayout.CENTER);
+ Driver.newPanel.mainPanel.add(gamePanel);
+ Driver.newPanel.mainPanel.setBackground(Color.MAGENTA);
+
+ Driver.newPanel.chatPanel.setFocusable(false);
+
+ Driver.newPanel.chatPanel.messageField.setEditable(false);
+ Driver.newPanel.chatPanel.messageField.setText("Help your team win!");
+ Driver.newPanel.chatPanel.send.setEnabled(false);
+
+ Driver.newPanel.chatPanel.restartThread();
+ Driver.newPanel.revalidate(); Driver.newPanel.repaint();
+ }
+ else if (e.getSource() == snake) {
+ Driver.playingSnake = true;
+ int DBscore = Integer.parseInt((DBOps.getData("users", Driver.currentUser.getName(), "user", "playedSnake")).get(0)) + 1;
+ DBOps.updateData("users", "playedSnake", "" + DBscore, "user", Driver.currentUser.getName() );
+
+ Driver.newPanel.mainPanel.setLayout(new FlowLayout());
+ Driver.newPanel.mainPanel.removeAll();
+ Driver.newPanel.mainPanel.setPreferredSize(null);
+ PApplet mySnakeApplet = new GameApplet();
+ mySnakeApplet.init();
+ JPanel gamePanel = new JPanel();
+ gamePanel.setPreferredSize(new Dimension(300,300));
+ gamePanel.setLayout(new BorderLayout());
+ gamePanel.add(mySnakeApplet, BorderLayout.CENTER);
+ Driver.newPanel.mainPanel.add(gamePanel);
+ Driver.newPanel.mainPanel.setBackground(Color.MAGENTA);
+
+ Driver.newPanel.chatPanel.setFocusable(false);
+
+ Driver.newPanel.chatPanel.messageField.setEditable(false);
+ Driver.newPanel.chatPanel.messageField.setText("Help your team win!");
+ Driver.newPanel.chatPanel.send.setEnabled(false);
+
+ Driver.newPanel.chatPanel.restartThread();
+
+ Driver.newPanel.revalidate(); Driver.newPanel.repaint();
+
+ }
+ else if (e.getSource() == stats) {
+ Driver.newPanel.mainPanel.setLayout(new FlowLayout());
+ Driver.newPanel.mainPanel.removeAll();
+ Driver.newPanel.mainPanel.setPreferredSize(null);
+ Driver.newPanel.mainPanel.add(new StatsPanel());
+ Driver.newPanel.mainPanel.setBackground(Color.MAGENTA);
+
+ Driver.newPanel.revalidate(); Driver.newPanel.repaint();
+ }
+
+ }
+
+ }
+
+ private class EnableButton implements ActionListener{
+
+ public void actionPerformed(ActionEvent arg0) {
+ if (Driver.returnRunning() == true) {
+ snake.setEnabled(true);
+ collector.setEnabled(true);
+ }
+ else {
+ snake.setEnabled(false);
+ collector.setEnabled(false);
+ }
+ }
+ }
+
+}
diff --git a/src/gui/StatsPanel.java b/src/gui/StatsPanel.java
new file mode 100644
index 0000000..1222ca5
--- /dev/null
+++ b/src/gui/StatsPanel.java
@@ -0,0 +1,112 @@
+package gui;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingConstants;
+import javax.swing.Timer;
+
+import main.DBOps;
+import main.Driver;
+
+public class StatsPanel extends JPanel {
+
+ private static final long serialVersionUID = 1L;
+ public JLabel messages, loggedIn, playedSnake, playedCollector, scoredSnake, scoredCollector, wonSnake, wonCollector;
+ public JPanel labelPanel;
+ public JButton menuButton;
+ public GridLayout gLayout;
+
+ public Timer enabler = new Timer(1000, new StatsListener());
+
+ public StatsPanel() {
+
+ messages = new JLabel("Messages: " + (DBOps.getData("users", Driver.currentUser.getName(), "user", "messages")).get(0));
+ messages.setForeground(Color.WHITE);
+ messages.setBackground(Color.BLACK);
+ loggedIn = new JLabel("Logged in: " + (DBOps.getData("users", Driver.currentUser.getName(), "user", "loggedIn")).get(0));
+ loggedIn.setForeground(Color.WHITE);
+ loggedIn.setBackground(Color.BLACK);
+ playedSnake = new JLabel("Played Snake: " + (DBOps.getData("users", Driver.currentUser.getName(), "user", "playedSnake")).get(0));
+ playedSnake.setForeground(Color.WHITE);
+ playedSnake.setBackground(Color.BLACK);
+ playedCollector = new JLabel("Played Collector: " + (DBOps.getData("users", Driver.currentUser.getName(), "user", "playedCollector")).get(0));
+ playedCollector.setForeground(Color.WHITE);
+ playedCollector.setBackground(Color.BLACK);
+ scoredSnake = new JLabel("Snake score: " + (DBOps.getData("users", Driver.currentUser.getName(), "user", "scoredSnake")).get(0));
+ scoredSnake.setForeground(Color.WHITE);
+ scoredSnake.setBackground(Color.BLACK);
+ scoredCollector = new JLabel("Collector score: " + (DBOps.getData("users", Driver.currentUser.getName(), "user", "scoredCollector")).get(0));
+ scoredCollector.setForeground(Color.WHITE);
+ scoredCollector.setBackground(Color.BLACK);
+ wonSnake = new JLabel("Team Snake wins: " + (DBOps.getData("users", Driver.currentUser.getName(), "user", "wonSnake")).get(0));
+ wonSnake.setForeground(Color.WHITE);
+ wonSnake.setBackground(Color.BLACK);
+ wonCollector = new JLabel("Team Collector wins: " + (DBOps.getData("users", Driver.currentUser.getName(), "user", "wonCollector")).get(0));
+ wonCollector.setForeground(Color.WHITE);
+ wonCollector.setBackground(Color.BLACK);
+
+ menuButton = new JButton("Back to Menu");
+ menuButton.setBackground(Color.WHITE);
+ menuButton.setHorizontalAlignment(SwingConstants.CENTER);
+ menuButton.setFocusPainted(false);
+ menuButton.addActionListener(new MenuListener());
+
+ labelPanel = new JPanel();
+ gLayout = new GridLayout(7,2);
+ labelPanel.setLayout(gLayout);
+ labelPanel.setBackground(Color.BLACK);
+ setBackground(Color.BLACK);
+ setLayout(new BorderLayout());
+
+ labelPanel.add(messages);
+ labelPanel.add(loggedIn);
+ labelPanel.add(new JLabel(""));
+ labelPanel.add(new JLabel(""));
+ labelPanel.add(playedSnake);
+ labelPanel.add(playedCollector);
+ labelPanel.add(new JLabel(""));
+ labelPanel.add(new JLabel(""));
+ labelPanel.add(scoredSnake);
+ labelPanel.add(scoredCollector);
+ labelPanel.add(new JLabel(""));
+ labelPanel.add(new JLabel(""));
+ labelPanel.add(wonSnake);
+ labelPanel.add(wonCollector);
+
+ add(labelPanel, BorderLayout.CENTER);
+ add(menuButton, BorderLayout.PAGE_END);
+
+ enabler.start();
+ }
+
+ private class MenuListener implements ActionListener {
+
+ public void actionPerformed(ActionEvent arg0) {
+ enabler.stop();
+ Driver.newPanel.mainPanel.setLayout(new FlowLayout());
+ Driver.newPanel.mainPanel.removeAll();
+ Driver.newPanel.mainPanel.setPreferredSize(null);
+
+ Driver.newPanel.mainPanel.add(new MenuPanel());
+
+ Driver.newPanel.revalidate(); Driver.newPanel.repaint();
+ }
+
+ }
+
+ private class StatsListener implements ActionListener {
+
+ public void actionPerformed(ActionEvent arg0) {
+ messages.setText("Messages: " + (DBOps.getData("users", Driver.currentUser.getName(), "user", "messages")).get(0));
+ }
+
+ }
+}
diff --git a/src/main.java b/src/main.java
deleted file mode 100644
index ea117e8..0000000
--- a/src/main.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Created by newScanTron on 10/23/2014.
- */
-public class main
-{
- public static void main(String args[])
- {
- System.out.println("what is up dawg");
- DBOps connOps = new DBOps();
- connOps.connect();
-
-
-
- }
-
-
-
-}
diff --git a/src/DBOps.java b/src/main/DBOps.java
similarity index 75%
rename from src/DBOps.java
rename to src/main/DBOps.java
index ef01efe..c0b8a28 100644
--- a/src/DBOps.java
+++ b/src/main/DBOps.java
@@ -1,3 +1,4 @@
+package main;
import java.sql.*;
import java.util.ArrayList;
@@ -10,14 +11,13 @@ public final class DBOps {
static ResultSet resultSet = null;
ResultSet workingSet = null;
User[] users = {};
- View[] views = {};
int found_id = 0;
public static void connect()
{
String url = "jdbc:mysql://minazone.com:3306/";
- String db = "project3";
+ String db = "project3?useUnicode=true&characterEncoding=utf8";
String driver = "com.mysql.jdbc.Driver";
String user = "guest";
String pass = "victini494";
@@ -36,13 +36,13 @@ public static void connect()
}
}
- public static ArrayList getData(String location, String data, String where, String column) {
+ public static ArrayList getData(String location, String data, String where, String column) {
try {
String statement = "SELECT `" + column + "` FROM `" + location + "` WHERE `" + where + "` = \"" + data + "\"";
pst = conn.prepareStatement(statement);
resultSet = pst.executeQuery();
- ArrayList results = new ArrayList();
+ ArrayList results = new ArrayList();
while (resultSet.next())
results.add(resultSet.getString(1));
return results;
@@ -52,6 +52,23 @@ public static ArrayList getData(String location, String data, String where, Stri
}
return null;
}
+
+ public static ArrayList getColumn(String location, String column) {
+ try {
+
+ String statement = "SELECT `" + column + "` FROM `" + location + "`";
+ pst = conn.prepareStatement(statement);
+ resultSet = pst.executeQuery();
+ ArrayList results = new ArrayList();
+ while (resultSet.next())
+ results.add(resultSet.getString(1));
+ return results;
+ }
+ catch (SQLException error) {
+ System.out.println("The state change failed. " + error.getMessage());
+ }
+ return null;
+ }
public static void updateData(String location, String column, String data, String where, String condition) {
try {
@@ -63,6 +80,7 @@ public static void updateData(String location, String column, String data, Strin
catch (SQLException error) {
System.out.println("The state change failed. " + error.getMessage());
}
+
}
/* This creates an entire new entry into the table. Think carefully about whether
@@ -72,13 +90,13 @@ public static void updateData(String location, String column, String data, Strin
public static void insertData(String location, String column, String data) {
try {
String statement = "INSERT INTO `" + location + "`(`" + column + "`) VALUES(\"" + data + "\")";
- System.out.println(statement);
pst = conn.prepareStatement(statement);
pst.executeUpdate();
System.out.println("Inserted data to table");
}
catch (SQLException error) {
System.out.println("The state change failed. " + error.getMessage());
+
}
}
}
diff --git a/src/main/Driver.java b/src/main/Driver.java
new file mode 100644
index 0000000..50937c7
--- /dev/null
+++ b/src/main/Driver.java
@@ -0,0 +1,93 @@
+package main;
+/* *************************************************************
+ File Name: Driver.java
+ Last Changed Date: October 27th, 2014
+ Purpose: Displays the TestPanel showing inter-user connectivity
+ Author: Adam Clemons
+ ************************************************************* */
+
+import gui.GUI;
+
+import javax.swing.*;
+import javax.swing.text.BadLocationException;
+
+import java.awt.*;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.TimeZone;
+
+
+public class Driver {
+
+ public static GUI newPanel;
+ public static JFrame displayFrame;
+ public static ArrayList users;
+ public static User currentUser;
+ public static boolean playingSnake;
+ public static boolean playingCollector;
+
+ public static void main(String[] args) throws IOException, ParseException, BadLocationException {
+ DBOps.connect();
+ updateUsers();
+
+ // Creates the JFrame, sets what happens when we close it, and makes it a fixed size (dependent on JPanel sizes)
+ displayFrame = new JFrame("Server Time!");
+ displayFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ displayFrame.setResizable(false);
+ displayFrame.setLayout(new BorderLayout());
+
+ newPanel = new GUI();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+
+ displayFrame.getContentPane().add(newPanel);
+
+ // Tells the DB the user has disconnected
+ displayFrame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e){
+ if (currentUser != null) {
+ DBOps.updateData("users", "connected", "0", "user", currentUser.getName());
+ DBOps.updateData("info", "string_colour", "SkyNet" + ": " + currentUser.getName() + " ran away from chat.", "id", "2");
+ try {
+ DBOps.updateData("info", "time_stamp", "" + Driver.newPanel.chatPanel.getTimeStamp(), "id", "2");
+ } catch (ParseException e1) {
+ e1.printStackTrace();
+ }
+ }
+ System.out.println("Disconnected");
+ System.exit(0);
+ }
+ });
+
+ // Packs the Frame up for delivery to the console
+ displayFrame.pack();
+ displayFrame.setLocationRelativeTo(null);
+ displayFrame.setVisible(true); // Allows us to see the Frame
+
+ }
+
+ public static void updateUsers() {
+ users = new ArrayList();
+ ArrayList usernames = DBOps.getColumn("users", "user");
+ ArrayList passwords = DBOps.getColumn("users", "password");
+ for (int i = 0; i < usernames.size(); i ++)
+ users.add(new User((String) usernames.get(i), (String)passwords.get(i)));
+ }
+
+ public static String onlineUsers() {
+ updateUsers();
+ String onlineUsers = "SkyNet";
+ for (int i = 0; i < users.size(); i ++) {
+ if ((Integer.parseInt((DBOps.getData("users", users.get(i).getName(), "user", "connected")).get(0))) == 1) {
+ onlineUsers = onlineUsers + ", " + users.get(i).getName();
+ };
+ }
+ return onlineUsers;
+ }
+
+ public static boolean returnRunning() {
+ return Boolean.parseBoolean((DBOps.getData("info", "3", "id", "time_stamp")).get(0));
+ }
+}
diff --git a/src/Listener.java b/src/main/Listener.java
similarity index 56%
rename from src/Listener.java
rename to src/main/Listener.java
index 0ba5164..ab3508e 100644
--- a/src/Listener.java
+++ b/src/main/Listener.java
@@ -1,4 +1,4 @@
-import java.awt.Color;
+package main;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
@@ -18,14 +18,14 @@ public Listener() throws FileNotFoundException {
public void run() {
color = (String)(DBOps.getData("info", "1", "id", "string_colour")).get(0);
- if (color.equals("RED"))
- Driver.newPanel.sharedView.setBackground(Color.RED);
- if (color.equals("GREEN"))
- Driver.newPanel.sharedView.setBackground(Color.GREEN);
- if (color.equals("CYAN"))
- Driver.newPanel.sharedView.setBackground(Color.CYAN);
- if (color.equals("BLACK"))
- Driver.newPanel.sharedView.setBackground(Color.BLACK);
+// if (color.equals("RED"))
+// Driver.newPanel.sharedView.setBackground(Color.RED);
+// if (color.equals("GREEN"))
+// Driver.newPanel.sharedView.setBackground(Color.GREEN);
+// if (color.equals("CYAN"))
+// Driver.newPanel.sharedView.setBackground(Color.CYAN);
+// if (color.equals("BLACK"))
+// Driver.newPanel.sharedView.setBackground(Color.BLACK);
}
}
diff --git a/src/TestPanel.java b/src/main/TestPanel.java
similarity index 92%
rename from src/TestPanel.java
rename to src/main/TestPanel.java
index 91bbd53..ee7de6e 100644
--- a/src/TestPanel.java
+++ b/src/main/TestPanel.java
@@ -1,7 +1,9 @@
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.GridBagLayout;
+
+package main;
+
+import javax.swing.*;
+import javax.swing.border.LineBorder;
+import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
@@ -11,14 +13,9 @@
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import javax.swing.JButton;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.SwingConstants;
-import javax.swing.border.LineBorder;
-
-public class TestPanel extends JPanel{
+public class TestPanel extends JPanel
+{
private static final long serialVersionUID = 1L;
diff --git a/src/user.java b/src/main/User.java
similarity index 65%
rename from src/user.java
rename to src/main/User.java
index e3ac3a6..df2690c 100644
--- a/src/user.java
+++ b/src/main/User.java
@@ -1,17 +1,16 @@
+package main;
/**
* Created by newScanTron on 10/24/2014.
*/
public class User
{
- String email;
String password;
String name;
- public void User(String name, String email, String password)
+ public User(String name, String password)
{
this.name = name;
- this.email = email;
this.password = password;
}
@@ -25,16 +24,6 @@ public void setName(String name)
this.name = name;
}
- public String getEmail()
- {
- return email;
- }
-
- public void setEmail(String email)
- {
- this.email = email;
- }
-
public String getPassword()
{
return password;
diff --git a/src/runner/forceApply.java b/src/runner/forceApply.java
deleted file mode 100644
index ff01f51..0000000
--- a/src/runner/forceApply.java
+++ /dev/null
@@ -1,214 +0,0 @@
-package runner;
-
-
-
- import org.jbox2d.collision.shapes.EdgeShape;
- import org.jbox2d.collision.shapes.PolygonShape;
- import org.jbox2d.common.MathUtils;
- import org.jbox2d.common.Rot;
- import org.jbox2d.common.Transform;
- import org.jbox2d.common.Vec2;
- import org.jbox2d.dynamics.Body;
- import org.jbox2d.dynamics.BodyDef;
- import org.jbox2d.dynamics.BodyType;
- import org.jbox2d.dynamics.FixtureDef;
- import org.jbox2d.dynamics.joints.FrictionJointDef;
- import org.jbox2d.testbed.framework.TestbedSettings;
- import org.jbox2d.testbed.framework.TestbedTest;
-
-/**
- * @author Daniel Murphy
- */
-public class forceApply extends TestbedTest {
- private static final long BODY_TAG = 12;
-
- Body m_body;
-
- @Override
- public void initTest(boolean deserialized) {
- if (deserialized) {
- return;
- }
-
- getWorld().setGravity(new Vec2(0.0f, 0.0f));
-
- final float k_restitution = 0.4f;
-
- Body ground;
- {
- BodyDef bd = new BodyDef();
- bd.position.set(0.0f, 20.0f);
- ground = getWorld().createBody(bd);
-
- EdgeShape shape = new EdgeShape();
-
- FixtureDef sd = new FixtureDef();
- sd.shape = shape;
- sd.density = 0.0f;
- sd.restitution = k_restitution;
-
- // Left vertical
- shape.set(new Vec2(-20.0f, -20.0f), new Vec2(-20.0f, 20.0f));
- ground.createFixture(sd);
-
- // Right vertical
- shape.set(new Vec2(20.0f, -20.0f), new Vec2(20.0f, 20.0f));
- ground.createFixture(sd);
-
- // Top horizontal
- shape.set(new Vec2(-20.0f, 20.0f), new Vec2(20.0f, 20.0f));
- ground.createFixture(sd);
-
- // Bottom horizontal
- shape.set(new Vec2(-20.0f, -20.0f), new Vec2(20.0f, -20.0f));
- ground.createFixture(sd);
- }
-
- {
- Transform xf1 = new Transform();
- xf1.q.set(0.3524f * MathUtils.PI);
- Rot.mulToOutUnsafe(xf1.q, new Vec2(1.0f, 0.0f), xf1.p);
-
- Vec2 vertices[] = new Vec2[3];
- vertices[0] = Transform.mul(xf1, new Vec2(-1.0f, 0.0f));
- vertices[1] = Transform.mul(xf1, new Vec2(1.0f, 0.0f));
- vertices[2] = Transform.mul(xf1, new Vec2(0.0f, 0.5f));
-
- PolygonShape poly1 = new PolygonShape();
- poly1.set(vertices, 3);
-
- FixtureDef sd1 = new FixtureDef();
- sd1.shape = poly1;
- sd1.density = 4.0f;
-
- Transform xf2 = new Transform();
- xf2.q.set(-0.3524f * MathUtils.PI);
- Rot.mulToOut(xf2.q, new Vec2(-1.0f, 0.0f), xf2.p);
-
- vertices[0] = Transform.mul(xf2, new Vec2(-1.0f, 0.0f));
- vertices[1] = Transform.mul(xf2, new Vec2(1.0f, 0.0f));
- vertices[2] = Transform.mul(xf2, new Vec2(0.0f, 0.5f));
-
- PolygonShape poly2 = new PolygonShape();
- poly2.set(vertices, 3);
-
- FixtureDef sd2 = new FixtureDef();
- sd2.shape = poly2;
- sd2.density = 2.0f;
-
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.angularDamping = 2.0f;
- bd.linearDamping = 0.5f;
-
- bd.position.set(0.0f, 2.0f);
- bd.angle = MathUtils.PI;
- bd.allowSleep = false;
- m_body = getWorld().createBody(bd);
- m_body.createFixture(sd1);
- m_body.createFixture(sd2);
- }
-
- {
- PolygonShape shape = new PolygonShape();
- shape.setAsBox(0.5f, 0.5f);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = shape;
- fd.density = 1.0f;
- fd.friction = 0.3f;
-
- for (int i = 0; i < 10; ++i) {
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
-
- bd.position.set(0.0f, 5.0f + 1.54f * i);
- Body body = getWorld().createBody(bd);
-
- body.createFixture(fd);
-
- float gravity = 10.0f;
- float I = body.getInertia();
- float mass = body.getMass();
-
- // For a circle: I = 0.5 * m * r * r ==> r = sqrt(2 * I / m)
- float radius = MathUtils.sqrt(2.0f * I / mass);
-
- FrictionJointDef jd = new FrictionJointDef();
- jd.localAnchorA.setZero();
- jd.localAnchorB.setZero();
- jd.bodyA = ground;
- jd.bodyB = body;
- jd.collideConnected = true;
- jd.maxForce = mass * gravity;
- jd.maxTorque = mass * radius * gravity;
-
- getWorld().createJoint(jd);
- }
- }
- }
-
- @Override
- public void keyPressed(char keyCar, int keyCode) {
- // TODO Auto-generated method stub
- super.keyPressed(keyCar, keyCode);
- }
-
- @Override
- public void step(TestbedSettings settings) {
- super.step(settings);
-
- addTextLine("Use 'wasd' to move, 'e' and 's' drift.");
- if (getModel().getKeys()['w']) {
- Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f));
- Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(0.0f, 2.0f)));
- m_body.applyForce(f, p);
- } else if (getModel().getKeys()['q']) {
- Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f));
- Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(-.2f, 0f)));
- m_body.applyForce(f, p);
- } else if (getModel().getKeys()['e']) {
- Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f));
- Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(.2f, 0f)));
- m_body.applyForce(f, p);
- } else if (getModel().getKeys()['s']) {
- Vec2 f = m_body.getWorldVector(new Vec2(0.0f, 30.0f));
- Vec2 p = m_body.getWorldCenter();
- m_body.applyForce(f, p);
- }
-
- if (getModel().getKeys()['a']) {
- m_body.applyTorque(20.0f);
- }
-
- if (getModel().getKeys()['d']) {
- m_body.applyTorque(-20.0f);
- }
- }
-
- @Override
- public boolean isSaveLoadEnabled() {
- return true;
- }
-
- @Override
- public Long getTag(Body body) {
- if (body == m_body) {
- return BODY_TAG;
- }
- return super.getTag(body);
- }
-
- @Override
- public void processBody(Body body, Long tag) {
- if (tag == BODY_TAG) {
- m_body = body;
- }
- super.processBody(body, tag);
- }
-
- @Override
- public String getTestName() {
- return "Apply Force";
- }
-}
\ No newline at end of file
diff --git a/src/snake/.classpath b/src/snake/.classpath
new file mode 100644
index 0000000..0453d87
--- /dev/null
+++ b/src/snake/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/src/snake/.project b/src/snake/.project
new file mode 100644
index 0000000..6c308c0
--- /dev/null
+++ b/src/snake/.project
@@ -0,0 +1,17 @@
+
+
+ Snake
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/src/snake/.settings/org.eclipse.jdt.core.prefs b/src/snake/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..7341ab1
--- /dev/null
+++ b/src/snake/.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.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+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.7
diff --git a/src/Snake/GameApplet$Block.class b/src/snake/GameApplet$Block.class
similarity index 100%
rename from src/Snake/GameApplet$Block.class
rename to src/snake/GameApplet$Block.class
diff --git a/src/Snake/GameApplet$Snake.class b/src/snake/GameApplet$Snake.class
similarity index 100%
rename from src/Snake/GameApplet$Snake.class
rename to src/snake/GameApplet$Snake.class
diff --git a/src/Snake/GameApplet.class b/src/snake/GameApplet.class
similarity index 100%
rename from src/Snake/GameApplet.class
rename to src/snake/GameApplet.class
diff --git a/src/Snake/src/GameApplet.java b/src/snake/GameApplet.java
similarity index 55%
rename from src/Snake/src/GameApplet.java
rename to src/snake/GameApplet.java
index f004a61..5ad2e54 100644
--- a/src/Snake/src/GameApplet.java
+++ b/src/snake/GameApplet.java
@@ -1,3 +1,8 @@
+
+package snake;
+
+import main.DBOps;
+import main.Driver;
import processing.core.*;
@@ -7,43 +12,54 @@ public class GameApplet extends PApplet {
Snake mySnake;
Snake mySnake2;
Snake mySnake3;
- Block myBlock;
+ Block[] myBlocks;
Block myBlock2;
PFont scoreFont;
int score;
int score2;
boolean gameOver;
-
+ double curClosest = 10000;
+ private Thread scoreThread = new Thread(new UpdateScore());
+
+ static public void main(String args[]) {
+ PApplet.main(new String[] { "snake.GameApplet" });
+ }
+
public void setup() {
- size(600, 600);
+ size(300, 300);
background(0);
-
+ frameRate(20);
+
mySnake = new Snake(color(255,0,0), width/2 - 100, height/2, 10, false);
- mySnake2 = new Snake(color(0, 0, 255), width/2 + 100, height/2, 10, false);
+// mySnake2 = new snake(color(0, 0, 255), width/2 + 100, height/2, 10, false);
mySnake.snakeSize = 1;
- mySnake2.snakeSize = 1;
+// mySnake2.snakeSize = 1;
mySnake3 = null;
- myBlock = new Block(color(255, 0, 0));
- myBlock2 = new Block(color(0, 0, 255));
+ myBlocks = new Block[5];
+ for (int i = 0; i < 5; i++)
+ myBlocks[i] = (new Block(color(0, 255, 0)));
+// myBlock2 = new Block(color(0, 0, 255));
mySnake.direction = DOWN;
- mySnake2.direction = DOWN;
+// mySnake2.direction = DOWN;
gameOver = false;
score = 0;
- score2 = 0;
+// score2 = 0;
scoreFont = createFont("Arial", 16, true);
textAlign(CENTER);
+ curClosest = 10000;
}
public void draw() {
background(0);
- myBlock.display();
- myBlock2.display();
+ for (int i = 0; i < 5; i++)
+ myBlocks[i].display();
+// myBlock2.display();
mySnake.display();
- mySnake2.display();
+// mySnake2.display();
if (mySnake3 != null)
mySnake3.display();
@@ -60,10 +76,10 @@ public void draw() {
mySnake.oldPositionsY[i] = mySnake.partsY[i];
}
- for (int i = 0; i < mySnake2.snakeSize; i++) {
- mySnake2.oldPositionsX[i] = mySnake2.partsX[i];
- mySnake2.oldPositionsY[i] = mySnake2.partsY[i];
- }
+// for (int i = 0; i < mySnake2.snakeSize; i++) {
+// mySnake2.oldPositionsX[i] = mySnake2.partsX[i];
+// mySnake2.oldPositionsY[i] = mySnake2.partsY[i];
+// }
if (mySnake3 != null) {
for (int i = 0; i < mySnake3.snakeSize; i++) {
@@ -90,23 +106,23 @@ public void draw() {
break;
}
- switch(mySnake2.direction) {
- case(RIGHT):
- mySnake2.moveRight();
- break;
-
- case(UP):
- mySnake2.moveUp();
- break;
-
- case(DOWN):
- mySnake2.moveDown();
- break;
-
- case(LEFT):
- mySnake2.moveLeft();
- break;
- }
+// switch(mySnake2.direction) {
+// case(RIGHT):
+// mySnake2.moveRight();
+// break;
+//
+// case(UP):
+// mySnake2.moveUp();
+// break;
+//
+// case(DOWN):
+// mySnake2.moveDown();
+// break;
+//
+// case(LEFT):
+// mySnake2.moveLeft();
+// break;
+// }
if (mySnake3 != null) {
switch(mySnake3.direction) {
@@ -135,12 +151,12 @@ public void draw() {
}
}
- if (mySnake2.speed > 0) {
- for (int i = 0; i < mySnake2.snakeSize; i++) {
- mySnake2.partsX[i+1] = mySnake2.oldPositionsX[i];
- mySnake2.partsY[i+1] = mySnake2.oldPositionsY[i];
- }
- }
+// if (mySnake2.speed > 0) {
+// for (int i = 0; i < mySnake2.snakeSize; i++) {
+// mySnake2.partsX[i+1] = mySnake2.oldPositionsX[i];
+// mySnake2.partsY[i+1] = mySnake2.oldPositionsY[i];
+// }
+// }
if (mySnake3 != null) {
if (mySnake3.speed > 0) {
@@ -151,17 +167,20 @@ public void draw() {
}
}
- if (detectHit(mySnake, myBlock)) {
- myBlock = new Block(color(255, 0, 0));
- score += 10;
- mySnake.snakeSize++;
+ for (int i = 0; i < 5; i++) {
+ if (detectHit(mySnake, myBlocks[i])) {
+ myBlocks[i] = new Block(color(0, 255, 0));
+ scoreThread = new Thread(new UpdateScore());
+ scoreThread.start();
+ mySnake.snakeSize++;
+ }
}
- if (detectHit(mySnake2, myBlock2)) {
- myBlock2 = new Block(color(0, 0, 255));
- score2 += 10;
- mySnake2.snakeSize++;
- }
+// if (detectHit(mySnake2, myBlock2)) {
+// myBlock2 = new Block(color(0, 0, 255));
+// score2 += 10;
+// mySnake2.snakeSize++;
+// }
if (mySnake3 != null) {
if (detectHit (mySnake, mySnake3)) {
@@ -173,68 +192,72 @@ public void draw() {
mySnake.partsY[i] = mySnake.oldPositionsY[i];
}
}
- if (detectHit(mySnake2, mySnake3)) {
- mySnake2.speed = 0;
-
- for (int i = 0; i < mySnake2.snakeSize; i++) {
- mySnake2.partsX[i] = mySnake2.oldPositionsX[i];
- mySnake2.partsY[i] = mySnake2.oldPositionsY[i];
- }
- }
- }
-
-
- if (myBlock.passedTime == 0) {
- myBlock = new Block(color(255, 0, 0));
- }
-
- if (myBlock2.passedTime == 0) {
- myBlock2 = new Block(color(0, 0, 255));
- }
-
- if (detectHit(mySnake, mySnake2)) {
- mySnake.speed = 0;
-
- for (int i = 0; i < mySnake.snakeSize; i++) {
- mySnake.partsX[i] = mySnake.oldPositionsX[i];
- mySnake.partsY[i] = mySnake.oldPositionsY[i];
- }
-
- mySnake3 = new Snake(color(0, 255, 0), 0, 0, 10, true);
- mySnake3.snakeSize = 20;
- mySnake3.direction = RIGHT;
+// if (detectHit(mySnake2, mySnake3)) {
+// mySnake2.speed = 0;
+//
+// for (int i = 0; i < mySnake2.snakeSize; i++) {
+// mySnake2.partsX[i] = mySnake2.oldPositionsX[i];
+// mySnake2.partsY[i] = mySnake2.oldPositionsY[i];
+// }
+// }
}
- if (detectHit(mySnake2, mySnake)) {
- mySnake2.speed = 0;
-
- for (int i = 0; i < mySnake2.snakeSize; i++) {
- mySnake2.partsX[i] = mySnake2.oldPositionsX[i];
- mySnake2.partsY[i] = mySnake2.oldPositionsY[i];
- }
-
- mySnake3 = new Snake(color(0, 255, 0), 0, 0, 10, true);
- mySnake3.snakeSize = 20;
- mySnake3.direction = RIGHT;
+ for (int i = 0; i < 5; i++) {
+ if (myBlocks[i].passedTime == 0) {
+ myBlocks[i] = new Block(color(0, 255, 0));
+ }
}
- if (score > score2 && mySnake2.speed == 0)
- gameOver = true;
+// if (myBlock2.passedTime == 0) {
+// myBlock2 = new Block(color(0, 0, 255));
+// }
+
+// if (detectHit(mySnake, mySnake)) {
+// mySnake.speed = 0;
+//
+// for (int i = 0; i < mySnake.snakeSize; i++) {
+// mySnake.partsX[i] = mySnake.oldPositionsX[i];
+// mySnake.partsY[i] = mySnake.oldPositionsY[i];
+// }
+//
+// mySnake3 = new snake(color(0, 255, 0), 0, 0, 10, true);
+// mySnake3.snakeSize = 20;
+// mySnake3.direction = RIGHT;
+// }
+
+// if (detectHit(mySnake2, mySnake)) {
+// mySnake2.speed = 0;
+//
+// for (int i = 0; i < mySnake2.snakeSize; i++) {
+// mySnake2.partsX[i] = mySnake2.oldPositionsX[i];
+// mySnake2.partsY[i] = mySnake2.oldPositionsY[i];
+// }
+//
+// mySnake3 = new snake(color(0, 255, 0), 0, 0, 10, true);
+// mySnake3.snakeSize = 20;
+// mySnake3.direction = RIGHT;
+// }
+
+// if (score > score2 && mySnake2.speed == 0)
+// gameOver = true;
if (score2 > score && mySnake.speed == 0)
gameOver = true;
- if (mySnake.speed == 0 && mySnake2.speed == 0)
- gameOver = true;
+// if (mySnake.speed == 0 && mySnake2.speed == 0)
+// gameOver = true;
}
else {
text("GAME OVER", width/2, height/2);
text("(Press Spacebar to Continue)", width/2, height/2 + 20);
}
+
+ detectClosest();
+
}
public void keyPressed() {
-
+
switch(key) {
case('w'):
mySnake.direction = UP;
@@ -256,16 +279,16 @@ public void keyPressed() {
setup();
}
- if (key == CODED) {
- if (keyCode == LEFT)
- mySnake2.direction = LEFT;
- else if (keyCode == RIGHT)
- mySnake2.direction = RIGHT;
- else if (keyCode == UP)
- mySnake2.direction = UP;
- else if (keyCode == DOWN)
- mySnake2.direction = DOWN;
- }
+// if (key == CODED) {
+// if (keyCode == LEFT)
+// mySnake2.direction = LEFT;
+// else if (keyCode == RIGHT)
+// mySnake2.direction = RIGHT;
+// else if (keyCode == UP)
+// mySnake2.direction = UP;
+// else if (keyCode == DOWN)
+// mySnake2.direction = DOWN;
+// }
}
class Snake {
@@ -376,8 +399,8 @@ class Block {
Block(int c) {
displayColor = c;
- xpos = (int)random(width-10);
- ypos = (int)random(height-30) + 20;
+ xpos = (int)random(width/10-1)*10;
+ ypos = (int)random(height/10-3)*10 + 20;
savedTime = millis();
}
@@ -396,13 +419,13 @@ void display() {
boolean detectHit(Snake a, Block b) {
- if (a.partsX[0] + 10 < b.xpos)
+ if (a.partsX[0] + 9 < b.xpos)
return false;
- else if (a.partsX[0] > b.xpos + 10)
+ else if (a.partsX[0] > b.xpos + 9)
return false;
- else if (a.partsY[0] + 10 < b.ypos)
+ else if (a.partsY[0] + 9 < b.ypos)
return false;
- else if (a.partsY[0] > b.ypos + 10)
+ else if (a.partsY[0] > b.ypos + 9)
return false;
else {
@@ -433,17 +456,17 @@ else if (a.partsY[0] > b.ypos + 10)
boolean detectHit(Snake a, Snake b) {
- for (int i = 0; i < b.snakeSize; i++) {
+ for (int i = 1; i < b.snakeSize; i++) {
boolean hit = true;
- if (a.partsX[0] + 10 <= b.partsX[i])
+ if (a.partsX[0] + 9 <= b.partsX[i])
hit = false;
- else if (a.partsX[0] >= b.partsX[i] + 10)
+ else if (a.partsX[0] >= b.partsX[i] + 9)
hit = false;
- else if (a.partsY[0] + 10 <= b.partsY[i])
+ else if (a.partsY[0] + 9 <= b.partsY[i])
hit = false;
- else if (a.partsY[0] >= b.partsY[i] + 10)
+ else if (a.partsY[0] >= b.partsY[i] + 9)
hit = false;
if (hit)
@@ -452,4 +475,32 @@ else if (a.partsY[0] >= b.partsY[i] + 10)
return false;
}
+
+ void detectClosest() {
+ curClosest = 10000;
+ for (int i = 0; i < 5; i++) {
+ double temp = Math.sqrt(Math.pow((mySnake.partsX[0] - myBlocks[i].xpos),2) + Math.pow((mySnake.partsY[0] - myBlocks[i].ypos),2));
+// System.out.println("Temp: " + temp + "\tCurrent: " + curClosest);
+ if (temp < curClosest) {
+ curClosest = temp;
+
+ for (int j = 0; j < 5; j++)
+ myBlocks[j].displayColor = color(0,255,0);
+ myBlocks[i].displayColor = color(255,0,0);
+ }
+ }
+
+ }
+
+ private class UpdateScore implements Runnable {
+
+ public void run() {
+ int DBscore = Integer.parseInt((DBOps.getData("scores", "1", "id", "Snake")).get(0)) + 5;
+ DBOps.updateData("scores", "Snake", "" + DBscore, "id", "1");
+ DBscore = Integer.parseInt((DBOps.getData("users", Driver.currentUser.getName(), "user", "scoredSnake")).get(0)) + 5;
+ DBOps.updateData("users", "scoredSnake", "" + DBscore, "user", Driver.currentUser.getName() );
+ return;
+ }
+
+ }
}
diff --git a/tests/DBOpsTest.java b/tests/DBOpsTest.java
index 0bbf2f4..e5b0f4e 100644
--- a/tests/DBOpsTest.java
+++ b/tests/DBOpsTest.java
@@ -8,7 +8,7 @@ public class DBOpsTest
{
protected int opsTestInt;
protected String opsTestString = "";
- DBOps ops = new DBOps();
+
public class TestJunit {
@Test
@@ -33,7 +33,7 @@ public void tearDown() throws Exception
@Test
public void testConnect() throws Exception
{
- org.junit.Assert.assertEquals(true, ops.connect());
+ //org.junit.Assert.assertEquals(true, DBOps.connect());
}
@Test