Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .classpath

This file was deleted.

19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#including all files and folders except src and readme
*
!src/
!README.md

#macos system files
**/.DS_Store

#eclipse files
.settings/
.classpath
.project

#intellij
.idea/

#vscode
.vscode/

4 changes: 0 additions & 4 deletions .idea/encodings.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

17 changes: 0 additions & 17 deletions .project

This file was deleted.

14 changes: 0 additions & 14 deletions .settings/org.eclipse.jdt.core.prefs

This file was deleted.

2 changes: 1 addition & 1 deletion MiniGameAp2020.iml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="jdk-12.0.2" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a description on how to import the source files into IDE:
https://github.com/aeirya/MiniGameAp2020/issues/1
11 changes: 11 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import controller.Administrator;

public class Main implements Runnable {
public static void main(String[] args) {
new Main().run();
}

public void run() {
Administrator.getInstance().start();
}
}
10 changes: 10 additions & 0 deletions src/channels/GamePanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package channels;

public class GamePanel extends Panel {

public GamePanel() {
//this is an empty panel
}

private static final long serialVersionUID = 1L;
}
35 changes: 35 additions & 0 deletions src/channels/Panel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package channels;

import java.awt.Graphics;
import java.util.List;
import javax.swing.JPanel;

import controller.Administrator;
import mvvm.Data;
import mvvm.ViewModel;

/**
* Wrapper of JPanel, sends data to view model for drawing
* @see ViewModel
*/
public class Panel extends JPanel {

private final transient ViewModel viewModel;

public Panel() {
this.viewModel = ViewModel.getInstance();
}

@Override
public void paint(Graphics g) {
super.paint(g);
sendToViewModel(g);
}

private void sendToViewModel(Graphics g) {
final List<Data> data = Administrator.getInstance().getData();
viewModel.draw(g, data);
}

private static final long serialVersionUID = 1L;
}
21 changes: 0 additions & 21 deletions src/channels/game.java

This file was deleted.

115 changes: 115 additions & 0 deletions src/controller/Administrator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package controller;

import java.util.ArrayList;
import java.util.List;
import tv.View;
import logic.GameLogic;
import model.GameObject;
import mvvm.Data;
import net.DataParser;
import net.DummyNetworkManager;
import net.INetworkManager;

/** Main controller of the game,
* responsible for retrieving and keeping data from network,
* and also starting different components of the game
*/

public class Administrator {

private final View view;
private final GameLogic game;
private final DataParser dataParser;
private final List<GameObject> gameObjects;
private INetworkManager network;
private List<Data> data;

/* lazy instantiation of the singleton Administrator */
private static class InstanceHolder {
public static final Administrator instance = new Administrator();
}

public static Administrator getInstance() {
return InstanceHolder.instance;
}

public Administrator() {
data = new ArrayList<>();

//models
gameObjects = new ArrayList<>();
//logic
game = new GameLogic();
//graphics
view = new View();
//network
network = new DummyNetworkManager(); //does nothing!!
dataParser = new DataParser();
}

/**
* starts main components of the game
* @see INetworkManager
* @see GameLogic
* @see View
*/
public void start() {
network.connect();
new DataUpdater().start();

game.start();
view.start();
}

public List<Data> getData() {
return data;
}

/**
* used by the game logic to do calculations
* @return game objects
* @see GameLogic
*/
public List<GameObject> getGameObjects() {
return gameObjects;
}

/**
* calls retrieve data on a time basis,
* @author it would be better to make a timer instead!
*/
private class DataUpdater {

private final Runnable update = () -> {
while (true) {
this.retrieveData();
try {
Thread.sleep(32); // sync with view later
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
};

public void start() {
new Thread(this.update).start();
}

/**
* recieves data from network
* @see Data
* @see INetworkManager
*/
private void retrieveData() {
final List<Data> retrievedData = network.retrieveData();
if (retrievedData != null) {
// this is the part things are prone to bug..
// it depennds on our design: either we always send all data or we only send new data from server
data = retrievedData;
gameObjects.addAll(
dataParser.parse(retrievedData)
);
}
}
}
}
7 changes: 4 additions & 3 deletions src/enums/Channels.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package enums;

/**
* different menus of the game
* @apiNote these will be mapped to JPanels */
public enum Channels {

game , menu , pause;

GAME, MENU, PAUSE
}
3 changes: 2 additions & 1 deletion src/enums/DrawType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package enums;

public enum DrawType {

REC, OVAL, IMAGE
}

5 changes: 5 additions & 0 deletions src/enums/ShapeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package enums;

public enum ShapeType {
CIRCLE
}
5 changes: 5 additions & 0 deletions src/listeners/Collidable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package listeners;

public interface Collidable {
boolean collides(Collidable other);
}
6 changes: 6 additions & 0 deletions src/listeners/IAnimate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package listeners;

public interface IAnimate {
boolean isAlive();
void setAlive(boolean isAlive);
}
16 changes: 12 additions & 4 deletions src/listeners/Movable.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package listeners;

import model.Vector;

public interface Movable {


void move() ;


default void move() {
this.setLocation(
this.getLocation().add(this.getSpeed())
);
}

void setLocation(Vector newLocation);
void setSpeed(Vector speed);
Vector getLocation();
Vector getSpeed();
}
Loading