From d6afccb50d8b5a3d08899ea7aed7ec5cffa18643 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Mon, 14 Nov 2022 18:01:49 +0100 Subject: [PATCH] ADD: fonctions abstract de Game et Match --- bob_party/src/core/Game.ts | 3 ++ bob_party/src/core/User/user.ts | 70 +++++++++++++------------- bob_party/src/core/User/userCreator.ts | 6 ++- bob_party/src/core/gameCasino.ts | 8 ++- bob_party/src/core/gameMulti.ts | 16 +++--- bob_party/src/core/gameSolo.ts | 16 +++--- bob_party/src/core/match.ts | 15 +----- bob_party/src/core/matchCasino.ts | 7 +++ bob_party/src/core/matchMulti.ts | 6 +++ bob_party/src/core/matchSolo.ts | 6 +++ 10 files changed, 89 insertions(+), 64 deletions(-) diff --git a/bob_party/src/core/Game.ts b/bob_party/src/core/Game.ts index 48065bf..2274d6c 100644 --- a/bob_party/src/core/Game.ts +++ b/bob_party/src/core/Game.ts @@ -1,5 +1,6 @@ import { randomBytes } from "crypto"; import { ImageSourcePropType } from "react-native"; +import internal from "stream"; export abstract class Game{ readonly id:string; @@ -73,4 +74,6 @@ export abstract class Game{ setNbPlayerMax(nbPlayerMax:number){ this.nbPlayerMax=nbPlayerMax; } + + abstract coinsCalculator(points: number): number; } \ 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 cfbfd87..7fdffa6 100644 --- a/bob_party/src/core/User/user.ts +++ b/bob_party/src/core/User/user.ts @@ -1,6 +1,7 @@ import { Skin } from '../Skin' import { Conversation } from '../conversation'; import { sign } from 'crypto'; +import { TextBase } from 'react-native'; export class User{ readonly id: string; @@ -14,11 +15,11 @@ export class User{ private nbGamesPlayed: number; private currentSkin: Skin; private tabSkin: Skin[]; - private tabConv?: Conversation[]; + private tabConv: Conversation[]; /* Consturctor of the class */ constructor(id: string, username: string, password:string, nationality: string, sexe: string, dateOfBirth: Date, currentCoins: number, totalCoins: number, - nbGamesPlayed:number, currentSkin: Skin, tabSkin: Skin[], tabConv?: Conversation[] ){ + nbGamesPlayed:number, currentSkin: Skin, tabSkin: Skin[], tabConv: Conversation[] ){ this.id=id; this.username=username; this.password=password; @@ -30,135 +31,136 @@ export class User{ this.totalCoins=totalCoins; this.currentSkin=currentSkin; this.tabSkin=[...tabSkin]; - if(tabConv!==undefined){ - this.tabConv=[...tabConv]; - } - else{ - this.tabConv=tabConv; - } + this.tabConv=[...tabConv]; } - /* Brief : Function getting the name of an user */ + /* Brief : Function getting the name of a user */ getUsername(){ return this.username; } - /* Brief : Function setting the name of an user */ + /* Brief : Function setting the name of a user */ setUsername(username: string){ this.username=username; } - /* Brief : Function getting the id of an user */ + /* Brief : Function getting the id of a user */ getId(){ return this.id; } + /* Brief : Function getting the password of a user */ getPassword(){ return this.password; } + /* Brief : Function setting the password of a user */ setPassword(password:string){ this.password=password; } - /* Brief : Function getting the current number of coins of an user */ + /* Brief : Function getting the current number of coins of a user */ getCurrentCoins(){ return this.currentCoins; } - /* Brief : Function setting the current number of coins of an user */ + /* Brief : Function setting the current number of coins of a user */ setCurrentCoins(currentCoins: number){ this.currentCoins=currentCoins; } - /* Brief : Function getting the sex of an user */ + /* Brief : Function getting the sex of a user */ getSexe(){ return this.sexe; } - /* Brief : Function getting the sex of an user */ + /* Brief : Function getting the sex of a user */ setSexe(sexe: string){ this.sexe=sexe; } - /* Brief : Function getting the date of birth of an user */ + /* Brief : Function getting the date of birth of a user */ getDateOfBirth(){ return this.dateOfBirth; } - /* Brief : Function setting the date of birth of an user */ + /* Brief : Function setting the date of birth of a user */ setDateOfBirth(dateOfBirth: Date){ this.dateOfBirth=dateOfBirth; } - /* Brief : Function getting the nationality of an user */ + /* Brief : Function getting the nationality of a user */ getNationality(){ return this.nationality; } - /* Brief : Function setting the nationality of an user */ + /* Brief : Function setting the nationality of a user */ setNationality(nationality: string){ this.nationality=nationality; } - /* Brief : Function getting the total number of coins of an user */ + /* Brief : Function getting the total number of coins of a user */ getTotalCoins(){ return this.totalCoins; } - /* Brief : Function setting the total number of coins of an user */ + /* Brief : Function setting the total number of coins of a user */ setTotalCoins(totalCoins: number){ this.totalCoins=totalCoins; } - /* Brief : Function getting the current number of games played by an user */ + /* Brief : Function getting the current number of games played by a user */ getGamesPlayed(){ return this.nbGamesPlayed; } - /* Brief : Function setting the current number of games played by an user */ + /* Brief : Function setting the current number of games played by a user */ setGamesPlayed(nb: number){ this.nbGamesPlayed=nb; } - /* Brief : Function getting the current skin of an user */ + /* Brief : Function getting the current skin of a user */ getCurrentSkin(){ return this.currentSkin; } - /* Brief : Function setting the current skin of an user */ + /* Brief : Function setting the current skin of a user */ setCurrentSkin(newSkin: Skin){ this.currentSkin=newSkin; } - /* Brief : Function getting the skins of an user */ + /* Brief : Function getting the skins of a user */ getTabSkin(){ return this.tabSkin; } - /* Brief : Function setting the skins of an user */ + /* Brief : Function setting the skins of a user */ setTabSkin(tabSkin: Skin[]){ this.tabSkin=[...tabSkin]; } - /* Brief : Function getting the conversations of an user */ + /* Brief : Function getting the conversations of a user */ getTabConv(){ return this.tabConv; } - /* Brief : Function setting the conversations of an user */ - setTabConv(tabConv?: Conversation[]){ - tabConv?.forEach(conv => { - this.tabConv?.push(conv); - }); + /* Brief : Function setting the conversations of a user */ + setTabConv(tabConv: Conversation[]){ + this.tabConv=[...tabConv] } - + + /* Brief : Function adding a skin to a user */ addSkin(skin:Skin){ this.tabSkin.push(skin); } + /* Brief : Function adding a conversation to a user */ + addConversation(conv:Conversation){ + this.tabConv.push(conv); + } + } \ No newline at end of file diff --git a/bob_party/src/core/User/userCreator.ts b/bob_party/src/core/User/userCreator.ts index 765e58e..f93240e 100644 --- a/bob_party/src/core/User/userCreator.ts +++ b/bob_party/src/core/User/userCreator.ts @@ -1,10 +1,12 @@ import { User } from "./user"; import tabSkinApp from "../../constSkin"; +import { Conversation } from "../conversation"; export class UserCreator{ - createUser(username:string, password:string, passConf:string, nationality:string, sexe:string, date:Date){ + createUser(username:string, password:string, nationality:string, sexe:string, date:Date){ + let tabConv:Conversation[]=[]; //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); + const u = new User('0000', username, password, nationality, sexe, date, 0, 0, 0, tabSkinApp[0], [tabSkinApp[0]], tabConv); //Ajout du joueur dans la bdd return u; } diff --git a/bob_party/src/core/gameCasino.ts b/bob_party/src/core/gameCasino.ts index 1786def..6029a90 100644 --- a/bob_party/src/core/gameCasino.ts +++ b/bob_party/src/core/gameCasino.ts @@ -3,7 +3,11 @@ import { Game } from './game' export class GameCasino extends Game{ - constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ - super(name, imageSource, gameSource, nbPlayerMin, nbPlayerMax); + constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ + super(id, name, imageSource, gameSource, nbPlayerMin, nbPlayerMax); + } + + coinsCalculator(points: number): number { + return points; } } \ No newline at end of file diff --git a/bob_party/src/core/gameMulti.ts b/bob_party/src/core/gameMulti.ts index 3fc5ea0..e76862e 100644 --- a/bob_party/src/core/gameMulti.ts +++ b/bob_party/src/core/gameMulti.ts @@ -4,8 +4,8 @@ import { Game } from './game' export class GameMulti extends Game{ readonly rankToCoins:Map - constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map){ - super(name, imageSource, gameSource, nbPlayerMin, nbPlayerMax); + constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map){ + super(id, name, imageSource, gameSource, nbPlayerMin, nbPlayerMax); this.rankToCoins=rankToCoins; } @@ -15,11 +15,15 @@ export class GameMulti extends Game{ } //Returns the coins gained depending on the rank - CoinsWithRank(rank:number){ - let coins; + coinsCalculator(points:number): number{ + let coins=0; + let test; for (let key of this.rankToCoins.keys()){ - coins = this.rankToCoins.get(key); - if (rank==key ){ + test = this.rankToCoins.get(key); + if (test != undefined){ + coins=test; + } + if (points==key ){ return coins; } } diff --git a/bob_party/src/core/gameSolo.ts b/bob_party/src/core/gameSolo.ts index 5ac5668..4f38b9a 100644 --- a/bob_party/src/core/gameSolo.ts +++ b/bob_party/src/core/gameSolo.ts @@ -4,8 +4,8 @@ import { Game } from './game' export class GameSolo extends Game{ readonly ptsToCoins:Map - constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map){ - super(name, imageSource, gameSource, nbPlayerMin,nbPlayerMax); + constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map){ + super(id, name, imageSource, gameSource, nbPlayerMin,nbPlayerMax); this.ptsToCoins=ptsToCoins; } @@ -15,11 +15,15 @@ export class GameSolo extends Game{ } //Returns the gain depending on the number of points - CoinsWithPoints(nbPoints:number){ - let coins; + coinsCalculator(points:number): number{ + let coins=0; + let test; for (let key of this.ptsToCoins.keys()){ - coins = this.ptsToCoins.get(key); - if (nbPoints