Skip to content
Snippets Groups Projects
Commit fa2bccf9 authored by Taha's avatar Taha
Browse files

faciiiiiiiiiiiiiiiiile

parent 6c9c1316
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ class Game extends Component { ...@@ -29,7 +29,7 @@ class Game extends Component {
playerId: this.props.playerId, playerId: this.props.playerId,
gameId: this.props.gameId, gameId: this.props.gameId,
errorMessage: 'No error', errorMessage: 'No error',
gameState: 'Building Phase', gameState: 'Waiting for players',
turn: 'Players take turns once all ships are placed', turn: 'Players take turns once all ships are placed',
endGame: false, endGame: false,
API_URL: this.props.backendUrl + "/api/game/", API_URL: this.props.backendUrl + "/api/game/",
...@@ -226,6 +226,12 @@ class Game extends Component { ...@@ -226,6 +226,12 @@ class Game extends Component {
console.log("Game Over"); console.log("Game Over");
} }
if (data.isBuildPhase){
if (data.player1Id != 0 && data.player2Id != 0){
this.setState({gameState: "Building Phase"});
}
}
if (!data.isBuildPhase){ if (!data.isBuildPhase){
this.setState({gameState: "Attacking Phase"}); this.setState({gameState: "Attacking Phase"});
this.player.mode = 0; this.player.mode = 0;
...@@ -341,12 +347,6 @@ class Game extends Component { ...@@ -341,12 +347,6 @@ class Game extends Component {
shipSelection = 4; shipSelection = 4;
} }
} }
if (event.code == 'Digit5') {
if (!this.player.ships[4].isSetup) {
this.player.tpUnsetShips(4);
shipSelection = 5;
}
}
if (event.code == 'KeyR') { if (event.code == 'KeyR') {
this.player.hoverRotation += 1; this.player.hoverRotation += 1;
if (this.player.hoverRotation > 1) this.player.hoverRotation = 0; if (this.player.hoverRotation > 1) this.player.hoverRotation = 0;
...@@ -381,6 +381,7 @@ class Game extends Component { ...@@ -381,6 +381,7 @@ class Game extends Component {
console.log(ship); console.log(ship);
let shipOriginIndexs = this.board.getPointedTile(this.camera); let shipOriginIndexs = this.board.getPointedTile(this.camera);
if (shipOriginIndexs.x != -1 && shipOriginIndexs.z != -1) { if (shipOriginIndexs.x != -1 && shipOriginIndexs.z != -1) {
// lock ship to grid
ship.position.x = shipOriginIndexs.x; ship.position.x = shipOriginIndexs.x;
ship.position.z = shipOriginIndexs.z; ship.position.z = shipOriginIndexs.z;
ship.rotation = this.player.hoverRotation; ship.rotation = this.player.hoverRotation;
...@@ -389,6 +390,7 @@ class Game extends Component { ...@@ -389,6 +390,7 @@ class Game extends Component {
const y = shipOriginIndexs.z; const y = shipOriginIndexs.z;
const horizontalOrientation = this.player.hoverRotation ? "false" : "true"; const horizontalOrientation = this.player.hoverRotation ? "false" : "true";
const shipType = ship.index - 1; const shipType = ship.index - 1;
// send request to server
fetch(this.state.API_URL + this.props.gameId + '/ship/' + this.props.playerId + '?x=' + x + '&y=' + y + '&horizontalOrientation=' + horizontalOrientation + '&shipType=' + shipType, { fetch(this.state.API_URL + this.props.gameId + '/ship/' + this.props.playerId + '?x=' + x + '&y=' + y + '&horizontalOrientation=' + horizontalOrientation + '&shipType=' + shipType, {
method: 'POST' method: 'POST'
}) })
...@@ -424,7 +426,6 @@ class Game extends Component { ...@@ -424,7 +426,6 @@ class Game extends Component {
else { else {
// get the tile that the player is pointing at // get the tile that the player is pointing at
const indexes = this.ennemyBoard.getPointedTile(this.camera); const indexes = this.ennemyBoard.getPointedTile(this.camera);
console.log(indexes);
if (indexes.x != -1 && indexes.z != -1) { if (indexes.x != -1 && indexes.z != -1) {
const tile = this.ennemyBoard.getTileByIndex(indexes); const tile = this.ennemyBoard.getTileByIndex(indexes);
fetch(this.state.API_URL + this.props.gameId + '/shoot/' + this.props.playerId + '?x=' + indexes.x + '&y=' + indexes.z, fetch(this.state.API_URL + this.props.gameId + '/shoot/' + this.props.playerId + '?x=' + indexes.x + '&y=' + indexes.z,
...@@ -471,7 +472,7 @@ class Game extends Component { ...@@ -471,7 +472,7 @@ class Game extends Component {
if (this.state.winner) { if (this.state.winner) {
return ( return (
<> <>
<h1 style={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' }}>Game Over</h1> <h1 style={{ position: 'absolute', top: '30%', left: '50%', transform: 'translate(-50%, -50%)' }}>Game Over</h1>
<h2 style={{ position: 'absolute', top: '70%', left: '50%', transform: 'translate(-50%, -50%)' }}>{(this.state.winner === this.props.playerId) ? "You won!" : "You lost!"}</h2> <h2 style={{ position: 'absolute', top: '70%', left: '50%', transform: 'translate(-50%, -50%)' }}>{(this.state.winner === this.props.playerId) ? "You won!" : "You lost!"}</h2>
<h2 style={{ position: 'absolute', top: '60%', left: '50%', transform: 'translate(-50%, -50%)' }}>Reload the page to play again</h2> <h2 style={{ position: 'absolute', top: '60%', left: '50%', transform: 'translate(-50%, -50%)' }}>Reload the page to play again</h2>
......
...@@ -6,8 +6,7 @@ const hoverModes = { ...@@ -6,8 +6,7 @@ const hoverModes = {
MicroRecon: 1, MicroRecon: 1,
Warship: 2, Warship: 2,
GalactixRacer: 3, GalactixRacer: 3,
RedFighter: 4, RedFighter: 4
DualStriker: 5
} }
const hoverAreas = [ const hoverAreas = [
...@@ -15,8 +14,7 @@ const hoverAreas = [ ...@@ -15,8 +14,7 @@ const hoverAreas = [
{ x: 2, y: 1 }, { x: 2, y: 1 },
{ x: 3, y: 2 }, { x: 3, y: 2 },
{ x: 3, y: 1 }, { x: 3, y: 1 },
{ x: 4, y: 2 }, { x: 4, y: 2 }
{ x: 5, y: 1 }
]; ];
const hoverRotationDirections = [ const hoverRotationDirections = [
......
...@@ -123,7 +123,7 @@ code { ...@@ -123,7 +123,7 @@ code {
} }
.Buttons { .Buttons {
margin-top: 14%; margin-top:7%;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment