Ajout du cookie clicker, Alban relie au reste stp
continuous-integration/drone/push Build is failing Details

Persistance
Thomas Chazot 2 years ago
parent d779403b62
commit 570ade854a

@ -0,0 +1,216 @@
import React, { Component, useEffect, useState } from 'react'
import {
StyleSheet,
TouchableOpacity,
Text,
View,
Pressable,
Image,
TouchableHighlight,
Alert,
} from 'react-native'
import { MANAGER_USER } from '../../../App';
import { useUserStore } from '../../context/userContext';
import { Match } from '../../core/match';
import { User } from '../../core/User/user';
function CookieClicker(props: { navigation: any, match:Match}){
const GAMING_TIME=15;
const setUser = useUserStore((state) => state.setUser);
const nav = props.navigation;
const match=props.match;
const [count, setCount] = useState(0);
const [money, setMoney] = useState(0);
const [clickSpeed, setClickSpeed] = useState(1);
const [grandmaCost, setGrandmaCost] = useState(10);
const [farmCost, setFarmCost] = useState(250);
const [factoryCost, setFactoryCost] = useState(2000);
const [wizardCost, setWizardCost] = useState(25000);
const [portalCost, setPortalCost] = useState(200000);
const [timer, setTimer] = useState(GAMING_TIME);
function onPressCookie(){
setMoney(money+clickSpeed);
setCount(count+clickSpeed);
}
function onPressGrandma(){
if (money>=grandmaCost){
setMoney(money-grandmaCost);
setClickSpeed(clickSpeed+1);
setGrandmaCost(grandmaCost+10);
}
}
function onPressFarm(){
if (money>=farmCost){
setMoney(money-farmCost);
setClickSpeed(clickSpeed+25);
setFarmCost(farmCost+250);
}
}
function onPressFactory(){
if (money>=factoryCost){
setMoney(money-factoryCost);
setClickSpeed(clickSpeed+200);
setFactoryCost(factoryCost+2000);
}
}
function onPressWizard(){
if (money>=wizardCost){
setMoney(money-wizardCost);
setClickSpeed(clickSpeed+2500);
setWizardCost(wizardCost+25000);
}
}
function onPressPortal(){
if (money>=portalCost){
setMoney(money-portalCost);
setClickSpeed(clickSpeed+20000);
setPortalCost(portalCost+200000);
}
}
function endGame(){
let tmp: User | null;
tmp=MANAGER_USER.getCurrentUser();
if (tmp!=null){
if (match.getTabUsers().includes(tmp)){
match.updatePostMatch(tmp, count);
setUser(tmp);
nav.goBack();
}
}
}
useEffect(() => {
let counter=GAMING_TIME;
var oneSecInterval = setInterval(() => {
setTimer(timer => timer - 1);
counter --;
if (counter == 0) {
clearInterval(oneSecInterval);
Alert.alert("fin du jeu");
endGame();
}
}, 1000);
},[]);
return (
<View style={styles.container}>
<View >
<Text>
Timer: {timer}
</Text>
<TouchableHighlight onPress={onPressCookie} >
<Image style={styles.photo} source={{uri: 'https://cdn-icons-png.flaticon.com/512/614/614131.png'}}/>
</TouchableHighlight>
<Text>
Argent {money}
</Text>
<Text>
Points {count}
</Text>
</View>
<View style={styles.containerRight}>
<TouchableHighlight onPress={onPressGrandma}>
<Image style={styles.photo} source={{uri: 'https://www.pngall.com/wp-content/uploads/12/Grandma-Happy-PNG-Photo.png'}}/>
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {grandmaCost}
</Text>
</View>
<TouchableHighlight onPress={onPressFarm} style={styles.photo}>
<Image style={styles.photo} source={{uri: 'https://www.pngall.com/wp-content/uploads/8/Farming-PNG-Picture.png'}}/>
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {farmCost}
</Text>
</View>
<TouchableHighlight onPress={onPressFactory}>
<Image style={styles.photo} source={{uri: 'https://cdn.pixabay.com/photo/2018/04/16/09/12/factory-3323977_960_720.png'}}/>
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {factoryCost}
</Text>
</View>
<TouchableHighlight onPress={onPressWizard}>
<Image style={styles.photo} source={{uri: 'https://www.clasher.us/images/coc/units/Wizard_Tower7.png'}}/>
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {wizardCost}
</Text>
</View>
<TouchableHighlight onPress={onPressPortal}>
<Image style={styles.photo} source={{uri: 'https://i.pinimg.com/originals/98/29/21/9829215db6f9210c0ae4e318e854cb1f.png'}}/>
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {portalCost}
</Text>
</View>
</View>
</View>
)
}
const styles = StyleSheet.create({
container: {
top: 5,
margin: 10,
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
containerRight: {
flex: 1,
flexWrap: "wrap",
top: 100,
marginBottom: 20,
left: 100,
},
button: {
alignItems: 'center',
backgroundColor: '#DDDDDD',
padding: 10,
marginBottom: 10
},
button2: {
alignItems: 'center',
backgroundColor: '#FFDDFF',
padding: 10,
marginBottom: 10
},
photo: {
width: 50,
height: 50
},
cout: {
marginBottom: 20
}
})
export default CookieClicker;

@ -19,7 +19,7 @@ FC<{game: Game, nav: any}> =
{ {
return ( return (
<View> <View>
<Pressable onPress={() => Alert.alert("Lancement du jeu")}> <Pressable onPress={() => nav.navigate('')}>
<Image <Image
style={styles.image} style={styles.image}
source={game.getImageSource()} source={game.getImageSource()}

@ -16,7 +16,7 @@ let tabConv:Conversation[]=[];
const msc = require('../../assets/Icons/FondGris.png'); const msc = require('../../assets/Icons/FondGris.png');
//const UserActu=new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[0], tabSkinApp, tabConv); //const UserActu=new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[0], tabSkinApp, tabConv);
const jeuTest= new GameSolo("1", "SNAKE", require('../../assets/Icons/UnSelected/Gamepad.png'),"ouin", 1, 1, new Map<number,number>); const cookieClicker= new GameSolo("1", "Cookie Clicker", require('../../assets/Icons/UnSelected/Gamepad.png'), "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map<number,number>);
function GameChoice(props: { navigation: any; }) { function GameChoice(props: { navigation: any; }) {
const { navigation } = props const { navigation } = props
return ( return (
@ -26,7 +26,7 @@ function GameChoice(props: { navigation: any; }) {
/> />
<View style={styles.body}> <View style={styles.body}>
<GameComponent <GameComponent
game={jeuTest} game={cookieClicker}
nav={navigation} nav={navigation}
/> />
</View> </View>

Loading…
Cancel
Save