Commit 62810051 authored by Quere David's avatar Quere David 🤜

Les joueurs joue mtn sur une carte aléatoire (parmis 3 maps)

parent db3207e0
2 13 17
#################
#****** ******#
# #*# #*#*# #*#*#
#b** *#* ***#
#*#*# #*# # #*# #
#*******# *****#
#p#*#*#*#*#*### #
# ******#*** r#
# #*# #*#*#*# #*#
#*******#*******#
#*# #*#*# #*#*# #
#****** *****#
#################
Meta data:
(Number or Level) (Rows) (Columns)
Info Tiles:
# - Wall
* - Brick
x - Portal
Mobs:
p - Player1
R - Player2
1 - Balloom
2 - Oneal
Powerups:
b - Powerup Bombs
f - Powerup Flames
s - Powerup Speed
\ No newline at end of file
3 13 17
#################
# r#
# ##############
# ****** #
#*#*#*#*#*#*#*#*#
#*#*#*#*#*#*#*#*#
#*#*#*#*#*#*#*#*#
#*#*#*#*#*#*#*#*#
#*#*#*#*#*#*#*#*#
# ****** #
############### #
#p #
#################
Meta data:
(Number or Level) (Rows) (Columns)
Info Tiles:
# - Wall
* - Brick
x - Portal
Mobs:
p - Player1
R - Player2
1 - Balloom
2 - Oneal
Powerups:
b - Powerup Bombs
f - Powerup Flames
s - Powerup Speed
\ No newline at end of file
...@@ -52,7 +52,8 @@ public class Board implements IRender { ...@@ -52,7 +52,8 @@ public class Board implements IRender {
Keyboard input, Keyboard input,
Screen screen, Screen screen,
ServerGame serverGame, ServerGame serverGame,
int playerNum){ int playerNum,
int level){
_game = game; _game = game;
_playerNum = playerNum; _playerNum = playerNum;
System.out.print(playerNum); System.out.print(playerNum);
...@@ -65,7 +66,7 @@ public class Board implements IRender { ...@@ -65,7 +66,7 @@ public class Board implements IRender {
} catch (RemoteException e){ } catch (RemoteException e){
e.printStackTrace(); e.printStackTrace();
} }
changeLevel(1); //start in level 1 changeLevel(level); //start the correct map
} }
/* /*
......
...@@ -7,7 +7,7 @@ import server.ServerGame; ...@@ -7,7 +7,7 @@ import server.ServerGame;
public class Bomberman { public class Bomberman {
public static void play(ServerGame serverGame, int playerNum) throws BombermanException { public static void play(ServerGame serverGame, int playerNum, int level) throws BombermanException {
new Frame(serverGame, playerNum); new Frame(serverGame, playerNum, level);
} }
} }
...@@ -66,14 +66,14 @@ public class Game extends Canvas { ...@@ -66,14 +66,14 @@ public class Game extends Canvas {
private BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); private BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
private int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData(); private int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
public Game(Frame frame) throws BombermanException { public Game(Frame frame, int level) throws BombermanException {
_frame = frame; _frame = frame;
_title = _title + "- Player "+this._frame._playerNum; _title = _title + "- Player "+this._frame._playerNum;
_frame.setTitle(_title); _frame.setTitle(_title);
screen = new Screen(WIDTH, HEIGHT); screen = new Screen(WIDTH, HEIGHT);
_input = new Keyboard(); _input = new Keyboard();
_board = new Board(this, _input, screen, this._frame._serverGame, this._frame._playerNum); _board = new Board(this, _input, screen, this._frame._serverGame, this._frame._playerNum, level);
addKeyListener(_input); addKeyListener(_input);
} }
......
...@@ -23,12 +23,12 @@ public class Frame extends JFrame { ...@@ -23,12 +23,12 @@ public class Frame extends JFrame {
private Game _game; private Game _game;
public int _playerNum; public int _playerNum;
public ServerGame _serverGame; public ServerGame _serverGame;
public Frame(ServerGame serverGame, int playerNum) { public Frame(ServerGame serverGame, int playerNum, int level) {
setJMenuBar(new Menu(this)); setJMenuBar(new Menu(this));
_serverGame = serverGame; _serverGame = serverGame;
_playerNum = playerNum;; _playerNum = playerNum;;
_containerpane = new JPanel(new BorderLayout()); _containerpane = new JPanel(new BorderLayout());
_gamepane = new GamePanel(this); _gamepane = new GamePanel(this, level);
_infopanel = new InfoPanel(_gamepane.getGame()); _infopanel = new InfoPanel(_gamepane.getGame());
_containerpane.add(_infopanel, BorderLayout.PAGE_START); _containerpane.add(_infopanel, BorderLayout.PAGE_START);
......
...@@ -16,12 +16,12 @@ public class GamePanel extends JPanel { ...@@ -16,12 +16,12 @@ public class GamePanel extends JPanel {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Game _game; private Game _game;
public GamePanel(Frame frame) { public GamePanel(Frame frame, int level) {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
setPreferredSize(new Dimension(Game.WIDTH * Game.SCALE, Game.HEIGHT * Game.SCALE)); setPreferredSize(new Dimension(Game.WIDTH * Game.SCALE, Game.HEIGHT * Game.SCALE));
try { try {
_game = new Game(frame); _game = new Game(frame, level);
add(_game); add(_game);
......
...@@ -14,6 +14,7 @@ public class ClientGameImpl extends UnicastRemoteObject implements ClientGame, R ...@@ -14,6 +14,7 @@ public class ClientGameImpl extends UnicastRemoteObject implements ClientGame, R
public Bomberman bbman; public Bomberman bbman;
private int playerNum; private int playerNum;
private boolean authorizedConnexion; private boolean authorizedConnexion;
protected ClientGameImpl(String userName, String gameId, ServerGame serverGame) throws RemoteException { protected ClientGameImpl(String userName, String gameId, ServerGame serverGame) throws RemoteException {
this.userName = userName; this.userName = userName;
this.serverGame = serverGame; this.serverGame = serverGame;
...@@ -51,7 +52,7 @@ public class ClientGameImpl extends UnicastRemoteObject implements ClientGame, R ...@@ -51,7 +52,7 @@ public class ClientGameImpl extends UnicastRemoteObject implements ClientGame, R
while (true){ while (true){
try{ try{
if (this.serverGame.isGameRunning() == true){ if (this.serverGame.isGameRunning() == true){
Bomberman.play(this.serverGame, this.playerNum); Bomberman.play(this.serverGame, this.playerNum, this.serverGame.getChosenLevel());
this.serverGame.resetServer(); this.serverGame.resetServer();
this.authorizedConnexion = false; this.authorizedConnexion = false;
break; break;
......
...@@ -210,7 +210,7 @@ public class ClientUI extends javax.swing.JFrame { ...@@ -210,7 +210,7 @@ public class ClientUI extends javax.swing.JFrame {
try{ try{
String serverGameURL = "rmi://"+ipServer+"/RMIGameServer"; String serverGameURL = "rmi://"+ipServer+"/RMIGameServer";
ServerGame serverGame = (ServerGame) Naming.lookup(serverGameURL); ServerGame serverGame = (ServerGame) Naming.lookup(serverGameURL);
new Thread(new ClientGameImpl(userName,gameId,serverGame)).start(); new Thread(new ClientGameImpl(userName, gameId, serverGame)).start();
}catch(MalformedURLException e){ }catch(MalformedURLException e){
e.printStackTrace(); e.printStackTrace();
}catch(RemoteException e){ }catch(RemoteException e){
......
...@@ -3,6 +3,10 @@ package server; ...@@ -3,6 +3,10 @@ package server;
import java.io.Serializable; import java.io.Serializable;
public class PlayerPosition implements Serializable{ public class PlayerPosition implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
public int posX = 0; public int posX = 0;
public int posY = 0; public int posY = 0;
public int direction = 0; public int direction = 0;
......
...@@ -17,4 +17,5 @@ public interface ServerGame extends Remote{ ...@@ -17,4 +17,5 @@ public interface ServerGame extends Remote{
int getBomb(int playerNum) throws RemoteException; int getBomb(int playerNum) throws RemoteException;
PlayerPosition getMove(int playerNum) throws RemoteException; PlayerPosition getMove(int playerNum) throws RemoteException;
String getPlayerID(int playerNum) throws RemoteException; String getPlayerID(int playerNum) throws RemoteException;
} int getChosenLevel() throws RemoteException;
\ No newline at end of file }
\ No newline at end of file
...@@ -3,6 +3,7 @@ package server; ...@@ -3,6 +3,7 @@ package server;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;
import client.ClientGame; import client.ClientGame;
...@@ -11,6 +12,7 @@ public class ServerGameImpl extends UnicastRemoteObject implements ServerGame { ...@@ -11,6 +12,7 @@ public class ServerGameImpl extends UnicastRemoteObject implements ServerGame {
private ArrayList<ClientGame> clientGames; private ArrayList<ClientGame> clientGames;
private Boolean gameRunning = false; private Boolean gameRunning = false;
private String gameId; private String gameId;
private int level;
private PlayerPosition playerTwoPos = new PlayerPosition(0, 0, 0); private PlayerPosition playerTwoPos = new PlayerPosition(0, 0, 0);
private PlayerPosition playerOnePos = new PlayerPosition(0, 0, 0); private PlayerPosition playerOnePos = new PlayerPosition(0, 0, 0);
private int[] playerBomb = new int[2]; private int[] playerBomb = new int[2];
...@@ -26,6 +28,7 @@ public class ServerGameImpl extends UnicastRemoteObject implements ServerGame { ...@@ -26,6 +28,7 @@ public class ServerGameImpl extends UnicastRemoteObject implements ServerGame {
return false; return false;
} else if (this.clientGames.size()==1){ } else if (this.clientGames.size()==1){
if (this.gameId.equals(player.getGameId())){ if (this.gameId.equals(player.getGameId())){
this.level = randomLevelNumber(3);
sendBroadcastMessage(player.getUserName() + " joined the game !!!"); sendBroadcastMessage(player.getUserName() + " joined the game !!!");
this.clientGames.add(player); this.clientGames.add(player);
player.setPlayerNum(2); player.setPlayerNum(2);
...@@ -46,16 +49,25 @@ public class ServerGameImpl extends UnicastRemoteObject implements ServerGame { ...@@ -46,16 +49,25 @@ public class ServerGameImpl extends UnicastRemoteObject implements ServerGame {
} }
} }
private int randomLevelNumber(int max) {
return ThreadLocalRandom.current().nextInt(1, max + 1);
}
public synchronized void sendBroadcastMessage(String message) throws RemoteException { public synchronized void sendBroadcastMessage(String message) throws RemoteException {
int i = 0; int i = 0;
while (i < clientGames.size()){ while (i < clientGames.size()){
clientGames.get(i++).retrieveMessage(message); clientGames.get(i++).retrieveMessage(message);
} }
} }
public void startGame() throws RemoteException { public void startGame() throws RemoteException {
this.gameRunning = true; this.gameRunning = true;
} }
public int getChosenLevel() throws RemoteException {
return this.level;
}
public synchronized void notifyPlayerMove(PlayerPosition playerPos, int playerNum) throws RemoteException { public synchronized void notifyPlayerMove(PlayerPosition playerPos, int playerNum) throws RemoteException {
if (playerNum == 0) if (playerNum == 0)
this.playerOnePos = playerPos; this.playerOnePos = playerPos;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment