Add: Black jack + online tic tac toe
continuous-integration/drone/push Build is passing Details

peristanceBDD
Thomas Chazot 2 years ago
parent 0f97baac5d
commit 0057d8ecca

@ -3,7 +3,8 @@ import store from './src/redux/store'
import { Provider } from 'react-redux'
import React, { useCallback } from 'react';
import { useFonts } from 'expo-font';
import TicTacToeOnline from './src/Games/Tic-Tac-Toe/tic_tac_toe_online';
import BlackJack from './src/Games/BlackJack/blackJack';
export default function App() {
@ -19,6 +20,7 @@ export default function App() {
return (
<Provider store={store} >
<MainTabNavigator />
</Provider>

@ -16,10 +16,17 @@ io.on('connection', (socket) => {
});
socket.on("messageSent", (conv) =>{
console.log("C"+conv.id);
socket.to("C"+conv.id).emit("messageReceived");
console.log("Message envoyé");
});
socket.on('inMatch', (match) => {
socket.join("M" + match);
});
socket.on("playTicTacToe", (match, rowIndex, columnIndex, turn) =>{
socket.to("M"+match).emit("oppPlayTicTacToe", rowIndex, columnIndex, turn);
});
});
server.listen(3000, () => {

@ -0,0 +1,243 @@
import React,{Component, useState} from 'react';
import {
View,
StyleSheet,
ImageBackground,
UIManager,
StatusBar,
NativeModules,
AppState,
Platform
} from 'react-native';
import cardsDeck from './source/data/cards';
import {shuffle} from './source/helpers';
import {Overlay,ChipSelector, UserControls,FloatingText} from './source/components';
import boardBg from './source/assets/board.png';
import { MANAGER_USER } from '../../../appManagers';
import { UserCoinsModifier } from '../../core/User/userCoinsModifier';
export default function BlackJack(){
const [totalBet, setTotalBet] = useState(0);
const [amount, setAmount] = useState(MANAGER_USER.getCurrentUser()?.getCurrentCoins());
const [playerHand, setPlayerHand] = useState([]);
const [dealerHand, setDealerHand] = useState([]);
const [gameover, setGameover] = useState(false);
const [cardCount, setCardCount] = useState(0);
const [gameMessage, setGameMessage] = useState("");
const [gameStarted, setGameStarted] = useState(false);
const [startGame, setStartGame] = useState(false);
return(
<>
<ImageBackground
source={boardBg}
style={styles.container}>
<StatusBar backgroundColor={"green"} translucent={true} />
<View style={styles.bottom}>
<UserControls
playerHand={playerHand}
dealerHand={dealerHand}
newGame={() => newGame()}
hit={() => hit()}
doubleGame={() => doubleGame()}
endgame={() => endgame()}
gameover={gameover}
totalBet={totalBet}
/>
<View style={styles.center}>
<FloatingText
text={`Total Bet $ ${totalBet}`}
/>
</View>
<ChipSelector
onSelect={(chipValue) => {
if(!gameover && startGame){
if(chipValue <= amount && !gameStarted){
setTotalBet(totalBet+chipValue);
setAmount(amount-chipValue);
}
}
else{
if (amount > 0 && amount>=chipValue){
newGame();
setTotalBet(totalBet+chipValue);
setAmount(amount-chipValue);
}
}
}}
/>
<View style={styles.center}>
<FloatingText
text={`Available $ ${amount}`}
/>
</View>
{gameover && gameMessage != "" && <Overlay text={gameMessage} onClose={() => { newGame() }} />}
</View>
</ImageBackground>
</>
)
async function modifAmount(money){
const modif = new UserCoinsModifier();
const tmp=MANAGER_USER.getCurrentUser();
setAmount(money);
if (tmp!=null){
await modif.changeCurrentCoins(tmp, money);
}
}
function newGame(){
let cardCount = 0;
shuffle(cardsDeck);
let playerHand = [],
dealerHand = [];
for(let i = 0; i < 2; i++){
playerHand.push(cardsDeck[cardCount]);
cardCount++;
dealerHand.push(cardsDeck[cardCount]);
cardCount++;
}
setPlayerHand(playerHand);
setDealerHand(dealerHand);
setGameover(false);
setCardCount(cardCount);
setGameMessage("");
setStartGame(true);
}
function hit(){
const hand=playerHand;
hand.push(cardsDeck[cardCount]);
let userPoints = checkTotalPlayerPoints(hand);
setGameStarted(true);
setPlayerHand(hand);
setCardCount(cardCount+1)
if(userPoints > 21){
endgame();
return;
}
}
function doubleGame(){
hit();
endgame();
}
async function endgame(){
let _cardCount = cardCount;
let dealerPoints = checkTotalPlayerPoints(dealerHand),
playerPoints = checkTotalPlayerPoints(playerHand);
//alert(dealerPoints)
while(dealerPoints < 17){
dealerHand.push(cardsDeck[_cardCount]);
_cardCount++;
dealerPoints = checkTotalPlayerPoints(dealerHand);
}
let betValue = totalBet * 1.5;
setGameStarted(false);
//who won
if(playerPoints == 21 && playerHand.length == 2){
//multiplicar su apuesta x 1.5
let newAmount = totalBet * 1.5;
await modifAmount(newAmount);
setTotalBet(0);
setGameover(true);
setGameMessage("Player BlackJack!");
}
if(
(playerPoints < 22 && dealerPoints < playerPoints) ||
(dealerPoints > 21 && playerPoints < 22)
){
await modifAmount(amount+betValue);
setTotalBet(0);
setGameover(true);
setGameMessage("You Win $ "+ betValue);
}else if(dealerPoints > 21 && playerPoints < 22){
await modifAmount(amount+betValue);
setTotalBet(0);
setGameover(true);
setGameMessage("You Win $ "+ betValue);
}
else if(playerPoints > 21 && dealerPoints <= 21){
await modifAmount(amount);
setCardCount(_cardCount);
setTotalBet(0);
setGameover(true);
setGameMessage("Bust!");
}else if(playerPoints == dealerPoints){
await modifAmount(amount+totalBet);
setTotalBet(0);
setGameover(true);
setGameMessage("Push!");
}else{
await modifAmount(amount+totalBet);
setTotalBet(0);
setGameover(true);
setGameMessage("Dealer Wins, You Lost");
}
}
function checkTotalPlayerPoints(playerHand){
let aceAdjuts = false,
points = 0;
playerHand.map((card,_index) => {
if(card.name == 'A' && !aceAdjuts) {
aceAdjuts = true;
points = points + 10;
}
points = points + card.value;
});
if(aceAdjuts && points > 21){
points = points - 10;
}
return points;
}
}
const styles = StyleSheet.create({
container : {
flex : 1
},
center : {
alignItems : "center"
},
bottom : {
position : "absolute",
left : 0,
right : 0,
bottom : 0,
zIndex : 2
}
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

@ -0,0 +1,52 @@
import React from 'react';
import {
StyleSheet,
View,
TouchableOpacity,
Text
} from 'react-native';
const ActionButton = props => {
return(
<TouchableOpacity
onPress={() => {
if(props.onPress) props.onPress()
}}
>
<View style={[
props.direction == 'right' ? styles.rightDirection :
props.direction == 'left' ? styles.leftDirection : {},
styles.wrap,
props.style
]}>
<Text style={styles.text}>{props.text.replace(" ",'\n')}</Text>
</View>
</TouchableOpacity>
)
}
const styles = StyleSheet.create({
wrap : {
padding : 6,
backgroundColor : "rgba(255,255,255,0.7)",
borderColor : "rgba(255,255,255,0.9)",
borderWidth : 2,
marginBottom : 12
},
rightDirection : {
borderTopRightRadius : 6,
borderBottomRightRadius : 6
},
leftDirection : {
borderTopLeftRadius : 6,
borderBottomLeftRadius : 6
},
text : {
color : "white",
fontWeight : "bold",
fontSize : 14,
textAlign : "center"
}
});
export default ActionButton;

@ -0,0 +1,65 @@
import React,{Component} from 'react';
import {
View,
Text,
Image,
StyleSheet,
Dimensions
} from 'react-native';
import backCard from '../assets/cards/back.png';
const {width} = Dimensions.get("window");
const CARD_WIDTH = (width / 3) - 50;
const CARD_HEIGHT = (width / 3) + 5;
const CARD_SEPARATION = 50;
class CardDeck extends Component{
render(){
const {cards, isDealer, gameover} = this.props
return(
<View style={styles.container}>
<View
style={[
{marginLeft : -(cards.length * CARD_SEPARATION) / 1.8}
,styles.row]}>
{cards && cards.length > 0 && cards.map((card,i) => {
return (
<View
key={i}
style={[
i > 0 ? {
position : "absolute",
left : (i * CARD_SEPARATION),
} : {},
{
//elevation : 2,
borderWidth : 1,
borderColor : "black",
borderRadius : 6
}]}
><Image
source={ (isDealer && i == 0 && !gameover) ? backCard : cards[i].image}
style={{
width : CARD_WIDTH,
height : CARD_HEIGHT,
//position : "absolute",
//left : cards.length == 2 ? -(i * CARD_SEPARATION) : (i * -20)
}}
resizeMode={"stretch"}
/></View>)
})}
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container : {
justifyContent : "center"
},
row : {
}
});
export default CardDeck;

@ -0,0 +1,79 @@
import React,{Component} from 'react';
import {
View,
ScrollView,
StyleSheet,
Image,
Text,
TouchableOpacity,
Dimensions
} from 'react-native';
import chips from '../data/chips';
const {width} = Dimensions.get('window');
const PADDING_WRAP = 8;
const MARGIN_SIDE = 20;
const CHIPS_SHOWN = 7;
const CHIP_WIDTH = (width / CHIPS_SHOWN) - ((MARGIN_SIDE / 2) * 2);
class ChipSelector extends Component{
render(){
const {onSelect} = this.props;
return(
<View style={styles.chipsWrapper}>
<ScrollView
horizontal={true}
contentContainerStyle={styles.scrollableContent}
showsHorizontalScrollIndicator={false}
>
{chips && chips.length > 0 && chips.map((chip,_index) => (
<TouchableOpacity
key={_index}
onPress={() => onSelect(chip.value)}
>
<View style={
_index < (chips.length-1) ? styles.chipWrap : {}
}>
<Image
source={chip.image}
resizeMode={'cover'}
style={styles.chip}
/>
</View>
</TouchableOpacity>
))}
</ScrollView>
</View>
)
}
}
const styles = StyleSheet.create({
chipsWrapper : {
backgroundColor : "#8A5D3C",
borderColor : "#AF7B56",
borderTopWidth : 2,
borderBottomWidth : 2,
/*elevation : 5,
position : "absolute",
bottom : 0,
left : 0,
right : 0,
zIndex : 3*/
},
scrollableContent:{
padding : PADDING_WRAP
},
chipWrap: {
marginRight : MARGIN_SIDE
},
chip : {
width : CHIP_WIDTH,
height: CHIP_WIDTH
}
})
export default ChipSelector;

@ -0,0 +1,32 @@
import React from 'react';
import {
View,
Text,
StyleSheet
} from 'react-native';
const FloatingText = props => {
return(
<View style={styles.indicator}>
<Text style={styles.indicatorTxt}>{props.text}</Text>
</View>
)
}
const styles = StyleSheet.create({
indicator : {
backgroundColor : "rgba(0,0,0,0.6)",
borderColor : "rgba(0,0,0,0.9)",
padding : 8,
alignItems : "center",
marginTop : 8,
marginBottom : 8,
borderRadius : 4
},
indicatorTxt : {
color : "white",
fontSize : 12
}
});
export default FloatingText;

@ -0,0 +1,62 @@
import React from 'react';
import {
View,
Text,
StyleSheet,
TouchableOpacity,
Dimensions
} from 'react-native';
const {width,height} = Dimensions.get("window");
const Overlay = props =>{
return(
<View style={styles.overlay}>
<Text style={styles.text}>{props.text}</Text>
<TouchableOpacity onPress={() => props.onClose()}>
<View style={styles.btn}>
<Text style={styles.continueBtn}>CONTINUE</Text>
</View>
</TouchableOpacity>
</View>
)
}
const styles = StyleSheet.create({
overlay : {
backgroundColor : "rgba(0,0,0,0.8)",
position : "absolute",
top : (height / 2) - 60,
left : 0,
right : 0,
zIndex : 5,
alignItems : "center",
justifyContent : "center",
padding : 12
},
text : {
color : "#fff",
fontSize : 40,
textAlign : "center"
},
center : {
alignItems : "center",
justifyContent : "center"
},
btn : {
marginTop : 10,
borderWidth : 1,
borderColor : "#fff",
padding : 8
},
continueBtn : {
color : "#fff",
fontSize : 14,
textAlign : "center"
}
});
export default Overlay;

@ -0,0 +1,132 @@
import React,{Component} from 'react';
import {
View,
Text,
TouchableOpacity,
StyleSheet,
Dimensions
} from 'react-native';
import {calculatePoints} from '../helpers';
import {ActionButton, FloatingText, CardDeck} from '../components';
const {width} = Dimensions.get('window');
const CIRCLE_BET_SIZE = (width / 4) - 20;
class UserControls extends Component{
constructor(){
super();
this.state = {
playerPoints : 0
}
}
UNSAFE_componentWillReceiveProps(nextProps){
if(nextProps.playerHand){
this.setState({
playerPoints : calculatePoints(nextProps.playerHand),
dealerPoints : calculatePoints(nextProps.dealerHand)
});
}
}
render(){
const {playerHand, dealerHand, newGame, hit, endgame, doubleGame, gameover, totalBet, moreMoney} = this.props;
const {playerPoints, dealerPoints} = this.state;
return(
<View style={styles.centerView}>
{/*<View>
<ActionButton
direction={'right'}
text={"DOUBLE WIN"}
/>
</View>*/}
<View style={styles.center}>
{gameover && <FloatingText text={dealerPoints} />}
<CardDeck
cards={dealerHand}
isDealer={true}
gameover={gameover}
/>
</View>
<View style={styles.center}>
<FloatingText text={playerPoints} />
<CardDeck
cards={playerHand}
/>
</View>
{totalBet == false && (<View style={styles.absoluteBtnRight}>
<ActionButton
direction={'left'}
text={"NEW CARDS"}
onPress={() => newGame()}
/>
</View>)}
{!!totalBet && (<View style={[styles.absoluteBtnRight,{top:60}]}>
<ActionButton
direction={'left'}
text={"HIT"}
onPress={() => hit()}
/>
</View>)}
{!!totalBet && (<View style={[styles.absoluteBtnRight,{top:105}]}>
<ActionButton
direction={'left'}
text={"DOUBLE"}
onPress={() => doubleGame()}
/>
</View>)}
{!!totalBet && (<View style={[styles.absoluteBtnRight,{top:150}]}>
<ActionButton
direction={'left'}
text={"DEAL"}
onPress={() => endgame()}
/>
</View>)}
</View>
)
}
}
const styles = StyleSheet.create({
centerView : {
//flexDirection : "row",
alignItems : "center",
justifyContent : "space-around",
paddingTop : 10,
paddingBottom : 10
},
/*betCircle : {
width : CIRCLE_BET_SIZE,
height : CIRCLE_BET_SIZE,
borderRadius : (CIRCLE_BET_SIZE / 2),
borderColor : 'white',
borderWidth : 1,
padding : 2
},*/
betText : {
color : "white",
textAlign : "center"
},
center : {
alignItems : "center",
justifyContent : "center"
},
absoluteBtnRight : {
position : "absolute",
right : 0,
zIndex : 2
}
});
export default UserControls;

@ -0,0 +1,15 @@
import ChipSelector from './ChipSelector';
import UserControls from './UserControls';
import ActionButton from './ActionButton';
import FloatingText from './FloatingText';
import CardDeck from './CardDeck';
import Overlay from './Overlay';
export {
ChipSelector,
UserControls,
ActionButton,
FloatingText,
CardDeck,
Overlay
}

@ -0,0 +1,314 @@
export default [
{
name : 'A',
deck : 'spades',
value : 1,
image : require('../assets/cards/spades/A.png')
},
{
name : 'J',
deck : 'spades',
value : 10,
image : require('../assets/cards/spades/J.png')
},
{
name : 'Q',
deck : 'spades',
value : 10,
image : require('../assets/cards/spades/Q.png')
},
{
name : 'K',
deck : 'spades',
value : 10,
image : require('../assets/cards/spades/K.png')
},
{
name : '2',
deck : 'spades',
value : 2,
image : require('../assets/cards/spades/2.png')
},
{
name : '3',
deck : 'spades',
value : 3,
image : require('../assets/cards/spades/3.png')
},
{
name : '4',
deck : 'spades',
value : 4,
image : require('../assets/cards/spades/4.png')
},
{
name : '5',
deck : 'spades',
value : 5,
image : require('../assets/cards/spades/5.png')
},
{
name : '6',
deck : 'spades',
value : 6,
image : require('../assets/cards/spades/6.png')
},
{
name : '7',
deck : 'spades',
value : 7,
image : require('../assets/cards/spades/7.png')
},
{
name : '8',
deck : 'spades',
value : 8,
image : require('../assets/cards/spades/8.png')
},
{
name : '9',
deck : 'spades',
value : 9,
image : require('../assets/cards/spades/9.png')
},
{
name : '10',
deck : 'spades',
value : 10,
image : require('../assets/cards/spades/10.png')
},
{
name : 'A',
deck : 'hearts',
value : 1,
image : require('../assets/cards/hearts/A.png')
},
{
name : 'J',
deck : 'hearts',
value : 10,
image : require('../assets/cards/hearts/J.png')
},
{
name : 'Q',
deck : 'hearts',
value : 10,
image : require('../assets/cards/hearts/Q.png')
},
{
name : 'K',
deck : 'hearts',
value : 10,
image : require('../assets/cards/hearts/K.png')
},
{
name : '2',
deck : 'hearts',
value : 2,
image : require('../assets/cards/hearts/2.png')
},
{
name : '3',
deck : 'hearts',
value : 3,
image : require('../assets/cards/hearts/3.png')
},
{
name : '4',
deck : 'hearts',
value : 4,
image : require('../assets/cards/hearts/4.png')
},
{
name : '5',
deck : 'hearts',
value : 5,
image : require('../assets/cards/hearts/5.png')
},
{
name : '6',
deck : 'hearts',
value : 6,
image : require('../assets/cards/hearts/6.png')
},
{
name : '7',
deck : 'hearts',
value : 7,
image : require('../assets/cards/hearts/7.png')
},
{
name : '8',
deck : 'hearts',
value : 8,
image : require('../assets/cards/hearts/8.png')
},
{
name : '9',
deck : 'hearts',
value : 9,
image : require('../assets/cards/hearts/9.png')
},
{
name : '10',
deck : 'hearts',
value : 10,
image : require('../assets/cards/hearts/10.png')
},
{
name : 'A',
deck : 'clubs',
value : 1,
image : require('../assets/cards/clubs/A.png')
},
{
name : 'J',
deck : 'clubs',
value : 10,
image : require('../assets/cards/clubs/J.png')
},
{
name : 'Q',
deck : 'clubs',
value : 10,
image : require('../assets/cards/clubs/Q.png')
},
{
name : 'K',
deck : 'clubs',
value : 10,
image : require('../assets/cards/clubs/K.png')
},
{
name : '2',
deck : 'clubs',
value : 2,
image : require('../assets/cards/clubs/2.png')
},
{
name : '3',
deck : 'clubs',
value : 3,
image : require('../assets/cards/clubs/3.png')
},
{
name : '4',
deck : 'clubs',
value : 4,
image : require('../assets/cards/clubs/4.png')
},
{
name : '5',
deck : 'clubs',
value : 5,
image : require('../assets/cards/clubs/5.png')
},
{
name : '6',
deck : 'clubs',
value : 6,
image : require('../assets/cards/clubs/6.png')
},
{
name : '7',
deck : 'clubs',
value : 7,
image : require('../assets/cards/clubs/7.png')
},
{
name : '8',
deck : 'clubs',
value : 8,
image : require('../assets/cards/clubs/8.png')
},
{
name : '9',
deck : 'clubs',
value : 9,
image : require('../assets/cards/clubs/9.png')
},
{
name : '10',
deck : 'clubs',
value : 10,
image : require('../assets/cards/clubs/10.png')
},
{
name : 'A',
deck : 'diamonds',
value : 1,
image : require('../assets/cards/diamonds/A.png')
},
{
name : 'J',
deck : 'diamonds',
value : 10,
image : require('../assets/cards/diamonds/J.png')
},
{
name : 'Q',
deck : 'diamonds',
value : 10,
image : require('../assets/cards/diamonds/Q.png')
},
{
name : 'K',
deck : 'diamonds',
value : 10,
image : require('../assets/cards/diamonds/K.png')
},
{
name : '2',
deck : 'diamonds',
value : 2,
image : require('../assets/cards/diamonds/2.png')
},
{
name : '3',
deck : 'diamonds',
value : 3,
image : require('../assets/cards/diamonds/3.png')
},
{
name : '4',
deck : 'diamonds',
value : 4,
image : require('../assets/cards/diamonds/4.png')
},
{
name : '5',
deck : 'diamonds',
value : 5,
image : require('../assets/cards/diamonds/5.png')
},
{
name : '6',
deck : 'diamonds',
value : 6,
image : require('../assets/cards/diamonds/6.png')
},
{
name : '7',
deck : 'diamonds',
value : 7,
image : require('../assets/cards/diamonds/7.png')
},
{
name : '8',
deck : 'diamonds',
value : 8,
image : require('../assets/cards/diamonds/8.png')
},
{
name : '9',
deck : 'diamonds',
value : 9,
image : require('../assets/cards/diamonds/9.png')
},
{
name : '10',
deck : 'diamonds',
value : 10,
image : require('../assets/cards/diamonds/10.png')
}
];

@ -0,0 +1,42 @@
export default [
{
image : require("../assets/chips/1.png"),
value : 1
},
{
image : require("../assets/chips/5.png"),
value : 5
},
{
image : require("../assets/chips/25.png"),
value : 25
},
{
image : require("../assets/chips/100.png"),
value : 100
},
{
image : require("../assets/chips/500.png"),
value : 500
},
{
image : require("../assets/chips/1k.png"),
value : 1000
},
{
image : require("../assets/chips/2k.png"),
value : 2000
},
{
image : require("../assets/chips/5k.png"),
value : 5000
},
{
image : require("../assets/chips/10k.png"),
value : 10000
},
{
image : require("../assets/chips/25k.png"),
value : 25000
}
]

@ -0,0 +1,32 @@
export function shuffle(a){
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
export function calculatePoints(playerHand){
/*let points = 0;
arr.map((card,_index) => {
//if(card.name == 'A' && card.name == 'J')
points = points + card.value
});
return points;*/
let aceAdjuts = false,
points = 0;
playerHand.map((card,_index) => {
if(card.name == 'A' && !aceAdjuts) {
aceAdjuts = true;
points = points + 10;
}
points = points + card.value;
});
if(aceAdjuts && points > 21){
points = points - 10;
}
return points;
}

@ -3,11 +3,11 @@ import React, {useState} from "react";
import styles from './TicTacToeStyle.js';
import { useMatchStore } from "../../context/matchContext";
import { current } from "@reduxjs/toolkit";
import { ScreenIndicator } from "../../components/ScreenIndicator.tsx";
import { TopBar } from "../../components/TopBar.tsx";
import { ScreenIndicator } from "../../components/ScreenIndicator";
import { TopBar } from "../../components/TopBar";
export default function tic_tac_toe(props: { navigation: any}){
export default function TicTacToe(props: { navigation: any}){
const [map,setMap]=useState([
['','',''],
['','',''],

@ -0,0 +1,202 @@
import {Alert, Button, ImageBackground, Pressable, StyleSheet, Text, View } from "react-native";
import React, {useState} from "react";
import styles from './TicTacToeStyle.js';
import { useMatchStore } from "../../context/matchContext";
import { current } from "@reduxjs/toolkit";
import { ScreenIndicator } from "../../components/ScreenIndicator";
import { TopBar } from "../../components/TopBar";
import { socket } from "../../../socketConfig";
import { MANAGER_MATCH, MANAGER_USER } from "../../../appManagers";
export default function TicTacToeOnline(){
const [init, setInit]=useState(0);
setUpTicTacToeOnline();
const [map,setMap]=useState([
['','',''],
['','',''],
['','',''],
]);
const [turnUser, setTurnUser]=useState("x");
/*
if (MANAGER_MATCH.getCurrentMatch()?.getTabUsers()[0].isEqual(MANAGER_USER.getCurrentUser())){
turn="o";
}
*/
//const {navigation}=props;
const [currentTurn,setCurrentTurn] = useState("x");
const onPressCell = (rowIndex:number,columnIndex:number) => {
if (turnUser!==currentTurn){
Alert.alert("ce n'est pas à votre tour de jouer");
return;
}
if(map[rowIndex][columnIndex]==""){
setMap((existingMap) =>{
const updateMap = [...existingMap]
updateMap[rowIndex][columnIndex]=currentTurn;
return updateMap;
});
socket.emit("playTicTacToe", 1, rowIndex, columnIndex, currentTurn);
setCurrentTurn(currentTurn === "x"? "o" : "x");
const retour=checkWinning();
if(retour!=true){
checkComplete();
}
}else{
Alert.alert("Case déjà prise");
}
};
function setUpTicTacToeOnline() {
if (init===0){
setInit(1);
socket.emit("inMatch", 1);
socket.on("oppPlayTicTacToe", (rowIndex, columnIndex, turn) =>{
setMap((existingMap) =>{
const updateMap = [...existingMap]
updateMap[rowIndex][columnIndex]=turn;
return updateMap;
});
if (!checkWinning()){
checkComplete();
}
if (turn==="x"){
setCurrentTurn("o");
setTurnUser("o");
}
else{
setCurrentTurn("x");
setTurnUser("x");
}
});
}
}
const checkWinning = () =>{
// Checks rows
for (let i=0; i<3; i++){
const isRowXWinning = map[i].every((cell)=> cell==="x");
const isRowOWinning = map[i] .every((cell)=>cell==="o");
if(isRowXWinning==true){
Alert.alert("X won !");
//navigation.goBack();
return true;
}
else if(isRowOWinning==true){
Alert.alert("O won !");
//navigation.goBack();
return true;
}
}
// Checks columns
for (let col=0;col<3;col++){
let isColumnXWinning=true;
let isColumnOWinning=true;
for(let row=0;row<3;row++){
if(map[row][col] !== "x"){
isColumnXWinning=false;
}
if(map[row][col] !== "o"){
isColumnOWinning=false;
}
}
if (isColumnXWinning == true){
Alert.alert("X won !");
//navigation.goBack();
return true;
}
if(isColumnOWinning==true){
Alert.alert("O won !");
//navigation.goBack();
return true;
}
}
// Checks diag
let isDiag1XWinning=true;
let isDiag1OWinning=true;
let isDiag2XWinning=true;
let isDiag2OWinning=true;
for (let i=0;i<3;i++){
if(map[i][i]!=="x"){
isDiag1XWinning=false;
}
if(map[i][i]!=="o"){
isDiag1OWinning=false;
}
if(map[i][2-i]!=="x"){
isDiag2XWinning=false;
}
if(map[i][2-i]!=="o"){
isDiag2OWinning=false;
}
}
if(isDiag1OWinning==true || isDiag2OWinning==true){
Alert.alert("O won !");
//navigation.goBack();
return true;
}
if(isDiag1XWinning==true || isDiag2XWinning==true){
Alert.alert("X won !");
//navigation.goBack();
return true;
}
};
const checkComplete = () =>{
const isRow0Full = map[0].every((cell)=> cell!=="");
const isRow1Full = map[1] .every((cell)=>cell!=="");
const isRow2Full = map[2] .every((cell)=>cell!=="");
if(isRow0Full==true && isRow1Full==true && isRow2Full==true){
Alert.alert("Draw !");
//navigation.goBack();
return false;
}
};
return(
<View style={styles.container}>
<ScreenIndicator title='TIC TAC TOE'/>
<Text style={styles.text}>Current turn: {currentTurn}</Text>
<ImageBackground style={styles.grid} source={{uri:"https://upload.wikimedia.org/wikipedia/commons/6/64/Tic-tac-toe.png"}} >
<View style={styles.map}>
{map.map((row, rowIndex)=>(
<View key={`row-${rowIndex}`} style={styles.row}>
{row.map((cell, columnIndex)=> (
<Pressable
onPress={() => onPressCell(rowIndex,columnIndex)}
style={styles.cell}
key={`row-${rowIndex}-col-${columnIndex}`}
>
{cell === "o" && <View style={styles.circle}/>}
{cell === "x" &&(
<View style={styles.cross}>
<View style={styles.crossLine}/>
<View style={[styles.crossLine, styles.crossLineReversed]}/>
</View>
)}
</Pressable>
))}
</View>
))}
</View>
</ImageBackground>
</View>
);
}

@ -6,10 +6,10 @@ import React from "react"
Importing the correct stylesheet
*/
import styles from './style/BotBar.style';
import { useStoreStore } from "../context/storeContext";
import { useConversationStore } from "../context/conversationContext";
import { MANAGER_CONVERSATION, MANAGER_SKIN, MANAGER_USER } from "../../appManagers";
import { socket } from "../../socketConfig";
import { useSkinStore } from "../context/storeContext";
/*
Images that are required to create a bottom bar
@ -45,7 +45,7 @@ export const BotBar:
({ nav, state }) => {
const setTabSkin = useStoreStore((state) => state.setTabSkin);
const setTabSkin = useSkinStore((state) => state.setTabSkin);
const handleStoreChange = useCallback(async () => {

@ -11,7 +11,7 @@ import { useDispatch, useSelector } from "react-redux"
import { useUserStore } from "../context/userContext"
import { UserCoinsModifier } from "../core/User/userCoinsModifier"
import UserSkinModifier from "../core/User/userSkinModifier"
import { useStoreStore } from "../context/storeContext"
import { useSkinStore } from "../context/storeContext"
import { MANAGER_SKIN, MANAGER_USER } from "../../appManagers"
@ -34,7 +34,7 @@ export const SkinComponent:
const setUser = useUserStore((state) => state.setUser);
const setTabSkin = useStoreStore((state) => state.setTabSkin);
const setTabSkin = useSkinStore((state) => state.setTabSkin);
async function changerSkin(skin: Skin) {

@ -6,14 +6,14 @@ import { User } from "../core/User/user";
// Define store types
interface StoreState {
tabSkin: Skin[];
interface SkinState {
tabSkin: Skin[] | null;
setTabSkin: (tabSkin: Skin[]) => void;
resetTabSkin: () => void;
}
// Define store data and methods
export const useStoreStore = create<StoreState>()((set, get) => ({
export const useSkinStore = create<SkinState>()((set, get) => ({
tabSkin: [],
setTabSkin: (tabSkin) => set((state) => ({ tabSkin: tabSkin })),
resetTabSkin: () => set((state) => ({ tabSkin: [] })),

@ -147,9 +147,11 @@ export class User{
this.tabSkin.push(skin);
}
isEqual(u:User){
if (u.getId()==this.id){
return true;
isEqual(u:User | null){
if (u!= null){
if (u.getId()==this.id){
return true;
}
}
return false;
}

@ -14,11 +14,12 @@ import SignIn from '../screens/SignIn'
import SignUp from '../screens/SignUp'
import LobbySolo from '../screens/LobbySolo'
import CookieClicker from '../Games/CookieClicker/cookieClicker'
import Conversation from '../screens/Conversation'
import Conversation from '../screens/ConversationScreen'
import Test from '../screens/Test'
import MatchMaking from '../screens/MatchMaking'
import TicTacToe from '../Games/Tic-Tac-Toe/tic-tac-toe'
import TicTacToe from '../Games/Tic-Tac-Toe/tic_tac_toe'
import TicTacToeOnline from '../Games/Tic-Tac-Toe/tic_tac_toe_online'
import BlackJack from '../Games/BlackJack/blackJack'
const HomeStack = createStackNavigator();
@ -102,6 +103,8 @@ function GameSoloStackScreen() {
<GameSoloStack.Screen name='LobbySolo' component={LobbySolo} options={{animationEnabled: false,}}/>
<GameSoloStack.Screen name='CookieClicker' component={CookieClicker} />
<GameSoloStack.Screen name='TicTacToe' component={TicTacToe} />
<GameSoloStack.Screen name='TicTacToeOnline' component={TicTacToeOnline} />
<GameSoloStack.Screen name='BlackJack' component={BlackJack} />
</GameSoloStack.Navigator>
);
}

@ -22,36 +22,12 @@ function Home(props: { navigation: any; }) {
const { navigation } = props
const setTabConv = useConversationStore((state) => state.setTabConv);
const setCurrentConv = useConversationStore((state) => state.setCurrentConv);
//It has to be in the home page that way the database will reload the conversations when the user receive a message een if he is in another page
socket.on("messageReceived", async () =>{
console.log("Message reçu");
await handleConversationLoad();
});
async function handleConversationLoad(){
const tmp = MANAGER_USER.getCurrentUser();
if (tmp !== null) {
await MANAGER_CONVERSATION.getLoaderConversation().loadByUser(tmp).then((res) => {
const tmp=MANAGER_USER.getCurrentUser()
MANAGER_CONVERSATION.setTabConv(res);
if (tmp!==null){
const tmpConv=MANAGER_CONVERSATION.getCurrentConv();
if (tmpConv!==null){
const trouveIndex = (element: Conversation) => element.getId()===tmpConv.getId();
const index=MANAGER_CONVERSATION.getTabConv().findIndex(trouveIndex);
MANAGER_CONVERSATION.setCurrentConv(MANAGER_CONVERSATION.getTabConv()[index]);
setCurrentConv(MANAGER_CONVERSATION.getCurrentConv());
}
setTabConv(MANAGER_CONVERSATION.getTabConv());
}
});
}
}
return (
<View style={stylesScreen.container}>

@ -13,6 +13,8 @@ import { MANAGER_CONVERSATION, MANAGER_GAME, MANAGER_SKIN, MANAGER_USER } from '
import { socket } from "../../socketConfig";
import { useConversationStore } from '../context/conversationContext';
import { useGameStore } from '../context/gameContext';
import { Conversation } from '../core/conversation';
import { useSkinStore } from '../context/storeContext';
@ -22,11 +24,15 @@ function SignIn(props: { navigation: any; }) {
const setUser = useUserStore((state) => state.setUser);
const setTabConv = useConversationStore((state) => state.setTabConv);
const setCurrentConv = useConversationStore((state) => state.setCurrentConv);
const setTabGame = useGameStore((state) => state.setTabGame);
const setTabGameSolo = useGameStore((state) => state.setTabGameSolo);
const setTabGameMulti = useGameStore((state) => state.setTabGameMulti);
const setTabSkin = useSkinStore((state) => state.setTabSkin);
const errorList = useSelector((state: RootState) => state.credentialErrors.loginErrorList);
const [pseudo, setPseudo] = useState('');
@ -53,15 +59,14 @@ function SignIn(props: { navigation: any; }) {
await handleSkinLoad();
await handleConversationLoad();
await handleGameLoad();
/*
const conv=await MANAGER_CONVERSATION.getsaverConversation().saveConversation("Wesh la conv", res, [2,3], res.getUsername() + " a créé une conversation", new Date());
if (conv!=null){
MANAGER_CONVERSATION.getTabConv().push(conv);
}
*/
MANAGER_CONVERSATION.getTabConv()?.forEach( conv =>{
socket.emit("inConv", conv);
});
socket.on("messageReceived", async () =>{
await handleConversationLoad();
});
navigation.navigate('HomeTab');
}
else{
@ -74,18 +79,31 @@ function SignIn(props: { navigation: any; }) {
return;
}
async function handleConversationLoad(){
async function handleConversationLoad(){
const tmp = MANAGER_USER.getCurrentUser();
if (tmp !== null) {
await MANAGER_CONVERSATION.getLoaderConversation().loadByUser(tmp).then((res) => {
const tmp=MANAGER_USER.getCurrentUser()
MANAGER_CONVERSATION.setTabConv(res);
setTabConv(res);
if (tmp!==null){
const tmpConv=MANAGER_CONVERSATION.getCurrentConv();
if (tmpConv!==null){
const trouveIndex = (element: Conversation) => element.getId()===tmpConv.getId();
const index=MANAGER_CONVERSATION.getTabConv().findIndex(trouveIndex);
MANAGER_CONVERSATION.setCurrentConv(MANAGER_CONVERSATION.getTabConv()[index]);
setCurrentConv(MANAGER_CONVERSATION.getCurrentConv());
}
setTabConv(MANAGER_CONVERSATION.getTabConv());
}
});
}
}
}
async function handleSkinLoad(){
MANAGER_SKIN.setTabSkin(await MANAGER_SKIN.getLoaderSkin().loadAllSkin());
setTabSkin(MANAGER_SKIN.getTabSkin());
}
async function handleGameLoad(){

@ -7,7 +7,7 @@ import { BotBar } from '../components/BotBar';
import { FlatList } from 'react-native-gesture-handler';
import { SkinComponent } from '../components/Skin';
import { ScreenIndicator } from '../components/ScreenIndicator';
import { useStoreStore } from '../context/storeContext';
import { useSkinStore } from '../context/storeContext';
@ -22,7 +22,7 @@ function Store(props: { navigation: any; }) {
<View style={stylesScreen.bodyStart}>
<ScreenIndicator title='Store'/>
<FlatList
data={useStoreStore().tabSkin}
data={useSkinStore().tabSkin}
numColumns={2}
columnWrapperStyle={{ flex: 1, justifyContent: "space-around"}}
keyExtractor={item =>item.getSkinName()}

@ -1,4 +1,5 @@
import { Game } from "../../core/game";
import { GameMulti } from "../../core/gameMulti";
import { GameSolo } from "../../core/gameSolo";
import ILoaderGame from "./ILoaderGame";
@ -23,9 +24,11 @@ export default class LoaderGameApi implements ILoaderGame{
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 ticTacToe= new GameSolo(2,"TicTacToe", "https://is3-ssl.mzstatic.com/image/thumb/Purple123/v4/f2/06/ef/f206ef53-7206-ffae-af6b-52460ba5636f/source/256x256bb.jpg", "/Games/Tic-Tac-Toe/tic-tac-toe.tsx", 1, 1, map);
tab=[cookieClicker,ticTacToe];
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", "./src/Games/CookieClicker/cookieClicker.tsx", 1, 1, map);
const ticTacToe= new GameSolo(2,"TicTacToe", "https://is3-ssl.mzstatic.com/image/thumb/Purple123/v4/f2/06/ef/f206ef53-7206-ffae-af6b-52460ba5636f/source/256x256bb.jpg", "./src/Games/Tic-Tac-Toe/tic_tac_toe.tsx", 1, 1, map);
const ticTacToeOnline= new GameSolo(3,"TicTacToeOnline", "https://is3-ssl.mzstatic.com/image/thumb/Purple123/v4/f2/06/ef/f206ef53-7206-ffae-af6b-52460ba5636f/source/256x256bb.jpg", "./src/Games/Tic-Tac-Toe/tic_tac_toe_online.tsx", 2, 2, map);
const blackjack = new GameMulti(4, "BlackJack", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/peristanceBDD/bob_party/assets/ImagesJeux/blackjack.jpg", "./src/Games/BlackJack/blackJack", 1, 1, map)
tab=[cookieClicker,ticTacToe, ticTacToeOnline, blackjack];
});
return tab;

@ -22,6 +22,6 @@
"include": [
"**/*.ts",
"**/*.tsx"
, "socketConfig.js", "server.js" ],
, "socketConfig.js", "server.js", "src/Games/BlackJack/blackJack.js", "src/Games/BlackJack/blackJack.js" ],
"extends": "expo/tsconfig.base"
}

@ -5135,6 +5135,11 @@ globby@^11.0.1:
merge2 "^1.4.1"
slash "^3.0.0"
goober@^2.1.10:
version "2.1.11"
resolved "https://registry.yarnpkg.com/goober/-/goober-2.1.11.tgz#bbd71f90d2df725397340f808dbe7acc3118e610"
integrity sha512-5SS2lmxbhqH0u9ABEWq7WPU69a4i2pYcHeCxqaNq6Cw3mnrF0ghWNM4tEGid4dKy8XNIAUbuThuozDHHKJVh3A==
graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@^4.2.0, graceful-fs@^4.2.4, graceful-fs@^4.2.9:
version "4.2.10"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"
@ -7724,6 +7729,13 @@ react-dom@18.0.0:
loose-envify "^1.1.0"
scheduler "^0.21.0"
react-hot-toast@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/react-hot-toast/-/react-hot-toast-2.4.0.tgz#b91e7a4c1b6e3068fc599d3d83b4fb48668ae51d"
integrity sha512-qnnVbXropKuwUpriVVosgo8QrB+IaPJCpL8oBI6Ov84uvHZ5QQcTp2qg6ku2wNfgJl6rlQXJIQU5q+5lmPOutA==
dependencies:
goober "^2.1.10"
"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
@ -7739,6 +7751,11 @@ react-is@^17.0.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
react-native-casino-roulette@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/react-native-casino-roulette/-/react-native-casino-roulette-1.6.0.tgz#22336dc5ccb212f48c9f6b013733737df02d246b"
integrity sha512-6sFU5jtS595LnhpXJ74y7wT1G5ix0ZtJcBJsu7X2GWgdhMendUfi58wzsU2sSVSxUiMwQ8gvC3efHYk606acMQ==
react-native-codegen@^0.69.2:
version "0.69.2"
resolved "https://registry.yarnpkg.com/react-native-codegen/-/react-native-codegen-0.69.2.tgz#e33ac3b1486de59ddae687b731ddbfcef8af0e4e"

Loading…
Cancel
Save