diff --git a/api-rest/gateways/matchGateway.php b/api-rest/gateways/matchGateway.php
index e3f05bd..31611aa 100644
--- a/api-rest/gateways/matchGateway.php
+++ b/api-rest/gateways/matchGateway.php
@@ -41,7 +41,7 @@ class MatchGateway{
}
/// Brief : Adding a NEW match in database
- public function postMatch(int $idGame, int $idCreator){
+ public function postMatch(int $idGame, int $idCreator): ?Matchs{
$insertMatchQuery="INSERT INTO T_E_MATCH_MTC VALUES(NULL,0,:idGame)";
$insertPlayQuery = "INSERT INTO T_J_PLAY_MATCH_PLM VALUES(:idCreator,:id);";
$argInsertMatch=array('idGame'=>array($idGame, PDO::PARAM_INT));
@@ -57,7 +57,7 @@ class MatchGateway{
$argInsertPlay= array('idCreator'=>array($idCreator,PDO::PARAM_INT),
'id'=>array($id,PDO::PARAM_INT));
$this->connection->execQuery($insertPlayQuery,$argInsertPlay);
- return;
+ return new Matchs($id, 0, $idGame, [$idCreator]);
}
/// Brief : Modifying an EXISTING match in database
diff --git a/api-rest/index.php b/api-rest/index.php
index ea36d44..715cd49 100644
--- a/api-rest/index.php
+++ b/api-rest/index.php
@@ -164,6 +164,7 @@
$idCreator = !empty($url[5]) ? (int) $url[5] : null;
if ($idGame != null || $idCreator != null){
$match =$matchgw->postMatch($idGame,$idCreator);
+ echo json_encode($match, JSON_PRETTY_PRINT);
http_response_code(200);
} else{
header("HTTP/1.0 400 idGame or idCreator not given");
@@ -203,7 +204,6 @@
$totalnbCoins = (int) $url[10];
$nbGames = (int) $url[11];
$currentSkin = !empty($url[12]) ? (int) $url[12] : null;
- echo ($nbCurrentCoins . ' ' . $totalnbCoins . " ". $nbGames);
$usergw->putUser($id,$username,$password,$sexe, $nationality, $nbCurrentCoins,$totalnbCoins,$nbGames,$currentSkin);
http_response_code(200);
}
diff --git a/bob_party/server.js b/bob_party/server.js
index 4d9a866..9be4546 100644
--- a/bob_party/server.js
+++ b/bob_party/server.js
@@ -17,6 +17,10 @@ io.on('connection', (socket) => {
socket.join("C" + conv.id);
});
+ socket.on('quitConv', (conv) => {
+ socket.off("C" + conv);
+ });
+
socket.on("messageSent", (conv) =>{
socket.to("C"+conv.id).emit("messageReceived");
console.log("Message envoyé");
@@ -28,10 +32,15 @@ io.on('connection', (socket) => {
});
});
- socket.on('inMatch', (match) => {
+
+ socket.on('joinMatch', (match) => {
socket.join("M" + match);
});
+ socket.on('quitMatch', (match) => {
+ socket.off("M" + match);
+ });
+
socket.on("playTicTacToe", (match, rowIndex, columnIndex, turn) =>{
socket.to("M"+match).emit("oppPlayTicTacToe", rowIndex, columnIndex, turn);
});
diff --git a/bob_party/src/components/GameComponent.tsx b/bob_party/src/components/GameComponent.tsx
index 0d6a4e8..f181c13 100644
--- a/bob_party/src/components/GameComponent.tsx
+++ b/bob_party/src/components/GameComponent.tsx
@@ -10,9 +10,11 @@ import { Game } from "../core/game"
import styles from './style/Game.style';
import Lobby from "../screens/Lobby"
import ManagerMatch from "../services/matchServices/managerMatch"
-import MatchCreator from "../core/Match/matchCreator"
+import MatchModifier from "../core/Match/matchModifier"
import { useMatchStore } from "../context/matchContext"
-import { MANAGER_MATCH, MANAGER_USER } from "../../appManagers"
+import { MANAGER_GAME, MANAGER_MATCH, MANAGER_USER } from "../../appManagers"
+import { GameSolo } from "../core/gameSolo"
+import { socket } from "../../socketConfig"
export const GameComponent :
@@ -27,12 +29,13 @@ FC<{game: Game, nav: any}> =
const setMatch = useMatchStore((state) => state.setMatch);
- const createNewMatchSolo = useCallback(async (game : Game, nav: any) => {
+ const createNewMatch = useCallback(async (game : Game, nav: any) => {
- const m=new MatchCreator();
+ const m=new MatchModifier();
const tmp=MANAGER_USER.getCurrentUser();
if (tmp!==null){
let match=await m.createMatch(tmp, game);
+ socket.emit("joinMatch", match);
MANAGER_MATCH.setCurrentMatch(match);
setMatch(match);
nav.navigate("GameSolo");
@@ -42,7 +45,7 @@ FC<{game: Game, nav: any}> =
return (
- createNewMatchSolo(game, nav)}>
+ createNewMatch(game, nav)}>
=
if(MANAGER_GAME.currentGameType === "solo" ){
gameList = MANAGER_GAME.getTabGameSolo();
- console.log(gameList);
}
else if(MANAGER_GAME.currentGameType === "multi"){
gameList = MANAGER_GAME.getTabGameMulti();
diff --git a/bob_party/src/components/LobbyComponent.tsx b/bob_party/src/components/LobbyComponent.tsx
index e94474e..acaecbf 100644
--- a/bob_party/src/components/LobbyComponent.tsx
+++ b/bob_party/src/components/LobbyComponent.tsx
@@ -1,5 +1,5 @@
-import { FC} from "react"
-import { FlatList } from "react-native"
+import { FC, useState} from "react"
+import { Button, FlatList } from "react-native"
import React from "react"
import { Game } from "../core/game"
@@ -22,8 +22,28 @@ export const LobbyComponent :
FC<{nav: any}> =
({nav}) =>
{
+ const setTabUser = useMatchStore((state) => state.setTabUser);
+
+ const [initUsers, setInitUsers] = useState(0);
+
+ function getUsers(){
+ if (initUsers===0){
+ setInitUsers(1);
+ const tmp:any=[];
+ MANAGER_MATCH.getCurrentMatch()?.getTabUsers().forEach(user => {
+ tmp.push(user);
+ });
+ const tmpGame=MANAGER_MATCH.getCurrentMatch()?.getGame();
+ if (tmpGame!=undefined){
+ for (let i=tmp.length; i
@@ -35,16 +55,32 @@ FC<{nav: any}> =
/>
);
}
else{
+ getUsers();
return(
-
+ usr?.getUsername() || usr}
+ renderItem={({item}) => }
+ />
+
+
+
+
);
}
diff --git a/bob_party/src/components/TopBar.tsx b/bob_party/src/components/TopBar.tsx
index 98e7381..f1277b4 100644
--- a/bob_party/src/components/TopBar.tsx
+++ b/bob_party/src/components/TopBar.tsx
@@ -10,11 +10,12 @@ import { User } from "../core/User/user"
*/
import styles from './style/TopBar.style';
import { useMatchStore } from "../context/matchContext"
-import { MANAGER_CONVERSATION, MANAGER_USER } from "../../appManagers"
+import { MANAGER_CONVERSATION, MANAGER_MATCH, MANAGER_USER } from "../../appManagers"
import { useUserStore } from "../context/userContext"
import { useConversationStore } from "../context/conversationContext"
import { socket } from "../../socketConfig"
import { Conversation } from "../core/conversation"
+import MatchModifier from "../core/Match/matchModifier"
/*
Images required
@@ -36,6 +37,8 @@ FC<{nav: any, state?: string}> =
{
const resetMatch = useMatchStore((state) => state.resetMatch);
+ const resetTabUserMatch = useMatchStore((state) => state.resetTabUser);
+
const resetCurrentConv = useConversationStore((state) => state.resetCurrentConv);
const setTabConv = useConversationStore((state) => state.setTabConv);
@@ -56,10 +59,24 @@ FC<{nav: any, state?: string}> =
MANAGER_CONVERSATION.setCurrentConv(null);
setTabConv(MANAGER_CONVERSATION.getTabConv());
socket.emit("messageSent", tmpConv);
+ socket.emit("quitConv", tmpConv);
nav.goBack();
}
}
+ async function clickQuitMatch(){
+ const tmp=MANAGER_USER.getCurrentUser();
+ const tmpMatch=MANAGER_MATCH.getCurrentMatch();
+ const m=new MatchModifier();
+ if (tmp!==null && tmpMatch!==null){
+ socket.emit("quitMatch", tmpMatch);
+ await m.quitMatch(tmp, tmpMatch);
+ resetMatch();
+ resetTabUserMatch();
+ MANAGER_MATCH.setCurrentMatch(null);
+ }
+ }
+
/* The display of this component depends of the screen from where it has been called:
* From the Settings (icon) : Name of the page + cross button
* From other : skin + Title + parameters icon
@@ -85,7 +102,7 @@ FC<{nav: any, state?: string}> =
BOB PARTY
- { resetMatch(); nav.goBack()}}>
+ { clickQuitMatch(); nav.goBack()}}>
diff --git a/bob_party/src/components/UserPreview.tsx b/bob_party/src/components/UserPreview.tsx
index 529d9ff..3d6ed28 100644
--- a/bob_party/src/components/UserPreview.tsx
+++ b/bob_party/src/components/UserPreview.tsx
@@ -8,12 +8,6 @@ import { Game } from "../core/game"
Importing the correct stylesheet
*/
import styles from './style/UserPreview.style';
-import Lobby from "../screens/Lobby"
-import ManagerMatch from "../services/matchServices/managerMatch"
-import MatchCreator from "../core/Match/matchCreator"
-import { useMatchStore } from "../context/matchContext"
-import { MANAGER_MATCH, MANAGER_USER } from "../../appManagers"
-import { Match } from "../core/Match/match"
import { User } from "../core/User/user"
export const UserPreview :
@@ -22,10 +16,11 @@ export const UserPreview :
* match : match that must be displayed
* nav : tool needed to allow the navigation between the screens
*/
-FC<{user: User | undefined}> =
+FC<{user: User | null}> =
({user}) =>
{
- if(user != undefined){
+ console.log(user);
+ if(user !== null){
return (
void;
resetMatch: () => void;
- setTabUser: (tabUser: User[] | null[]) => void;
+ setTabUser: (tabUser: any[]) => void;
resetTabUser: () => void;
}
diff --git a/bob_party/src/core/Match/matchCreator.ts b/bob_party/src/core/Match/matchCreator.ts
deleted file mode 100644
index d598bf8..0000000
--- a/bob_party/src/core/Match/matchCreator.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import { MANAGER_MATCH } from "../../../appManagers";
-import { Game } from "../game";
-import { User } from "../User/user";
-import { Match } from "./match";
-
-export default class MatchCreator{
-
- async createMatch(u:User, g:Game): Promise{
- return await MANAGER_MATCH.getsaverMatch().saveMatch(u, g);
- }
-}
\ No newline at end of file
diff --git a/bob_party/src/core/Match/matchModifier.ts b/bob_party/src/core/Match/matchModifier.ts
new file mode 100644
index 0000000..774c110
--- /dev/null
+++ b/bob_party/src/core/Match/matchModifier.ts
@@ -0,0 +1,26 @@
+import { MANAGER_MATCH } from "../../../appManagers";
+import { Game } from "../game";
+import { GameSolo } from "../gameSolo";
+import { User } from "../User/user";
+import { Match } from "./match";
+import MatchSolo from "./matchSolo";
+
+export default class MatchModifier{
+
+ async createMatch(u:User, g:Game): Promise{
+ if (g instanceof GameSolo){
+ return new MatchSolo(0, false, [u], g);
+ }
+ return await MANAGER_MATCH.getsaverMatch().saveMatch(u, g);
+ }
+
+ async quitMatch(u:User, m:Match): Promise{
+ const saver=MANAGER_MATCH.getsaverMatch();
+ if (m.getTabUsers().length===1){
+ saver.deleteMatch(m);
+ }
+ else{
+ saver.deleteUserFromMatch(u);
+ }
+ }
+}
\ No newline at end of file
diff --git a/bob_party/src/screens/MatchMaking.tsx b/bob_party/src/screens/MatchMaking.tsx
index 1efdf51..f0826c0 100644
--- a/bob_party/src/screens/MatchMaking.tsx
+++ b/bob_party/src/screens/MatchMaking.tsx
@@ -10,6 +10,8 @@ import { BigBlueButton } from '../components/BigBlueButton';
import { useMatchStore } from '../context/matchContext';
import { FlatList, TextInput } from 'react-native-gesture-handler';
import { PlayerBox } from '../components/PlayerBox';
+import { MANAGER_MATCH } from '../../appManagers';
+import { User } from '../core/User/user';
function MatchMaking(props: { navigation: any; }) {
diff --git a/bob_party/src/screens/SignIn.tsx b/bob_party/src/screens/SignIn.tsx
index 01f4b7a..45ce430 100644
--- a/bob_party/src/screens/SignIn.tsx
+++ b/bob_party/src/screens/SignIn.tsx
@@ -63,8 +63,6 @@ function SignIn(props: { navigation: any; }) {
socket.on("messageReceived", async () =>{
await handleConversationLoad();
});
- const match=await MANAGER_MATCH.getLoaderMatch().loadByID(1);
- console.log(match);
navigation.navigate('HomeTab');
}
else{
diff --git a/bob_party/src/services/matchServices/ISaverMatch.ts b/bob_party/src/services/matchServices/ISaverMatch.ts
index 2786262..0d57b06 100644
--- a/bob_party/src/services/matchServices/ISaverMatch.ts
+++ b/bob_party/src/services/matchServices/ISaverMatch.ts
@@ -18,8 +18,15 @@ export default interface ISaverMatch{
deleteMatch(m:Match): Promise;
/**
- * updateMatch methode that update a Match in the data management system
- * m the Match we want to update
+ * deleteUserFromMatch methode that delete a User from a Match in the data management system
+ * u the User we want to delete
*/
- updateMatch(m:Match): Promise;
+ deleteUserFromMatch(u:User): Promise;
+
+ /**
+ * joinMatch methode that add a User to a Match in the data management system
+ * u the User we want to add
+ * id the id of the Match
+ */
+ joinMatch(u:User, id:number): Promise;
}
\ No newline at end of file
diff --git a/bob_party/src/services/matchServices/saverMatchApi.ts b/bob_party/src/services/matchServices/saverMatchApi.ts
index 2b12e60..7c314b1 100644
--- a/bob_party/src/services/matchServices/saverMatchApi.ts
+++ b/bob_party/src/services/matchServices/saverMatchApi.ts
@@ -8,25 +8,71 @@ import { GameMulti } from "../../core/gameMulti";
import MatchSolo from "../../core/Match/matchSolo";
import MatchMulti from "../../core/Match/matchMulti";
import MatchCasino from "../../core/Match/matchCasino";
+import { MANAGER_MATCH } from "../../../appManagers";
export default class SaverMatchApi implements ISaverMatch{
+ private axios = require('axios').default;
+
async saveMatch(u:User, g:Game): Promise {
- //match = mettre dans bdd
- if (g instanceof GameSolo){
- return new MatchSolo(12, false, [u], g);
- }
- else if(g instanceof GameMulti){
- return new MatchMulti(12, false, [u], g);
+ let id=0;
+ let url='http://localhost:8888/api-rest/index.php/postMatch/' + g.id + "/" + u.id;
+ await this.axios({
+ method: 'post',
+ url: url,
+ })
+ .then(async (response: any) => {
+ id=response.data.id;
+ });
+
+ if(g instanceof GameMulti){
+ return new MatchMulti(id, false, [u], g);
}
- return new MatchCasino(12, false, [u], g);
+ return new MatchCasino(id, false, [u], g);
}
async deleteMatch(m: Match): Promise {
- throw new Error("Method not implemented.");
+ let url='http://localhost:8888/api-rest/index.php/deleteMatch/' + m.getCode();
+ await this.axios({
+ method: 'delete',
+ url: url,
+ });
}
- async updateMatch(m: Match): Promise {
- throw new Error("Method not implemented.");
+
+ async deleteUserFromMatch(u: User): Promise {
+ let url='http://localhost:8888/api-rest/deleteUserFromMatch.php/' + u.id;
+ await this.axios({
+ method: 'put',
+ url: url,
+ });
}
+ async joinMatch(u:User, id:number): Promise{
+ let match:Match|null=null;
+ let url='http://localhost:8888/api-rest/index.php/addUserToMatch/' + id + "/" + u.id;
+
+ await MANAGER_MATCH.getLoaderMatch().loadByID(id).then(async (response)=>{
+ if (response!==undefined && response !== null){
+ if (response.getTabUsers().length