ADD: fonctions abstract de Game et Match
continuous-integration/drone/push Build is failing Details

temp
Thomas Chazot 2 years ago
parent 395dde5fb6
commit d6afccb50d

@ -1,5 +1,6 @@
import { randomBytes } from "crypto"; import { randomBytes } from "crypto";
import { ImageSourcePropType } from "react-native"; import { ImageSourcePropType } from "react-native";
import internal from "stream";
export abstract class Game{ export abstract class Game{
readonly id:string; readonly id:string;
@ -73,4 +74,6 @@ export abstract class Game{
setNbPlayerMax(nbPlayerMax:number){ setNbPlayerMax(nbPlayerMax:number){
this.nbPlayerMax=nbPlayerMax; this.nbPlayerMax=nbPlayerMax;
} }
abstract coinsCalculator(points: number): number;
} }

@ -1,6 +1,7 @@
import { Skin } from '../Skin' import { Skin } from '../Skin'
import { Conversation } from '../conversation'; import { Conversation } from '../conversation';
import { sign } from 'crypto'; import { sign } from 'crypto';
import { TextBase } from 'react-native';
export class User{ export class User{
readonly id: string; readonly id: string;
@ -14,11 +15,11 @@ export class User{
private nbGamesPlayed: number; private nbGamesPlayed: number;
private currentSkin: Skin; private currentSkin: Skin;
private tabSkin: Skin[]; private tabSkin: Skin[];
private tabConv?: Conversation[]; private tabConv: Conversation[];
/* Consturctor of the class */ /* Consturctor of the class */
constructor(id: string, username: string, password:string, nationality: string, sexe: string, dateOfBirth: Date, currentCoins: number, totalCoins: number, 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.id=id;
this.username=username; this.username=username;
this.password=password; this.password=password;
@ -30,135 +31,136 @@ export class User{
this.totalCoins=totalCoins; this.totalCoins=totalCoins;
this.currentSkin=currentSkin; this.currentSkin=currentSkin;
this.tabSkin=[...tabSkin]; this.tabSkin=[...tabSkin];
if(tabConv!==undefined){ this.tabConv=[...tabConv];
this.tabConv=[...tabConv];
}
else{
this.tabConv=tabConv;
}
} }
/* Brief : Function getting the name of an user */ /* Brief : Function getting the name of a user */
getUsername(){ getUsername(){
return this.username; return this.username;
} }
/* Brief : Function setting the name of an user */ /* Brief : Function setting the name of a user */
setUsername(username: string){ setUsername(username: string){
this.username=username; this.username=username;
} }
/* Brief : Function getting the id of an user */ /* Brief : Function getting the id of a user */
getId(){ getId(){
return this.id; return this.id;
} }
/* Brief : Function getting the password of a user */
getPassword(){ getPassword(){
return this.password; return this.password;
} }
/* Brief : Function setting the password of a user */
setPassword(password:string){ setPassword(password:string){
this.password=password; 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(){ getCurrentCoins(){
return this.currentCoins; 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){ setCurrentCoins(currentCoins: number){
this.currentCoins=currentCoins; this.currentCoins=currentCoins;
} }
/* Brief : Function getting the sex of an user */ /* Brief : Function getting the sex of a user */
getSexe(){ getSexe(){
return this.sexe; return this.sexe;
} }
/* Brief : Function getting the sex of an user */ /* Brief : Function getting the sex of a user */
setSexe(sexe: string){ setSexe(sexe: string){
this.sexe=sexe; this.sexe=sexe;
} }
/* Brief : Function getting the date of birth of an user */ /* Brief : Function getting the date of birth of a user */
getDateOfBirth(){ getDateOfBirth(){
return this.dateOfBirth; 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){ setDateOfBirth(dateOfBirth: Date){
this.dateOfBirth=dateOfBirth; this.dateOfBirth=dateOfBirth;
} }
/* Brief : Function getting the nationality of an user */ /* Brief : Function getting the nationality of a user */
getNationality(){ getNationality(){
return this.nationality; return this.nationality;
} }
/* Brief : Function setting the nationality of an user */ /* Brief : Function setting the nationality of a user */
setNationality(nationality: string){ setNationality(nationality: string){
this.nationality=nationality; 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(){ getTotalCoins(){
return this.totalCoins; 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){ setTotalCoins(totalCoins: number){
this.totalCoins=totalCoins; 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(){ getGamesPlayed(){
return this.nbGamesPlayed; 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){ setGamesPlayed(nb: number){
this.nbGamesPlayed=nb; this.nbGamesPlayed=nb;
} }
/* Brief : Function getting the current skin of an user */ /* Brief : Function getting the current skin of a user */
getCurrentSkin(){ getCurrentSkin(){
return this.currentSkin; return this.currentSkin;
} }
/* Brief : Function setting the current skin of an user */ /* Brief : Function setting the current skin of a user */
setCurrentSkin(newSkin: Skin){ setCurrentSkin(newSkin: Skin){
this.currentSkin=newSkin; this.currentSkin=newSkin;
} }
/* Brief : Function getting the skins of an user */ /* Brief : Function getting the skins of a user */
getTabSkin(){ getTabSkin(){
return this.tabSkin; return this.tabSkin;
} }
/* Brief : Function setting the skins of an user */ /* Brief : Function setting the skins of a user */
setTabSkin(tabSkin: Skin[]){ setTabSkin(tabSkin: Skin[]){
this.tabSkin=[...tabSkin]; this.tabSkin=[...tabSkin];
} }
/* Brief : Function getting the conversations of an user */ /* Brief : Function getting the conversations of a user */
getTabConv(){ getTabConv(){
return this.tabConv; return this.tabConv;
} }
/* Brief : Function setting the conversations of an user */ /* Brief : Function setting the conversations of a user */
setTabConv(tabConv?: Conversation[]){ setTabConv(tabConv: Conversation[]){
tabConv?.forEach(conv => { this.tabConv=[...tabConv]
this.tabConv?.push(conv);
});
} }
/* Brief : Function adding a skin to a user */
addSkin(skin:Skin){ addSkin(skin:Skin){
this.tabSkin.push(skin); this.tabSkin.push(skin);
} }
/* Brief : Function adding a conversation to a user */
addConversation(conv:Conversation){
this.tabConv.push(conv);
}
} }

@ -1,10 +1,12 @@
import { User } from "./user"; import { User } from "./user";
import tabSkinApp from "../../constSkin"; import tabSkinApp from "../../constSkin";
import { Conversation } from "../conversation";
export class UserCreator{ 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 //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 //Ajout du joueur dans la bdd
return u; return u;
} }

@ -3,7 +3,11 @@ import { Game } from './game'
export class GameCasino extends Game{ export class GameCasino extends Game{
constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){
super(name, imageSource, gameSource, nbPlayerMin, nbPlayerMax); super(id, name, imageSource, gameSource, nbPlayerMin, nbPlayerMax);
}
coinsCalculator(points: number): number {
return points;
} }
} }

@ -4,8 +4,8 @@ import { Game } from './game'
export class GameMulti extends Game{ export class GameMulti extends Game{
readonly rankToCoins:Map<number,number> readonly rankToCoins:Map<number,number>
constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map<number,number>){ constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map<number,number>){
super(name, imageSource, gameSource, nbPlayerMin, nbPlayerMax); super(id, name, imageSource, gameSource, nbPlayerMin, nbPlayerMax);
this.rankToCoins=rankToCoins; this.rankToCoins=rankToCoins;
} }
@ -15,11 +15,15 @@ export class GameMulti extends Game{
} }
//Returns the coins gained depending on the rank //Returns the coins gained depending on the rank
CoinsWithRank(rank:number){ coinsCalculator(points:number): number{
let coins; let coins=0;
let test;
for (let key of this.rankToCoins.keys()){ for (let key of this.rankToCoins.keys()){
coins = this.rankToCoins.get(key); test = this.rankToCoins.get(key);
if (rank==key ){ if (test != undefined){
coins=test;
}
if (points==key ){
return coins; return coins;
} }
} }

@ -4,8 +4,8 @@ import { Game } from './game'
export class GameSolo extends Game{ export class GameSolo extends Game{
readonly ptsToCoins:Map<number,number> readonly ptsToCoins:Map<number,number>
constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map<number,number>){ constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map<number,number>){
super(name, imageSource, gameSource, nbPlayerMin,nbPlayerMax); super(id, name, imageSource, gameSource, nbPlayerMin,nbPlayerMax);
this.ptsToCoins=ptsToCoins; this.ptsToCoins=ptsToCoins;
} }
@ -15,11 +15,15 @@ export class GameSolo extends Game{
} }
//Returns the gain depending on the number of points //Returns the gain depending on the number of points
CoinsWithPoints(nbPoints:number){ coinsCalculator(points:number): number{
let coins; let coins=0;
let test;
for (let key of this.ptsToCoins.keys()){ for (let key of this.ptsToCoins.keys()){
coins = this.ptsToCoins.get(key); test = this.ptsToCoins.get(key);
if (nbPoints<key ){ if (test != undefined){
coins=test;
}
if (points<key ){
return coins; return coins;
} }
} }

@ -70,19 +70,6 @@ export abstract class Match{
} }
/* abstract updatePostMatch(user:User, coins:number):void;
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);
}
return -1;
}
*/
} }

@ -2,10 +2,17 @@ import { Match } from "./match";
import { User } from "./User/user"; import { User } from "./User/user";
import { Game } from "./game"; import { Game } from "./game";
import { GameCasino } from "./gameCasino"; import { GameCasino } from "./gameCasino";
import { ManagerCoinsUser } from "./User/managerCoinsUser";
export class MatchMulti extends Match{ export class MatchMulti extends Match{
constructor(code:string, tabUser:User[], game:GameCasino){ constructor(code:string, tabUser:User[], game:GameCasino){
super(code, tabUser, game); super(code, tabUser, game);
} }
updatePostMatch(user:User, coins: number): void {
const manage= new ManagerCoinsUser();
manage.addCoins(user, this.getGame().coinsCalculator(coins));
}
} }

@ -2,10 +2,16 @@ import { Match } from "./match";
import { User } from "./User/user"; import { User } from "./User/user";
import { Game } from "./game"; import { Game } from "./game";
import { GameMulti } from "./gameMulti"; import { GameMulti } from "./gameMulti";
import { ManagerCoinsUser } from "./User/managerCoinsUser";
export class MatchMulti extends Match{ export class MatchMulti extends Match{
constructor(code:string, tabUser:User[], game:GameMulti){ constructor(code:string, tabUser:User[], game:GameMulti){
super(code, tabUser, game); super(code, tabUser, game);
} }
updatePostMatch(user:User, coins: number): void {
const manage= new ManagerCoinsUser();
manage.addCoins(user, this.getGame().coinsCalculator(coins));
}
} }

@ -2,10 +2,16 @@ import { Match } from "./match";
import { GameSolo } from "./gameSolo"; import { GameSolo } from "./gameSolo";
import { User } from "./User/user"; import { User } from "./User/user";
import { Game } from "./game"; import { Game } from "./game";
import { ManagerCoinsUser } from "./User/managerCoinsUser";
export class MatchSolo extends Match{ export class MatchSolo extends Match{
constructor(code:string, tabUser:User[], game:GameSolo){ constructor(code:string, tabUser:User[], game:GameSolo){
super(code, tabUser, game); super(code, tabUser, game);
} }
updatePostMatch(user:User, coins: number): void {
const manage= new ManagerCoinsUser();
manage.addCoins(user, this.getGame().coinsCalculator(coins));
}
} }
Loading…
Cancel
Save