Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const PathFinderServise = require('../services/PathFinderService')
- class GameControler {
- constructor() {
- this.findCoordinate = this.findCoordinate.bind(this)
- this.getPath = this.getPath.bind(this)
- }
- _shipCoordinates() {
- return [
- {id: 1, x: 660 , y: 730 ,entity:1, obsticle: false},
- {id: 2, x: 530 , y: 730 , entity:1,obsticle: {bonus: {multiply: true}}}, // daugiklis x2
- {id: 3, x: 440 , y: 700 , entity:1,obsticle: {penalty: {newgame: true}}}, // new game
- {id: 4, x: 495 , y: 610 ,entity:1, obsticle: false},
- {id: 5, x: 540 , y: 530 , entity:1,obsticle: {penalty: {test: true}}}, // testas prides +1
- {id: 6, x: 440 , y: 510 , entity:1,obsticle: {bonus: {multiply: true }}},, // daugiklis x2
- {id: 7, x: 345 , y: 520, entity:1, obsticle: false},
- {id: 8, x: 250 , y: 490 ,entity:1, obsticle: false},
- {id: 9, x: 230 , y: 405, entity:1, obsticle: false},
- {id: 10, x: 150 , y: 340 ,entity:1, obsticle: {penalty: {backstep: true}}}, // 3 zingsniai atgal
- {id: 11, x: 190 , y: 260 , entity:2, obsticle: false},
- {id: 12, x: 230 , y: 170 , entity:2, obsticle: false},
- {id: 13, x: 280 ,y: 110 , entity:2, obsticle: false},
- {id: 14, x: 270 , y: 120 , entity:2, obsticle: false},
- {id: 15, x: 480 , y: 130 ,entity:2 , obsticle: {penalty: {backstep: true}}}, // 3 zingsniai atgal
- {id: 16, x: 565 , y: 100 ,entity:2 , obsticle: {penalty: {newgame: true}}},
- {id: 17, x: 650 , y: 120 , entity:2 , obsticle: {bonus: {stepfurther: true }}}, // 2 zingsniai i prieki ( laimi zaidima )
- {id: 18, x: 690 , y: 180 ,entity:2 , obsticle: {penalty: {test: true}}}, // testas
- {id: 19, x: 740 , y: 240 , entity:2, obsticle: false},
- ]
- }
- findCoordinate(req, res, next) {
- const coordinateId = parseInt(req.body.coordinateId) || 0
- const coordinates = this._shipCoordinates()
- const amount = coordinates.length
- let result = {}
- for (let i = 0; i < amount; i++) {
- let coordinate = coordinates[i]
- if (coordinate.id == coordinateId) {
- result = coordinate
- break
- }
- }
- }
- _onHandleBonus(actionType, bonus = {}) {
- bonus = {steps: -3, activePosition: 3}
- actionType = 'bonus'
- const result = {
- actionType,
- bonus
- }
- fetch('http://localhost:3000/api/coordinate', {
- method: 'POST' ,
- body: JSON.stringify(result)
- })
- .then(res => res.json() )
- .then(result => {
- this.setState({
- currentCoordinate: result + (bonus)
- })
- })
- }
- componentDidUpdate(prevProps, prevState) {
- const {newPosition} = this.props;
- if (prevProps.activePosition !== newPosition) {
- const {coordinate} = prevState;
- console.log('${prevProps.activePosition} keliaujate i ${newPosition}');
- }
- }
- _dice(){
- return Math.floor(Math.random() * 6) + 1;
- }
- getPath(req, res, next) {
- let newPosition = 0
- let dice = 2
- let activePosition = '3'
- let bonus = '-3'
- let amount = 19
- activePosition = parseInt(activePosition)
- bonus = parseInt(bonus)
- const actionType = req.body.actionType
- if(actionType == 'dice') {
- //turi kviesti dice funckija ir ispausdinti kiek gavo back ende skaicius i front enda
- newPosition = this._dice()
- } else if (actionType == 'bonus') {
- newPosition = activePosition + (bonus)
- }
- const pathFinderService = new PathFinderServise(dice, activePosition, amount)
- const result = pathFinderService.getPath()
- console.log(result)
- return res.json(result)
- }
- }
- module.exports = GameControler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement