Skip to content

Commit

Permalink
Merge pull request #22 from callbacka/guesserlogic
Browse files Browse the repository at this point in the history
Guesserlogic
  • Loading branch information
crispinamuriel authored Nov 26, 2019
2 parents d8ece08 + 6a945be commit 6b53bcb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 35 deletions.
25 changes: 20 additions & 5 deletions client/components/Hand.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export default class Hand extends React.Component {
constructor(props) {
super(props)
this.state = {
clue: ''
clue: '',
clueNum: ''
}
this.handleChange = this.handleChange.bind(this)
this.giveClue = this.giveClue.bind(this)
Expand All @@ -14,7 +15,12 @@ export default class Hand extends React.Component {

giveClue = evt => {
evt.preventDefault()
socket.emit('give clue', this.props.room, this.state.clue)
socket.emit(
'give clue',
this.props.room,
this.state.clue,
this.state.clueNum
)
}

handleChange(evt) {
Expand All @@ -41,14 +47,22 @@ export default class Hand extends React.Component {
onChange={this.handleChange}
value={this.state.clue}
/>
<label htmlFor="clue">Number:</label>
<input
name="clueNum"
type="number"
autoComplete="off"
onChange={this.handleChange}
value={this.state.clueNum}
/>
<button type="submit">Submit</button>
</form>
)
} else {
return (
<div id="hand-bottom">
Your codemaster gave the clue {this.props.currentClue.clue} Please
select your guesses.{' '}
Your codemaster gave the clue {this.props.currentClue.clue} for{' '}
{this.props.currentClue.clueNum}. Please select your guesses.{' '}
<button type="button" onClick={this.handleClick}>
Change turn
</button>
Expand All @@ -68,7 +82,8 @@ export default class Hand extends React.Component {
return (
<div id="hand-bottom">
Player {this.props.currentClue.player} gave the clue{' '}
{this.props.currentClue.clue} Waiting for{' '}
{this.props.currentClue.clue} for {this.props.currentClue.clueNum}.
Waiting for the
{this.props.currentPlayer.team} {this.props.currentPlayer.role} to
submit their guesses.
</div>
Expand Down
74 changes: 45 additions & 29 deletions server/classes/deck.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,59 @@
class deck {
constructor() {
this.words = [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24
]
this.words = []
this.redWordIndices = []
this.blueWordIndices = []
this.beigeWordIndices = []
this.greyWordIndices = []
}

newDeck() {
this.shuffle()
console.log('in newDeck')
this.shuffleWords()
this.shuffleColors()
}

shuffle() {
// will need to populate the array below with a randomized selection of 25 words.
shuffleWords() {
const shuffled = [
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y'
]
let i = 25
let index
let temp
while (i--) {
index = Math.floor((i + 1) * Math.random())
temp = shuffled[index]
shuffled[index] = shuffled[i]
shuffled[i] = temp
}
this.words = shuffled
}
shuffleColors() {
const shuffled = [
0,
1,
Expand Down
3 changes: 2 additions & 1 deletion server/socket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ module.exports = io => {
socket.emit('guesser view', rooms[roomName].deck.words)
})

socket.on('give clue', (roomName, clue) => {
socket.on('give clue', (roomName, clue, clueNum) => {
const {player} = rooms[roomName].players.filter(
client => client.id === socket.id
)[0]
rooms[roomName].boardstate.currentClue.clue = clue
rooms[roomName].boardstate.currentClue.clueNum = clueNum
rooms[roomName].boardstate.currentClue.player = player
rooms[roomName].boardstate.activePlayer =
rooms[roomName].boardstate.activePlayer % 4 + 1
Expand Down

0 comments on commit 6b53bcb

Please sign in to comment.