ADD: bouton quitter partie BlackJack

Bouton déconnecter
peristanceBDD
Alban GUILHOT 2 years ago
parent 75a4a525bc
commit 5cb33fe713

@ -15,9 +15,11 @@ import {Overlay,ChipSelector, UserControls,FloatingText} from './source/componen
import boardBg from './source/assets/board.png';
import { MANAGER_USER } from '../../../appManagers';
import { UserCoinsModifier } from '../../core/User/userCoinsModifier';
import { useNavigation } from '@react-navigation/native';
import { useUserStore } from '../../context/userContext';
export default function BlackJack(){
export default function BlackJack(props){
const [totalBet, setTotalBet] = useState(0);
const [amount, setAmount] = useState(MANAGER_USER.getCurrentUser()?.getCurrentCoins());
@ -29,7 +31,7 @@ export default function BlackJack(){
const [gameStarted, setGameStarted] = useState(false);
const [startGame, setStartGame] = useState(false);
const navigation = useNavigation();
return(
<>
@ -44,7 +46,7 @@ export default function BlackJack(){
<UserControls
playerHand={playerHand}
dealerHand={dealerHand}
newGame={() => newGame()}
goBack={() => navigation.goBack()}
hit={() => hit()}
doubleGame={() => doubleGame()}
endgame={() => endgame()}
@ -93,6 +95,7 @@ export default function BlackJack(){
setAmount(money);
if (tmp!=null){
await modif.changeCurrentCoins(tmp, money);
useUserStore().setUser(MANAGER_USER.getCurrentUser());
}
}
@ -102,7 +105,7 @@ export default function BlackJack(){
let playerHand = [],
dealerHand = [];
for(let i = 0; i < 2; i++){
playerHand.push(cardsDeck[cardCount]);
cardCount++;

@ -32,7 +32,7 @@ class UserControls extends Component{
render(){
const {playerHand, dealerHand, newGame, hit, endgame, doubleGame, gameover, totalBet, moreMoney} = this.props;
const {playerHand, dealerHand, goBack, hit, endgame, doubleGame, gameover, totalBet, moreMoney} = this.props;
const {playerPoints, dealerPoints} = this.state;
return(
@ -64,8 +64,8 @@ class UserControls extends Component{
{totalBet == false && (<View style={styles.absoluteBtnRight}>
<ActionButton
direction={'left'}
text={"NEW CARDS"}
onPress={() => newGame()}
text={"QUITER PARTIE"}
onPress={() => goBack()}
/>
</View>)}

@ -22,7 +22,7 @@ let points = 0;
function CookieClicker(props: { navigation: any }) {
const { navigation } = props
const GAMING_TIME = 120;
const GAMING_TIME = 50;
const setUser = useUserStore((state) => state.setUser);

@ -1,5 +1,5 @@
import { StatusBar } from 'expo-status-bar'
import { View, Text } from 'react-native'
import { View, Text, Button, Pressable } from 'react-native'
import React, { useState } from 'react';
import stylesScreen from './style/screens.style';
import styles from './style/Settings.style';
@ -9,7 +9,11 @@ import { PickerGreySmall } from '../components/PickerGreySmall';
import { useUserStore } from '../context/userContext';
import DialogInput from 'react-native-dialog-input';
import UserModificationManager from '../core/User/userModificationManager';
import { MANAGER_USER } from '../../appManagers';
import { MANAGER_CONVERSATION, MANAGER_GAME, MANAGER_MATCH, MANAGER_SKIN, MANAGER_USER } from '../../appManagers';
import { useConversationStore } from '../context/conversationContext';
import { useGameStore } from '../context/gameContext';
import { useSkinStore } from '../context/storeContext';
import { useMatchStore } from '../context/matchContext';
function Settings(props: { navigation: any; }) {
const { navigation } = props
@ -24,7 +28,6 @@ function Settings(props: { navigation: any; }) {
const [selectedSex, setSelectedSex] = useState("");
const [selectedNationality, setSelectedNationality] = useState("");
async function changeUsername(username:string){
let userManager = new UserModificationManager();
let tmp=MANAGER_USER.getCurrentUser();
@ -65,6 +68,28 @@ function Settings(props: { navigation: any; }) {
}
}
const resetUser = useUserStore((state) => state.resetUser);
const resetTabConv = useConversationStore((state) => state.resetTabConv);
const resetCurrentConv = useConversationStore((state) => state.resetCurrentConv);
const resetTabGame = useGameStore((state) => state.resetTabGame);
const resetTabGameMulti = useGameStore((state) => state.resetTabGameMulti);
const resetTabGameSolo = useGameStore((state) => state.resetTabGameSolo);
const resetTabSkin = useSkinStore((state) => state.resetTabSkin);
const resetMatch = useMatchStore((state) => state.resetMatch);
const resetTabUser = useMatchStore((state) => state.resetTabUser);
function disconnect(){
resetTabConv();
resetCurrentConv();
resetTabGame();
resetTabGameMulti();
resetTabGameSolo();
resetTabSkin();
resetMatch();
resetTabUser();
}
return (
<View style={stylesScreen.container}>
@ -82,7 +107,7 @@ function Settings(props: { navigation: any; }) {
<ButtonGreySmall onPress={() => {setDialogPseudoVisible(true)}} title='Changer le pseudo'/>
</View>
<View>
<Text style={styles.text}>Mot de passe: {useUserStore().user?.getPassword()}</Text>
<Text style={styles.text}>Mot de passe: *****</Text>
<ButtonGreySmall onPress={() => setDialogPasswordVisible(true) } title='Changer le mot de passe'/>
</View>
<View>
@ -97,6 +122,13 @@ function Settings(props: { navigation: any; }) {
<Text style={styles.textID}>ID: {useUserStore().user?.getId()}</Text>
</View>
</View>
</View>
<View style={{alignSelf: "flex-end", padding: 50, alignItems: "center", width: "100%"}}>
<Pressable onPress={() => {disconnect(); navigation.navigate("SignIn");}} style={styles.button}>
<Text style={styles.buttonText}>Se déconnecter</Text>
</Pressable>
</View>
<DialogInput
@ -120,4 +152,6 @@ function Settings(props: { navigation: any; }) {
);
}
export default Settings
export default Settings
//{useUserStore().user?.getPassword()}

@ -39,12 +39,9 @@ function SignIn(props: { navigation: any; }) {
const errorList = useSelector((state: RootState) => state.credentialErrors.loginErrorList);
const [pseudo, setPseudo] = useState('');
const [password, setPassword] = useState('');
const dispatch=useDispatch();
if (errorList.incorrectCredentials){
Alert.alert("Pseudo ou Mot de passe incorrect");
dispatch(updateIncorrectCredentials(true));
}
console.log(MANAGER_USER.getCurrentUser());
async function handleUserConnect(username: string, password: string){
@ -64,10 +61,15 @@ function SignIn(props: { navigation: any; }) {
socket.on("messageReceived", async () =>{
await handleConversationLoad();
});
setPseudo("");
setPassword("");
navigation.navigate('HomeTab');
}
else{
Alert.alert("Incorrect Username or Password");
setPseudo("");
setPassword("");
console.log(pseudo, password);
setWaitConnect(0);
}
@ -140,8 +142,13 @@ function SignIn(props: { navigation: any; }) {
return (
<View style={stylesScreen.container}>
<View style={stylesScreen.bodyCenter}>
<TextInput style={styles.textInput} placeholder='Login' onChangeText={(val) => setPseudo(val)} autoCapitalize='none' />
<TextInput style={styles.textInput} placeholder='Password' onChangeText={(val) => setPassword(val)} autoCapitalize='none' secureTextEntry={true}/>
<TextInput style={styles.textInput} placeholder='Login'
value={pseudo}
onChangeText={(val) => setPseudo(val)} autoCapitalize='none' />
<TextInput style={styles.textInput} placeholder='Password'
value={password}
onChangeText={(val) => setPassword(val)} autoCapitalize='none'
secureTextEntry={true}/>
<Pressable style={styles.button} onPress={() => handleUserConnect(pseudo, password)}>
<Text style={styles.text}>Se connecter</Text>
</Pressable>

@ -179,6 +179,7 @@ function SignUp(props: { navigation: any; }) {
const tmp:User|null = await MANAGER_USER.getLoaderUser().loadByUsername(pseudo);
if (tmp!=null){
Alert.alert("Ce pseudo existe déjà");
return;
}
await MANAGER_USER.getsaverUser().saveUser(pseudo, password, selectedNationality, selectedSex, date).then(async (res)=>{
MANAGER_USER.setCurrentUser(res);

@ -7,12 +7,14 @@ export default StyleSheet.create({
letterSpacing: 0.25,
color: 'white',
textAlign: 'right',
paddingVertical: 5,
},
text: {
fontSize: 16,
lineHeight: 21,
letterSpacing: 0.25,
color: 'white',
paddingVertical: 5,
},
title: {
fontSize: 20,
@ -29,4 +31,18 @@ export default StyleSheet.create({
margin: 15,
padding: 15,
},
button: {
alignItems: 'center',
justifyContent: 'center',
padding: 30,
borderRadius: 10,
backgroundColor: '#888898',
},
buttonText: {
fontSize: 20,
lineHeight: 21,
fontWeight: 'bold',
letterSpacing: 0.25,
color: 'white',
},
});
Loading…
Cancel
Save