Merge branch 'Persistance' of https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY into Persistance
continuous-integration/drone/push Build is failing Details

Persistance
Mathilde JEAN 2 years ago
commit 23811c669b

@ -1,4 +1,4 @@
import React, { Component, useEffect, useState } from 'react' import React, { Component, useCallback, useEffect, useState } from 'react'
import { import {
StyleSheet, StyleSheet,
TouchableOpacity, TouchableOpacity,
@ -9,25 +9,24 @@ import {
TouchableHighlight, TouchableHighlight,
Alert, Alert,
} from 'react-native' } from 'react-native'
import { MANAGER_USER } from '../../../App'; import { MANAGER_MATCH, MANAGER_USER } from '../../../App';
import { useMatchStore } from '../../context/matchContext'; import { useMatchStore } from '../../context/matchContext';
import { useUserStore } from '../../context/userContext'; import { useUserStore } from '../../context/userContext';
import { Match } from '../../core/Match/match'; import { Match } from '../../core/Match/match';
import { User } from '../../core/User/user'; import { User } from '../../core/User/user';
let points=0;
function CookieClicker(props: { navigation: any}){ function CookieClicker(props: { navigation: any}){
const { navigation } = props const { navigation } = props
const GAMING_TIME=30;
const GAMING_TIME=15;
const setUser = useUserStore((state) => state.setUser); const setUser = useUserStore((state) => state.setUser);
const resetMatch = useMatchStore((state) => state.resetMatch); const resetMatch = useMatchStore((state) => state.resetMatch);
const [count, setCount] = useState(0); const [count, setCount] = useState(0);
const [money, setMoney] = useState(0); const [money, setMoney] = useState(0);
const [clickSpeed, setClickSpeed] = useState(1); const [clickSpeed, setClickSpeed] = useState(1);
@ -43,6 +42,7 @@ function CookieClicker(props: { navigation: any}){
function onPressCookie(){ function onPressCookie(){
setMoney(money+clickSpeed); setMoney(money+clickSpeed);
setCount(count+clickSpeed); setCount(count+clickSpeed);
points=count+clickSpeed;
} }
function onPressGrandma(){ function onPressGrandma(){
@ -89,13 +89,12 @@ function CookieClicker(props: { navigation: any}){
let tmp: User | null; let tmp: User | null;
tmp=MANAGER_USER.getCurrentUser(); tmp=MANAGER_USER.getCurrentUser();
if (tmp!=null){ if (tmp!=null){
if (useMatchStore().match?.getTabUsers().includes(tmp)){ if (MANAGER_MATCH.getCurrentMatch()?.getTabUsers().includes(tmp)){
useMatchStore().match?.updatePostMatch(tmp, count); MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, points);
setUser(tmp); setUser(tmp);
} }
resetMatch();
navigation.goBack();
} }
resetMatch();
} }
useEffect(() => { useEffect(() => {
@ -106,8 +105,9 @@ function CookieClicker(props: { navigation: any}){
if (counter == 0) { if (counter == 0) {
clearInterval(oneSecInterval); clearInterval(oneSecInterval);
Alert.alert("fin du jeu");
endGame(); endGame();
Alert.alert("fin du jeu");
navigation.navigate('Home');
} }
}, 1000); }, 1000);
},[]); },[]);
@ -182,7 +182,7 @@ function CookieClicker(props: { navigation: any}){
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
top: 20, top: 75,
margin: 10, margin: 10,
flex: 1, flex: 1,
justifyContent: 'center', justifyContent: 'center',

@ -1,4 +1,4 @@
import { FC, ReactNode } from "react" import { FC, ReactNode, useCallback } from "react"
import { Pressable, Image, ImageStyle, Text, View, Alert, ImageSourcePropType, TextStyle } from "react-native" import { Pressable, Image, ImageStyle, Text, View, Alert, ImageSourcePropType, TextStyle } from "react-native"
import React from "react" import React from "react"
import { trace } from "console" import { trace } from "console"
@ -26,7 +26,9 @@ FC<{game: Game, nav: any}> =
const setMatch = useMatchStore((state) => state.setMatch); const setMatch = useMatchStore((state) => state.setMatch);
async function createNewMatchSolo(game : Game, nav: any) {
const createNewMatchSolo = useCallback(async (game : Game, nav: any) => {
const m=new MatchCreator(); const m=new MatchCreator();
let tmp=MANAGER_USER.getCurrentUser(); let tmp=MANAGER_USER.getCurrentUser();
if (tmp!=null){ if (tmp!=null){
@ -35,7 +37,7 @@ FC<{game: Game, nav: any}> =
setMatch(match); setMatch(match);
nav.navigate("GameSolo"); nav.navigate("GameSolo");
} }
} }, []);
return ( return (

@ -19,10 +19,8 @@ export class GameSolo extends Game{
let test; let test;
for (let key of this.ptsToCoins.keys()){ for (let key of this.ptsToCoins.keys()){
test = this.ptsToCoins.get(key); test = this.ptsToCoins.get(key);
if (test != undefined){ coins=key;
coins=test; if (test != undefined && test>=points){
}
if (points<key ){
return coins; return coins;
} }
} }

@ -12,12 +12,11 @@ import { Conversation } from '../core/conversation';
import { GameSolo } from '../core/gameSolo'; import { GameSolo } from '../core/gameSolo';
let tabConv:Conversation[]=[]; let tabConv:Conversation[]=[];
const map = new Map();
const cookieClicker= new GameSolo(1, "Cookie Clicker", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pong.png", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map([ map.set(0,0);
[100, 100], map.set(15,10);
[1000, 300], map.set(20,15);
[10000, 400] const cookieClicker= new GameSolo(1, "Cookie Clicker", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pong.png", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, map);
]));
function GameChoice(props: { navigation: any; }) { function GameChoice(props: { navigation: any; }) {

Loading…
Cancel
Save