mastermind fini

pull/67/head
Thomas Chazot 2 years ago
parent a2e9d7ff9d
commit 55f2a35414

@ -32,11 +32,17 @@ let lastAskingPlayer = 0
let lastNodeId = -1
let first = true
let askedWrong = false
let solo: boolean = true
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({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<players.length; i++){
@ -50,15 +56,16 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
if (first){
first = false
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<MyGraphComponentProps> = ({onNodeClick, handleS
console.error("Container not found");
return;
}
// Charger les données dans le graph
const nodes = new DataSet(graph.nodesPerson);
@ -99,7 +105,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
const networkData = { nodes: nodes, edges: graph.edges };
const network = new Network(container, networkData, initialOptions);
if (!solo){
socket.on("asked all", (id) =>{
const pers = personNetwork.getPersons().find((p) => p.getId() == id)
if (pers!=undefined){
@ -177,6 +183,8 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
}
})
}
@ -209,14 +217,12 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
if(params.nodes.length > 0){
setNodeIdData(params.nodes[0])
// Renvoyer un true pour afficher la choice bar
if (!solo){
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
@ -226,7 +232,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
askedWrong = false
}
}
}
else if (thisPlayerIndex == playerIndex){
onNodeClick(true)
@ -235,6 +240,21 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
onNodeClick(false)
}
}
else{
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<MyGraphComponentProps> = ({onNodeClick, handleS
<div id="graph-container"/>
</>
);
function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
}

@ -72,7 +72,7 @@ function Lobby() {
setPersonNetworkData(network)
setIndicesData(choosenIndices)
first = true
navigate('/game');
navigate('/game?solo=false');
});
socket.on("new player", (tab) =>{

@ -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() {
/>
</div>
<div className='buttonGroupVertical'>
<Link to="/">
<button className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Jouer seul </button>
</Link>
<button onClick={launchMastermind} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Jouer seul </button>
<button onClick={createLobby} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Créer une partie </button>
<Link to="/">
<button className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Rejoindre </button>
</Link>
</div>
</div>
<div className='rightContainer'>

Loading…
Cancel
Save