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
160 changes: 58 additions & 102 deletions rpg_game/src/components/MainGame/MainGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import createStreet from "../Maps/Street/StreetFunctions";
import createHouse from "../Maps/House/HouseFunctions";
import createGraveyard from "../Maps/Graveyard/GraveyardFunctions";
import { connect } from "react-redux";
import Pusher from "pusher-js";
import Node from "../Node/Node";
import {
makeStreetGrid,
Expand All @@ -24,9 +23,9 @@ import characterTwo from "../Node/images/character_two.png";
import characterThree from "../Node/images/character_three.png";
import characterFour from "../Node/images/character_four.png";
import characterFive from "../Node/images/character_five.png";
import Pusher from 'pusher-js';

// eslint-disable-next-line
let playerPosition;

const pusher = new Pusher("f2df1cd773bc785afe1e", {
cluster: "eu",
Expand All @@ -45,11 +44,10 @@ class MainGame extends React.Component {
};
}

componentWillMount = () => {
componentDidMount = () => {
this.createForest();
};


componentDidMount = () => {
window.addEventListener("keydown", e => {
this.handleKeyDown(e);
});
Expand Down Expand Up @@ -94,30 +92,18 @@ class MainGame extends React.Component {
const positionDown = this.props.grid[this.props.playerPosition.i + 1][
this.props.playerPosition.j
];
// if (positionDown.toForest) {
// this.createForest();
// }
// if (positionDown.toHouse) {
// this.createHouse();
// }
// if (positionDown.toGraveyard) {
// this.createGraveyard();
// }
// if (positionDown.exitStreet) {
// this.createStreet();
// }
if (
this.props.playerPosition.s_to !== 0 &&
!positionDown.treeOne &&
!positionDown.treeTwo &&
!positionDown.treeThree
!positionDown.treeThree &&
!positionDown.skeleton &&
!positionDown.grave &&
!positionDown.goldOne &&
!positionDown.goldStatue &&
!positionDown.darkTree
) {
const newGrid = this.movePlayer(
this.props.grid,
this.props.playerPosition.i + 1,
this.props.playerPosition.j
);
this.props.moveThePlayer(newGrid, positionDown, "s");
this.props.moveThePlayer("s");
}
return;
}
Expand All @@ -128,21 +114,18 @@ class MainGame extends React.Component {
const positionLeft = this.props.grid[this.props.playerPosition.i][
this.props.playerPosition.j - 1
];
// if (positionLeft.toForest) {
// this.createForest();
// }
if (
this.props.playerPosition.w_to !== 0 && // .neighbors.includes(positionLeft) was old code
!positionLeft.treeOne &&
!positionLeft.treeTwo &&
!positionLeft.treeThree
!positionLeft.treeThree &&
!positionLeft.skeleton &&
!positionLeft.grave &&
!positionLeft.goldOne &&
!positionLeft.goldStatue &&
!positionLeft.darkTree
) {
const newGrid = this.movePlayer(
this.props.grid,
this.props.playerPosition.i,
this.props.playerPosition.j - 1
);
this.props.moveThePlayer(newGrid, positionLeft, "w");
this.props.moveThePlayer("w");
}
return;
}
Expand All @@ -153,27 +136,18 @@ class MainGame extends React.Component {
const positionRight = this.props.grid[this.props.playerPosition.i][
this.props.playerPosition.j + 1
];
// if (positionRight.toForest) {
// this.createForest();
// }
// if (positionRight.toStreet) {
// this.createStreet();
// }
// if (positionRight.toGraveyard) {
// this.createGraveyard();
// }
if (
this.props.playerPosition.e_to !== 0 &&
!positionRight.treeOne &&
!positionRight.treeTwo &&
!positionRight.treeThree
!positionRight.treeThree &&
!positionRight.skeleton &&
!positionRight.grave &&
!positionRight.goldOne &&
!positionRight.goldStatue &&
!positionRight.darkTree
) {
const newGrid = this.movePlayer(
this.props.grid,
this.props.playerPosition.i,
this.props.playerPosition.j + 1
);
this.props.moveThePlayer(newGrid, positionRight, "e");
this.props.moveThePlayer("e");
}
return;
}
Expand All @@ -184,21 +158,18 @@ class MainGame extends React.Component {
const positionUp = this.props.grid[this.props.playerPosition.i - 1][
this.props.playerPosition.j
];
// if (positionUp.toStreet) {
// this.createStreet();
// }
if (
this.props.playerPosition.n_to !== 0 &&
!positionUp.treeOne &&
!positionUp.treeTwo &&
!positionUp.treeThree
!positionUp.treeThree &&
!positionUp.skeleton &&
!positionUp.grave &&
!positionUp.goldOne &&
!positionUp.goldStatue &&
!positionUp.darkTree
) {
const newGrid = this.movePlayer(
this.props.grid,
this.props.playerPosition.i - 1,
this.props.playerPosition.j
);
this.props.moveThePlayer(newGrid, positionUp, "n");
this.props.moveThePlayer("n");
}
return;
}
Expand All @@ -213,27 +184,15 @@ class MainGame extends React.Component {
};

createStreet = () => {
const streetGrid = createStreet([]);
this.props.makeStreetGrid(streetGrid);
grid = streetGrid;
playerPosition = grid[0][0];
document.querySelector(".grid").style.backgroundImage = `url(${street})`;
this.props.makeStreetGrid();
};

createHouse = () => {
const houseGrid = createHouse([]);
this.props.makeHouseGrid(houseGrid);
grid = houseGrid;
playerPosition = grid[0][0];
document.querySelector(".grid").style.backgroundImage = `url(${wood})`;
this.props.makeHouseGrid();
};

createGraveyard = () => {
const graveyardGrid = createGraveyard([]);
this.props.makeGraveyardGrid(graveyardGrid);
grid = graveyardGrid;
playerPosition = grid[0][0];
document.querySelector(".grid").style.backgroundImage = `url(${img})`;
this.props.makeGraveyardGrid();
};

movePlayer = (grid, i, j) => {
Expand All @@ -245,9 +204,6 @@ class MainGame extends React.Component {
};

render() {
if (this.props.grid) {
// console.log(this.props.grid);
}
return (
<StyledMainGame>
<button onClick={this.props.doLogOut}>Logout</button>
Expand Down Expand Up @@ -379,6 +335,7 @@ const StyledMainGame = styled.div`
margin: 20px;
width: 70%;
box-shadow: 0px 1.87781px 6.25935px rgba(0, 0, 0, 2.06);

}

.game-info {
Expand All @@ -395,43 +352,20 @@ const StyledMainGame = styled.div`
height: auto;
margin-bottom: 30px;
box-shadow: 0px 1.87781px 6.25935px rgba(0, 0, 0, 2.06);

h5 {
margin-top: 30px;
color: #fff;
font-size: 20px;
}

li {
margin-top: 10px;
color: #fff;
font-size: 13px;
}
}

.chat-space {
border: 2px solid #01134c;
width: 100%;
min-height: 250px;
height: auto;
box-shadow: 0px 1.87781px 6.25935px rgba(0, 0, 0, 2.06);
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 10px;

.message-view {
border: 1px solid white;
background: #fff;
flex: 1;
padding: 10px;

span {
color: black;
font-size: 12px;
}
}

.input-field {
margin-top: 20px;
input {
Expand All @@ -443,8 +377,31 @@ const StyledMainGame = styled.div`
color: #111;
}
}
button {
padding: 5px;
}
}

h5 {
margin-top: 30px;
color: #fff;
font-size: 20px;
}

li {
margin-top: 10px;
color: #fff;
font-size: 13px;
}
}

.chat-space {
border: 2px solid #01134c;
width: 100%;
min-height: 250px;
height: auto;
box-shadow: 0px 1.87781px 6.25935px rgba(0, 0, 0, 2.06);
}
}

.node {
Expand Down Expand Up @@ -484,4 +441,3 @@ export default connect(

const rows = 10;
const cols = 10;
let grid;
4 changes: 2 additions & 2 deletions rpg_game/src/components/Maps/Forest/ForestFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ const createNode = (i, j) => {
(i === 9 && j === 13) ||
(i === 9 && j === 14),
grave: i === 0 && j === 8,
goldOne: i === 0 && j === 9,
toStreet: i === 0 && j === 14,
goldOne: i === 0 && j === 7,
toStreet: i === 0 && j === 9,
toHouse: i === 9 && j === 3
// add other neccessary key value pairs for more functionality
};
Expand Down
40 changes: 38 additions & 2 deletions rpg_game/src/components/Maps/Street/StreetFunctions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const rows = 10;
const cols = 15;
const cols = 10;

const createStreet = (grid) => {
for (let i = 0; i < rows; i++) {
Expand All @@ -26,8 +26,44 @@ const createNode = (i, j) => {
start: i === 0 && j === 0, // create start point
neighbors: [],
goldStatue:
(i === 9 && j === 14) || (i === 0 && j === 14) || (i === 9 && j === 0),
(i === 3 && j === 9) || (i === 1 && j === 2) || (i === 9 && j === 0),
skeleton: i === 5 && j === 7,
darkTree:
(i === 0 && j === 1) ||
(i === 1 && j === 1) ||
(i === 2 && j === 1) ||
(i === 2 && j === 2) ||
(i === 2 && j === 3) ||
(i === 4 && j === 1) ||
(i === 5 && j === 1) ||
(i === 6 && j === 1) ||
(i === 7 && j === 1) ||
(i === 9 && j === 1) ||
(i === 9 && j === 2) ||
(i === 9 && j === 3) ||
(i === 9 && j === 4) ||
(i === 9 && j === 5) ||
(i === 4 && j === 2) ||
(i === 2 && j === 4) ||
(i === 2 && j === 6) ||
(i === 2 && j === 7) ||
(i === 2 && j === 8) ||
(i === 2 && j === 9) ||
(i === 4 && j === 3) ||
(i === 4 && j === 4) ||
(i === 4 && j === 6) ||
(i === 4 && j === 7) ||
(i === 4 && j === 8) ||
(i === 4 && j === 9) ||
(i === 1 && j === 6) ||
(i === 1 && j === 4) ||
(i === 5 && j === 4) ||
(i === 6 && j === 4) ||
(i === 5 && j === 6) ||
(i === 6 && j === 6)
,
grave: (i === 0 && j === 9),
goldOne: (i === 1 && j === 2),
toForest: i === 9 && j === 8
};
};
Expand Down
2 changes: 2 additions & 0 deletions rpg_game/src/store/actions/authenticationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const doLogIn = (user, history ) => dispatch => {
history.push("/character")
})
.catch(error => {
debugger

let errorMessage = error.response.data;
dispatch(genericAction(LOGIN_ERROR, errorMessage));
Expand All @@ -40,6 +41,7 @@ export const doSignUp = (user, history) => dispatch => {
axios
.post(`${appURL}/api/registration/`, user)
.then(response => {
debugger

const { key } = response.data;
localStorage.setItem("token", key);
Expand Down
Loading