From c94585f07f2edeb66d9a2135818b3722e7314325 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Fri, 21 Oct 2022 16:12:59 +0200 Subject: [PATCH 1/2] ADD: class pour le principe S --- bob_party/src/core/gameCasino.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/bob_party/src/core/gameCasino.ts b/bob_party/src/core/gameCasino.ts index b58caa4..1786def 100644 --- a/bob_party/src/core/gameCasino.ts +++ b/bob_party/src/core/gameCasino.ts @@ -2,20 +2,8 @@ import { ImageSourcePropType } from 'react-native'; import { Game } from './game' export class GameCasino extends Game{ - readonly Coef:number; - constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayer:number, coef:number){ - super(name, imageSource, gameSource, nbPlayer); - this.Coef=coef; - } - - //Get the coefficient of the casino game - getCoef(){ - return this.Coef; - } - - //Returns the coins gained with the initial bet of the user times the coefficient of the game - betToCoins(bet:number){ - return this.Coef*bet; + constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ + super(name, imageSource, gameSource, nbPlayerMin, nbPlayerMax); } } \ No newline at end of file From fe24058f3896c88fae68bff0b08ab4cb8b61ca2e Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Fri, 21 Oct 2022 16:13:08 +0200 Subject: [PATCH 2/2] ADD: class pour le principe S --- bob_party/src/constCov.ts | 2 +- bob_party/src/core/Game.ts | 50 ++++++---- bob_party/src/core/User/SkinBuyer.ts | 14 +++ bob_party/src/core/User/managerCoinsUser.ts | 16 +++ bob_party/src/core/{ => User}/user.ts | 105 ++++++++++---------- bob_party/src/core/conversation.test.ts | 3 +- bob_party/src/core/conversation.ts | 13 ++- bob_party/src/core/gameMulti.ts | 16 +-- bob_party/src/core/gameSolo.ts | 16 +-- bob_party/src/core/match.ts | 45 ++++----- bob_party/src/core/matchCasino.ts | 11 ++ bob_party/src/core/matchMulti.ts | 11 ++ bob_party/src/core/matchSolo.ts | 11 ++ bob_party/src/core/message.test.ts | 2 +- bob_party/src/core/message.ts | 2 +- bob_party/src/core/skin.ts | 30 +++--- bob_party/src/core/users.test.ts | 2 +- bob_party/src/screens/Chat.tsx | 2 +- bob_party/src/screens/GameChoice.tsx | 4 +- bob_party/src/screens/Home.tsx | 2 +- bob_party/src/screens/Profile.tsx | 2 +- 21 files changed, 216 insertions(+), 143 deletions(-) create mode 100644 bob_party/src/core/User/SkinBuyer.ts create mode 100644 bob_party/src/core/User/managerCoinsUser.ts rename bob_party/src/core/{ => User}/user.ts (62%) create mode 100644 bob_party/src/core/matchCasino.ts create mode 100644 bob_party/src/core/matchMulti.ts create mode 100644 bob_party/src/core/matchSolo.ts diff --git a/bob_party/src/constCov.ts b/bob_party/src/constCov.ts index 5918814..9051b6a 100644 --- a/bob_party/src/constCov.ts +++ b/bob_party/src/constCov.ts @@ -1,7 +1,7 @@ import { Message } from "./core/message" import { Conversation } from "./core/conversation" import tabSkinApp from './constSkin' -import { User } from "./core/user"; +import { User } from "./core/User/user"; let UserActu:User=new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[0], tabSkinApp, undefined); diff --git a/bob_party/src/core/Game.ts b/bob_party/src/core/Game.ts index 0b2653d..23dbd69 100644 --- a/bob_party/src/core/Game.ts +++ b/bob_party/src/core/Game.ts @@ -2,56 +2,68 @@ import { randomBytes } from "crypto"; import { ImageSourcePropType } from "react-native"; export abstract class Game{ - private Name:string; - private ImageSource:ImageSourcePropType; - private GameSource:string; - private NbPlayer: number; + private name:string; + private imageSource:ImageSourcePropType; + private gameSource:string; + private nbPlayerMin: number; + private nbPlayerMax:number; /* Constructor of the class */ - constructor (name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayer:number){ - this.Name=name; - this.ImageSource=imageSource; - this.GameSource=gameSource; - this.NbPlayer=nbPlayer; + constructor (name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ + this.name=name; + this.imageSource=imageSource; + this.gameSource=gameSource; + this.nbPlayerMin=nbPlayerMin; + this.nbPlayerMax=nbPlayerMax; } /* Brief : Function getting the name of a game */ getName(){ - return this.Name; + return this.name; } /* Brief : Function setting the name of a game */ setName(name:string){ - this.Name=name; + this.name=name; } /* Brief : Function getting the image of a game */ getImageSource(){ - return this.ImageSource; + return this.imageSource; } /* Brief : Function setting the image of a game */ setImageSource(imageSource:ImageSourcePropType){ - this.ImageSource=imageSource; + this.imageSource=imageSource; } /* Brief : Function getting the source of a game */ getGameSource(){ - return this.GameSource; + return this.gameSource; } /* Brief : Function setting the source of a game */ setGameSource(gameSource:string){ - this.GameSource=gameSource; + this.gameSource=gameSource; } /* Brief : Function getting the number of player */ - getNbPlayer(){ - return this.NbPlayer; + getNbPlayerMin(){ + return this.nbPlayerMin; } /* Brief : Function setting the number of player*/ - setNbPlayer(nbPlayer:number){ - this.NbPlayer=nbPlayer; + setNbPlayerMin(nbPlayerMin:number){ + this.nbPlayerMin=nbPlayerMin; + } + + /* Brief : Function getting the number of player */ + getNbPlayerMax(){ + return this.nbPlayerMax; + } + + /* Brief : Function setting the number of player*/ + setNbPlayerMax(nbPlayerMax:number){ + this.nbPlayerMax=nbPlayerMax; } } \ No newline at end of file diff --git a/bob_party/src/core/User/SkinBuyer.ts b/bob_party/src/core/User/SkinBuyer.ts new file mode 100644 index 0000000..692c9b2 --- /dev/null +++ b/bob_party/src/core/User/SkinBuyer.ts @@ -0,0 +1,14 @@ +import { User } from "./user"; +import { Skin } from "../Skin"; +import { ManagerCoinsUser } from "./managerCoinsUser"; +//import ManagerCoinsUser + + +export class SkinBuyer{ + buy(u:User, s:Skin){ + const manage=new ManagerCoinsUser(); + u.getTabSkin().push(s); + manage.removeCoins(u, s.getSkinCost()); + + } +} \ No newline at end of file diff --git a/bob_party/src/core/User/managerCoinsUser.ts b/bob_party/src/core/User/managerCoinsUser.ts new file mode 100644 index 0000000..2f81893 --- /dev/null +++ b/bob_party/src/core/User/managerCoinsUser.ts @@ -0,0 +1,16 @@ +import { User } from "./user"; + +export class ManagerCoinsUser{ + addCoins(u:User, coins:number){ + u.setCurrentCoins(u.getCurrentCoins()+coins); + u.setTotalCoins(u.getTotalCoins()+coins); + } + + removeCoins(u:User, coins:number){ + u.setCurrentCoins(u.getCurrentCoins()-coins); + } + + changeCurrentCoins(u:User, coins:number){ + u.setCurrentCoins(coins); + } +} \ No newline at end of file diff --git a/bob_party/src/core/user.ts b/bob_party/src/core/User/user.ts similarity index 62% rename from bob_party/src/core/user.ts rename to bob_party/src/core/User/user.ts index f2ce858..c421f9c 100644 --- a/bob_party/src/core/user.ts +++ b/bob_party/src/core/User/user.ts @@ -1,159 +1,159 @@ -import { Skin } from './Skin' -import { Conversation } from './conversation'; +import { Skin } from '../Skin' +import { Conversation } from '../conversation'; import { sign } from 'crypto'; export class User{ - readonly Id: string; - private Username: string; - private Password: string; - private Nationality: string; - private Sexe: string; - private DateOfBirth: Date; - private CurrentCoins: number; - private TotalCoins: number; - private NbGamePlayed: number; - private CurrentSkin: Skin; - private TabSkin: Skin[]; - private TabConv?: Conversation[]; + readonly id: string; + private username: string; + private password: string; + private nationality: string; + private sexe: string; + private dateOfBirth: Date; + private currentCoins: number; + private totalCoins: number; + private nbGamePlayed: 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[] ){ - this.Id=id; - this.Username=username; - this.Password=password; - this.Nationality=nationality; - this.Sexe=sexe; - this.DateOfBirth=dateOfBirth; - this.NbGamePlayed=nbGamePlayed; - this.CurrentCoins=currentCoins; - this.TotalCoins=totalCoins; - this.CurrentSkin=currentSkin; - this.TabSkin=[...tabSkin]; + this.id=id; + this.username=username; + this.password=password; + this.nationality=nationality; + this.sexe=sexe; + this.dateOfBirth=dateOfBirth; + this.nbGamePlayed=nbGamePlayed; + this.currentCoins=currentCoins; + this.totalCoins=totalCoins; + this.currentSkin=currentSkin; + this.tabSkin=[...tabSkin]; tabConv?.forEach(conv => { - this.TabConv?.push(conv); + this.tabConv?.push(conv); }); } /* Brief : Function getting the name of an user */ getUsername(){ - return this.Username; + return this.username; } /* Brief : Function setting the name of an user */ setUsername(username: string){ - this.Username=username; + this.username=username; } /* Brief : Function getting the id of an user */ getId(){ - return this.Id; + return this.id; } getPassword(){ - return this.Password; + return this.password; } setPassword(password:string){ - this.Password=password; + this.password=password; } /* Brief : Function getting the current number of coins of an user */ getCurrentCoins(){ - return this.CurrentCoins; + return this.currentCoins; } /* Brief : Function setting the current number of coins of an user */ setCurrentCoins(currentCoins: number){ - this.CurrentCoins=currentCoins; + this.currentCoins=currentCoins; } /* Brief : Function getting the sex of an user */ getSexe(){ - return this.Sexe; + return this.sexe; } /* Brief : Function getting the sex of an user */ setSexe(sexe: string){ - this.Sexe=sexe; + this.sexe=sexe; } /* Brief : Function getting the date of birth of an user */ getDateOfBirth(){ - return this.DateOfBirth; + return this.dateOfBirth; } /* Brief : Function setting the date of birth of an user */ setDateOfBirth(dateOfBirth: Date){ - this.DateOfBirth=dateOfBirth; + this.dateOfBirth=dateOfBirth; } /* Brief : Function getting the nationality of an user */ getNationality(){ - return this.Nationality; + return this.nationality; } /* Brief : Function setting the nationality of an user */ setNationality(nationality: string){ - this.Nationality=nationality; + this.nationality=nationality; } /* Brief : Function getting the total number of coins of an user */ getTotalCoins(){ - return this.TotalCoins; + return this.totalCoins; } /* Brief : Function setting the total number of coins of an user */ setTotalCoins(totalCoins: number){ - this.TotalCoins=totalCoins; + this.totalCoins=totalCoins; } /* Brief : Function getting the current number of game played by an user */ getGamePlayed(){ - return this.NbGamePlayed; + return this.nbGamePlayed; } /* Brief : Function setting the current number of game played by an user */ setGamePlayed(nb: number){ - this.NbGamePlayed=nb; + this.nbGamePlayed=nb; } /* Brief : Function getting the current skin of an user */ getCurrentSkin(){ - return this.CurrentSkin; + return this.currentSkin; } /* Brief : Function setting the current skin of an user */ setCurrentSkin(newSkin: Skin){ - this.CurrentSkin=newSkin; + this.currentSkin=newSkin; } /* Brief : Function getting the skins of an user */ getTabSkin(){ - return this.TabSkin; + return this.tabSkin; } /* Brief : Function setting the skins of an user */ setTabSkin(tabSkin: Skin[]){ - this.TabSkin=[...tabSkin]; + this.tabSkin=[...tabSkin]; } /* Brief : Function getting the conversations of an user */ getTabConv(){ - return this.TabConv; + return this.tabConv; } /* Brief : Function setting the conversations of an user */ setTabConv(tabConv?: Conversation[]){ tabConv?.forEach(conv => { - this.TabConv?.push(conv); + this.tabConv?.push(conv); }); } - + /* changeUserCoins(coin:number){ this.CurrentCoins+=coin; if (coin>0){ @@ -175,4 +175,9 @@ export class User{ } return false; } + + 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/conversation.test.ts b/bob_party/src/core/conversation.test.ts index dec2b53..5a83756 100644 --- a/bob_party/src/core/conversation.test.ts +++ b/bob_party/src/core/conversation.test.ts @@ -1,8 +1,9 @@ import { Conversation } from './Conversation'; import { Message } from './Message'; -import { User } from './User'; import { Skin } from './Skin'; +import { User } from './User/user'; + // Instances let conv:Conversation[] = []; diff --git a/bob_party/src/core/conversation.ts b/bob_party/src/core/conversation.ts index 856eb3d..1627f55 100644 --- a/bob_party/src/core/conversation.ts +++ b/bob_party/src/core/conversation.ts @@ -1,5 +1,5 @@ import { Message } from "./message" -import { User } from "./user"; +import { User } from "./User/user"; export class Conversation{ @@ -15,13 +15,14 @@ export class Conversation{ } /* Brief : function returning the messages of a conversation */ - gettabMessage(){ + getTabMessage(){ this.sortMessageDesc(); return this.tabMessage; } /* Brief : function returning the users of a conversation */ - gettabUser(){ + + getTabUser(){ return this.tabUser; } @@ -37,12 +38,14 @@ export class Conversation{ } /* Brief : function returning the name to a conversation */ - getname(){ + getName(){ + return this.name; } /* Brief : function setting the name to a conversation */ - setname(name:string){ + + setName(name:string){ this.name=name; } diff --git a/bob_party/src/core/gameMulti.ts b/bob_party/src/core/gameMulti.ts index 13a1ad6..3fc5ea0 100644 --- a/bob_party/src/core/gameMulti.ts +++ b/bob_party/src/core/gameMulti.ts @@ -2,24 +2,24 @@ import { ImageSourcePropType } from 'react-native'; import { Game } from './game' export class GameMulti extends Game{ - readonly RankToCoins:Map + readonly rankToCoins:Map - constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayer:number, rankToCoins:Map){ - super(name, imageSource, gameSource, nbPlayer); - this.RankToCoins=rankToCoins; + constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map){ + super(name, imageSource, gameSource, nbPlayerMin, nbPlayerMax); + this.rankToCoins=rankToCoins; } //Get the map of the game with the rank as the key and the coins as the values getMultiMap(){ - return this.RankToCoins; + return this.rankToCoins; } //Returns the coins gained depending on the rank CoinsWithRank(rank:number){ let coins; - for (let key of this.RankToCoins.keys()){ - coins = this.RankToCoins.get(key); - if (rank==key){ + for (let key of this.rankToCoins.keys()){ + coins = this.rankToCoins.get(key); + if (rank==key ){ return coins; } } diff --git a/bob_party/src/core/gameSolo.ts b/bob_party/src/core/gameSolo.ts index 3d88006..ba88a33 100644 --- a/bob_party/src/core/gameSolo.ts +++ b/bob_party/src/core/gameSolo.ts @@ -2,24 +2,24 @@ import { ImageSourcePropType } from 'react-native'; import { Game } from './game' export class GameSolo extends Game{ - readonly PtsToCoins:Map + readonly ptsToCoins:Map - constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayer:number, ptsToCoins:Map){ - super(name, imageSource, gameSource, nbPlayer); - this.PtsToCoins=ptsToCoins; + constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map){ + super(name, imageSource, gameSource, nbPlayerMin,nbPlayerMax); + this.ptsToCoins=ptsToCoins; } //Get the map of the game with points millestone as the keys and coins as the values getSoloMap(){ - return this.PtsToCoins; + return this.ptsToCoins; } //Returns the gain depending on the number of points CoinsWithPoints(nbPoints:number){ let coins; - for (let key of this.PtsToCoins.keys()){ - coins = this.PtsToCoins.get(key); - if (nbPoints