From e2fb286b00ccf799ad64fe3350cb57e160ca0262 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Wed, 4 Jan 2023 16:13:52 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20du=20probl=C3=A8me=20lors=20du=20l?= =?UTF-8?q?oad=20des=20jeux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api-rest/gateways/gameGateway.php | 6 ++-- .../src/Games/CookieClicker/cookieClicker.tsx | 1 + .../src/Games/Tic-Tac-Toe/tic_tac_toe.tsx | 35 +++++++++++++++---- bob_party/src/screens/Chat.tsx | 8 ++++- .../src/services/gameService/loaderGameApi.ts | 7 ++-- 5 files changed, 43 insertions(+), 14 deletions(-) diff --git a/api-rest/gateways/gameGateway.php b/api-rest/gateways/gameGateway.php index 13fb5e9..1647662 100644 --- a/api-rest/gateways/gameGateway.php +++ b/api-rest/gateways/gameGateway.php @@ -23,8 +23,9 @@ class GameGateway{ $mapQuery="SELECT * FROM T_J_GAME_MAP_GMP WHERE FK_GAME=:id ORDER BY GMP_KEY"; $this->connection->execQuery($gamesQuery,[]); $res = $this->connection->getRes(); + $i=0; foreach($res as $row){ - $tabkey=[]; + $tabKey=[]; $tabValue=[]; $arg=array(':id'=>array($row['PK_ID'], PDO::PARAM_INT)); $this->connection->execQuery($mapQuery,$arg); @@ -40,8 +41,7 @@ class GameGateway{ $row['GAM_NB_PLAYER_MIN'], $row['GAM_NB_PLAYER_MAX'], $tabKey, - $tabValue); - + $tabValue); } return $tabGames; } diff --git a/bob_party/src/Games/CookieClicker/cookieClicker.tsx b/bob_party/src/Games/CookieClicker/cookieClicker.tsx index 3c1f534..48bc2ad 100644 --- a/bob_party/src/Games/CookieClicker/cookieClicker.tsx +++ b/bob_party/src/Games/CookieClicker/cookieClicker.tsx @@ -91,6 +91,7 @@ function CookieClicker(props: { navigation: any }) { if (tmp !== null) { if (MANAGER_MATCH.getCurrentMatch()?.getTabUsers().includes(tmp)) { MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, points); + MANAGER_USER.setCurrentUser(tmp); setUser(tmp); } } diff --git a/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe.tsx b/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe.tsx index 29f34cc..912cfa2 100644 --- a/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe.tsx +++ b/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe.tsx @@ -5,9 +5,16 @@ import { useMatchStore } from "../../context/matchContext"; import { current } from "@reduxjs/toolkit"; import { ScreenIndicator } from "../../components/ScreenIndicator"; import { TopBar } from "../../components/TopBar"; +import { MANAGER_MATCH, MANAGER_USER } from "../../../appManagers"; +import { useUserStore } from "../../context/userContext"; export default function TicTacToe(props: { navigation: any}){ + + const setUser = useUserStore((state) => state.setUser); + + const resetMatch = useMatchStore((state) => state.resetMatch); + const [map,setMap]=useState([ ['','',''], ['','',''], @@ -46,12 +53,12 @@ export default function TicTacToe(props: { navigation: any}){ const isRowOWinning = map[i] .every((cell)=>cell==="o"); if(isRowXWinning==true){ Alert.alert("X won !"); - navigation.goBack(); + endGame(); return true; } else if(isRowOWinning==true){ Alert.alert("O won !"); - navigation.goBack(); + endGame(); return true; } } @@ -70,12 +77,12 @@ export default function TicTacToe(props: { navigation: any}){ } if (isColumnXWinning == true){ Alert.alert("X won !"); - navigation.goBack(); + endGame(); return true; } if(isColumnOWinning==true){ Alert.alert("O won !"); - navigation.goBack(); + endGame(); return true; } @@ -101,12 +108,12 @@ export default function TicTacToe(props: { navigation: any}){ } if(isDiag1OWinning==true || isDiag2OWinning==true){ Alert.alert("O won !"); - navigation.goBack(); + endGame(); return true; } if(isDiag1XWinning==true || isDiag2XWinning==true){ Alert.alert("X won !"); - navigation.goBack(); + endGame(); return true; } }; @@ -117,11 +124,25 @@ export default function TicTacToe(props: { navigation: any}){ const isRow2Full = map[2] .every((cell)=>cell!==""); if(isRow0Full==true && isRow1Full==true && isRow2Full==true){ Alert.alert("Draw !"); - navigation.goBack(); + endGame(); return false; } }; + + function endGame() { + const tmp = MANAGER_USER.getCurrentUser(); + if (tmp !== null) { + if (MANAGER_MATCH.getCurrentMatch()?.getTabUsers().includes(tmp)) { + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); + MANAGER_USER.setCurrentUser(tmp); + setUser(tmp); + } + } + navigation.goBack(); + resetMatch(); + } + return( diff --git a/bob_party/src/screens/Chat.tsx b/bob_party/src/screens/Chat.tsx index 8c8ccec..58e7c96 100644 --- a/bob_party/src/screens/Chat.tsx +++ b/bob_party/src/screens/Chat.tsx @@ -1,5 +1,5 @@ import { StatusBar } from 'expo-status-bar' -import {View} from 'react-native' +import {Pressable, View, Image} from 'react-native' import React, { useCallback } from 'react'; import stylesScreen from './style/screens.style'; import { TopBar } from '../components/TopBar'; @@ -11,9 +11,12 @@ import { io } from 'socket.io-client'; import { socket } from '../../socketConfig'; import { MANAGER_CONVERSATION, MANAGER_USER } from '../../appManagers'; import { Message } from '../core/message'; +import styles from '../components/style/TopBar.style'; + function Chat(props: { navigation: any; }) { const { navigation } = props + const cross = require('../../assets/Icons/UnSelected/Cross.png'); return ( @@ -27,6 +30,9 @@ function Chat(props: { navigation: any; }) { renderItem={({item}) => } /> + navigation.navigate('Settings')}> + +