heroku deploy and added moving pawns
This commit is contained in:
parent
981b5fd032
commit
57358b0105
1
.env.development
Normal file
1
.env.development
Normal file
@ -0,0 +1 @@
|
||||
HOST=smaga-wiktor-ludo.herokuapp.com
|
||||
@ -1,5 +1,6 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
const RoomModel = require('../schemas/room');
|
||||
|
||||
function setNextPlayer(req, res){
|
||||
RoomModel.findOne({_id: req.session.roomId}, function (err, doc){
|
||||
@ -20,11 +21,58 @@ function setNextPlayer(req, res){
|
||||
}
|
||||
|
||||
router.get('/roll', function (req, res){
|
||||
res.send({number: Math.ceil(Math.random() * 6)});
|
||||
const rolledNumber = Math.ceil(Math.random() * 6);
|
||||
req.session.rolledNumber = rolledNumber;
|
||||
res.send({number: rolledNumber});
|
||||
});
|
||||
|
||||
router.post('/move', function (req, res){
|
||||
|
||||
router.post('/move', async function (req, res){
|
||||
const rolledNumber = req.session.rolledNumber;
|
||||
req.session.rolledNumber = null;
|
||||
const room = await RoomModel.findOne({_id: req.session.roomId});
|
||||
console.log(room);
|
||||
const indexOfMovedPawn = room.pawns.findIndex( pawn => pawn._id === req.body.pawnId);
|
||||
let { position } = room.pawns[indexOfMovedPawn];
|
||||
switch (req.session.color){
|
||||
case 'red':
|
||||
if(position >= 0 && position <= 3){
|
||||
position = 4;
|
||||
}else if(position > 15 && position + rolledNumber <= 66){
|
||||
position = position + rolledNumber;
|
||||
}else{
|
||||
position = 67 + (position + rolledNumber - 66);
|
||||
}
|
||||
break;
|
||||
case 'blue':
|
||||
if(position >= 4 && position <= 7){
|
||||
position = 55;
|
||||
}else if(position+rolledNumber>55 || position+rolledNumber <= 53){
|
||||
position = position + rolledNumber;
|
||||
}else{
|
||||
position = 71 + (position + rolledNumber - 53);
|
||||
}
|
||||
break;
|
||||
case 'green':
|
||||
if(pawn.position >= 8 && pawn.position <= 11){
|
||||
position = 42;
|
||||
}else if(position + rolledNumber > 42 || position+rolledNumber <= 40){
|
||||
position = position + rolledNumber;
|
||||
}else{
|
||||
position = 76 - (position + rolledNumber - 40)
|
||||
}
|
||||
break;
|
||||
case 'yellow':
|
||||
if(pawn.position >= 12 && pawn.position <= 15){
|
||||
return 29;
|
||||
}else if(position + rolledNumber > 29 || position+rolledNumber <= 27){
|
||||
position = position + rolledNumber;
|
||||
}else{
|
||||
position = 82 + (position + rolledNumber - 27)
|
||||
}
|
||||
break;
|
||||
}
|
||||
RoomModel.findOneAndUpdate({_id: req.session.roomId, 'pawnw._id': req.body.pawnId}, room);
|
||||
res.send("Correctly Moved!");
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ router.post('/ready', function (req, res){
|
||||
|
||||
//deleting user in case he left before game started
|
||||
router.post('/exit', function(req,res){
|
||||
changeReadyState(req,res, true)
|
||||
// changeReadyState(req,res, true)
|
||||
});
|
||||
|
||||
//return session data
|
||||
|
||||
@ -26,7 +26,7 @@ const mongoose = require("mongoose");
|
||||
mongoose.set('useFindAndModify', false);
|
||||
const CONNECTION_URI = require("./credentials.js").MONGODB_URL;
|
||||
|
||||
mongoose.connect(CONNECTION_URI, {
|
||||
mongoose.connect(process.env.MONGODB_URL || CONNECTION_URI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true
|
||||
})
|
||||
@ -51,6 +51,10 @@ app.use(session({
|
||||
secure: false,},
|
||||
}));
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
app.use(express.static('../build'))
|
||||
}
|
||||
|
||||
//ROUTES CONFIG
|
||||
const roomRoutes = require("./routes/room");
|
||||
const playerRoutes = require("./routes/player");
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"heroku-postbuild": "cd backend && npm install && cd .. && npm install && npm run build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
@ -39,5 +40,5 @@
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"proxy": "http://localhost:3000"
|
||||
"proxy": "http://localhost:5000"
|
||||
}
|
||||
|
||||
@ -57,11 +57,12 @@ function App() {
|
||||
<NameInput idCallback = {idCallback}/>
|
||||
</Route>
|
||||
<Route path="/game">
|
||||
{playerData ?
|
||||
<Beforeunload onBeforeunload={handleExit}>
|
||||
<PlayerDataContext.Provider value={playerData}>
|
||||
<Gameboard/>
|
||||
</PlayerDataContext.Provider>
|
||||
</Beforeunload>
|
||||
</Beforeunload> : null}
|
||||
</Route>
|
||||
</Switch>
|
||||
</Router>
|
||||
|
||||
@ -37,6 +37,7 @@ const Gameboard = () => {
|
||||
setNowMoving(false);
|
||||
}
|
||||
}
|
||||
console.log(nowMoving);
|
||||
setPlayers(response.data.players);
|
||||
setPawns(response.data.pawns);
|
||||
setTime(response.data.nextMoveTime);
|
||||
|
||||
@ -34,7 +34,7 @@ const Map = ({ pawns, nowMoving, rolledNumber }) => {
|
||||
axios.post('http://localhost:3000/game/move', {
|
||||
withCredentials: true,
|
||||
mode: 'cors',
|
||||
data: {_id: pawn._id}
|
||||
data: {pawnId: pawn._id}
|
||||
});
|
||||
setHintPawn(null);
|
||||
}
|
||||
@ -52,6 +52,8 @@ const Map = ({ pawns, nowMoving, rolledNumber }) => {
|
||||
case 'red':
|
||||
if(pawn.position >= 0 && pawn.position <= 3){
|
||||
return 16;
|
||||
}else if(pawn.position>15 && pawn.position<67){
|
||||
return pawn.position + rolledNumber
|
||||
}
|
||||
break;
|
||||
case 'blue':
|
||||
@ -80,6 +82,7 @@ const Map = ({ pawns, nowMoving, rolledNumber }) => {
|
||||
x = event.clientX - rect.left,
|
||||
y = event.clientY - rect.top;
|
||||
canvas.style.cursor = "default";
|
||||
console.log("Ruszam się")
|
||||
for (const pawn of pawns){
|
||||
if(pawn.circle){
|
||||
/*
|
||||
|
||||
@ -33,7 +33,7 @@ const positions = [
|
||||
{x: 200, y: 45},
|
||||
{x: 200, y: 14},
|
||||
// Top
|
||||
{x: 230, y: 14},
|
||||
{x: 230, y: 14}, //25
|
||||
{x: 261, y: 14},
|
||||
{x: 261, y: 45},
|
||||
{x: 261, y: 76},
|
||||
@ -55,14 +55,14 @@ const positions = [
|
||||
{x: 383, y: 261},
|
||||
{x: 352, y: 261},
|
||||
{x: 321, y: 261},
|
||||
{x: 291, y: 261},
|
||||
{x: 291, y: 261}, //44
|
||||
|
||||
{x: 261, y: 291},
|
||||
{x: 261, y: 322},
|
||||
{x: 261, y: 353},
|
||||
{x: 261, y: 384},
|
||||
{x: 261, y: 414},
|
||||
{x: 261, y: 445},
|
||||
{x: 261, y: 445},
|
||||
// Bottom
|
||||
{x: 230, y: 445},
|
||||
|
||||
@ -74,42 +74,42 @@ const positions = [
|
||||
{x: 200, y: 291},
|
||||
|
||||
{x: 169, y: 261},
|
||||
{x: 138, y: 261},
|
||||
{x: 138, y: 261}, //59
|
||||
{x: 107, y: 261},
|
||||
{x: 76, y: 261},
|
||||
{x: 45, y: 261},
|
||||
|
||||
{x: 15, y: 261},
|
||||
// Left
|
||||
{x: 15, y: 231},
|
||||
{x: 15, y: 231}, //64
|
||||
// One behind red base
|
||||
{x: 15, y: 200},
|
||||
{x: 15, y: 200}, //65
|
||||
// Red end
|
||||
{x: 45, y: 231},
|
||||
{x: 45, y: 231}, //66
|
||||
{x: 76, y: 231},
|
||||
{x: 107, y: 231},
|
||||
{x: 138, y: 231},
|
||||
{x: 169, y: 231},
|
||||
// Blue end
|
||||
{x: 231, y: 445},
|
||||
{x: 231, y: 445}, //71
|
||||
{x: 231, y: 414},
|
||||
{x: 231, y: 384},
|
||||
{x: 231, y: 353},
|
||||
{x: 231, y: 353}, //74
|
||||
{x: 231, y: 322},
|
||||
{x: 231, y: 291},
|
||||
// Green end
|
||||
{x: 414, y: 231},
|
||||
{x: 414, y: 231}, // 77
|
||||
{x: 383, y: 231},
|
||||
{x: 352, y: 231},
|
||||
{x: 321, y: 231},
|
||||
{x: 290, y: 231},
|
||||
// Yellow base
|
||||
{x: 230, y: 15},
|
||||
{x: 230, y: 15}, //82
|
||||
{x: 230, y: 45},
|
||||
{x: 230, y: 76},
|
||||
{x: 230, y: 107},
|
||||
{x: 230, y: 138},
|
||||
{x: 230, y: 169},
|
||||
{x: 230, y: 169}, //87
|
||||
];
|
||||
|
||||
export default positions;
|
||||
Loading…
Reference in New Issue
Block a user