ADD: class pour le principe S

stub-api
Thomas Chazot 3 years ago
parent c94585f07f
commit fe24058f38

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

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

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

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

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

@ -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[] = [];

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

@ -2,24 +2,24 @@ import { ImageSourcePropType } from 'react-native';
import { Game } from './game'
export class GameMulti extends Game{
readonly RankToCoins:Map<number,number>
readonly rankToCoins:Map<number,number>
constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayer:number, rankToCoins:Map<number,number>){
super(name, imageSource, gameSource, nbPlayer);
this.RankToCoins=rankToCoins;
constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map<number,number>){
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;
}
}

@ -2,24 +2,24 @@ import { ImageSourcePropType } from 'react-native';
import { Game } from './game'
export class GameSolo extends Game{
readonly PtsToCoins:Map<number,number>
readonly ptsToCoins:Map<number,number>
constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayer:number, ptsToCoins:Map<number,number>){
super(name, imageSource, gameSource, nbPlayer);
this.PtsToCoins=ptsToCoins;
constructor(name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map<number,number>){
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<key){
for (let key of this.ptsToCoins.keys()){
coins = this.ptsToCoins.get(key);
if (nbPoints<key ){
return coins;
}
}

@ -3,55 +3,42 @@ import { Game } from './game';
import { GameCasino } from './gameCasino';
import { GameMulti } from './gameMulti';
import { GameSolo } from './gameSolo';
import { User } from "./user";
import { User } from "./User/user";
let index:number=0;
export class Match{
readonly Code:string;
private TabUsers:User[];
private TheGame:Game;
private GainingMechanism:number=0;
export abstract class Match{
readonly code:string;
private tabUsers:User[];
private theGame:Game;
constructor(tabUser:User[], game:Game){
index++;
this.Code=index.toString();
this.TabUsers=[...tabUser];
this.TheGame=game;
constructor(code:string, tabUser:User[], game:Game){
this.code=code;
this.tabUsers=[...tabUser];
this.theGame=game;
}
getTabUsers(){
return this.TabUsers;
}
ajouterUser(us:User){
this.TabUsers.push(us);
return this.tabUsers;
}
setTabUser(tabUser:User[]){
this.TabUsers=[...tabUser];
this.tabUsers=[...tabUser];
}
getCode(){
return this.Code;
return this.code;
}
getGame(){
return this.TheGame;
return this.theGame;
}
setGame(game:Game){
this.TheGame=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);
@ -62,6 +49,8 @@ export class Match{
else if (this.TheGame instanceof GameCasino){
return this.TheGame.betToCoins(this.GainingMechanism);
}
return -1;
}
*/
}

@ -0,0 +1,11 @@
import { Match } from "./match";
import { User } from "./User/user";
import { Game } from "./game";
import { GameCasino } from "./gameCasino";
export class MatchMulti extends Match{
constructor(code:string, tabUser:User[], game:GameCasino){
super(code, tabUser, game);
}
}

@ -0,0 +1,11 @@
import { Match } from "./match";
import { User } from "./User/user";
import { Game } from "./game";
import { GameMulti } from "./gameMulti";
export class MatchMulti extends Match{
constructor(code:string, tabUser:User[], game:GameMulti){
super(code, tabUser, game);
}
}

@ -0,0 +1,11 @@
import { Match } from "./match";
import { GameSolo } from "./gameSolo";
import { User } from "./User/user";
import { Game } from "./game";
export class MatchSolo extends Match{
constructor(code:string, tabUser:User[], game:GameSolo){
super(code, tabUser, game);
}
}

@ -1,5 +1,5 @@
import { Message } from './Message';
import { User } from './User';
import { User } from './User/user';
import { Conversation } from './Conversation';
import { Skin } from './Skin';

@ -1,4 +1,4 @@
import { User } from './user'
import { User } from './User/user'
export class Message{

@ -1,51 +1,51 @@
import { ImageSourcePropType } from "react-native";
export class Skin{
readonly Id: string;
private Name: string;
private Source: ImageSourcePropType;
private Cost:number;
readonly id: string;
private name: string;
private source: ImageSourcePropType;
private cost:number;
/* Constructor of the class */
constructor(id:string, name: string, source:ImageSourcePropType, Cost:number){
this.Id=id;
this.Name=name;
this.Source=source;
this.Cost=Cost;
this.id=id;
this.name=name;
this.source=source;
this.cost=Cost;
}
/* Brief : Fuction setting the name of a skin */
setSkinName(name: string){
this.Name=name;
this.name=name;
}
/* Brief : Fuction setting the source of the image of a skin */
setSkinSource(source: ImageSourcePropType){
this.Source=source;
this.source=source;
}
/* Brief : Fuction getting the source of the image of a skin */
getSkinSource(){
return this.Source;
return this.source;
}
/* Brief : Fuction getting the name of a skin */
getSkinName(){
return this.Name;
return this.name;
}
/* Brief : Fuction getting the id of a skin */
getSkinId(){
return this.Id;
return this.id;
}
/* Brief : Fuction getting the cost of a skin */
getSkinCost(){
return this.Cost;
return this.cost;
}
/* Brief : Fuction getting the cost of a skin */
setSkinCost(cost:number){
this.Cost=cost;
this.cost=cost;
}
}

@ -1,4 +1,4 @@
import { User } from './User';
import { User } from './User/user';
import { Skin } from './Skin';
import { Conversation } from './Conversation';

@ -6,7 +6,7 @@ import { Skin } from '../core/skin';
import { TopBar } from '../components/TopBar';
import { BotBar } from '../components/BotBar';
import { ScreenIndicator } from '../components/ScreenIndicator';
import { User } from '../core/user';
import { User } from '../core/User/user';
import { FlatList } from 'react-native-gesture-handler';
import { ConversationComponent } from '../components/ConversationComponent';

@ -1,12 +1,12 @@
import { StatusBar } from 'expo-status-bar'
import { StyleSheet, View, Text, Alert, Pressable, Image} from 'react-native'
import React from 'react';
import { Game } from '../core/Game';
import { Game } from '../core/game';
import { Skin } from '../core/skin';
import { TopBar } from '../components/TopBar';
import { BotBar } from '../components/BotBar';
import { GameComponent } from '../components/GameComponent';
import { User } from '../core/user';
import { User } from '../core/User/user';
import tabSkinApp from '../constSkin';
import { Conversation } from '../core/conversation';
import { GameSolo } from '../core/gameSolo';

@ -2,7 +2,7 @@ import { StatusBar } from 'expo-status-bar'
import { StyleSheet, View, ImageSourcePropType} from 'react-native'
import React from 'react';
import stylesScreen from './style/screens.style'
import { User } from '../core/user';
import { User } from '../core/User/user';
import { Skin } from '../core/skin';
import { TopBar } from '../components/TopBar';
import { BotBar } from '../components/BotBar';

@ -6,7 +6,7 @@ import styles from './style/Profile.style'
import { TopBar } from '../components/TopBar';
import { BotBar } from '../components/BotBar';
import { SkinComponent } from '../components/Skin';
import { User } from '../core/user';
import { User } from '../core/User/user';
import tabSkinApp from '../constSkin';
import tabConv from '../constCov'
import { ButtonChangeSkin } from '../components/ButtonChangeSkin';

Loading…
Cancel
Save