Skip to content

Commit

Permalink
Merge pull request #381 from NicolasJourdan/release/2.0.0
Browse files Browse the repository at this point in the history
Release/2.0.0
  • Loading branch information
NicolasJourdan authored Jan 24, 2019
2 parents 529f0f1 + 491f629 commit 2573a40
Show file tree
Hide file tree
Showing 192 changed files with 8,105 additions and 556 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# BREF'N'Games
This Java application gathers several mini games you can play with a friend.

Two modes are included:
Three modes are included:
- Training mode
- Contest
- Online contest

The contest mode will save statistics related to each game and to each player.

Expand All @@ -17,19 +18,29 @@ Differents aspects of the game can be configured like:
- Cookie Clicker
- Runner
- Connect Four
- Hangman
- Fifteen Vainc

## Screenshots
### Menus
![Homepage](https://user-images.githubusercontent.com/20768914/50188598-73ea0a00-0322-11e9-9119-d6382cb00157.png)
![Training Menu](https://user-images.githubusercontent.com/20768914/50188599-7482a080-0322-11e9-950e-c4df01514929.png)
![Contest Settings](https://user-images.githubusercontent.com/20768914/50188606-751b3700-0322-11e9-9038-d6422611a529.png)
![Training Menu](https://user-images.githubusercontent.com/20768914/51715350-9fa29300-2038-11e9-9eae-163245135599.png)
![Contest Settings](https://user-images.githubusercontent.com/20768914/51715354-a03b2980-2038-11e9-996a-593d19db8eb2.png)
![Contest Map](https://user-images.githubusercontent.com/20768914/50188609-75b3cd80-0322-11e9-9ff7-c700cf93d1cc.png)

### Online Contest
![Online Menu](https://user-images.githubusercontent.com/20768914/51715351-a03b2980-2038-11e9-8b1e-a4a598e9cd3e.png)
![Online Create Contest](https://user-images.githubusercontent.com/20768914/51715352-a03b2980-2038-11e9-9c44-957decfbb6a5.png)
![Online Join Contest](https://user-images.githubusercontent.com/20768914/51715355-a0d3c000-2038-11e9-8f34-aac516702071.png)
![Online End](https://user-images.githubusercontent.com/20768914/51715353-a03b2980-2038-11e9-9dc9-dfdc8a6856dc.png)

### Games
![Tic Tac Toe](https://user-images.githubusercontent.com/20768914/50188601-7482a080-0322-11e9-8333-b72492126375.png)
![Cookie Clicker](https://user-images.githubusercontent.com/20768914/50188603-7482a080-0322-11e9-924f-eace4ec5dfef.png)
![Runner](https://user-images.githubusercontent.com/20768914/50188605-751b3700-0322-11e9-9b76-29ea2c1ffad8.png)
![Connect Four](https://user-images.githubusercontent.com/20768914/50188604-7482a080-0322-11e9-896d-13a1c382458a.png)
![Hangman](https://user-images.githubusercontent.com/20768914/51715220-2145f100-2038-11e9-8004-6b4850f24da5.png)
![Fifteen Vainc](https://user-images.githubusercontent.com/20768914/51715221-21de8780-2038-11e9-82f5-70bb4b953887.png)

### Statistics
![Statistics Menu](https://user-images.githubusercontent.com/20768914/50188610-75b3cd80-0322-11e9-9282-16e3b149f223.png)
Expand All @@ -46,7 +57,11 @@ It is possible to consult UML [here](https://nicolasjourdan.github.io/brefngames
## Git History
Visual representation of the git repository history

[![Git History](https://img.youtube.com/vi/6LCyB9z3E8c/0.jpg)](https://youtu.be/6LCyB9z3E8c)
### First iteration
[![Git History 1](https://img.youtube.com/vi/6LCyB9z3E8c/0.jpg)](https://youtu.be/6LCyB9z3E8c)

### Second iteration
[![Git History 2](https://img.youtube.com/vi/RKLHyhleYVQ/0.jpg)](https://youtu.be/RKLHyhleYVQ)

## Team Members 👨‍💻
- Florian Merle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import Scene.Model.SceneEnum;
import Scene.View.AbstractSceneManagerView;

public class ContestController extends AbstractSceneManagerController {
public class LocalContestController extends AbstractSceneManagerController {

public ContestController(AbstractSceneManagerModel model, AbstractSceneManagerView view) {
public LocalContestController(AbstractSceneManagerModel model, AbstractSceneManagerView view) {
super(model, view, new GameSceneFactory(((AbstractContest) model).getPlayersList(), false));

this.switchScene(SceneEnum.CONTEST_MENU);
Expand All @@ -27,6 +27,7 @@ protected SceneEnum getNextScene(ActionEnum actionEnum) {
((AbstractContest) this.model).setUpContest(
((ContestSettingsScene) this.currentScene).getSettingsDataObject()
);
((AbstractContest) this.model).savePlayers(((AbstractContest) this.model).getPlayersList());

// update gameSceneFactory values
((GameSceneFactory) this.sceneFactory).updatePlayersList(((AbstractContest) this.model).getPlayersList());
Expand Down
226 changes: 226 additions & 0 deletions src/Contest/Controller/OnlineContestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
package Contest.Controller;

import Contest.Interface.SocketObserverController;
import Contest.Model.AbstractContest;
import Contest.Model.OnlineContest;
import ContestSettings.ContestSettingsScene;
import Game.GameSceneFactory;
import Game.OnlineGameSceneFactory;
import Map.Model.History;
import Online.Client.ClientScene;
import Online.Server.ServerScene;
import Online.Socket.Message.MessageDataObject;
import Online.Socket.Message.MessageType;
import Online.Socket.SocketCommunicatorService;
import Player.Player;
import Scene.Controller.AbstractSceneManagerController;
import Scene.Model.AbstractSceneManagerModel;
import Scene.Model.ActionEnum;
import Scene.Model.SceneEnum;
import Scene.View.AbstractSceneManagerView;

import java.net.Socket;
import java.util.Observable;
import java.util.Observer;

public class OnlineContestController extends AbstractSceneManagerController {

private boolean isServer;
private SocketCommunicatorService socketCommunicatorService;

/**
* @param model
* @param view
*/
public OnlineContestController(AbstractSceneManagerModel model, AbstractSceneManagerView view) {
super(model, view, new OnlineGameSceneFactory(((AbstractContest) model).getPlayersList(), false));

this.switchScene(SceneEnum.ONLINE_CONTEST_MENU);
}

@Override
protected SceneEnum getNextScene(ActionEnum actionEnum) {
switch (actionEnum) {
/**
* Create server
*/
case CREATE_SERVER:
return SceneEnum.CREATE_SERVER_SCENE;

/**
* Join server
*/
case JOIN_SERVER:
return SceneEnum.JOIN_SERVER_SCENE;

/**
* Client connected
*/
case CLIENT_CONNECTED:
this.setupContestConnection(
true,
((ServerScene) this.currentScene).getSocket()
);
return SceneEnum.CONTEST_MENU;

/**
* Connected to server
*/
case CONNECTED_TO_SERVER:
this.setupContestConnection(
false,
((ClientScene) this.currentScene).getSocket()
);
return SceneEnum.CONTEST_MENU;

/**
* Start contest (only received by the server)
*/
case START_CONTEST:
((AbstractContest) this.model).setUpContest(
((ContestSettingsScene) this.currentScene).getSettingsDataObject()
);
((OnlineContest) this.model).savePlayers(((OnlineContest) this.model).getPlayersList());
this.socketCommunicatorService.emit(new MessageDataObject(MessageType.SETTINGS_SAVE_PLAYER, ((OnlineContest) this.model).getPlayersList()));

// update gameSceneFactory values
((OnlineGameSceneFactory) this.sceneFactory).updatePlayersList(((AbstractContest) this.model).getPlayersList());
((OnlineGameSceneFactory) this.sceneFactory).updateHistory(((AbstractContest) this.model).getHistory());
this.socketCommunicatorService.emit(new MessageDataObject(
MessageType.SETTINGS_PLAYERS_LIST,
((AbstractContest) this.model).getPlayersList()
));
this.socketCommunicatorService.emit(new MessageDataObject(
MessageType.SETTINGS_HISTORY,
((AbstractContest) this.model).getHistory()
));

return this.loadNextScene();
/**
* Quit
*/
case END_ONLINE_CONTEST:
System.out.println("quit !");
this.setChanged();
this.notifyObservers(actionEnum);
return SceneEnum.END_SCENE;

/**
* Game finished
*/
case FIRST_PLAYER_WON:
case SECOND_PLAYER_WON:
case DRAW:
if (this.isServer) {
((AbstractContest) this.model).setWinner(actionEnum);

((GameSceneFactory) this.sceneFactory).updateHistory(((AbstractContest) this.model).getHistory());

this.socketCommunicatorService.emit(new MessageDataObject(
MessageType.CONTEST_UPDATE_HISTORY,
((AbstractContest) this.model).getHistory()
));
}

/**
* Map
*/
case END_MAP:
return this.loadNextScene();

/**
* Start new contest
*/
case ONLINE_ENDING_START_NEW_CONTEST:
this.socketCommunicatorService.emit(new MessageDataObject(
MessageType.CONTEST_NEXT_SCENE,
SceneEnum.CONTEST_MENU
));

return SceneEnum.CONTEST_MENU;
case ERROR:
case ONLINE_CONTEST_MENU:
return SceneEnum.ONLINE_CONTEST_MENU;

default:
throw new RuntimeException("Unable to find : " + actionEnum);
}
}

private SceneEnum loadNextScene() {
SceneEnum nextGameScene = ((AbstractContest) this.model).getNextGameScene();

// communicate the next scene to the client before returning it
this.socketCommunicatorService.emit(new MessageDataObject(
MessageType.CONTEST_NEXT_SCENE,
nextGameScene
));

return nextGameScene;
}

private void setupContestConnection(boolean isServer, Socket socket) {
this.isServer = isServer;
((OnlineContest) this.model).setServer(this.isServer);
this.socketCommunicatorService = new SocketCommunicatorService(socket);

this.socketCommunicatorService.addReceptionObserver(new ReceptionObserver());

((OnlineGameSceneFactory) this.sceneFactory).setIsServer(this.isServer);
((OnlineGameSceneFactory) this.sceneFactory).setSocketCommunicatorService(this.socketCommunicatorService);
}

private class ReceptionObserver implements Observer {
@Override
public void update(Observable o, Object arg) {
MessageDataObject messageDataObject = (MessageDataObject) arg;

switch (messageDataObject.getType()) {
case CONTEST_NEXT_SCENE:
// next scene received from the server, update current one
OnlineContestController.this.switchScene((SceneEnum) messageDataObject.getData());
break;
case CONTEST_UPDATE_HISTORY:
// new history received from the server, it will be used when the map is displayed
((OnlineGameSceneFactory) OnlineContestController.this.sceneFactory).updateHistory(
(History) messageDataObject.getData()
);
break;
case SETTINGS_PLAYERS_LIST:
((OnlineGameSceneFactory) OnlineContestController.this.sceneFactory).updatePlayersList(
(Player[]) messageDataObject.getData()
);
break;
case SETTINGS_HISTORY:
((OnlineGameSceneFactory) OnlineContestController.this.sceneFactory).updateHistory(
(History) messageDataObject.getData()
);
break;
case SETTINGS_SAVE_PLAYER:
((OnlineContest) OnlineContestController.this.model).savePlayers((Player[]) messageDataObject.getData());
break;
case ERROR:
case SETTINGS_END:
OnlineContestController.this.switchScene(SceneEnum.ONLINE_CONTEST_MENU);
break;
}
}
}

/**
* When changing the current scene, the old scene should stop observing the socket message receiver thread
*
* @param sceneEnum
*/
@Override
protected void switchScene(SceneEnum sceneEnum) {
if (null != this.currentScene) {
Object currentController = this.currentScene.getController();
if (currentController instanceof SocketObserverController) {
((SocketObserverController) currentController).stopObserver();
}
}

super.switchScene(sceneEnum);
}
}
7 changes: 7 additions & 0 deletions src/Contest/Interface/SocketObserverController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Contest.Interface;

public interface SocketObserverController {

public void stopObserver();

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package Contest;

import Contest.Controller.ContestController;
import Contest.Controller.LocalContestController;
import Contest.Model.LocalContest;
import Contest.View.ContestView;
import Scene.Model.AbstractSceneManagerModel;
import Scene.Model.Scene;
import Scene.View.AbstractSceneManagerView;

public class ContestScene extends Scene {
public class LocalContestScene extends Scene {

public ContestScene() {
public LocalContestScene() {
this.model = new LocalContest();
this.view = new ContestView();
this.controller = new ContestController((AbstractSceneManagerModel) this.model, (AbstractSceneManagerView) this.view);
this.controller = new LocalContestController((AbstractSceneManagerModel) this.model, (AbstractSceneManagerView) this.view);
this.controller.addObserver(this);

}
Expand Down
18 changes: 15 additions & 3 deletions src/Contest/Model/AbstractContest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

public abstract class AbstractContest extends AbstractSceneManagerModel {

/**
* Default number of player
*/
protected static final int DEFAULT_NB_PLAYERS = 2;

/**
* Total amount of matches
*/
Expand Down Expand Up @@ -99,9 +104,6 @@ public void setUpContest(ContestSettingsDataObject settingsDataObject) {
(null == secondPlayerStats) ? AbstractPlayer.initialStatsMap() : secondPlayerStats
);

PlayerRepository.save(this.playersList[0]);
PlayerRepository.save(this.playersList[1]);

this.history = new History(
this.playersList,
new ArrayList<GameHistory>(),
Expand All @@ -112,6 +114,16 @@ public void setUpContest(ContestSettingsDataObject settingsDataObject) {
this.nextSceneIsMap = true;
}

public void savePlayers(Player[] players) {
if (AbstractContest.DEFAULT_NB_PLAYERS != players.length) {
throw new RuntimeException("Exactly " + AbstractContest.DEFAULT_NB_PLAYERS + " are required");
}

for (Player player : players) {
PlayerRepository.save(player);
}
}

/**
* Randomize the next game type to be played
*
Expand Down
Loading

0 comments on commit 2573a40

Please sign in to comment.