Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gamecontroler:
- class GameControler {
- constructor() {
- this.getUsers = this.getUsers.bind(this)
- this.findUser = this.findUser.bind(this)
- this.getCurrentPath = this.getCurrentPath.bind(this)
- this._diceNumber = this._diceNumber.bind(this)
- }
- _diceNumber(){
- return Math.floor(Math.random() * this.props.sides.length);
- }
- _usersList() {
- return [
- {id: 1, x: '100', y: '50', },
- {id: 2, x: '200', y: '100', obsticle: {
- bonus: {
- stepfurther: 1
- }
- }},
- {id: 3, x: '300', y: '200', obsticle: {
- penelty: {
- backstep: 2
- },
- }},
- {id: 3, x: '400', y: '250'},
- {id: 4, x: '500', y: '300'},
- {id: 5, x: '600', y: '350'},
- {id: 6, x: '700', y: '400'},
- {id: 7, x: '800', y: '450'},
- {id: 8, x: '900', y: '500'},
- {id: 9, x: '1000', y: '550'},
- ]
- }
- getUsers(req, res, next){
- const users = this._usersList()
- return res.json(users)
- }
- findUser(req, res, next) {
- const userId = parseInt(req.body.userId) || 0
- const users = this._usersList()
- const amount = users.length
- let result = {}
- for (let i = 0; i < amount; i++) {
- let user = users[i]
- if (user.id == userId) {
- result = user
- break
- }
- }
- const dice = 1
- const activePosition = 3
- const ammount = 19
- console.log(activePosition)
- return res.json(result)
- }
- getCurrentPath(){
- const dice = 2
- const activePosition = 3
- const amount = 19
- const pathFinderService = new pathFinderService(dice, activePosition, amount)
- const result = pathFinderService.getPath()
- console.log(dice)
- return res.json(result)
- }
- }
- module.exports = GameControler
- app:
- import React, {Component} from 'react'
- class App extends Component {
- constructor(props) {
- super(props)
- this.inputSelect = React.createRef()
- this.onHandleCurrentUser = this.onHandleCurrentUser.bind(this)
- this.state = {
- isLoaded: false,
- //shipLocation: [x: 0, y: 0],
- value: '',
- users: [],
- activeCoordinates: result
- }
- }
- onHandleCurrentUser() {
- const userId = this.inputSelect.current.value//passiima values kelintas
- const data = {userId: userId}
- fetch("http://localhost:3000/api/user", {
- method: 'POST',
- headers: {"Content-type": "application/json" },
- body: JSON.stringify(data)
- })
- .then(res => res.json())
- .then(result => {
- this.setState({
- isLoaded: false,
- currentUser: result
- })
- })
- .catch(e => console.log(e))
- }
- render() {
- const {currentUser} = this.state
- return (
- <div>
- <input type="number" ref={this.inputSelect}></input>
- <button onClick={this.onHandleCurrentUser}>Gauti pasirinkta koordinate</button>
- <div>
- {
- currentUser && <div>coordinate: {currentUser.id} x: {currentUser.x} y: {currentUser.y} obsticle: {currentUser.obsticle} bcv: {currentUser._diceNumber()}</div>
- }
- </div>
- </div>
- )
- }
- }
- export default App
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement