Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["es2015","react","stage-0","stage-2"],
"plugins": ["react-hot-loader/babel"]
"presets": ["es2015", "react", "stage-0", "stage-2"],
"plugins": ["react-hot-loader/babel"]
}
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
## Development

* npm install
* npm run start-dev
* localhost:4445
- npm install
- npm run start-dev
- localhost:4445

## Production

* npm install
* npm run all
* localhost:4445
- npm install
- npm run all
- localhost:4445

demo users:

- amitush 123
- deanush 234
- avivush 345
- amitush 123
- deanush 234
- avivush 345
19 changes: 11 additions & 8 deletions dev/app/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export const DICING = "DICING";
//export const SET_TURN = "SET_TURN";
//export const INIT_STATE = "INIT_STATE";

export const switchTurn = () => ({type:SWITCH_TURN});
export const switchTurn = () => ({ type: SWITCH_TURN });
//export const initState = () => ({type:INIT_STATE});
export const step = step => ({type:STEP, content: step});
export const dice = dicesResult => ({type:DICING, content: dicesResult});
export const step = (step) => ({ type: STEP, content: step });
export const dice = (dicesResult) => ({ type: DICING, content: dicesResult });
//export const setTurn = isClientTurn => ({type:SET_TURN, content:isClientTurn});

export const LOG_IN = "LOG_IN";
Expand All @@ -16,8 +16,11 @@ export const SEARCH_OPPONENT = "SEARCH_OPPONENT";
export const SRART_GAME = "SRART_GAME";
export const OPPONENT_RETIRED = "OPPONENT_RETIRED";

export const login = user => ({type:LOG_IN, content: user});
export const logout = () => ({type:LOG_OUT});
export const searchOpponent = () => ({type:SEARCH_OPPONENT});
export const startGame = (isClientStart, opponentInfo) => ({type:SRART_GAME, content:{isClientStart, opponentInfo}});
export const opponentRetirment = () => ({type:OPPONENT_RETIRED});
export const login = (user) => ({ type: LOG_IN, content: user });
export const logout = () => ({ type: LOG_OUT });
export const searchOpponent = () => ({ type: SEARCH_OPPONENT });
export const startGame = (isClientStart, opponentInfo) => ({
type: SRART_GAME,
content: { isClientStart, opponentInfo },
});
export const opponentRetirment = () => ({ type: OPPONENT_RETIRED });
33 changes: 17 additions & 16 deletions dev/app/components/App/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import React from 'react'
import MainPage from '../MainPage'
import PrivateRoute from '../../containers/PrivateRoute'
import Login from '../../containers/Login'
import React from "react";
import MainPage from "../MainPage";
import PrivateRoute from "../../containers/PrivateRoute";
import Login from "../../containers/Login";

import { Link, Redirect } from 'react-router-dom'
import { Router, Switch, Route } from 'react-router'
import createBrowserHistory from 'history/createBrowserHistory'
import { Link, Redirect } from "react-router-dom";
import { Router, Switch, Route } from "react-router";
import createBrowserHistory from "history/createBrowserHistory";

const history = createBrowserHistory()
const history = createBrowserHistory();

const App = () =>
<Router history={history}>
<Switch>
<PrivateRoute path="/main" component={MainPage} history={history}/>
<Route component={Login}/>
</Switch>
</Router>
const App = () => (
<Router history={history}>
<Switch>
<PrivateRoute path="/main" component={MainPage} history={history} />
<Route component={Login} />
</Switch>
</Router>
);

export default App
export default App;
81 changes: 46 additions & 35 deletions dev/app/components/GameZone/index.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,59 @@
import React from 'react';
import Game from '../game/Game'
import { PLAY_STATUS, IN_GAME_STATUS } from '../../constants'
import { Segment, Header } from 'semantic-ui-react'
import style from './style.css'

const GameZome = ({inGameStatus, playStatus, play, stopSearch}) => {
import React from "react";
import Game from "../game/Game";
import { PLAY_STATUS, IN_GAME_STATUS } from "../../constants";
import { Segment, Header } from "semantic-ui-react";
import style from "./style.css";

const GameZome = ({ inGameStatus, playStatus, play, stopSearch }) => {
let message;
let onClickAction;
let buttonLabel;

switch (playStatus){
case PLAY_STATUS.PLAY:{
return <Game/>
}
case PLAY_STATUS.SEARCH_OPPONENT:{
message = "Wait for another player"
onClickAction = stopSearch
buttonLabel = "stop search"
switch (playStatus) {
case PLAY_STATUS.PLAY: {
return <Game />;
}
case PLAY_STATUS.SEARCH_OPPONENT: {
message = "Wait for another player";
onClickAction = stopSearch;
buttonLabel = "stop search";
break;
}
case PLAY_STATUS.OPPONENT_RETIRED:{
message = "The player retired. For Search a new player:"
onClickAction = play
buttonLabel = "search"
}
case PLAY_STATUS.OPPONENT_RETIRED: {
message = "The player retired. For Search a new player:";
onClickAction = play;
buttonLabel = "search";
break;
}
case PLAY_STATUS.NOT_PLAY:{
onClickAction = play
buttonLabel = "play"
}
case PLAY_STATUS.NOT_PLAY: {
onClickAction = play;
buttonLabel = "play";

if (inGameStatus == IN_GAME_STATUS.WINNER || inGameStatus == IN_GAME_STATUS.LOSER){
message = `You are the ${inGameStatus} of the game. For play again: `
}else{
message = `For search opponent: `
if (
inGameStatus == IN_GAME_STATUS.WINNER ||
inGameStatus == IN_GAME_STATUS.LOSER
) {
message = `You are the ${inGameStatus} of the game. For play again: `;
} else {
message = `For search opponent: `;
}
break;
}
}
}
}

return <Segment textAlign="center" style={{backgroundColor: 'inherit', height:'100%'}}>
<Header textAlign="left" size='large'>{message}</Header>
<button className={style.actionButtom }onClick={onClickAction}>{buttonLabel}</button>
</Segment>
}
return (
<Segment
textAlign="center"
style={{ backgroundColor: "inherit", height: "100%" }}
>
<Header textAlign="left" size="large">
{message}
</Header>
<button className={style.actionButtom} onClick={onClickAction}>
{buttonLabel}
</button>
</Segment>
);
};

export default GameZome;
34 changes: 16 additions & 18 deletions dev/app/components/Loading/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import React, {Component} from 'react';
import React, { Component } from "react";

class Loading extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
};
}

constructor(props){
super(props)
this.state = {
loading: true
};
}
render() {
const { loading } = this.state;

render(){
const {loading} = this.state;

return (this.state.loading?
<div>
{this.props.message}
</div>
:this.props.children
)
}
return this.state.loading ? (
<div>{this.props.message}</div>
) : (
this.props.children
);
}
}

export default Loading
export default Loading;
133 changes: 77 additions & 56 deletions dev/app/components/Login/LoginForm.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,96 @@
import React, { Component } from 'react'
import { Form, Message } from 'semantic-ui-react'
import axios from 'axios'
import React, { Component } from "react";
import { Form, Message } from "semantic-ui-react";
import axios from "axios";

class LoginForm extends Component {
constructor(props) {
super(props)
this.state = { formData:{playAsGuest:true,username:"amitush",password:"123"},
isServerChecking:false,
actionFailed:false};
super(props);
this.state = {
formData: { playAsGuest: true, username: "amitush", password: "123" },
isServerChecking: false,
actionFailed: false,
};
}

handleChangeField = (e, { name, value }) => this.setState({formData:{ ...this.state.formData, [name]: value }})
handleChangeField = (e, { name, value }) =>
this.setState({ formData: { ...this.state.formData, [name]: value } });

handleLogin(e){
handleLogin(e) {
e.preventDefault();
this.setState({isServerChecking:true});
this.setState({ isServerChecking: true });

axios.post('/login', this.state.formData)
.then(res => {
axios
.post("/login", this.state.formData)
.then((res) => {
this.props.login(res.data.user);
history.push('/');
history.push("/");
})
.catch(err => {
this.setState({isServerChecking:false,actionFailed:true,message:err.message});
.catch((err) => {
this.setState({
isServerChecking: false,
actionFailed: true,
message: err.message,
});
});

}

toggle = (name) => () => this.setState({formData:{ ...this.state.formData, [name]: !this.state.formData[name] }})

toggle = (name) => () =>
this.setState({
formData: { ...this.state.formData, [name]: !this.state.formData[name] },
});

render() {
const { username, password, playAsGuest } = this.state.formData;

const {username, password, playAsGuest} = this.state.formData;

return <Form onSubmit={::this.handleLogin} inverted
error={this.state.actionFailed}>
<Form.Checkbox
name="playAsGuest"
label='play as guest'
checked={playAsGuest}
onChange={::this.toggle("playAsGuest")}/>
<Form.Input
name="username"
label="Username"
icon='user'
iconPosition='left'
placeholder='Username'
value={username}
onChange={::this.handleChangeField}
required />
<Form.Input
name="password"
label="Password"
icon='lock'
type="password"
iconPosition='left'
placeholder='Password'
value={password}
onChange={::this.handleChangeField}
disabled={playAsGuest}
required={!playAsGuest}/>
<Form.Button type='submit' color='green'
loading={this.state.isServerChecking}>Login</Form.Button>
<Message
error
header='Logging was failed'
content={this.state.message}
/>
</Form>
return (
<Form
onSubmit={::this.handleLogin}
inverted
error={this.state.actionFailed}
>
<Form.Checkbox
name="playAsGuest"
label="play as guest"
checked={playAsGuest}
onChange={::this.toggle("playAsGuest")}
/>
<Form.Input
name="username"
label="Username"
icon="user"
iconPosition="left"
placeholder="Username"
value={username}
onChange={::this.handleChangeField}
required
/>
<Form.Input
name="password"
label="Password"
icon="lock"
type="password"
iconPosition="left"
placeholder="Password"
value={password}
onChange={::this.handleChangeField}
disabled={playAsGuest}
required={!playAsGuest}
/>
<Form.Button
type="submit"
color="green"
loading={this.state.isServerChecking}
>
Login
</Form.Button>
<Message
error
header="Logging was failed"
content={this.state.message}
/>
</Form>
);
}
}

export default LoginForm
export default LoginForm;
Loading