From 121abcae4e71d8579e2b8ec2eee122499a4d68de Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 6 Dec 2022 17:50:27 +0100 Subject: [PATCH] flat list de jeu faite --- bob_party/App.tsx | 5 ++- .../src/Games/CookieClicker/cookieClicker.tsx | 2 +- bob_party/src/components/BotBar.tsx | 2 +- bob_party/src/context/gameContext.tsx | 23 +++++++++++ bob_party/src/screens/GameChoice.tsx | 35 ++++++++--------- bob_party/src/screens/Home.tsx | 23 +++++++++-- .../src/services/gameService/ILoaderGame.ts | 17 +++++++++ .../src/services/gameService/loaderGameApi.ts | 38 +++++++++++++++++++ .../src/services/gameService/managerGame.ts | 30 +++++++++++++++ 9 files changed, 152 insertions(+), 23 deletions(-) create mode 100644 bob_party/src/context/gameContext.tsx create mode 100644 bob_party/src/services/gameService/ILoaderGame.ts create mode 100644 bob_party/src/services/gameService/loaderGameApi.ts create mode 100644 bob_party/src/services/gameService/managerGame.ts diff --git a/bob_party/App.tsx b/bob_party/App.tsx index 87920dc..816ab1b 100644 --- a/bob_party/App.tsx +++ b/bob_party/App.tsx @@ -12,13 +12,16 @@ import { FakeSaverConversation } from './src/services/conversationService/fakeSa import ManagerMatch from './src/services/matchServices/managerMatch' import LoaderMatchApi from './src/services/matchServices/loaderMatchApi' import SaverMatchApi from './src/services/matchServices/saverMatchApi' +import LoaderGameApi from './src/services/gameService/loaderGameApi' +import ManagerGame from './src/services/gameService/managerGame' export const MANAGER_USER = new ManagerUser(new LoaderUserApi, new FakeSaverUser); export const MANAGER_CONVERSATION = new ManagerConversation(new LoaderConversationApi, new FakeSaverConversation); export const MANAGER_MATCH = new ManagerMatch(new LoaderMatchApi, new SaverMatchApi); +export const MANAGER_GAME = new ManagerGame(new LoaderGameApi); + - export default function App() { return ( diff --git a/bob_party/src/Games/CookieClicker/cookieClicker.tsx b/bob_party/src/Games/CookieClicker/cookieClicker.tsx index c5243af..17a97fc 100644 --- a/bob_party/src/Games/CookieClicker/cookieClicker.tsx +++ b/bob_party/src/Games/CookieClicker/cookieClicker.tsx @@ -21,7 +21,7 @@ let points=0; function CookieClicker(props: { navigation: any}){ const { navigation } = props - const GAMING_TIME=30; + const GAMING_TIME=45; const setUser = useUserStore((state) => state.setUser); diff --git a/bob_party/src/components/BotBar.tsx b/bob_party/src/components/BotBar.tsx index c7c51ef..71e9f39 100644 --- a/bob_party/src/components/BotBar.tsx +++ b/bob_party/src/components/BotBar.tsx @@ -59,7 +59,7 @@ FC<{nav: any, state?: String}> = } }, []); - const handleConversationChange = useCallback(async () => { + const handleConversationChange = useCallback(async () => { let tmp=MANAGER_USER.getCurrentUser(); if (tmp!=undefined){ await MANAGER_CONVERSATION.getLoaderConversation().loadByUser(tmp).then((res) => { diff --git a/bob_party/src/context/gameContext.tsx b/bob_party/src/context/gameContext.tsx new file mode 100644 index 0000000..26cda4e --- /dev/null +++ b/bob_party/src/context/gameContext.tsx @@ -0,0 +1,23 @@ +import React from "react"; +import create from "zustand"; +import { MANAGER_USER } from "../../App"; +import tabSkinApp from "../constSkin"; +import { Game } from "../core/game"; +import { Skin } from "../core/Skin"; +import { User } from "../core/User/user"; + + +// Define store types +interface GameState { + tabGame: Game[] | undefined; + setTabGame: (tabGame: Game[]) => void; + resetTabGame: () => void; + } + +// Define store data and methods +export const useGameStore = create()((set, get) => ({ + tabGame: undefined, + setTabGame: (tabGame) => set((state) => ({ tabGame: tabGame })), + resetTabGame: () => set((state) => ({ tabGame: undefined })), +})); + diff --git a/bob_party/src/screens/GameChoice.tsx b/bob_party/src/screens/GameChoice.tsx index fdd2a70..f590f4e 100644 --- a/bob_party/src/screens/GameChoice.tsx +++ b/bob_party/src/screens/GameChoice.tsx @@ -1,5 +1,5 @@ import { StatusBar } from 'expo-status-bar' -import { StyleSheet, View, Text, Alert, Pressable, Image} from 'react-native' +import { StyleSheet, View, Text, Alert, Pressable, Image, FlatList} from 'react-native' import React from 'react'; import { Game } from '../core/game'; import { Skin } from '../core/skin'; @@ -10,33 +10,34 @@ import { User } from '../core/User/user'; import tabSkinApp from '../constSkin'; import { Conversation } from '../core/conversation'; import { GameSolo } from '../core/gameSolo'; +import { ScreenIndicator } from '../components/ScreenIndicator'; +import stylesScreen from './style/screens.style' +import { MANAGER_GAME } from '../../App'; +import { useGameStore } from '../context/gameContext'; let tabConv:Conversation[]=[]; -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; }) { - const { navigation } = props - +function GameChoice(props: { navigation: any}) { + const { navigation} = props + console.log(MANAGER_GAME.getTabGame()); return ( - + - - + + + item.getName()} + renderItem={({item}) => } /> ); diff --git a/bob_party/src/screens/Home.tsx b/bob_party/src/screens/Home.tsx index c88e7dd..d3447e1 100644 --- a/bob_party/src/screens/Home.tsx +++ b/bob_party/src/screens/Home.tsx @@ -1,11 +1,13 @@ import { StatusBar } from 'expo-status-bar' import { View} from 'react-native' -import React from 'react'; +import React, { useCallback } from 'react'; import stylesScreen from './style/screens.style' import { TopBar } from '../components/TopBar'; import { BotBar } from '../components/BotBar'; import { Conversation } from '../core/conversation'; import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice'; +import { MANAGER_GAME } from '../../App'; +import { useGameStore } from '../context/gameContext'; @@ -15,6 +17,21 @@ function Home(props: { navigation: any; }) { const { navigation } = props + const setTabGame = useGameStore((state) => state.setTabGame); + + const handleGame = useCallback(async () => { + let tmp=MANAGER_GAME.getTabGame(); + if (tmp==null){ + await MANAGER_GAME.getLoaderGame().loadAllGame().then((res) => { + MANAGER_GAME.setTabGame(res); + setTabGame(res); + navigation.navigate('GameChoiceTab') + }); + } + else{ + navigation.navigate('GameChoiceTab') + } + }, []); return ( @@ -25,11 +42,11 @@ function Home(props: { navigation: any; }) { navigation.navigate('GameChoiceTab')} + onPress={() => {handleGame()}} /> navigation.navigate('GameChoiceTab')} + onPress={() => handleGame()} /> ; + + /** + * loadByID methode that load a match from the data management system by its id + * id the id we want to search + * return a Game if found, if not null + */ + loadByID(id:string): Promise; +} \ No newline at end of file diff --git a/bob_party/src/services/gameService/loaderGameApi.ts b/bob_party/src/services/gameService/loaderGameApi.ts new file mode 100644 index 0000000..3112ff3 --- /dev/null +++ b/bob_party/src/services/gameService/loaderGameApi.ts @@ -0,0 +1,38 @@ +import { Game } from "../../core/game"; +import { GameSolo } from "../../core/gameSolo"; +import ILoaderGame from "./ILoaderGame"; + +export default class LoaderGameApi implements ILoaderGame{ + + private axios = require('axios').default; + + + async loadAllGame(): Promise { + let tab: Game[]=[]; + await this.axios({ + method: 'get', + url: 'https://jsonplaceholder.typicode.com/todos/1', + params: { + name: "getAllUser", + //Les params genre nom de la fonction en php + } + }) + .then(function (response: any) { + const map = new Map(); + map.set(0,0); + map.set(100,50); + map.set(300,150); + map.set(450,1000); + 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); + const test= new GameSolo(1, "Test", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pendu.jpg", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, map); + tab=[cookieClicker, test]; + console.log(tab); + }); + return tab; + + } + async loadByID(id: string): Promise { + throw new Error("Method not implemented."); + } + +} \ No newline at end of file diff --git a/bob_party/src/services/gameService/managerGame.ts b/bob_party/src/services/gameService/managerGame.ts new file mode 100644 index 0000000..16a6aac --- /dev/null +++ b/bob_party/src/services/gameService/managerGame.ts @@ -0,0 +1,30 @@ +import { Game } from "../../core/game"; +import ILoaderGame from "./ILoaderGame"; + +export default class ManagerGame{ + + private tabGame: Game[] | null=null; + + private loaderGame: ILoaderGame; + + constructor(loader:ILoaderGame){ + this.loaderGame=loader; + } + + getTabGame(){ + return this.tabGame; + } + + setTabGame(g:Game[] | null){ + this.tabGame=g; + } + + getLoaderGame(){ + return this.loaderGame; + } + + setLoaderGame(l:ILoaderGame){ + this.loaderGame=l; + } + +} \ No newline at end of file