From dec83bf0c3b2db90c158c6432baee4f804aae465 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Mon, 17 Oct 2022 15:57:23 +0200 Subject: [PATCH] ADD: -Class match --- bob_party/src/constCov.ts | 8 ++-- bob_party/src/core/Game.ts | 18 ++++++-- bob_party/src/core/conversation.ts | 4 +- bob_party/src/core/gameCasino.ts | 4 +- bob_party/src/core/gameMulti.ts | 4 +- bob_party/src/core/gameSolo.ts | 4 +- bob_party/src/core/match.ts | 67 ++++++++++++++++++++++++++++ bob_party/src/screens/GameChoice.tsx | 2 +- bob_party/src/testGameSolo.ts | 2 +- 9 files changed, 96 insertions(+), 17 deletions(-) create mode 100644 bob_party/src/core/match.ts diff --git a/bob_party/src/constCov.ts b/bob_party/src/constCov.ts index 7dee778..5918814 100644 --- a/bob_party/src/constCov.ts +++ b/bob_party/src/constCov.ts @@ -8,10 +8,10 @@ let UserActu:User=new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date let UserTest:User=new User("48", "Wesh Wesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[1], tabSkinApp, undefined); let tabMessageTest:Message[]=[ - new Message("Salut", UserActu, new Date(2022,12,12)), - new Message("Wesh", UserTest, new Date(2022,12,13)), - new Message("Ca va", UserActu, new Date(2022,12,14)), - new Message("Ouais et toi?", UserTest, new Date(2022,12,15)), + new Message("Salut", UserActu, new Date(2022,12,12,11,30,40)), + new Message("Wesh", UserTest, new Date(2022,12,13,12,20,40)), + new Message("Ca va", UserActu, new Date(2022,12,14, 12, 30, 35)), + new Message("Ouais et toi?", UserTest, new Date(2022,12,14,12,35,0)), ] let tabUS:User[]=[UserActu, UserTest]; diff --git a/bob_party/src/core/Game.ts b/bob_party/src/core/Game.ts index 7abbad5..52c1b0a 100644 --- a/bob_party/src/core/Game.ts +++ b/bob_party/src/core/Game.ts @@ -4,13 +4,15 @@ import { ImageSourcePropType } from "react-native"; export class Game{ private Name:string; private ImageSource:ImageSourcePropType; - private GameSource:string ; + private GameSource:string; + private NbPlayer: number; /* Constructor of the class */ - constructor (name:string, imageSource:ImageSourcePropType, gameSource:string){ + constructor (name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayer:number){ this.Name=name; this.ImageSource=imageSource; this.GameSource=gameSource; + this.NbPlayer=nbPlayer; } /* Brief : Function getting the name of a game */ @@ -38,8 +40,18 @@ export class Game{ return this.GameSource; } - /* Brief : Function getting the source of a game */ + /* Brief : Function setting the source of a game */ setGameSource(gameSource:string){ this.GameSource=gameSource; } + + /* Brief : Function getting the number of player */ + getNbPlayer(){ + return this.NbPlayer; + } + + /* Brief : Function setting the number of player*/ + setNbPlayer(nbPlayer:number){ + this.NbPlayer=nbPlayer; + } } \ No newline at end of file diff --git a/bob_party/src/core/conversation.ts b/bob_party/src/core/conversation.ts index dcc0db0..76a49cc 100644 --- a/bob_party/src/core/conversation.ts +++ b/bob_party/src/core/conversation.ts @@ -5,10 +5,10 @@ import { User } from "./user"; export class Conversation{ private TabUser: User[]; private TabMessage: Message[]; - private Name?: string; + private Name: string; /* Constructor of the class */ - constructor(tabUser: User[], tabMessage:Message[], name?:string){ + constructor(tabUser: User[], tabMessage:Message[], name:string){ this.TabUser=[...tabUser]; this.TabMessage=[...tabMessage]; this.Name=name; diff --git a/bob_party/src/core/gameCasino.ts b/bob_party/src/core/gameCasino.ts index 3e37553..b58caa4 100644 --- a/bob_party/src/core/gameCasino.ts +++ b/bob_party/src/core/gameCasino.ts @@ -4,8 +4,8 @@ import { Game } from './game' export class GameCasino extends Game{ readonly Coef:number; - constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, coef:number){ - super(name, imageSource, gameSource); + constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayer:number, coef:number){ + super(name, imageSource, gameSource, nbPlayer); this.Coef=coef; } diff --git a/bob_party/src/core/gameMulti.ts b/bob_party/src/core/gameMulti.ts index f8e5a77..4555331 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, rankToCoins:Map){ - super(name, imageSource, gameSource); + constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayer:number, rankToCoins:Map){ + super(name, imageSource, gameSource, nbPlayer); this.RankToCoins=rankToCoins; } diff --git a/bob_party/src/core/gameSolo.ts b/bob_party/src/core/gameSolo.ts index 30c3f2a..64cecdb 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, ptsToCoins:Map){ - super(name, imageSource, gameSource); + constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayer:number, ptsToCoins:Map){ + super(name, imageSource, gameSource, nbPlayer); this.PtsToCoins=ptsToCoins; } diff --git a/bob_party/src/core/match.ts b/bob_party/src/core/match.ts new file mode 100644 index 0000000..8365997 --- /dev/null +++ b/bob_party/src/core/match.ts @@ -0,0 +1,67 @@ +import { ImageSourcePropType } from 'react-native'; +import { Game } from './game'; +import { GameCasino } from './gameCasino'; +import { GameMulti } from './gameMulti'; +import { GameSolo } from './gameSolo'; +import { User } from "./user"; + +let index:number=0; + +export class Match{ + readonly Code:string; + private TabUsers:User[]; + private TheGame:Game; + private GainingMechanism:number=0; + + constructor(tabUser:User[], game:Game){ + index++; + this.Code=index.toString(); + this.TabUsers=[...tabUser]; + this.TheGame=game; + } + + getTabUsers(){ + return this.TabUsers; + } + + ajouterUser(us:User){ + this.TabUsers.push(us); + } + + setTabUser(tabUser:User[]){ + this.TabUsers=[...tabUser]; + } + + getCode(){ + return this.Code; + } + + getGame(){ + return this.TheGame; + } + + setGame(game:Game){ + this.TheGame=game; + } + + getGainingMechanism(){ + return this.GainingMechanism; + } + + setGainingMechanism(gain:number){ + this.GainingMechanism=gain; + } + + convertMechanismToCoins(){ + if (this.TheGame instanceof GameSolo){ + return this.TheGame.CoinsWithPoints(this.GainingMechanism); + } + else if (this.TheGame instanceof GameMulti){ + return this.TheGame.CoinsWithRank(this.GainingMechanism); + } + else if (this.TheGame instanceof GameCasino){ + return this.TheGame.betToCoins(this.GainingMechanism); + } + } + +} \ No newline at end of file diff --git a/bob_party/src/screens/GameChoice.tsx b/bob_party/src/screens/GameChoice.tsx index 1540849..c5088d5 100644 --- a/bob_party/src/screens/GameChoice.tsx +++ b/bob_party/src/screens/GameChoice.tsx @@ -15,7 +15,7 @@ let tabConv:Conversation[]=[]; const msc = require('../../assets/Icons/FondGris.png'); const UserActu=new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[0], tabSkinApp, tabConv); -const jeuTest= new Game("SNAKE", require('../../assets/Icons/UnSelected/Gamepad.png'),"ouin"); +const jeuTest= new Game("SNAKE", require('../../assets/Icons/UnSelected/Gamepad.png'),"ouin", 1); function GameChoice(props: { navigation: any; }) { const { navigation } = props return ( diff --git a/bob_party/src/testGameSolo.ts b/bob_party/src/testGameSolo.ts index f1c8f3d..c8d6c14 100644 --- a/bob_party/src/testGameSolo.ts +++ b/bob_party/src/testGameSolo.ts @@ -7,6 +7,6 @@ let myMap = new Map([ [150, 6] ]); -let game=new GameSolo("bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", myMap); +let game=new GameSolo("bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", 1, myMap); export default game; \ No newline at end of file