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

@ -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}> =
</Pressable>
</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 (
<View style={styles.header}>
<Pressable onPress={() => nav.navigate('ProfileTab', {screen: 'Profile'})}>

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

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

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

Loading…
Cancel
Save