From d677886aa4100b82822579dcfdf4f3153aa4c108 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Wed, 4 Jan 2023 14:49:16 +0100 Subject: [PATCH] Fin conversation --- .../Games/Tic-Tac-Toe/tic_tac_toe_online.tsx | 77 +++++++++++++++---- bob_party/src/components/TopBar.tsx | 19 ++++- bob_party/src/screens/Chat.tsx | 1 + bob_party/src/screens/ConversationScreen.tsx | 62 ++++++++------- .../managerConversation.ts | 2 +- 5 files changed, 116 insertions(+), 45 deletions(-) diff --git a/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe_online.tsx b/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe_online.tsx index 81faefc..06d5996 100644 --- a/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe_online.tsx +++ b/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe_online.tsx @@ -9,7 +9,7 @@ import { socket } from "../../../socketConfig"; import { MANAGER_MATCH, MANAGER_USER } from "../../../appManagers"; -export default function TicTacToeOnline(){ +export default function TicTacToeOnline(props: { navigation: any }){ const [init, setInit]=useState(0); @@ -22,13 +22,9 @@ export default function TicTacToeOnline(){ ]); const [turnUser, setTurnUser]=useState("x"); - /* - if (MANAGER_MATCH.getCurrentMatch()?.getTabUsers()[0].isEqual(MANAGER_USER.getCurrentUser())){ - turn="o"; - } - */ - //const {navigation}=props; + + const {navigation}=props; const [currentTurn,setCurrentTurn] = useState("x"); @@ -85,18 +81,35 @@ export default function TicTacToeOnline(){ } const checkWinning = () =>{ + const tmp=MANAGER_USER.getCurrentUser() // Checks rows for (let i=0; i<3; i++){ const isRowXWinning = map[i].every((cell)=> cell==="x"); const isRowOWinning = map[i] .every((cell)=>cell==="o"); if(isRowXWinning==true){ + if (tmp!==null){ + if (turnUser==="x"){ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); + } + else{ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); + } + } Alert.alert("X won !"); - //navigation.goBack(); + navigation.goBack(); return true; } else if(isRowOWinning==true){ + if (tmp!==null){ + if (turnUser==="x"){ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); + } + else{ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); + } + } Alert.alert("O won !"); - //navigation.goBack(); + navigation.goBack(); return true; } } @@ -114,13 +127,29 @@ export default function TicTacToeOnline(){ } } if (isColumnXWinning == true){ + if (tmp!==null){ + if (turnUser==="x"){ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); + } + else{ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); + } + } Alert.alert("X won !"); - //navigation.goBack(); + navigation.goBack(); return true; } if(isColumnOWinning==true){ + if (tmp!==null){ + if (turnUser==="x"){ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); + } + else{ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); + } + } Alert.alert("O won !"); - //navigation.goBack(); + navigation.goBack(); return true; } @@ -145,13 +174,29 @@ export default function TicTacToeOnline(){ } } if(isDiag1OWinning==true || isDiag2OWinning==true){ + if (tmp!==null){ + if (turnUser==="x"){ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); + } + else{ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); + } + } Alert.alert("O won !"); - //navigation.goBack(); + navigation.goBack(); return true; } if(isDiag1XWinning==true || isDiag2XWinning==true){ + if (tmp!==null){ + if (turnUser==="x"){ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); + } + else{ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); + } + } Alert.alert("X won !"); - //navigation.goBack(); + navigation.goBack(); return true; } }; @@ -161,8 +206,12 @@ export default function TicTacToeOnline(){ const isRow1Full = map[1] .every((cell)=>cell!==""); const isRow2Full = map[2] .every((cell)=>cell!==""); if(isRow0Full==true && isRow1Full==true && isRow2Full==true){ + const tmp=MANAGER_USER.getCurrentUser(); + if (tmp!==null){ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 1); + } Alert.alert("Draw !"); - //navigation.goBack(); + navigation.goBack(); return false; } }; diff --git a/bob_party/src/components/TopBar.tsx b/bob_party/src/components/TopBar.tsx index 7a21262..48059b8 100644 --- a/bob_party/src/components/TopBar.tsx +++ b/bob_party/src/components/TopBar.tsx @@ -10,8 +10,9 @@ import { User } from "../core/User/user" */ import styles from './style/TopBar.style'; import { useMatchStore } from "../context/matchContext" -import { MANAGER_USER } from "../../appManagers" +import { MANAGER_CONVERSATION, MANAGER_USER } from "../../appManagers" import { useUserStore } from "../context/userContext" +import { useConversationStore } from "../context/conversationContext" /* Images required @@ -32,6 +33,7 @@ FC<{nav: any, state?: string}> = { const resetMatch = useMatchStore((state) => state.resetMatch); + const resetCurrentConv = useConversationStore((state) => state.resetCurrentConv); /* The display of this component depends of the screen from where it has been called: @@ -64,8 +66,21 @@ FC<{nav: any, state?: string}> = ) - default: + case 'conversation': + return ( + + { resetCurrentConv; MANAGER_CONVERSATION.setCurrentConv(null); nav.goBack()}}> + + + {useConversationStore().currentConv?.getName()} + + + + + ) + + default: return ( nav.navigate('ProfileTab', {screen: 'Profile'})}> diff --git a/bob_party/src/screens/Chat.tsx b/bob_party/src/screens/Chat.tsx index b7b2392..8c8ccec 100644 --- a/bob_party/src/screens/Chat.tsx +++ b/bob_party/src/screens/Chat.tsx @@ -27,6 +27,7 @@ function Chat(props: { navigation: any; }) { renderItem={({item}) => } /> + - - item.getMessageId().toString()} - style={{flexDirection:'column-reverse'}} - /> - - {sendMessage(val)}} - blurOnSubmit - /> - - + + + + + item.getMessageId().toString()} + inverted + /> + + {sendMessage(val)}} + blurOnSubmit + /> + + + ); } diff --git a/bob_party/src/services/conversationService/managerConversation.ts b/bob_party/src/services/conversationService/managerConversation.ts index c11602a..3dd6e49 100644 --- a/bob_party/src/services/conversationService/managerConversation.ts +++ b/bob_party/src/services/conversationService/managerConversation.ts @@ -21,7 +21,7 @@ export default class ManagerConversation{ return this.currentConv; } - setCurrentConv(c:Conversation){ + setCurrentConv(c:Conversation | null){ this.currentConv=c; }