From 52e5a1eb83ff6d43188324ab33d725c184c2e58b Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 6 Dec 2022 16:44:48 +0100 Subject: [PATCH] Cookie clicker qui marche --- .../src/Games/CookieClicker/cookieClicker.tsx | 24 +++++++++---------- bob_party/src/components/GameComponent.tsx | 8 ++++--- bob_party/src/core/gameSolo.ts | 6 ++--- bob_party/src/screens/GameChoice.tsx | 11 ++++----- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/bob_party/src/Games/CookieClicker/cookieClicker.tsx b/bob_party/src/Games/CookieClicker/cookieClicker.tsx index 5bb8fd5..c5243af 100644 --- a/bob_party/src/Games/CookieClicker/cookieClicker.tsx +++ b/bob_party/src/Games/CookieClicker/cookieClicker.tsx @@ -1,4 +1,4 @@ -import React, { Component, useEffect, useState } from 'react' +import React, { Component, useCallback, useEffect, useState } from 'react' import { StyleSheet, TouchableOpacity, @@ -9,25 +9,24 @@ import { TouchableHighlight, Alert, } from 'react-native' -import { MANAGER_USER } from '../../../App'; +import { MANAGER_MATCH, MANAGER_USER } from '../../../App'; import { useMatchStore } from '../../context/matchContext'; import { useUserStore } from '../../context/userContext'; import { Match } from '../../core/Match/match'; import { User } from '../../core/User/user'; +let points=0; + function CookieClicker(props: { navigation: any}){ const { navigation } = props - - - const GAMING_TIME=15; + const GAMING_TIME=30; const setUser = useUserStore((state) => state.setUser); const resetMatch = useMatchStore((state) => state.resetMatch); - const [count, setCount] = useState(0); const [money, setMoney] = useState(0); const [clickSpeed, setClickSpeed] = useState(1); @@ -43,6 +42,7 @@ function CookieClicker(props: { navigation: any}){ function onPressCookie(){ setMoney(money+clickSpeed); setCount(count+clickSpeed); + points=count+clickSpeed; } function onPressGrandma(){ @@ -89,13 +89,12 @@ function CookieClicker(props: { navigation: any}){ let tmp: User | null; tmp=MANAGER_USER.getCurrentUser(); if (tmp!=null){ - if (useMatchStore().match?.getTabUsers().includes(tmp)){ - useMatchStore().match?.updatePostMatch(tmp, count); + if (MANAGER_MATCH.getCurrentMatch()?.getTabUsers().includes(tmp)){ + MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, points); setUser(tmp); } - resetMatch(); - navigation.goBack(); } + resetMatch(); } useEffect(() => { @@ -106,8 +105,9 @@ function CookieClicker(props: { navigation: any}){ if (counter == 0) { clearInterval(oneSecInterval); - Alert.alert("fin du jeu"); endGame(); + Alert.alert("fin du jeu"); + navigation.navigate('Home'); } }, 1000); },[]); @@ -182,7 +182,7 @@ function CookieClicker(props: { navigation: any}){ const styles = StyleSheet.create({ container: { - top: 20, + top: 75, margin: 10, flex: 1, justifyContent: 'center', diff --git a/bob_party/src/components/GameComponent.tsx b/bob_party/src/components/GameComponent.tsx index 8b5579b..85286b9 100644 --- a/bob_party/src/components/GameComponent.tsx +++ b/bob_party/src/components/GameComponent.tsx @@ -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 React from "react" import { trace } from "console" @@ -26,7 +26,9 @@ FC<{game: Game, nav: any}> = 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(); let tmp=MANAGER_USER.getCurrentUser(); if (tmp!=null){ @@ -35,7 +37,7 @@ FC<{game: Game, nav: any}> = setMatch(match); nav.navigate("GameSolo"); } - } + }, []); return ( diff --git a/bob_party/src/core/gameSolo.ts b/bob_party/src/core/gameSolo.ts index 5ebcf59..b07a155 100644 --- a/bob_party/src/core/gameSolo.ts +++ b/bob_party/src/core/gameSolo.ts @@ -20,10 +20,8 @@ export class GameSolo extends Game{ let test; for (let key of this.ptsToCoins.keys()){ test = this.ptsToCoins.get(key); - if (test != undefined){ - coins=test; - } - if (points=points){ return coins; } } diff --git a/bob_party/src/screens/GameChoice.tsx b/bob_party/src/screens/GameChoice.tsx index 068c3c1..fdd2a70 100644 --- a/bob_party/src/screens/GameChoice.tsx +++ b/bob_party/src/screens/GameChoice.tsx @@ -12,12 +12,11 @@ import { Conversation } from '../core/conversation'; import { GameSolo } from '../core/gameSolo'; let tabConv:Conversation[]=[]; - -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([ - [100, 100], - [1000, 300], - [10000, 400] -])); +const map = new Map(); +map.set(0,0); +map.set(15,10); +map.set(20,15); +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; }) {