diff --git a/cryptide_project/src/Pages/SoloGame.tsx b/cryptide_project/src/Pages/SoloGame.tsx
index 3b2cced..1162ad9 100644
--- a/cryptide_project/src/Pages/SoloGame.tsx
+++ b/cryptide_project/src/Pages/SoloGame.tsx
@@ -107,9 +107,9 @@ const SoloGame = ({locale, changeLocale}) => {
return (
-
+
-
+
Date: Wed, 15 Nov 2023 08:12:21 +0100
Subject: [PATCH 4/5] mastermind fini
---
.../src/Components/GraphContainer.tsx | 224 ++++++++++--------
cryptide_project/src/Pages/Lobby.tsx | 2 +-
cryptide_project/src/Pages/Play.tsx | 23 +-
3 files changed, 142 insertions(+), 107 deletions(-)
diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx
index 3bc315a..0aa002c 100644
--- a/cryptide_project/src/Components/GraphContainer.tsx
+++ b/cryptide_project/src/Components/GraphContainer.tsx
@@ -32,11 +32,17 @@ let lastAskingPlayer = 0
let lastNodeId = -1
let first = true
let askedWrong = false
+let solo: boolean = true
+
const MyGraphComponent: React.FC
= ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange}) => {
const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, onlyFalse, setOnlyFalseData } = useGame();
+ const params = new URLSearchParams(window.location.search);
+ const solotmp = params.get('solo');
+
+
let playerIndex: number = turnPlayerIndex
let index = 0
for (let i=0; i = ({onNodeClick, handleS
if (first){
first = false
- setActualPlayerIndexData(index)
- if (playerIndex == thisPlayerIndex){
- handleTurnBarTextChange("À vous de jouer")
- handleShowTurnBar(true)
-
+ if (solotmp == "false"){
+ solo=false
+ }
+ if (!solo){
+ setActualPlayerIndexData(index)
+ if (playerIndex == thisPlayerIndex){
+ handleTurnBarTextChange("À vous de jouer")
+ handleShowTurnBar(true)
+ }
}
- indices.forEach(i => {
- console.log(i.ToString("en"))
- });
}
useEffect(() => {
@@ -72,7 +79,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS
console.error("Container not found");
return;
}
-
// Charger les données dans le graph
const nodes = new DataSet(graph.nodesPerson);
@@ -99,84 +105,86 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS
const networkData = { nodes: nodes, edges: graph.edges };
const network = new Network(container, networkData, initialOptions);
-
- socket.on("asked all", (id) =>{
- const pers = personNetwork.getPersons().find((p) => p.getId() == id)
- if (pers!=undefined){
- askedPersons.push(pers)
- }
- })
-
- socket.on("node checked",(id, works, color, newPlayerIndex) => {
- const node = nodes.get().find((n) => id == n.id)
- if (node!=undefined){
- onNodeClick(false)
- playerIndex = newPlayerIndex
- if (!node.label.includes(colorToEmoji(color, works))){
- networkData.nodes.update({id: id, label: node.label + colorToEmoji(color, works)})
- }
- if (playerIndex === thisPlayerIndex){
- handleTurnBarTextChange("À vous de jouer")
- handleShowTurnBar(true)
- }
- else{
- handleShowTurnBar(false)
- }
- }
- lastAskingPlayer = 0
- lastNodeId = -1
- })
-
- socket.on("already asked", (nodeId, askedPlayer) =>{
- console.log("player: " + askedPlayer + " already asked on node " + nodeId)
- })
-
- socket.on("asked wrong", () =>{
- setOnlyFalseData(true)
- askedWrong = true
- handleShowTurnBar(true)
- handleTurnBarTextChange("Mauvais choix, posez un carré !")
- })
-
-
- socket.on("asked", (nodeId, askingPlayer, askingPlayerIndex) => {
- console.log(askingPlayerIndex)
- if (askingPlayer.id !== lastAskingPlayer || nodeId !== lastNodeId ){
- lastAskingPlayer = askingPlayer.id
- lastNodeId = nodeId
- const pers = personNetwork.getPersons().find((p) => p.getId() == nodeId)
+ if (!solo){
+ socket.on("asked all", (id) =>{
+ const pers = personNetwork.getPersons().find((p) => p.getId() == id)
if (pers!=undefined){
- if (askedPersons.includes(pers)){
- socket.emit("already asked", nodeId, askingPlayer, socket.id)
- return
+ askedPersons.push(pers)
+ }
+ })
+
+ socket.on("node checked",(id, works, color, newPlayerIndex) => {
+ const node = nodes.get().find((n) => id == n.id)
+ if (node!=undefined){
+ onNodeClick(false)
+ playerIndex = newPlayerIndex
+ if (!node.label.includes(colorToEmoji(color, works))){
+ networkData.nodes.update({id: id, label: node.label + colorToEmoji(color, works)})
+ }
+ if (playerIndex === thisPlayerIndex){
+ handleTurnBarTextChange("À vous de jouer")
+ handleShowTurnBar(true)
}
else{
- askedPersons.push(pers)
- const node = nodes.get().find((n) => nodeId == n.id)
- if (node != undefined && indice != null){
- var tester = IndiceTesterFactory.Create(indice)
- let maybe = thisPlayerIndex
- playerIndex = playerIndex + 1
- if(playerIndex == players.length){
- playerIndex = 0
- }
- if (tester.Works(pers)){
- socket.emit("node checked", nodeId, true, positionToColor(thisPlayerIndex), room, playerIndex)
- }
- else{
- maybe = maybe - 1
- if(maybe == 0){
- maybe = players.length - 1
+ handleShowTurnBar(false)
+ }
+ }
+ lastAskingPlayer = 0
+ lastNodeId = -1
+ })
+
+ socket.on("already asked", (nodeId, askedPlayer) =>{
+ console.log("player: " + askedPlayer + " already asked on node " + nodeId)
+ })
+
+ socket.on("asked wrong", () =>{
+ setOnlyFalseData(true)
+ askedWrong = true
+ handleShowTurnBar(true)
+ handleTurnBarTextChange("Mauvais choix, posez un carré !")
+ })
+
+
+ socket.on("asked", (nodeId, askingPlayer, askingPlayerIndex) => {
+ console.log(askingPlayerIndex)
+ if (askingPlayer.id !== lastAskingPlayer || nodeId !== lastNodeId ){
+ lastAskingPlayer = askingPlayer.id
+ lastNodeId = nodeId
+ const pers = personNetwork.getPersons().find((p) => p.getId() == nodeId)
+ if (pers!=undefined){
+ if (askedPersons.includes(pers)){
+ socket.emit("already asked", nodeId, askingPlayer, socket.id)
+ return
+ }
+ else{
+ askedPersons.push(pers)
+ const node = nodes.get().find((n) => nodeId == n.id)
+ if (node != undefined && indice != null){
+ var tester = IndiceTesterFactory.Create(indice)
+ let maybe = thisPlayerIndex
+ playerIndex = playerIndex + 1
+ if(playerIndex == players.length){
+ playerIndex = 0
+ }
+ if (tester.Works(pers)){
+ socket.emit("node checked", nodeId, true, positionToColor(thisPlayerIndex), room, playerIndex)
+ }
+ else{
+ maybe = maybe - 1
+ if(maybe == 0){
+ maybe = players.length - 1
+ }
+ socket.emit("node checked", nodeId, false, positionToColor(thisPlayerIndex), room, maybe)
+ socket.emit("asked wrong", askingPlayer, room)
}
- socket.emit("node checked", nodeId, false, positionToColor(thisPlayerIndex), room, maybe)
- socket.emit("asked wrong", askingPlayer, room)
}
- }
- }
+ }
+ }
}
- }
-
- })
+
+ })
+ }
+
@@ -209,32 +217,44 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS
if(params.nodes.length > 0){
setNodeIdData(params.nodes[0])
- // Renvoyer un true pour afficher la choice bar
- if (askedWrong){
- console.log(askedWrong)
- const person = personNetwork?.getPersons().find((p) => p.getId() == params.nodes[0])
- if (person !== undefined && indice !== null){
- const tester = IndiceTesterFactory.Create(indice)
- if (!tester.Works(person) && !askedPersons.includes(person)){
- console.log(playerIndex)
- playerIndex = thisPlayerIndex + 1
- if(playerIndex == players.length){
- playerIndex = 0
+ if (!solo){
+ if (askedWrong){
+ const person = personNetwork?.getPersons().find((p) => p.getId() == params.nodes[0])
+ if (person !== undefined && indice !== null){
+ const tester = IndiceTesterFactory.Create(indice)
+ if (!tester.Works(person) && !askedPersons.includes(person)){
+ playerIndex = thisPlayerIndex + 1
+ if(playerIndex == players.length){
+ playerIndex = 0
+ }
+ socket.emit("node checked", params.nodes[0], false, positionToColor(thisPlayerIndex), room, playerIndex)
+ askedPersons.push(person)
+ askedWrong = false
}
- socket.emit("node checked", params.nodes[0], false, positionToColor(thisPlayerIndex), room, playerIndex)
- askedPersons.push(person)
- askedWrong = false
}
}
-
- }
- else if (thisPlayerIndex == playerIndex){
- onNodeClick(true)
+ else if (thisPlayerIndex == playerIndex){
+ onNodeClick(true)
+ }
+ else{
+ onNodeClick(false)
+ }
}
else{
- onNodeClick(false)
+ const person = personNetwork?.getPersons().find((p) => p.getId() == params.nodes[0]) //person sélectionnée
+ if (person != undefined){
+ indices.forEach(async (i, index) =>{
+ const tester = IndiceTesterFactory.Create(i)
+ const test = tester.Works(person)
+ const node = nodes.get().find((n) => params.nodes[0] == n.id)
+ if (node!=undefined){
+ networkData.nodes.update({id: params.nodes[0], label: node.label + colorToEmoji(positionToColor(index), test)})
+ }
+ })
+ }
}
}
+ // Renvoyer un true pour afficher la choice bar
else{
// Renvoyer un false pour cacher la choice bar
onNodeClick(false)
@@ -247,6 +267,10 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS
>
);
+
+ function delay(ms: number) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+ }
}
diff --git a/cryptide_project/src/Pages/Lobby.tsx b/cryptide_project/src/Pages/Lobby.tsx
index 6b69e1d..a6d6930 100644
--- a/cryptide_project/src/Pages/Lobby.tsx
+++ b/cryptide_project/src/Pages/Lobby.tsx
@@ -72,7 +72,7 @@ function Lobby() {
setPersonNetworkData(network)
setIndicesData(choosenIndices)
first = true
- navigate('/game');
+ navigate('/game?solo=false');
});
socket.on("new player", (tab) =>{
diff --git a/cryptide_project/src/Pages/Play.tsx b/cryptide_project/src/Pages/Play.tsx
index be516d1..13d3f62 100644
--- a/cryptide_project/src/Pages/Play.tsx
+++ b/cryptide_project/src/Pages/Play.tsx
@@ -19,11 +19,16 @@ import param from '../res/icon/param.png';
import share from '../res/icon/share.png';
import { socket } from '../SocketConfig';
import { useNavigate } from 'react-router-dom';
+import GameCreator from '../model/GameCreator';
+import { useGame } from '../Contexts/GameContext';
function Play() {
const theme=useTheme()
+ const { setIndicesData, setPersonData, setPersonNetworkData } = useGame();
+
+
const [room, setRoom] = useState(null);
const navigate = useNavigate();
@@ -31,6 +36,15 @@ function Play() {
socket.emit("lobby created")
}
+ function launchMastermind(){
+ const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(5, 30)
+ setPersonData(choosenPerson)
+ setPersonNetworkData(networkPerson)
+ setIndicesData(choosenIndices)
+ setIndicesData(choosenIndices)
+ navigate('/game?solo=true');
+ }
+
useEffect(() => {
@@ -78,13 +92,10 @@ function Play() {
/>
-
-
-
+
-
-
-
+
+