Fin conversation
continuous-integration/drone/push Build is passing Details

peristanceBDD
Thomas Chazot 2 years ago
parent 172aeab0b5
commit d677886aa4

@ -9,7 +9,7 @@ import { socket } from "../../../socketConfig";
import { MANAGER_MATCH, MANAGER_USER } from "../../../appManagers"; import { MANAGER_MATCH, MANAGER_USER } from "../../../appManagers";
export default function TicTacToeOnline(){ export default function TicTacToeOnline(props: { navigation: any }){
const [init, setInit]=useState(0); const [init, setInit]=useState(0);
@ -22,13 +22,9 @@ export default function TicTacToeOnline(){
]); ]);
const [turnUser, setTurnUser]=useState("x"); 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"); const [currentTurn,setCurrentTurn] = useState("x");
@ -85,18 +81,35 @@ export default function TicTacToeOnline(){
} }
const checkWinning = () =>{ const checkWinning = () =>{
const tmp=MANAGER_USER.getCurrentUser()
// Checks rows // Checks rows
for (let i=0; i<3; i++){ for (let i=0; i<3; i++){
const isRowXWinning = map[i].every((cell)=> cell==="x"); const isRowXWinning = map[i].every((cell)=> cell==="x");
const isRowOWinning = map[i] .every((cell)=>cell==="o"); const isRowOWinning = map[i] .every((cell)=>cell==="o");
if(isRowXWinning==true){ 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 !"); Alert.alert("X won !");
//navigation.goBack(); navigation.goBack();
return true; return true;
} }
else if(isRowOWinning==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 !"); Alert.alert("O won !");
//navigation.goBack(); navigation.goBack();
return true; return true;
} }
} }
@ -114,13 +127,29 @@ export default function TicTacToeOnline(){
} }
} }
if (isColumnXWinning == true){ 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 !"); Alert.alert("X won !");
//navigation.goBack(); navigation.goBack();
return true; return true;
} }
if(isColumnOWinning==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 !"); Alert.alert("O won !");
//navigation.goBack(); navigation.goBack();
return true; return true;
} }
@ -145,13 +174,29 @@ export default function TicTacToeOnline(){
} }
} }
if(isDiag1OWinning==true || isDiag2OWinning==true){ 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 !"); Alert.alert("O won !");
//navigation.goBack(); navigation.goBack();
return true; return true;
} }
if(isDiag1XWinning==true || isDiag2XWinning==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 !"); Alert.alert("X won !");
//navigation.goBack(); navigation.goBack();
return true; return true;
} }
}; };
@ -161,8 +206,12 @@ export default function TicTacToeOnline(){
const isRow1Full = map[1] .every((cell)=>cell!==""); const isRow1Full = map[1] .every((cell)=>cell!=="");
const isRow2Full = map[2] .every((cell)=>cell!==""); const isRow2Full = map[2] .every((cell)=>cell!=="");
if(isRow0Full==true && isRow1Full==true && isRow2Full==true){ if(isRow0Full==true && isRow1Full==true && isRow2Full==true){
const tmp=MANAGER_USER.getCurrentUser();
if (tmp!==null){
MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 1);
}
Alert.alert("Draw !"); Alert.alert("Draw !");
//navigation.goBack(); navigation.goBack();
return false; return false;
} }
}; };

@ -10,8 +10,9 @@ import { User } from "../core/User/user"
*/ */
import styles from './style/TopBar.style'; import styles from './style/TopBar.style';
import { useMatchStore } from "../context/matchContext" import { useMatchStore } from "../context/matchContext"
import { MANAGER_USER } from "../../appManagers" import { MANAGER_CONVERSATION, MANAGER_USER } from "../../appManagers"
import { useUserStore } from "../context/userContext" import { useUserStore } from "../context/userContext"
import { useConversationStore } from "../context/conversationContext"
/* /*
Images required Images required
@ -32,6 +33,7 @@ FC<{nav: any, state?: string}> =
{ {
const resetMatch = useMatchStore((state) => state.resetMatch); 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: /* The display of this component depends of the screen from where it has been called:
@ -64,8 +66,21 @@ FC<{nav: any, state?: string}> =
</Pressable> </Pressable>
</View> </View>
) )
default:
case 'conversation':
return (
<View style={styles.header}>
<Pressable onPress={() => { resetCurrentConv; MANAGER_CONVERSATION.setCurrentConv(null); nav.goBack()}}>
<Image source={cross} style={styles.icon}/>
</Pressable>
<Text style={styles.titre}>{useConversationStore().currentConv?.getName()}</Text>
<Pressable>
<Image source={msc} style={styles.icon}/>
</Pressable>
</View>
)
default:
return ( return (
<View style={styles.header}> <View style={styles.header}>
<Pressable onPress={() => nav.navigate('ProfileTab', {screen: 'Profile'})}> <Pressable onPress={() => nav.navigate('ProfileTab', {screen: 'Profile'})}>

@ -27,6 +27,7 @@ function Chat(props: { navigation: any; }) {
renderItem={({item}) => <ConversationPreviewComponent conv={item} navigation={navigation}/>} renderItem={({item}) => <ConversationPreviewComponent conv={item} navigation={navigation}/>}
/> />
</View> </View>
<BotBar <BotBar
nav={navigation} nav={navigation}
state='Chat' state='Chat'

@ -51,34 +51,40 @@ function ConversationScreen(props: { navigation: any; }) {
); );
}; };
return( return(
<KeyboardAvoidingView behavior={Platform.OS == "ios" ? "padding" : "height"} style={stylesScreen.container}> <View style={stylesScreen.container}>
<View style={stylesScreen.bodyStart}> <TopBar
<FlatList nav={navigation}
data={useConversationStore().currentConv?.getTabMessage().reverse()} state="conversation"
renderItem={renderMessage} />
keyExtractor={item => item.getMessageId().toString()} <KeyboardAvoidingView behavior={Platform.OS == "ios" ? "padding" : "height"} style={stylesScreen.container}>
style={{flexDirection:'column-reverse'}} <View style={stylesScreen.bodyStart}>
/> <FlatList
data={useConversationStore().currentConv?.getTabMessage()}
<TextInput renderItem={renderMessage}
style={{height: '7%', keyExtractor={item => item.getMessageId().toString()}
width: '90%', inverted
borderRadius: '15%', />
backgroundColor: 'white',
padding: 10, <TextInput
marginBottom: '7%', style={{height: '7%',
alignSelf: 'center', width: '90%',
marginTop: '3%', borderRadius: '15%',
}} backgroundColor: 'white',
placeholder='Votre message...' padding: 10,
returnKeyType="send" marginBottom: '7%',
onChangeText={onChangeText} alignSelf: 'center',
value={text} marginTop: '3%',
onSubmitEditing={(val) => {sendMessage(val)}} }}
blurOnSubmit placeholder='Votre message...'
/> returnKeyType="send"
</View> onChangeText={onChangeText}
</KeyboardAvoidingView> value={text}
onSubmitEditing={(val) => {sendMessage(val)}}
blurOnSubmit
/>
</View>
</KeyboardAvoidingView>
</View>
); );
} }

@ -21,7 +21,7 @@ export default class ManagerConversation{
return this.currentConv; return this.currentConv;
} }
setCurrentConv(c:Conversation){ setCurrentConv(c:Conversation | null){
this.currentConv=c; this.currentConv=c;
} }

Loading…
Cancel
Save