diff --git a/googletrendsgame/src/App.js b/googletrendsgame/src/App.js index 2716b06..19de815 100644 --- a/googletrendsgame/src/App.js +++ b/googletrendsgame/src/App.js @@ -5,6 +5,7 @@ import openSocket from 'socket.io-client'; import NicknameInput from './components/nicknameInput'; import CreateRoomInput from './components/createRoomInput'; import RoomList from './components/RoomList'; +import GameScreen from './components/GameScreen'; const socket = openSocket('129.21.91.149:3000'); @@ -12,20 +13,30 @@ class App extends Component { constructor(props){ super(props); - this.state={ + this.state = { progression: 'register', - roomsList: [] + roomsList: [], + roomUpdateData: {} } socket.on('sendRooms', payload => { - var rooms = payload.rooms; + console.log(payload); this.setState({ - progression: 'roomChoose', - roomsList: rooms + roomsList: payload.rooms, + progression: 'roomChoose' }) }); + + socket.on('roomUpdate', payload => { + this.setState({ + progression: 'gameScreen', + roomUpdateData: payload + }) + }); + this.modifyStateToCreateRoom = this.modifyStateToCreateRoom.bind(this); this.modifyStateToRoomsScreen = this.modifyStateToRoomsScreen.bind(this); + this.modifyStateToGameScreen = this.modifyStateToGameScreen.bind(this); } modifyStateToCreateRoom() { @@ -36,17 +47,16 @@ class App extends Component { modifyStateToGameScreen() { this.setState({ - progression: '' - }) + progression: 'gameScreen' + }); } modifyStateToRoomsScreen(){ this.setState({ progression: 'roomChoose' - }) + }); } - render() { if (this.state.progression === 'register') { return( @@ -54,12 +64,16 @@ class App extends Component { ) } else if(this.state.progression === 'roomChoose') { return( - + ) } else if (this.state.progression === 'createRoom') { return( - + + ) + } else if (this.state.progression === 'gameScreen') { + return( + ) } } diff --git a/googletrendsgame/src/components/GameScreen.js b/googletrendsgame/src/components/GameScreen.js index ef867d9..783fc1b 100644 --- a/googletrendsgame/src/components/GameScreen.js +++ b/googletrendsgame/src/components/GameScreen.js @@ -1 +1,50 @@ import React, {Component} from 'react'; +import UserList from './UserList'; +import WordInput from './wordInput'; + +export default class GameScreen extends Component{ + constructor(props){ + super(props); + + console.log(this.props.gameData); + + this.state={ + inputValue: '' + } + } + + + + render(){ + if(this.props.gameData.gameState === 3){ + return( +
+

Round:

+

Results!

+

Round Winner{this.props.gameData.roundWinner}

+ +
+ ) + } else if(this.props.gameData.gameState === 2){ + console.log('multiple players in lobby') + return( +
+

Round: {this.props.gameData.round}

+ + + +
+ ) + } else if (this.props.gameData.gameState === 1){ + console.log('single player method called') + return( +
+

Round: {this.props.gameData.round}

+

+ + +
+ ) + } + }; + } diff --git a/googletrendsgame/src/components/RoomList.js b/googletrendsgame/src/components/RoomList.js index aa95502..4fe3e8b 100644 --- a/googletrendsgame/src/components/RoomList.js +++ b/googletrendsgame/src/components/RoomList.js @@ -3,17 +3,26 @@ import RoomListItem from './RoomListItem'; import {modifyStateToCreateRoom} from '../App' export default (props) => { - let rooms = props.roomArray; + let rooms = props.roomsArray; + console.log(props); if (rooms.length != 0) { - let roomsList = rooms.map((room) => - - ); + const roomNameArray = rooms.map(room => room.name); + const publicPrivateArray = rooms.map(room => room.passwordBool); + const capacityArray = rooms.map(room => room.capacity); + const occupancyArray = rooms.map(room => room.occupants) + + var roomsArray = []; + + for(var i = 0; i < roomNameArray.length; i++){ + roomsArray.push(); + } + return(
-
{roomsList}
+
{roomsArray}
- ); + ) } else { return (
diff --git a/googletrendsgame/src/components/RoomListItem.js b/googletrendsgame/src/components/RoomListItem.js index af2d943..b39ae8b 100644 --- a/googletrendsgame/src/components/RoomListItem.js +++ b/googletrendsgame/src/components/RoomListItem.js @@ -1,17 +1,47 @@ -import React from 'react'; +import React, {Component} from 'react'; -export default (props) => { - var privateString ='' - if (props.private === false){ - privateString = "Public" +export default class RoomListItem extends Component { + constructor(props){ + super(props); + + this.state={ + term:'' + } + + this.onInputChange = this.onInputChange.bind(this); + this.buttonClickHandler = this.buttonClickHandler.bind(this); + } + + + onInputChange(event) { + this.setState( { term: event.target.value }); + } + + buttonClickHandler(event){ + this.props.socket.emit('joinRoom', {roomName: this.props.roomName, password: this.state.term}) + } + + +render(){ + if (this.props.private === 'false'){ + return( +
+

{this.props.roomName}'s Room

+

{this.props.occupancy}/{this.props.capacity}

+
Public
+ +
+ ); } else { - privateString = "Private" + return( +
+

{this.props.roomName}'s Room

+

{this.props.occupancy}/{this.props.capacity}

+
Private
+ + +
+ ) } - return( -
-

{props.roomName}'s Room

-

{props.occupancy}/{props.capacity}

-
{privateString}
-
- ) +} } diff --git a/googletrendsgame/src/components/User.js b/googletrendsgame/src/components/User.js index 4d97ebf..a5a4fdc 100644 --- a/googletrendsgame/src/components/User.js +++ b/googletrendsgame/src/components/User.js @@ -2,31 +2,32 @@ import React from 'react'; import FontAwesome from 'react-fontawesome'; export default (props) => { - const name = this.props.name; - const score = this.props.score; + console.log('entered user obj') + const name = props.name; + const score = props.score; var word; - if (this.props.word === ''){ + if (props.word === ''){ word = 'true' } else { word = 'false' } - - if (word === 'true') { + console.log('Word is true'); return( -
  • -
    {name}
    -
    {score}
    +
    +
    Name: {name}
    +
    Score: {score}
    -
  • +
    ) } else { + console.log('Word is false') return ( -
  • +
    Name: {name}
    Score: {score}
    -
  • + ) } } diff --git a/googletrendsgame/src/components/UserList.js b/googletrendsgame/src/components/UserList.js index f4f173d..03ea559 100644 --- a/googletrendsgame/src/components/UserList.js +++ b/googletrendsgame/src/components/UserList.js @@ -2,14 +2,26 @@ import React from 'react'; import User from './User' export default (props) => { - var users = props.users; + console.log(props.gameDataPassed); + + const nameArray = props.gameDataPassed.users.map(name => name.name); + const scoreArray = props.gameDataPassed.users.map(score => score.score); + const wordArray = props.gameDataPassed.users.map(word => word.word); + + console.log(nameArray); + console.log(scoreArray); + console.log(wordArray); + + var users = []; + + for(var i = 0; i < nameArray.length; i++){ + users.push(); + } - var userList = users.map((user) => - - ); return( +
    -
      {userList}
    + {users}
    - ); + ) } diff --git a/googletrendsgame/src/components/activeButton.js b/googletrendsgame/src/components/activeButton.js index e4577d9..fcafd12 100644 --- a/googletrendsgame/src/components/activeButton.js +++ b/googletrendsgame/src/components/activeButton.js @@ -26,6 +26,16 @@ export default class activeButton extends Component { ) } + case 'inputWord': + if(this.props.input != '' && this.props.input <= 20){ + return( + + ) + } else { + return( + + ) + } } } diff --git a/googletrendsgame/src/components/createRoomInput.js b/googletrendsgame/src/components/createRoomInput.js index cf51ed2..dcc90be 100644 --- a/googletrendsgame/src/components/createRoomInput.js +++ b/googletrendsgame/src/components/createRoomInput.js @@ -25,9 +25,11 @@ export default class CreateRoomInput extends Component { sendRoomData(event){ event.preventDefault(); - + console.log("sendRoomData called"); this.props.socket.emit('createRoom', {password: this.state.passwordFieldValue, capacity: this.state.capacityFieldValue}); this.setState({ passwordFieldValue: '', capacityFieldValue: '' }); + this.props.socket.emit('joinRoom', {}) + //this.props.goToRoom() } render(){ @@ -36,7 +38,7 @@ export default class CreateRoomInput extends Component { - + ) diff --git a/googletrendsgame/src/components/nicknameInput.js b/googletrendsgame/src/components/nicknameInput.js index ae3365f..83a66c5 100644 --- a/googletrendsgame/src/components/nicknameInput.js +++ b/googletrendsgame/src/components/nicknameInput.js @@ -19,6 +19,7 @@ export default class NicknameInput extends Component { event.preventDefault(); this.props.socket.emit('register', this.state.fieldValue); + console.log("Sent Registration.") this.setState({fieldValue: ''}) } diff --git a/googletrendsgame/src/components/wordInput.js b/googletrendsgame/src/components/wordInput.js index e57f8e4..3f88301 100644 --- a/googletrendsgame/src/components/wordInput.js +++ b/googletrendsgame/src/components/wordInput.js @@ -1,12 +1,44 @@ import React, {Component} from 'react'; +import ActiveButton from './activeButton'; -class wordInput extends Component { +export default class wordInput extends Component { constructor(props){ super(props); this.state={fieldValue:''} - //this.onInputChange = this.onInputChange.bind(this); - //this.onInputChange + this.onInputChange = this.onInputChange.bind(this); + this.onSubmit = this.onSubmit.bind(this); + } + + onInputChange(event){ + console.log(event.target.value) + this.setState({ fieldValue: event.target.value }); + } + + onSubmit(event){ + event.preventDefault(); + console.log(this.state.fieldValue); + this.props.socket.emit('submitWord', this.state.fieldValue); + this.setState({ + fieldValue: '' + }); + } + + render() { + if(this.props.active === 'true'){ + return( +
    + + + + +
    + ) + } else { + return( +

    Waiting for players...

    + ) + } } }