Advertisement
Qpel

4prktnnnnn

Nov 20th, 2019
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. style.css:
  2.  
  3. * {
  4.   font-family: sans-serif;
  5.   margin: 0;
  6. }
  7. button {
  8.   height: 40px;
  9.   width: 200px;
  10.   margin: 10px;
  11. }
  12. .warning {
  13.   background-color: red;
  14.   text-align: center;
  15.   width: 100%;
  16.   padding: 10px;
  17.  
  18.   font-size: 14pt;
  19.   color: white;
  20. }
  21. .hide{
  22.     width: 30px;
  23.     height: 30px;
  24.     float: right;
  25. }
  26.  
  27.  
  28. body, html {
  29.   height: 100%;
  30.   width: 100%;
  31.  
  32. }
  33.  
  34.   .img {
  35.   background-image: url(../images/zemelapis.png);
  36.   background-repeat: no-repeat;
  37.   background-size: 1000px 1000px;
  38.   background-position: center;
  39.   height: 1000px;
  40.   justify-content: center;
  41.   position:relative;
  42.  
  43.  
  44.  
  45.  
  46.   }
  47.  
  48.  
  49.     .text {
  50.       font-family: Impact, Charcoal, sans-serif;
  51.       font-size: 22px;
  52.       letter-spacing: 1px;
  53.       word-spacing: 1.4px;
  54.       color: #E5B86C;
  55.       font-weight: normal;
  56.       text-decoration: none;
  57.       font-style: normal;
  58.       font-variant: normal;
  59.       text-transform: none;
  60.       }
  61.  
  62.  
  63.       .laivas {
  64.         content: url(../images/laivas.png);
  65.         position: absolute;
  66.        
  67.         top: 671px;
  68.         left: 855px;
  69.          width:200px;
  70.          height: 200px;
  71.         }
  72.  
  73.  
  74.        
  75.  
  76.  
  77.  
  78.  
  79. app:
  80.  
  81.  
  82. import React, {Component} from 'react'
  83.  
  84. class App extends Component {
  85.     constructor(props) {
  86.         super(props)
  87.         this.inputSelect = React.createRef()
  88.         this.onHandleCurrentCoordinate = this.onHandleCurrentCoordinate.bind(this)
  89.         this.state = {
  90.             isLoaded: false,
  91.             //shipLocation: [x: 0, y: 0],
  92.             value: '',
  93.             coordinates: []
  94.  
  95.     }
  96. }
  97.  
  98.  
  99.  
  100. componentDidMount(){
  101.     const result = {
  102.         actionType: 'start'
  103.     }
  104.    
  105.     fetch('http://localhost:3000/api/action', {
  106.         method: 'POST',
  107.         body: JSON.stringify(result)
  108.     })
  109.     .then(res => res.json())
  110.     .then(result => {
  111.         this.setState({
  112.             currentCoordinate: result
  113.         })
  114.     })
  115.  
  116. }
  117.  
  118. _onHandleAction(actionType, bonus = {}){
  119.     const result = {
  120.         actionType,
  121.         bonus
  122.     }
  123.    
  124.     fetch('http://localhost:3000/api/action', {
  125.         method: 'POST',
  126.         body: JSON.stringify(result)
  127.     })
  128.     .then(res => res.json())
  129.     .then(result => {
  130.         this.setState({
  131.             currentCoordinate: result
  132.         })
  133.     })
  134. }
  135.  
  136.  
  137.  
  138. onHandleCurrentCoordinate() {
  139.     const coordinateId = this.inputSelect.current.value//passiima values kelintas
  140.     const data = {coordinateId: coordinateId}
  141.     fetch("http://localhost:3000/api/coordinate", {
  142.         method: 'POST',
  143.         headers: {"Content-type": "application/json" },
  144.         body: JSON.stringify(data)
  145.     })
  146.     .then(res => res.json())
  147.     .then(result => {
  148.         this.setState({
  149.             isLoaded: false,
  150.             currentCoordinate: result
  151.         })
  152.     })
  153.     .catch(e => console.log(e))
  154. }
  155.  
  156.     render() {
  157.         const {currentCoordinate}  =this.state
  158.         return (
  159.             <div>              
  160.                
  161.             <div className="img">
  162.             <div className="laivas">  </div>
  163.            
  164.              <div className="text"> Žemėlapis </div>
  165.                
  166.                </div>
  167.             </div>
  168.         )
  169.     }
  170.    
  171. }
  172. export default App
  173.  
  174.  
  175.  
  176. gamecontroler:
  177.  
  178. const PathFinderServise = require('../services/PathFinderService')
  179.  
  180. class GameControler {
  181.     constructor() {
  182.         this.findCoordinate = this.findCoordinate.bind(this)
  183.         this.getPath = this.getPath.bind(this)
  184.  
  185.        
  186.  
  187.     }
  188.  
  189.     _shipCoordinates() {
  190.         return [
  191.             {id: 1, x: 671  , y: 855 ,entity:1, obsticle: false},
  192.             {id: 2, x: 580  , y: 834 , entity:1,obsticle: {bonus: {multiply: true}}}, // daugiklis x2
  193.             {id: 3, x: 494  , y: 784 , entity:1,obsticle: {penalty: {newgame: true}}}, // new game
  194.             {id: 4, x: 547  , y: 707 ,entity:1, obsticle: false},
  195.             {id: 5, x: 602  , y: 625 , entity:1,obsticle: {penalty: {test: true}}}, // testas prides +1
  196.             {id: 6, x: 499  , y: 601 , entity:1,obsticle: {bonus: {multiply: true }}},, // daugiklis x2
  197.             {id: 7, x: 400  , y: 623, entity:1, obsticle: false},
  198.             {id: 8, x: 315  , y: 583 ,entity:1, obsticle: false},
  199.             {id: 9, x: 285  , y: 501, entity:1, obsticle: false},
  200.             {id: 10, x:207  , y: 434 ,entity:1, obsticle: {penalty: {backstep: true}}}, //  3 zingsniai atgal
  201.             {id: 11, x: 248 , y: 346 , entity:2, obsticle: false},
  202.             {id: 12, x: 281 , y: 256  , entity:2, obsticle: false},
  203.             {id: 13, x: 343  ,y: 196 , entity:2, obsticle: false},
  204.             {id: 14, x: 436  , y:208   , entity:2, obsticle: false},
  205.             {id: 15, x: 540  , y:  216  ,entity:2   , obsticle: {penalty: {backstep: true}}}, //  3 zingsniai atgal
  206.             {id: 16, x: 630  , y: 193  ,entity:2   , obsticle: {penalty: {newgame: true}}},
  207.             {id: 17, x: 708  , y: 207 , entity:2 , obsticle: {bonus: {stepfurther: true }}}, // 2 zingsniai i prieki ( laimi zaidima )
  208.             {id: 18, x: 751  , y: 275  ,entity:2   , obsticle: {penalty: {test: true}}}, // testas
  209.             {id: 19, x: 806  , y: 323 , entity:2, obsticle: false},
  210.         ]
  211.     }
  212.  
  213.  
  214.     findCoordinate(req, res, next) {
  215.         const coordinateId = parseInt(req.body.coordinateId) || 0
  216.         const coordinates = this._shipCoordinates()
  217.         const amount = coordinates.length
  218.         let result = {}
  219.         for (let i = 0; i < amount; i++) {
  220.             let coordinate = coordinates[i]
  221.             if (coordinate.id == coordinateId) {
  222.                 result = coordinate
  223.                 break
  224.             }
  225.         }
  226.     }
  227.  
  228.  
  229.    
  230.     _dice(){
  231.         return  Math.floor(Math.random() * 6) + 1;
  232.     }
  233.     getPath(req, res, next) {
  234.         let newPosition = 0
  235.         let dice = this._dice()
  236.         let activePosition = dice
  237.         let bonus = '-5'
  238.         let amount = 19
  239.        
  240.         activePosition = parseInt(activePosition)
  241.         bonus = parseInt(bonus)
  242.         const actionType = 'dice'
  243.         //const actionType = req.body.actionType
  244.         if(actionType == 'dice') {
  245.             //turi kviesti dice funckija ir ispausdinti kiek gavo back ende skaicius i front enda
  246.             newPosition = dice
  247.             //console.log(newPosition)
  248.         } else if (actionType == 'bonus') {
  249.             newPosition = activePosition + (bonus)
  250.            // console.log(newPosition)
  251.         }
  252.         const pathFinderService = new PathFinderServise(dice, activePosition, amount, this._shipCoordinates())
  253.         const result = pathFinderService.getPath()
  254.         return res.json(result)
  255.     }
  256. }
  257.  
  258. module.exports = GameControler
  259.  
  260.  
  261. pathfinderservice:
  262.  
  263.  
  264. class PathFinderServise {
  265.     constructor(dice, activePosition, amount, coordinates){
  266.         this._dice = dice
  267.         this._activePosition = activePosition
  268.         this._amount = amount
  269.         this._coordinates = coordinates
  270.     }
  271.  
  272.     getPath() {
  273.       const lastPosition = this._getLastPosition()
  274.       const activePath = this._getActivePath(lastPosition)
  275.       return activePath
  276.     }
  277.    
  278.     _getLastPosition() {
  279.         let lastPosition = this._activePosition + this._dice
  280.         if (lastPosition > this._amount) lastPosition = this._amount//sitas isijungia tik jei virsyja
  281.         else if(lastPosition < 1) lastPosition = 1 //kas neitu i minusa bet i pirma laukeli
  282.         return lastPosition//current 3 dice 2 = 5
  283.     }
  284.  
  285.     _getActivePath(req, res, next) {
  286.  
  287.        //console.log(this._coordinates)
  288.         let result = {}
  289.         for (let i = 0; i < this._amount; i++) {
  290.             let coordinate = this._coordinates[i]
  291.             if (coordinate.id == this._activePosition) {
  292.                 result = coordinate
  293.                 break
  294.             }
  295.         }
  296.         //console.log(result)
  297.         return result
  298.     }
  299.  
  300. }
  301. module.exports = PathFinderServise
  302.  
  303.  
  304.  
  305. routes:
  306.  
  307. const GameControler = require('./controllers/GameControler')
  308. const gameControler = new GameControler()
  309.  
  310. module.exports = (app) => {
  311.     app.get('/', (req, res) => {
  312.         res.render('home')
  313.     })
  314.     app.get('/', gameControler.getPath)
  315.     app.get('/api/', gameControler.getPath)
  316.     app.post('/api/', gameControler.getPath)
  317.     return app
  318. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement