diff --git a/cryptide_project/server/server.js b/cryptide_project/server/server.js index 9364c59..46b2b64 100644 --- a/cryptide_project/server/server.js +++ b/cryptide_project/server/server.js @@ -28,20 +28,22 @@ io.on('connection', (socket) => { io.to(room).emit("game created", network, person, indices, Math.floor(Math.random() * map.get(room).length)) }); - socket.on("lobby joined", (room, name) =>{ - socket.join(room) + socket.on("lobby joined", (room, player) =>{ + if (player.type=="Human"){ + socket.join(room) + } if (map.get(room) == undefined){ - map.set(room, [{id: socket.id, name: name}]) + map.set(room, [{type: player.type, id: player.id, name: player.name}]) } else{ const tab = map.get(room) for(let i = 0; i = ({onNodeClick, handleS const solotmp = params.get('solo'); const navigate = useNavigate(); + console.log(person) useEffect(() =>{ touchedPlayer=playerTouched diff --git a/cryptide_project/src/Components/PersonStatus.tsx b/cryptide_project/src/Components/PersonStatus.tsx index 5a3ab8f..959b23b 100644 --- a/cryptide_project/src/Components/PersonStatus.tsx +++ b/cryptide_project/src/Components/PersonStatus.tsx @@ -6,7 +6,9 @@ import { useTheme } from '../Style/ThemeContext'; /* Ressources */ import Person from '../res/img/Person.png' -import leave from '../res/img/bot.png' +import BotImg from '../res/img/bot.png' +import { useGame } from '../Contexts/GameContext'; +import Bot from '../model/Bot'; interface PlayerStatusProps { img: any state: any @@ -14,12 +16,17 @@ interface PlayerStatusProps { index: number setPlayerTouched: (newPlayerTouch: number) => void; playerTouched: number + showCircle: boolean } let touchedPlayer = -1 //@ts-ignore -const PersonStatus: React.FC = ({img = Person, state= Person, name = "Dummy", index, playerTouched, setPlayerTouched}) => { +const PersonStatus: React.FC = ({img = Person, state= Person, name = "Dummy", index, playerTouched, setPlayerTouched, showCircle}) => { const theme=useTheme(); + const {players} = useGame() + if (players[index] instanceof Bot){ + img = BotImg + } const [touchedPlayer, setTouchedPlayer] = useState(-2) useEffect(() =>{ @@ -30,11 +37,12 @@ const PersonStatus: React.FC = ({img = Person, state= Person,
setPlayerTouched(index)}> player
{name}
- {(touchedPlayer == index) ?( + + {(touchedPlayer == index && showCircle) ?(
state
- ): + ): showCircle && (
state diff --git a/cryptide_project/src/Components/PlayerList.tsx b/cryptide_project/src/Components/PlayerList.tsx index 6d01a0f..850f524 100644 --- a/cryptide_project/src/Components/PlayerList.tsx +++ b/cryptide_project/src/Components/PlayerList.tsx @@ -25,7 +25,7 @@ const PlayerList: React.FC = ({ players, playerTouched, setPlay { //@ts-ignore players.map((player, index) => ( - player.id!=socket.id && + player.id!=socket.id && )) }
diff --git a/cryptide_project/src/JSONParser.ts b/cryptide_project/src/JSONParser.ts index 037cf19..fbd8ef2 100644 --- a/cryptide_project/src/JSONParser.ts +++ b/cryptide_project/src/JSONParser.ts @@ -1,3 +1,5 @@ +import EasyBot from "./model/EasyBot"; +import Human from "./model/Human"; import AgeIndice from "./model/Indices/AgeIndice"; import ColorEdgesIndice from "./model/Indices/ColorEdgesIndice"; import ColorIndice from "./model/Indices/ColorIndice"; @@ -7,6 +9,7 @@ import NbSportIndice from "./model/Indices/NbSportIndice"; import SportIndice from "./model/Indices/SportIndice"; import Person from "./model/Person"; import PersonNetwork from "./model/PersonsNetwork"; +import Player from "./model/Player"; class JSONParser{ @@ -78,6 +81,17 @@ class JSONParser{ }); return tabIndice } + + static JSONToPlayer(json: any): Player{ + switch (json.type){ + case "Human": + return new Human(json.id, json.name) + case "EasyBot": + return new EasyBot(json.id, json.name) + default: + throw new Error("PARSER unable to parse player: " + json.type); + } + } } export default JSONParser \ No newline at end of file diff --git a/cryptide_project/src/Pages/EndGame.css b/cryptide_project/src/Pages/EndGame.css index a7e77dd..0d69be8 100644 --- a/cryptide_project/src/Pages/EndGame.css +++ b/cryptide_project/src/Pages/EndGame.css @@ -31,4 +31,12 @@ justify-content: center; flex-direction: column; align-items: center; -} \ No newline at end of file +} + +.playerContainer { + display: flex; + flex-direction: column; + align-items: center; + padding-left: "5px"; + } + \ No newline at end of file diff --git a/cryptide_project/src/Pages/EndGame.tsx b/cryptide_project/src/Pages/EndGame.tsx index dea7588..cf3d932 100644 --- a/cryptide_project/src/Pages/EndGame.tsx +++ b/cryptide_project/src/Pages/EndGame.tsx @@ -26,7 +26,7 @@ import { useGame } from '../Contexts/GameContext'; function EndGame() { - const {winner, person} =useGame() + const {winner, person, players, indices} =useGame() console.log(winner) const theme = useTheme(); return ( @@ -39,19 +39,27 @@ function EndGame() {
+

{indices[players.findIndex((p) => p.id == winner?.id)].ToString("fr")}

-
- {/* - - - - */} +
    + { + players.map((player, index) => ( +
    + {player.id!=winner?.id && + <> + {}} index={index} showCircle={false}/> +
    {indices[players.findIndex((p) => p.id == player?.id)].ToString("fr")}
    + + } +
    + )) + } -
+
diff --git a/cryptide_project/src/Pages/Lobby.css b/cryptide_project/src/Pages/Lobby.css index 5c4bfbd..6a6f132 100644 --- a/cryptide_project/src/Pages/Lobby.css +++ b/cryptide_project/src/Pages/Lobby.css @@ -11,6 +11,7 @@ padding: 20px; margin-right: 10px; margin-left: 30px; + } .lobby-vertical-divider{ @@ -53,4 +54,9 @@ color: gray; font-size: 20px; cursor: pointer; +} + +.centerButton { + display: flex; + justify-content: center; } \ No newline at end of file diff --git a/cryptide_project/src/Pages/Lobby.tsx b/cryptide_project/src/Pages/Lobby.tsx index a6d6930..2d3ff79 100644 --- a/cryptide_project/src/Pages/Lobby.tsx +++ b/cryptide_project/src/Pages/Lobby.tsx @@ -23,6 +23,8 @@ import { useNavigate } from 'react-router-dom'; import { socket } from "../SocketConfig"; import { random } from 'lodash'; import Player from '../model/Player'; +import Human from '../model/Human'; +import EasyBot from '../model/EasyBot'; @@ -38,10 +40,14 @@ function Lobby() { const params = new URLSearchParams(window.location.search); const room = params.get('room'); + function addBot(){ + socket.emit("lobby joined", room, new EasyBot("botId" + Math.floor(Math.random() * 1000), "Bot" + Math.floor(Math.random() * 100)).toJson()) + } + useEffect(() => { if (first){ first = false - socket.emit("lobby joined", room, "test name" + Math.floor(Math.random() * 10)) + socket.emit("lobby joined", room, new Human(socket.id, "Test" + Math.floor(Math.random() * 100)).toJson()) return () => { socket.off('game created'); @@ -78,9 +84,10 @@ function Lobby() { socket.on("new player", (tab) =>{ const tmpTab: Player[] = [] for (const p of tab){ - tmpTab.push(new Player(p.id, p.name)) + tmpTab.push(JSONParser.JSONToPlayer(p)) + console.log(tmpTab) } - setPlayersData(tab.map((p: any) => new Player(p.id, p.name))) + setPlayersData(tmpTab) }) const [codeShowed, setCodeShowed] = useState(true); @@ -111,6 +118,14 @@ function Lobby() { {players.map((player, index) => ( ))} +
+ +
diff --git a/cryptide_project/src/Translations/en.json b/cryptide_project/src/Translations/en.json index 250600f..c81eafc 100644 --- a/cryptide_project/src/Translations/en.json +++ b/cryptide_project/src/Translations/en.json @@ -59,7 +59,7 @@ "nb_friends_indice_end": "friends", "nb_sports_indice_start": "The suspect is playing", - "nb_sports_indice_end": "sport", + "nb_sports_indice_end": "sport(s)", "sport_start": "The suspect plays at least", "sport_end": "" diff --git a/cryptide_project/src/model/Bot.ts b/cryptide_project/src/model/Bot.ts new file mode 100644 index 0000000..453a5b4 --- /dev/null +++ b/cryptide_project/src/model/Bot.ts @@ -0,0 +1,13 @@ +import PersonNetwork from "./PersonsNetwork"; +import Player from "./Player"; + +abstract class Bot extends Player{ + + constructor( id: string, name: string){ + super(id, name); + } + + abstract playRound(personNetwork : PersonNetwork, players: Player): [number, boolean] +} + +export default Bot \ No newline at end of file diff --git a/cryptide_project/src/model/EasyBot.ts b/cryptide_project/src/model/EasyBot.ts new file mode 100644 index 0000000..89fa803 --- /dev/null +++ b/cryptide_project/src/model/EasyBot.ts @@ -0,0 +1,28 @@ +import Bot from "./Bot"; +import Indice from "./Indices/Indice"; +import PersonNetwork from "./PersonsNetwork"; +import Player from "./Player"; + +class EasyBot extends Bot{ + + public indice: Indice | undefined + + constructor(id: string, name: string){ + super(id, name) + } + + toJson() { + return { + type: "EasyBot", + id: this.id, + name: this.name, + }; + } + + playRound(personNetwork: PersonNetwork, players: Player): [number, boolean] { + return [1, false] + } + +} + +export default EasyBot \ No newline at end of file diff --git a/cryptide_project/src/model/EdgesCreator.ts b/cryptide_project/src/model/EdgesCreator.ts index 8885158..80a0919 100644 --- a/cryptide_project/src/model/EdgesCreator.ts +++ b/cryptide_project/src/model/EdgesCreator.ts @@ -11,9 +11,8 @@ class EdgesCreator{ CreateWorkingEdge(personNetwork: PersonNetwork, choosenPerson: Person, indice: Indice, indices: Indice[]){ let creator = IndiceEdgesFactory.Create(indice) - const nbMaxEdge = Math.floor(Math.random() * 5) + 1 - creator.createWorkingEdges(personNetwork, choosenPerson, indices) + const nbMaxEdge = creator.createWorkingEdges(personNetwork, choosenPerson, indices) if (choosenPerson.getFriends().length < nbMaxEdge){ for (const p of personNetwork.getPersons()){ diff --git a/cryptide_project/src/model/Human.tsx b/cryptide_project/src/model/Human.tsx new file mode 100644 index 0000000..5c50dc9 --- /dev/null +++ b/cryptide_project/src/model/Human.tsx @@ -0,0 +1,18 @@ +import Player from "./Player"; + +class Human extends Player{ + + constructor(id: string, name: string){ + super(id, name) + } + + toJson() { + return { + type: "Human", + id: this.id, + name: this.name, + }; + } +} + +export default Human \ No newline at end of file diff --git a/cryptide_project/src/model/IndiceEdgesCreator.ts/ColorIndiceEdgesCreator.ts b/cryptide_project/src/model/IndiceEdgesCreator.ts/ColorIndiceEdgesCreator.ts index f68ee4a..69de618 100644 --- a/cryptide_project/src/model/IndiceEdgesCreator.ts/ColorIndiceEdgesCreator.ts +++ b/cryptide_project/src/model/IndiceEdgesCreator.ts/ColorIndiceEdgesCreator.ts @@ -40,7 +40,7 @@ class ColorIndiceEdgesCreator implements IndiceEdgesCreator{ if (testEdgeWork < indices.length){ p.addFriend(person) person.addFriend(p) - return 1 + return Math.floor(Math.random() * 4) } } } diff --git a/cryptide_project/src/model/IndiceTester/NbSportIndiceTester.ts b/cryptide_project/src/model/IndiceTester/NbSportIndiceTester.ts index a0cf2dc..2f88e41 100644 --- a/cryptide_project/src/model/IndiceTester/NbSportIndiceTester.ts +++ b/cryptide_project/src/model/IndiceTester/NbSportIndiceTester.ts @@ -13,7 +13,7 @@ class NbSportIndiceTester implements IndiceTester{ } Works(person: Person): boolean { - return this.nbSportIndice.getNbSport() == person.getSports().length + return this.nbSportIndice.getNbSport().includes(person.getSports().length) } } diff --git a/cryptide_project/src/model/Indices/NbSportIndice.ts b/cryptide_project/src/model/Indices/NbSportIndice.ts index a34bcbb..eab219e 100644 --- a/cryptide_project/src/model/Indices/NbSportIndice.ts +++ b/cryptide_project/src/model/Indices/NbSportIndice.ts @@ -2,21 +2,30 @@ import { GetJsonFile } from "../EnumExtender"; import Indice from "./Indice"; class NbSportIndice extends Indice { - private nbSport: number; + private nbSport: number[]; - constructor(id: number, nbSport: number) { + constructor(id: number, nbSport: number[]) { super(id); this.nbSport = nbSport; } - public getNbSport(): number{ + public getNbSport(): number[]{ return this.nbSport } // Implémentation de la méthode abstraite ToString(lang: string): string { let json = GetJsonFile(lang) - return `${json.nb_sports_indice_start} ${this.nbSport} ${json.nb_sports_indice_end}`; + let string = `${json.nb_sports_indice_start}`; + this.nbSport.forEach((i, index) =>{ + if (index == this.nbSport.length - 1){ + string += i + } + else{ + string += ` ${i} ${json.or} ` + } + }) + return string + ` ${json.nb_sports_indice_end}` } toJSON() { diff --git a/cryptide_project/src/model/NetworkGenerator.ts b/cryptide_project/src/model/NetworkGenerator.ts index ebd60bd..41584e7 100644 --- a/cryptide_project/src/model/NetworkGenerator.ts +++ b/cryptide_project/src/model/NetworkGenerator.ts @@ -13,30 +13,34 @@ class NetworkGenerator{ const tabAdo: number[] = [] const tabAdulte: number[] = [] const tabVieux: number[] = [] + const tabTresVieux: number[] = [] const tabPerson: Person[] = [] const tabNames = json.names + /* let id = 0 - for(let i = 0; i < nbPerson/4; i++){ + for(let i = 0; i < nbPerson/5; i++){ const nombreAleatoire = Math.floor(Math.random() * 14) + 1; tabJeune.push(nombreAleatoire) } - for(let i = 0; i < nbPerson/4; i++){ - const nombreAleatoire = Math.floor(Math.random() * 5) + 15; + */ + for(let i = 0; i < nbPerson/3; i++){ + const nombreAleatoire = Math.floor(Math.random() * 9) + 12; tabAdo.push(nombreAleatoire) } - for(let i = 0; i < nbPerson/4; i++){ + for(let i = 0; i < nbPerson/3; i++){ const nombreAleatoire = Math.floor(Math.random() * 10) + 20; tabAdulte.push(nombreAleatoire) } - for(let i = 0; i < nbPerson/4; i++){ - const nombreAleatoire = Math.floor(Math.random() * 31) + 30; + for(let i = 0; i < nbPerson/3; i++){ + const nombreAleatoire = Math.floor(Math.random() * 30) + 30; tabVieux.push(nombreAleatoire) } - const tabAge: number[][] = [tabJeune, tabAdo, tabAdulte, tabVieux] + + const tabAge: number[][] = [tabAdo, tabAdulte, tabVieux] let tmpTabSport=[...tabSports] let tmpTabColor = [...tabColor] diff --git a/cryptide_project/src/model/Player.ts b/cryptide_project/src/model/Player.ts index 4af4485..2f51004 100644 --- a/cryptide_project/src/model/Player.ts +++ b/cryptide_project/src/model/Player.ts @@ -1,5 +1,4 @@ -class Player{ - +abstract class Player{ public id: string public name: string; @@ -7,6 +6,8 @@ class Player{ this.id=id this.name=name } + + abstract toJson(): any } export default Player \ No newline at end of file diff --git a/cryptide_project/src/model/Stub.ts b/cryptide_project/src/model/Stub.ts index 2da86a4..f699d22 100644 --- a/cryptide_project/src/model/Stub.ts +++ b/cryptide_project/src/model/Stub.ts @@ -48,8 +48,14 @@ class Stub{ } for (let i=1; i<3; i++){ - indices.push(new NbSportIndice(test, i)) - test++ + for (let j=0; j<3; j++){ + if (j==i){ + continue + } + indices.push(new NbSportIndice(test, [i, j])) + test++ + } + } return indices }