});
}
}
-
-export class Connexion {
+export interface ConnexionInterface {
+ socket : any;
+ token : string;
+ email : string;
+ userId: string;
+ startedRoom : string;
+ createConnexion() : Promise<any>;
+ joinARoom(roomId : string) : void;
+ sharePosition(roomId : string, x : number, y : number, direction : string) : void;
+ positionOfAllUser() : void;
+}
+export class Connexion implements ConnexionInterface{
socket : any;
token : string;
email : string;
this.GameManager = GameManager;
}
- createConnexion(){
+ createConnexion() : Promise<ConnexionInterface>{
return Axios.post(`${API_URL}/login`, {email: this.email})
.then((res) => {
this.token = res.data.token;
this.errorMessage();
- return{
- userId: this.userId,
- roomId: this.startedRoom
- }
+ return this;
})
.catch((err) => {
console.error(err);
* Permit to join a room
* @param roomId
*/
- joinARoom(roomId : string){
+ joinARoom(roomId : string) : void {
let messageUserPosition = new MessageUserPosition(this.userId, this.startedRoom, new Point(0, 0));
this.socket.emit('join-room', messageUserPosition.toString());
}
* @param y
* @param direction
*/
- sharePosition(roomId : string, x : number, y : number, direction : string = "none"){
+ sharePosition(roomId : string, x : number, y : number, direction : string = "none") : void{
if(!this.socket){
return;
}
* ...
* ]
**/
- positionOfAllUser() {
+ positionOfAllUser() : void {
this.socket.on("user-position", (message: string) => {
let dataList = JSON.parse(message);
dataList.forEach((UserPositions: any) => {
});
}
- errorMessage(){
+ errorMessage() : void {
this.socket.on('message-error', (message : string) => {
console.error("message-error", message);
})
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
import {Player} from "../Player/Player";
import {MapManagerInterface} from "./MapManager";
-import {PlayerAnimationNames} from "../Player/Animation";
export interface CameraManagerInterface {
MapManager : MapManagerInterface;
import {GameSceneInterface, GameScene} from "./GameScene";
import {ROOM} from "../../Enum/EnvironmentVariable"
-import {Connexion, ListMessageUserPositionInterface} from "../../Connexion";
+import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion";
export enum StatusGameManagerEnum {
IN_PROGRESS = 1,
CURRENT_USER_CREATED = 2
}
-export let ConnexionInstance : Connexion;
+export let ConnexionInstance : ConnexionInterface;
export interface GameManagerInterface {
GameScenes: Array<GameSceneInterface>;
}
createGame(){
- return ConnexionInstance.createConnexion().then((data: any) => {
+ return ConnexionInstance.createConnexion().then(() => {
this.configureGame();
/** TODO add loader in the page **/
}).catch((err) => {
import {CameraManager, CameraManagerInterface} from "./CameraManager";
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
-import {Player} from "../Player/Player";
+import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player";
import {GameSceneInterface} from "./GameScene";
import {MessageUserPositionInterface} from "../../Connexion";
Terrain : Phaser.Tilemaps.Tileset;
Camera: CameraManagerInterface;
- CurrentPlayer: Player;
- MapPlayers : Player[];
+ CurrentPlayer: CurrentGamerInterface;
+ MapPlayers : GamerInterface[];
Scene: GameSceneInterface;
Map: Phaser.Tilemaps.Tilemap;
startX = (window.innerWidth / 2) / RESOLUTION;
//initialise camera
this.Camera = new CameraManager(this.Scene, this.Scene.cameras.main, this);
//initialise list of other player
- this.MapPlayers = new Array<Player>();
+ this.MapPlayers = new Array<GamerInterface>();
}
createCurrentPlayer(UserId : string){
import {CameraManagerInterface} from "../Game/CameraManager";
import {MessageUserPositionInterface} from "../../Connexion";
-export class Player extends Phaser.GameObjects.Sprite{
+export interface CurrentGamerInterface{
+ userId : string;
+ MapManager : MapManagerInterface;
+ PlayerValue : string;
+ CameraManager: CameraManagerInterface;
+ initAnimation() : void;
+ move() : void;
+}
+
+export interface GamerInterface{
+ userId : string;
+ MapManager : MapManagerInterface;
+ PlayerValue : string;
+ CameraManager: CameraManagerInterface;
+ initAnimation() : void;
+ updatePosition(MessageUserPosition : MessageUserPositionInterface) : void;
+}
+
+export class Player extends Phaser.GameObjects.Sprite implements CurrentGamerInterface, GamerInterface{
userId : string;
MapManager : MapManagerInterface;
PlayerValue : string;
this.CameraManager = CameraManager;
}
- initAnimation(){
+ initAnimation() : void{
getPlayerAnimations(this.PlayerValue).forEach(d => {
this.scene.anims.create({
key: d.key,
})
}
- move(){
+ move() : void{
//if user client on shift, camera and player speed
let speedMultiplier = this.MapManager.keyShift.isDown ? 5 : 1;
let haveMove = false;