From ce9c40f7b4a44671c8fa393fbac39a02a3f7fdfb Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Mon, 7 Nov 2022 15:36:31 +0100 Subject: [PATCH] =?UTF-8?q?CHANGE:=20Changement=20des=20m=C3=A9thodes=20et?= =?UTF-8?q?=20des=20attributs=20des=20classes=20ADD:=20Ajout=20de=20classe?= =?UTF-8?q?s=20qui=20d=C3=A9pendent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bob_party/src/core/Game.ts | 9 +++- bob_party/src/core/User/managerCoinsUser.ts | 3 ++ bob_party/src/core/User/user.ts | 46 +++++-------------- bob_party/src/core/User/userCreater.ts | 10 ---- bob_party/src/core/User/userCreator.ts | 11 +++++ .../src/core/User/userModificationManager.ts | 24 ++++++++++ bob_party/src/core/User/userSkinModifier.ts | 13 ++++++ bob_party/src/core/match.ts | 32 +++++++++++++ 8 files changed, 103 insertions(+), 45 deletions(-) delete mode 100644 bob_party/src/core/User/userCreater.ts create mode 100644 bob_party/src/core/User/userCreator.ts create mode 100644 bob_party/src/core/User/userModificationManager.ts create mode 100644 bob_party/src/core/User/userSkinModifier.ts diff --git a/bob_party/src/core/Game.ts b/bob_party/src/core/Game.ts index 23dbd69..48065bf 100644 --- a/bob_party/src/core/Game.ts +++ b/bob_party/src/core/Game.ts @@ -2,6 +2,7 @@ import { randomBytes } from "crypto"; import { ImageSourcePropType } from "react-native"; export abstract class Game{ + readonly id:string; private name:string; private imageSource:ImageSourcePropType; private gameSource:string; @@ -9,7 +10,8 @@ export abstract class Game{ private nbPlayerMax:number; /* Constructor of the class */ - constructor (name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ + constructor (id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ + this.id=id; this.name=name; this.imageSource=imageSource; this.gameSource=gameSource; @@ -17,6 +19,11 @@ export abstract class Game{ this.nbPlayerMax=nbPlayerMax; } + /* Brief : Function getting the id of a game */ + getId(){ + return this.id; + } + /* Brief : Function getting the name of a game */ getName(){ return this.name; diff --git a/bob_party/src/core/User/managerCoinsUser.ts b/bob_party/src/core/User/managerCoinsUser.ts index 2f81893..724a44c 100644 --- a/bob_party/src/core/User/managerCoinsUser.ts +++ b/bob_party/src/core/User/managerCoinsUser.ts @@ -4,13 +4,16 @@ export class ManagerCoinsUser{ addCoins(u:User, coins:number){ u.setCurrentCoins(u.getCurrentCoins()+coins); u.setTotalCoins(u.getTotalCoins()+coins); + //modif dans la bdd } removeCoins(u:User, coins:number){ u.setCurrentCoins(u.getCurrentCoins()-coins); + //modif dans la bdd } changeCurrentCoins(u:User, coins:number){ u.setCurrentCoins(coins); + //modif dans la bdd } } \ No newline at end of file diff --git a/bob_party/src/core/User/user.ts b/bob_party/src/core/User/user.ts index 92ac9f5..cfbfd87 100644 --- a/bob_party/src/core/User/user.ts +++ b/bob_party/src/core/User/user.ts @@ -11,21 +11,21 @@ export class User{ private dateOfBirth: Date; private currentCoins: number; private totalCoins: number; - private nbGamePlayed: number; + private nbGamesPlayed: number; private currentSkin: Skin; private tabSkin: Skin[]; private tabConv?: Conversation[]; /* Consturctor of the class */ constructor(id: string, username: string, password:string, nationality: string, sexe: string, dateOfBirth: Date, currentCoins: number, totalCoins: number, - nbGamePlayed:number, currentSkin: Skin, tabSkin: Skin[], tabConv?: Conversation[] ){ + nbGamesPlayed:number, currentSkin: Skin, tabSkin: Skin[], tabConv?: Conversation[] ){ this.id=id; this.username=username; this.password=password; this.nationality=nationality; this.sexe=sexe; this.dateOfBirth=dateOfBirth; - this.nbGamePlayed=nbGamePlayed; + this.nbGamesPlayed=nbGamesPlayed; this.currentCoins=currentCoins; this.totalCoins=totalCoins; this.currentSkin=currentSkin; @@ -38,6 +38,7 @@ export class User{ } } + /* Brief : Function getting the name of an user */ getUsername(){ return this.username; @@ -111,16 +112,16 @@ export class User{ this.totalCoins=totalCoins; } - /* Brief : Function getting the current number of game played by an user */ + /* Brief : Function getting the current number of games played by an user */ - getGamePlayed(){ - return this.nbGamePlayed; + getGamesPlayed(){ + return this.nbGamesPlayed; } - /* Brief : Function setting the current number of game played by an user */ + /* Brief : Function setting the current number of games played by an user */ - setGamePlayed(nb: number){ - this.nbGamePlayed=nb; + setGamesPlayed(nb: number){ + this.nbGamesPlayed=nb; } /* Brief : Function getting the current skin of an user */ @@ -156,31 +157,8 @@ export class User{ }); } - /* - changeUserCoins(coin:number){ - this.CurrentCoins+=coin; - if (coin>0){ - this.TotalCoins+=coin; - } - } - - changerCurrentSkin(skin:Skin){ - this.CurrentSkin=skin; - } - - ajouterSkin(skin:Skin){ - this.TabSkin.push(skin); - } - - canConnect(username:string, mdp:string){ - if (this.Username==username){ - return this.Password==mdp; - } - return false; + addSkin(skin:Skin){ + this.tabSkin.push(skin); } - usrPasswordEquals(username:string, password:string){ - return this.Password==password && this.Username==username; - } - */ } \ No newline at end of file diff --git a/bob_party/src/core/User/userCreater.ts b/bob_party/src/core/User/userCreater.ts deleted file mode 100644 index faf8392..0000000 --- a/bob_party/src/core/User/userCreater.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { User } from "./user"; - -export class UserCreater{ - create(username:string, password:string, passConf:string, nationality:string, sexe:string){ - if (username=="" || username.includes(" ") || nationality=="" || password!=passConf || password=="" || - sexe==""){ - return null; - } - } -} \ No newline at end of file diff --git a/bob_party/src/core/User/userCreator.ts b/bob_party/src/core/User/userCreator.ts new file mode 100644 index 0000000..765e58e --- /dev/null +++ b/bob_party/src/core/User/userCreator.ts @@ -0,0 +1,11 @@ +import { User } from "./user"; +import tabSkinApp from "../../constSkin"; + +export class UserCreator{ + createUser(username:string, password:string, passConf:string, nationality:string, sexe:string, date:Date){ + //Récup l'ID d'après dans la bdd + const u = new User('0000', username, password, nationality, sexe, date, 0, 0, 0, tabSkinApp[0], [tabSkinApp[0]], undefined); + //Ajout du joueur dans la bdd + return u; + } +} \ No newline at end of file diff --git a/bob_party/src/core/User/userModificationManager.ts b/bob_party/src/core/User/userModificationManager.ts new file mode 100644 index 0000000..cf71bd8 --- /dev/null +++ b/bob_party/src/core/User/userModificationManager.ts @@ -0,0 +1,24 @@ +import { User } from "./user"; + + +export default class UserModificationManager{ + changePassword(user:User, password:string){ + user.setPassword(password); + //modif dans la bdd + } + + changeUsername(user:User, username:string){ + user.setPassword(username); + //modif dans la bdd + } + + changeNationality(user:User, nationality:string){ + user.setNationality(nationality); + //modif dans la bdd + } + + changeSexe(user:User, sexe:string){ + user.setSexe(sexe); + //modif dans la bdd + } +} \ No newline at end of file diff --git a/bob_party/src/core/User/userSkinModifier.ts b/bob_party/src/core/User/userSkinModifier.ts new file mode 100644 index 0000000..a842281 --- /dev/null +++ b/bob_party/src/core/User/userSkinModifier.ts @@ -0,0 +1,13 @@ +import { Skin } from '../Skin' +import { User } from './user' + + +export default class UserSkinModifier{ + addSkin(user:User, skin:Skin){ + user.addSkin(skin); + } + + changeCurrentSkin(user:User, skin:Skin){ + user.setCurrentSkin(skin); + } +} \ No newline at end of file diff --git a/bob_party/src/core/match.ts b/bob_party/src/core/match.ts index 1fc8258..e2a3c38 100644 --- a/bob_party/src/core/match.ts +++ b/bob_party/src/core/match.ts @@ -8,31 +8,63 @@ import { User } from "./User/user"; export abstract class Match{ readonly code:string; + private inGame:Boolean; private tabUsers:User[]; private theGame:Game; constructor(code:string, tabUser:User[], game:Game){ this.code=code; + this.inGame=false; this.tabUsers=[...tabUser]; this.theGame=game; } + + /* Brief : Fuction getting if the match is currently in a game */ + + getInGame(){ + return this.inGame; + } + + + /* Brief : Fuction setting the boolean inGame */ + + setInGame(inGame:Boolean){ + this.inGame=inGame; + } + + + /* Brief : Fuction getting the array of User */ + getTabUsers(){ return this.tabUsers; } + + + /* Brief : Fuction setting the array of User */ + setTabUser(tabUser:User[]){ this.tabUsers=[...tabUser]; } + + /* Brief : Fuction getting code of a match */ + getCode(){ return this.code; } + + /* Brief : Fuction getting the game of a match */ + getGame(){ return this.theGame; } + + /* Brief : Fuction setting the game of a match */ + setGame(game:Game){ this.theGame=game; }