diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..9d346313 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..2421e386 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "files.exclude": { + "**/.classpath": true, + "**/.project": true, + "**/.settings": true, + "**/.factorypath": true + } +} \ No newline at end of file diff --git a/Server/.idea/workspace.xml b/Server/.idea/workspace.xml new file mode 100644 index 00000000..76f26ddc --- /dev/null +++ b/Server/.idea/workspace.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1602241973712 + + + + + + + + + + + + \ No newline at end of file diff --git a/Server/ServerMain.Java b/Server/ServerMain.Java new file mode 100644 index 00000000..e69de29b diff --git a/ServerTestClient/.idea/workspace.xml b/ServerTestClient/.idea/workspace.xml new file mode 100644 index 00000000..9aa202cb --- /dev/null +++ b/ServerTestClient/.idea/workspace.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1602242737493 + + + + + + \ No newline at end of file diff --git a/Tank game - Client/.idea/libraries/lib.xml b/Tank game - Client/.idea/libraries/lib.xml new file mode 100644 index 00000000..2fa94bd7 --- /dev/null +++ b/Tank game - Client/.idea/libraries/lib.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tank game - Client/.idea/misc.xml b/Tank game - Client/.idea/misc.xml new file mode 100644 index 00000000..5217e29a --- /dev/null +++ b/Tank game - Client/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Tank game - Client/.idea/modules.xml b/Tank game - Client/.idea/modules.xml new file mode 100644 index 00000000..03ae1cf6 --- /dev/null +++ b/Tank game - Client/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Tank game - Client/.idea/vcs.xml b/Tank game - Client/.idea/vcs.xml new file mode 100644 index 00000000..6c0b8635 --- /dev/null +++ b/Tank game - Client/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Tank game - Client/.idea/workspace.xml b/Tank game - Client/.idea/workspace.xml new file mode 100644 index 00000000..09363147 --- /dev/null +++ b/Tank game - Client/.idea/workspace.xml @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1601469582604 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tank game - Client/Tank game - Client.iml b/Tank game - Client/Tank game - Client.iml new file mode 100644 index 00000000..fb8e8667 --- /dev/null +++ b/Tank game - Client/Tank game - Client.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Tank game - Client/out/production/Tank game - Client/Collision.class b/Tank game - Client/out/production/Tank game - Client/Collision.class new file mode 100644 index 00000000..2bdf3c6a Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/Collision.class differ diff --git a/Tank game - Client/out/production/Tank game - Client/META-INF/Tank game - Client.kotlin_module b/Tank game - Client/out/production/Tank game - Client/META-INF/Tank game - Client.kotlin_module new file mode 100644 index 00000000..a49347af Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/META-INF/Tank game - Client.kotlin_module differ diff --git a/Tank game - Client/out/production/Tank game - Client/Main.class b/Tank game - Client/out/production/Tank game - Client/Main.class new file mode 100644 index 00000000..8553bff7 Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/Main.class differ diff --git a/Tank game - Client/out/production/Tank game - Client/Map.class b/Tank game - Client/out/production/Tank game - Client/Map.class new file mode 100644 index 00000000..ddb7f1f3 Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/Map.class differ diff --git a/Tank game - Client/out/production/Tank game - Client/Tank.class b/Tank game - Client/out/production/Tank game - Client/Tank.class new file mode 100644 index 00000000..c472fb6d Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/Tank.class differ diff --git a/Tank game - Client/out/production/Tank game - Client/Test2$1.class b/Tank game - Client/out/production/Tank game - Client/Test2$1.class new file mode 100644 index 00000000..99721cf5 Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/Test2$1.class differ diff --git a/Tank game - Client/out/production/Tank game - Client/Test2$2.class b/Tank game - Client/out/production/Tank game - Client/Test2$2.class new file mode 100644 index 00000000..682c2949 Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/Test2$2.class differ diff --git a/Tank game - Client/out/production/Tank game - Client/Test2.class b/Tank game - Client/out/production/Tank game - Client/Test2.class new file mode 100644 index 00000000..96bb9d24 Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/Test2.class differ diff --git a/Tank game - Client/out/production/Tank game - Client/test5$1.class b/Tank game - Client/out/production/Tank game - Client/test5$1.class new file mode 100644 index 00000000..c3855976 Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/test5$1.class differ diff --git a/Tank game - Client/out/production/Tank game - Client/test5$2.class b/Tank game - Client/out/production/Tank game - Client/test5$2.class new file mode 100644 index 00000000..30f784c5 Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/test5$2.class differ diff --git a/Tank game - Client/out/production/Tank game - Client/test5$Sprite.class b/Tank game - Client/out/production/Tank game - Client/test5$Sprite.class new file mode 100644 index 00000000..b4d9701f Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/test5$Sprite.class differ diff --git a/Tank game - Client/out/production/Tank game - Client/test5.class b/Tank game - Client/out/production/Tank game - Client/test5.class new file mode 100644 index 00000000..239b2479 Binary files /dev/null and b/Tank game - Client/out/production/Tank game - Client/test5.class differ diff --git a/Tank game - Client/src/Collision.java b/Tank game - Client/src/Collision.java new file mode 100644 index 00000000..b5606e75 --- /dev/null +++ b/Tank game - Client/src/Collision.java @@ -0,0 +1,5 @@ +public class Collision { + + + +} diff --git a/Tank game - Client/src/Main.java b/Tank game - Client/src/Main.java new file mode 100644 index 00000000..1c30f2ff --- /dev/null +++ b/Tank game - Client/src/Main.java @@ -0,0 +1,7 @@ +public class Main { + public static void main(String[] args) { + + } + + +} diff --git a/Tank game - Client/src/Map.java b/Tank game - Client/src/Map.java new file mode 100644 index 00000000..c251a49a --- /dev/null +++ b/Tank game - Client/src/Map.java @@ -0,0 +1,21 @@ +import java.awt.*; +import java.awt.image.BufferedImage; +import javax.swing.*; + +public class Map extends JPanel { + + public static void main(String[] args) { + + JFrame frame = new JFrame("My Drawing"); + frame.pack(); + frame.setVisible(true); + frame.setSize(720,720); + ImageIcon pic = new ImageIcon("path"); + Image tank = pic.getImage(); + } + + protected void paintComponent(Graphics g) { + super.paintComponent(g); + } +} + diff --git a/Tank game - Client/src/Tank.java b/Tank game - Client/src/Tank.java new file mode 100644 index 00000000..97919653 --- /dev/null +++ b/Tank game - Client/src/Tank.java @@ -0,0 +1,29 @@ +public class Tank { + private int xPos, yPos; + private static int WIDTH; + private static int HEIGHT; + boolean hit = false; + + + + void moveTank(){ + + } + + //====GET & SET X & Y==== + public void setxPos(int xPos) { + this.xPos = xPos; + } + + public void setyPos(int yPos) { + this.yPos = yPos; + } + + public int getxPos() { + return xPos; + } + + public int getyPos() { + return yPos; + } +} diff --git a/Tank game - Client/src/Test2.java b/Tank game - Client/src/Test2.java new file mode 100644 index 00000000..5f8f41b6 --- /dev/null +++ b/Tank game - Client/src/Test2.java @@ -0,0 +1,101 @@ +import javafx.animation.AnimationTimer; +import javafx.application.Application; +import javafx.event.EventHandler; +import javafx.scene.Group; +import javafx.scene.Scene; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; +import javafx.scene.paint.Color; +import javafx.scene.shape.Circle; +import javafx.scene.transform.Rotate; +import javafx.stage.Stage; +import javafx.scene.shape.Line; + + + +public class Test2 extends Application { + int move = 5; + int circleX = 200; + int circleY = 150; + int angleCount = 0; + double angleRadians; + + public static void main(String[] args) { + launch(args); + } + + @Override + public void start(Stage stage) { + + + Circle circle = createCircle(circleX, circleY, Color.GREEN); + Line line = createLine(); + final Group group = new Group(circle, line); + final Scene scene = new Scene(group, 600, 400, Color.WHITE); + + + moveCircleOnKeyPress(scene, circle, line); + stage.setScene(scene); + stage.show(); + } + + + void lineMove(Line line, int angle) { + line.getTransforms().add(new Rotate(angle, circleX, circleY)); + + angleCount += angle; + if (angleCount == 360) { + angleCount = 0; + } + if (angleCount == -360) { + angleCount = 0; + } + + angleRadians = Math.toRadians(angleCount); + } + + + private Circle createCircle(int circleX, int circleY, Color color) { + int radius = 30; + final Circle circle = new Circle(circleX, circleY, radius, color); + return circle; + } + + private Line createLine() { + final Line line = new Line(200, 150, 230, 150); + return line; + } + + + + + private void moveCircleOnKeyPress(Scene scene, final Circle circle, final Line line) { + scene.setOnKeyPressed(new EventHandler() { + @Override + public void handle(KeyEvent event) { + switch (event.getCode()) { + + case UP: + circle.setCenterX(circle.getCenterX() + move * Math.cos(angleRadians)); + circle.setCenterY(circle.getCenterY() + move * Math.sin(angleRadians)); + break; + + case RIGHT: + lineMove(line, 10); + break; + + case DOWN: + circle.setCenterX(circle.getCenterX() - move * Math.cos(angleRadians)); + circle.setCenterY(circle.getCenterY() - move * Math.sin(angleRadians)); + break; + + case LEFT: + lineMove(line, -10); + break; + + case SPACE: + } + } + }); + } +} diff --git a/Tank game - Client/src/test5.java b/Tank game - Client/src/test5.java new file mode 100644 index 00000000..f25fb1b5 --- /dev/null +++ b/Tank game - Client/src/test5.java @@ -0,0 +1,188 @@ +import javafx.animation.AnimationTimer; +import javafx.application.Application; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Color; +import javafx.scene.shape.Circle; +import javafx.scene.shape.Rectangle; +import javafx.scene.transform.Rotate; +import javafx.stage.Stage; +import java.util.List; +import java.util.stream.Collectors; + +public class test5 extends Application { + private Pane root = new Pane(); + + + private Sprite player = new Sprite(300, 300, 70, 40, "player", Color.BLUE); + + + private Parent createContent() { + root.setPrefSize(1200, 700); + root.getChildren().add(player); + + + AnimationTimer timer = new AnimationTimer() { + @Override + public void handle(long now) { + update(); + } + }; + timer.start(); + nextLevel(); + return root; + } + + private void nextLevel() { + for (int i = 0; i < 10; i++) { + Sprite s = new Sprite(90 + i * 100, 150, 30, 30, "enemy", Color.RED); + root.getChildren().add(s); + } + } + + private List sprites() { + return root.getChildren().stream().map(n -> (Sprite) n).collect(Collectors.toList()); + } + + private void update() { + sprites().forEach(s -> { //handles what happens to the sprites/bullets + switch (s.type) { + case "enemybullet": + s.moveDown(); + if (s.getBoundsInParent().intersects(player.getBoundsInParent())) { + player.dead = true; + s.dead = true; + } + break; + + case "playerbullet": + final int angle = player.getAngle(); + s.moveBullet(angle); + sprites().stream().filter(e -> e.type.equals("enemy")).forEach(enemy -> { + if (s.getBoundsInParent().intersects(enemy.getBoundsInParent())) { + enemy.dead = true; + s.dead = true; + } + }); + break; + } + }); + + root.getChildren().removeIf(n -> { + Sprite s = (Sprite) n; + return s.dead; + }); + } + + private void shoot(Sprite who) { //shoot function, creates sprites from shooting player + int bulletW = 5; //bullet width + int bulletH = 5; //bullet height + Sprite s = new Sprite((int) who.getTranslateX() + (int) who.getWidth() / 2, (int) who.getTranslateY() + (int) who.getHeight() / 2, bulletW, bulletH, who.type + "bullet", Color.BLACK); + root.getChildren().add(s); + } + + + public void start(Stage stage) throws Exception { + Scene scene = new Scene(createContent()); + + scene.setOnKeyPressed(e -> { //movement switch case + switch (e.getCode()) { + case LEFT: + player.rotateLeft(); + break; + case RIGHT: + player.rotateRight(); + break; + case UP: + player.moveForward(); + break; + case DOWN: + player.moveBackward(); + break; + case SPACE: + shoot(player); + } + }); + stage.setScene(scene); + stage.show(); + } + + + private static class Sprite extends Rectangle { + boolean dead = false; + int angle = 0; + int angleIncrease = 10; + int moveSpeed = 10; + final String type; //either bullet or player + + + Sprite(int x, int y, int w, int h, String type, Color color) { //constructor + super(w, h, color); + this.type = type; + setTranslateX(x); + setTranslateY(y); + } + + Sprite(int x, int y, int w, int h, String type, Color color, int angle) { //constructor + super(w, h, color); + this.type = type; + setTranslateX(x); + setTranslateY(y); + } + + void rotateLeft() { //function for rotating a sprite left, pivoting around its middle + getTransforms().add(new Rotate(-angleIncrease, getX() + getWidth() / 2, getY() + getHeight() / 2)); + angle += -angleIncrease; + } + + void rotateRight() { //function for rotating a sprite right, pivoting around its middle + getTransforms().add(new Rotate(+angleIncrease, getX() + getWidth() / 2, getY() + getHeight() / 2)); + angle += angleIncrease; + } + + void moveForward() { + double angleR = Math.toRadians(angle); + setTranslateX(getTranslateX() + moveSpeed * Math.cos(angleR)); + setTranslateY(getTranslateY() + moveSpeed * Math.sin(angleR)); + } + + void moveBackward() { + double angleR = Math.toRadians(angle); + setTranslateX(getTranslateX() - moveSpeed * Math.cos(angleR)); + setTranslateY(getTranslateY() - moveSpeed * Math.sin(angleR)); + } + + void moveBullet(int angleB) { + double angleR = Math.toRadians(angleB); + setX(getX() + moveSpeed * Math.cos(angleR)); + setY(getY() + moveSpeed * Math.sin(angleR)); + } + + int getAngle() { + return angle; + } + + void moveLeft() { + setTranslateX(getTranslateX() - 5); + } + + void moveRight() { + setTranslateX(getTranslateX() + 5); + } + + void moveUp() { + setTranslateY(getTranslateY() - 5); + } + + void moveDown() { + setTranslateY(getTranslateY() + 5); + } + } + + + public static void main(String[] args) { + launch(args); + } +} +