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 { 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;
}

@ -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);
}
}

@ -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;
}

@ -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;
}
}

@ -4,8 +4,8 @@ import { Game } from './game'
export class GameMulti extends Game{
readonly rankToCoins:Map<number,number>
constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map<number,number>){
super(name, imageSource, gameSource, nbPlayerMin, nbPlayerMax);
constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map<number,number>){
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;
}
}

@ -4,8 +4,8 @@ import { Game } from './game'
export class GameSolo extends Game{
readonly ptsToCoins:Map<number,number>
constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map<number,number>){
super(name, imageSource, gameSource, nbPlayerMin,nbPlayerMax);
constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map<number,number>){
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<key ){
test = this.ptsToCoins.get(key);
if (test != undefined){
coins=test;
}
if (points<key ){
return coins;
}
}

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

@ -2,10 +2,17 @@ import { Match } from "./match";
import { User } from "./User/user";
import { Game } from "./game";
import { GameCasino } from "./gameCasino";
import { ManagerCoinsUser } from "./User/managerCoinsUser";
export class MatchMulti extends Match{
constructor(code:string, tabUser:User[], game:GameCasino){
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 { Game } from "./game";
import { GameMulti } from "./gameMulti";
import { ManagerCoinsUser } from "./User/managerCoinsUser";
export class MatchMulti extends Match{
constructor(code:string, tabUser:User[], game:GameMulti){
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 { User } from "./User/user";
import { Game } from "./game";
import { ManagerCoinsUser } from "./User/managerCoinsUser";
export class MatchSolo extends Match{
constructor(code:string, tabUser:User[], game:GameSolo){
super(code, tabUser, game);
}
updatePostMatch(user:User, coins: number): void {
const manage= new ManagerCoinsUser();
manage.addCoins(user, this.getGame().coinsCalculator(coins));
}
}
Loading…
Cancel
Save