Skip to content
Snippets Groups Projects
Commit 393467be authored by KaspHell's avatar KaspHell
Browse files

Fixed problems with passing result from aicamera to game

parent 849fad0c
No related branches found
No related tags found
No related merge requests found
......@@ -75,7 +75,7 @@ class App extends Component {
<Header />
</div>
<div className="app flexbox-container">
<AiCamera handlePlay={this.handlePlay}/>
<AiCamera updateMatch={this.updateMatch}/>
<GameUI updateMatch={this.updateMatch} handlePlay={this.handlePlay} match={this.state.match} matchId={this.state.matchId}/>
<Result match={this.state.match}/>
</div>
......
......@@ -31,9 +31,51 @@ function AiCamera(props) {
}
}
function handlePlay(userChoice) {
const plays = ["Rock", "Paper", "Scissors"]
const aiChoice = plays[Math.floor(Math.random() * plays.length)]
console.log("...............")
console.log(userChoice)
console.log(aiChoice)
switch (userChoice + aiChoice) {
case "RockRock":
case "ScissorsScissors":
case "PaperPaper":
console.log("draw")
props.updateMatch({
result: "Draw",
userChoice: userChoice,
aiChoice: aiChoice
})
break;
case "RockScissors":
case "ScissorsPaper":
case "PaperRock":
console.log("win")
props.updateMatch({
result: "Win",
userChoice: userChoice,
aiChoice: aiChoice
})
break;
case "ScissorsRock":
case "PaperScissors":
case "RockPaper":
console.log("lose")
props.updateMatch({
result: "Lose",
userChoice: userChoice,
aiChoice: aiChoice
})
break;
}
}
// registers players mark and plays a turn
async function makeMove() {
props.handlePlay("Paper")
console.log(results);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment