Merge branch 'Persistance' of https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY into Persistance
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
commit
1f55c75bcd
After Width: | Height: | Size: 405 KiB |
After Width: | Height: | Size: 1009 KiB |
After Width: | Height: | Size: 447 KiB |
After Width: | Height: | Size: 595 KiB |
After Width: | Height: | Size: 634 KiB |
After Width: | Height: | Size: 798 KiB |
@ -1,11 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import App from './App'
|
|
||||||
// export for others scripts to use
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function Index(){
|
|
||||||
return(
|
|
||||||
<App/>
|
|
||||||
)
|
|
||||||
}
|
|
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const app = express();
|
||||||
|
const http = require('http');
|
||||||
|
const server = http.createServer(app);
|
||||||
|
const { Server } = require("socket.io");
|
||||||
|
const io = new Server(server);
|
||||||
|
|
||||||
|
const connectUsers = [];
|
||||||
|
|
||||||
|
io.on('connection', (socket) => {
|
||||||
|
console.log(socket.id)
|
||||||
|
|
||||||
|
|
||||||
|
socket.on('inConv', (conv) => {
|
||||||
|
socket.join("C" + conv.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("messageSent", (conv) =>{
|
||||||
|
socket.to("C"+conv.id).emit("messageReceived");
|
||||||
|
console.log("Message envoyé");
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(3000, () => {
|
||||||
|
console.log('listening on *:3000');
|
||||||
|
});
|
@ -0,0 +1,4 @@
|
|||||||
|
const { io } = require("socket.io-client");
|
||||||
|
|
||||||
|
|
||||||
|
export const socket = io("http://localhost:3000");
|
@ -0,0 +1,212 @@
|
|||||||
|
import {Alert, ImageBackground, Pressable, StyleSheet, Text, View } from "react-native";
|
||||||
|
import React, {useState} from "react";
|
||||||
|
import { useMatchStore } from "../../context/matchContext";
|
||||||
|
|
||||||
|
|
||||||
|
export default function tic_tac_toe(props: { navigation: any}){
|
||||||
|
const [map,setMap]=useState([
|
||||||
|
['','',''],
|
||||||
|
['','',''],
|
||||||
|
['','',''],
|
||||||
|
]);
|
||||||
|
|
||||||
|
const {navigation}=props;
|
||||||
|
|
||||||
|
const [currentTurn,setCurrentTurn] = useState("x");
|
||||||
|
|
||||||
|
//const resetMatch = useMatchStore((state) => state.resetMatch);
|
||||||
|
|
||||||
|
const onPressCell = (rowIndex:number,columnIndex:number) => {
|
||||||
|
if(map[rowIndex][columnIndex]==""){
|
||||||
|
setMap((existingMap) =>{
|
||||||
|
const updateMap = [...existingMap]
|
||||||
|
updateMap[rowIndex][columnIndex]=currentTurn;
|
||||||
|
return updateMap;
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
Alert.alert("Case déjà prise");
|
||||||
|
}
|
||||||
|
setCurrentTurn(currentTurn === "x"? "o" : "x");
|
||||||
|
checkWinning();
|
||||||
|
checkComplete();
|
||||||
|
};
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
else if(isRowOWinning==true){
|
||||||
|
Alert.alert("X won !");
|
||||||
|
navigation.goBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
if(isColumnOWinning==true){
|
||||||
|
Alert.alert("O won !");
|
||||||
|
navigation.goBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
if(isDiag1XWinning==true || isDiag2XWinning==true){
|
||||||
|
Alert.alert("X won !");
|
||||||
|
navigation.goBack();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkComplete = () =>{
|
||||||
|
/*let isFull;
|
||||||
|
for (let row=0; row<3; row++){
|
||||||
|
for(let col=0;col<3;col++){
|
||||||
|
if(map[row][col]==="o" || map[row][col]==="x"){
|
||||||
|
isFull=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isFull!=false){
|
||||||
|
Alert.alert("Draw !");
|
||||||
|
navigation.goBack();
|
||||||
|
}*/
|
||||||
|
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(
|
||||||
|
<View style={styles.container}>
|
||||||
|
<Text style={styles.text}>TIC TAC TOE</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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles= StyleSheet.create({
|
||||||
|
container:{
|
||||||
|
height:"100%",
|
||||||
|
width:"100%",
|
||||||
|
flex:1,
|
||||||
|
backgroundColor:"#45444E",
|
||||||
|
alignItems:"center",
|
||||||
|
justifyContent:"center",
|
||||||
|
},
|
||||||
|
grid:{
|
||||||
|
width:375,
|
||||||
|
height:375,
|
||||||
|
alignItems:"center",
|
||||||
|
justifyContent:"center",
|
||||||
|
},
|
||||||
|
row:{
|
||||||
|
flex:1,
|
||||||
|
flexDirection:"row",
|
||||||
|
},
|
||||||
|
cell:{
|
||||||
|
width:100,
|
||||||
|
flex:1,
|
||||||
|
},
|
||||||
|
circle:{
|
||||||
|
left:15,
|
||||||
|
top:15,
|
||||||
|
width:90,
|
||||||
|
height:90,
|
||||||
|
backgroundColor:"#0085FF",
|
||||||
|
borderRadius:50
|
||||||
|
},
|
||||||
|
cross:{
|
||||||
|
width:"100%",
|
||||||
|
height:"100%",
|
||||||
|
},
|
||||||
|
crossLine:{
|
||||||
|
left:52,
|
||||||
|
top:15,
|
||||||
|
position:"absolute",
|
||||||
|
width:15,
|
||||||
|
height:100,
|
||||||
|
borderRadius:50,
|
||||||
|
backgroundColor:"#EE9433",
|
||||||
|
transform:[{rotate:"45deg"},],
|
||||||
|
},
|
||||||
|
crossLineReversed:{
|
||||||
|
transform:[{rotate:"-45deg"},],
|
||||||
|
},
|
||||||
|
map:{
|
||||||
|
aspectRatio:1,
|
||||||
|
padding:5
|
||||||
|
},
|
||||||
|
text:{
|
||||||
|
fontSize: 26,
|
||||||
|
lineHeight: 21,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
letterSpacing: 0.25,
|
||||||
|
color: 'white',
|
||||||
|
marginBottom:25
|
||||||
|
}
|
||||||
|
})
|
@ -0,0 +1,39 @@
|
|||||||
|
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"
|
||||||
|
import { Game } from "../core/game"
|
||||||
|
|
||||||
|
/*
|
||||||
|
Importing the correct stylesheet
|
||||||
|
*/
|
||||||
|
import styles from './style/Game.style';
|
||||||
|
import LobbySolo from "../screens/LobbySolo"
|
||||||
|
import ManagerMatch from "../services/matchServices/managerMatch"
|
||||||
|
import MatchCreator from "../core/Match/matchCreator"
|
||||||
|
import { useMatchStore } from "../context/matchContext"
|
||||||
|
import { MANAGER_MATCH, MANAGER_USER } from "../../appManagers"
|
||||||
|
import { Match } from "../core/Match/match"
|
||||||
|
import { User } from "../core/User/user"
|
||||||
|
|
||||||
|
export const PlayerBox :
|
||||||
|
|
||||||
|
/*
|
||||||
|
* match : match that must be displayed
|
||||||
|
* nav : tool needed to allow the navigation between the screens
|
||||||
|
*/
|
||||||
|
FC<{user: User}> =
|
||||||
|
({user}) =>
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
style={styles.image}
|
||||||
|
source={{uri: user.getCurrentSkin().getSkinSource()}}
|
||||||
|
/>
|
||||||
|
<Text style={styles.name}>{user.getUsername()}</Text>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
import { StatusBar } from 'expo-status-bar'
|
||||||
|
import { View, Image, Text, Button} from 'react-native'
|
||||||
|
import React from 'react';
|
||||||
|
import stylesScreen from './style/screens.style';
|
||||||
|
import styles from './style/Settings.style';
|
||||||
|
import { TopBar } from '../components/TopBar';
|
||||||
|
import { BotBar } from '../components/BotBar';
|
||||||
|
import { Conversation } from '../core/conversation';
|
||||||
|
import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice';
|
||||||
|
import { useMatchStore } from '../context/matchContext';
|
||||||
|
import { FlatList, TextInput } from 'react-native-gesture-handler';
|
||||||
|
import { PlayerBox } from '../components/PlayerBox';
|
||||||
|
|
||||||
|
|
||||||
|
function MatchMaking(props: { navigation: any; }) {
|
||||||
|
|
||||||
|
const { navigation } = props
|
||||||
|
|
||||||
|
const match = useMatchStore().match;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={stylesScreen.container}>
|
||||||
|
<TopBar
|
||||||
|
nav={navigation}
|
||||||
|
state='matchmacking'
|
||||||
|
/>
|
||||||
|
<FlatList
|
||||||
|
data={match?.getTabUsers()}
|
||||||
|
keyExtractor={usr =>usr.getUsername()}
|
||||||
|
renderItem={({item}) => <PlayerBox user={item}/>}
|
||||||
|
/>
|
||||||
|
<View style={stylesScreen.bodyCenter}>
|
||||||
|
<Button
|
||||||
|
title='Lancer la partie'
|
||||||
|
onPress={() => navigation.navigate(match?.getGame().getName().replace(/\s/g, ''))}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<Image
|
||||||
|
style={{width:100, height:100}}
|
||||||
|
source={{uri: match?.getGame().getImageSource()}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MatchMaking
|
@ -1,62 +0,0 @@
|
|||||||
import LoaderUserApi from '../userServices/loaderUserApi';
|
|
||||||
import ILoaderUser from '../userServices/ILoaderUser';
|
|
||||||
import { Match } from '../../core/Match/match';
|
|
||||||
import MatchSolo from '../../core/Match/matchSolo';
|
|
||||||
import { GameSolo } from '../../core/gameSolo';
|
|
||||||
import tabUS from '../../constUser';
|
|
||||||
import { Conversation } from '../../core/conversation';
|
|
||||||
|
|
||||||
// Instances
|
|
||||||
const img = "";
|
|
||||||
let loader:ILoaderUser = new LoaderUserApi();
|
|
||||||
let map = new Map<number, number>([
|
|
||||||
[50, 3],
|
|
||||||
[75, 4],
|
|
||||||
[100, 5],
|
|
||||||
[150, 6]
|
|
||||||
]);
|
|
||||||
let game:GameSolo = new GameSolo(1, 'SuperJeu', img, 'source', 1, 1, map);
|
|
||||||
let match:Match = new MatchSolo(1, false, tabUS, game);
|
|
||||||
let convo:Conversation = new Conversation(1, tabUS, [], 'superConvo');
|
|
||||||
|
|
||||||
|
|
||||||
// Tests
|
|
||||||
describe('LoaderUserApi tests', () => {
|
|
||||||
describe('loadById tests', () => {
|
|
||||||
it('should return UserTest (id: 48)', () => {
|
|
||||||
expect(loader.loadByID(48)).toEqual(tabUS[0]);
|
|
||||||
})
|
|
||||||
it('should return null', () => {
|
|
||||||
expect(loader.loadByID(99999999999)).toBe(null);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('loadByUserName tests', () => {
|
|
||||||
it('should return USerTest (name: WeshWesh)', () => {
|
|
||||||
expect(loader.loadByUsername('WeshWesh')).toEqual(tabUS[0]);
|
|
||||||
})
|
|
||||||
it('should return null', () => {
|
|
||||||
expect(loader.loadByUsername('jExistePas')).toBe(null);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('loadByUserNamePassword tests', () => {
|
|
||||||
it('should return UserTest (name: WeshWesh, password: MdpDeOuf)', () => {
|
|
||||||
expect(loader.loadByUsernamePassword('WeshWesh', 'MdpDeOuf')).toEqual(tabUS[0]);
|
|
||||||
})
|
|
||||||
it('should return null', () => {
|
|
||||||
expect(loader.loadByUsernamePassword('jExistePas', 'jExistePas')).toBe(null);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('loadUserByMatch tests', () => {
|
|
||||||
it('should return tabUS', () => {
|
|
||||||
expect(loader.loadUserByMatch(match)).toEqual(tabUS);
|
|
||||||
})
|
|
||||||
it('should return null', () => {
|
|
||||||
expect(loader.loadByUsernamePassword('jExistePas', 'jExistePas')).toEqual(null);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('loadUserByConversation tests', () => {
|
|
||||||
it('should return tabUS', () => {
|
|
||||||
expect(loader.loadUserByConversation(convo)).toEqual(tabUS);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
import LoaderUserApi from '../userServices/loaderUserApi';
|
|
||||||
import SaverUserApi from '../userServices/saverUserApi';
|
|
||||||
|
|
||||||
|
|
||||||
// Instances
|
|
||||||
let saver:SaverUserApi = new SaverUserApi();
|
|
||||||
let loader = new LoaderUserApi();
|
|
||||||
|
|
||||||
|
|
||||||
// Tests
|
|
||||||
|
|
||||||
describe('SaverUserApi tests', () => {
|
|
||||||
describe('saverUser tests', () => {
|
|
||||||
})
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
|
|
||||||
it('should return true', () => {
|
|
||||||
expect(1+1).toBe(2);
|
|
||||||
})
|
|
@ -1,78 +0,0 @@
|
|||||||
import StubUser from '../userServices/stub';
|
|
||||||
import { User } from '../../core/User/user';
|
|
||||||
import { Skin } from '../../core/skin';
|
|
||||||
import { GameSolo } from '../../core/gameSolo';
|
|
||||||
import MatchSolo from '../../core/Match/matchSolo';
|
|
||||||
import { Match } from '../../core/Match/match';
|
|
||||||
import { Conversation } from '../../core/conversation';
|
|
||||||
|
|
||||||
// Instances
|
|
||||||
const img = "";
|
|
||||||
let stub:StubUser = new StubUser();
|
|
||||||
let map = new Map<number, number>([
|
|
||||||
[50, 3],
|
|
||||||
[75, 4],
|
|
||||||
[100, 5],
|
|
||||||
[150, 6]
|
|
||||||
]);
|
|
||||||
let tabUS:User[] = [
|
|
||||||
new User(1, "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
|
|
||||||
new User(2, "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
|
|
||||||
new User(3, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)],),
|
|
||||||
new User(4, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
|
|
||||||
];
|
|
||||||
let game:GameSolo = new GameSolo(1, 'SuperJeu', img, 'source', 1, 1, map);
|
|
||||||
let match:Match = new MatchSolo(1, false, tabUS, game);
|
|
||||||
let convo:Conversation = new Conversation(1, tabUS, [], 'superConvo');
|
|
||||||
|
|
||||||
|
|
||||||
// Tests
|
|
||||||
describe('StubUser tests', () => {
|
|
||||||
describe('loadAllUser tests', () => {
|
|
||||||
it('should return tabUS', () => {
|
|
||||||
expect(stub.loadAllUser()).toEqual(tabUS);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('loadById tests', () => {
|
|
||||||
it('should return UserTest (id: 48)', () => {
|
|
||||||
expect(stub.loadByID(48)).toEqual(tabUS[0]);
|
|
||||||
})
|
|
||||||
it('should return null', () => {
|
|
||||||
expect(stub.loadByID(999999999999)).toBe(null);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('loadByUserName tests', () => {
|
|
||||||
it('should return USerTest (name: WeshWesh)', () => {
|
|
||||||
expect(stub.loadByUsername('WeshWesh')).toEqual(tabUS[0]);
|
|
||||||
})
|
|
||||||
it('should return null', () => {
|
|
||||||
expect(stub.loadByUsername('jExistePas')).toBe(null);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('loadByUserNamePassword tests', () => {
|
|
||||||
it('should return UserTest (name: WeshWesh, password: MdpDeOuf)', () => {
|
|
||||||
expect(stub.loadByUsernamePassword('WeshWesh', 'MdpDeOuf')).toEqual(tabUS[0]);
|
|
||||||
})
|
|
||||||
it('should return null', () => {
|
|
||||||
expect(stub.loadByUsernamePassword('jExistePas', 'jExistePas')).toBe(null);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('loadUserByMatch tests', () => {
|
|
||||||
it('should return tabUS', () => {
|
|
||||||
expect(stub.loadUserByMatch(match)).toEqual(tabUS);
|
|
||||||
})
|
|
||||||
it('should return null', () => {
|
|
||||||
expect(stub.loadByUsernamePassword('jExistePas', 'jExistePas')).toEqual(null);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('loadUserByConversation tests', () => {
|
|
||||||
it('should return tabUS', () => {
|
|
||||||
expect(stub.loadUserByConversation(convo)).toEqual(tabUS);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('loadLastId', () => {
|
|
||||||
it('should return U0005', () => {
|
|
||||||
expect(stub.loadLastId()).toBe('U0005');
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue