Commit 31933f29 authored by Andrew Stephen Brown's avatar Andrew Stephen Brown
Browse files

added server folder

parent 4edffc8d
"use strict";
var battleship = /** @class */ (function () {
function battleship(w, h) {
if (w === void 0) { w = 10; }
if (h === void 0) { h = 10; }
this.w = w;
this.h = h;
this.board = this.emptyBoard();
}
battleship.prototype.emptyBoard = function () {
var arr = [];
for (var i = 0; i < this.h * this.w; i++) {
arr.push(0);
}
return arr;
};
battleship.prototype.boardIndex = function (x, y) {
return y * this.w + x;
};
battleship.prototype.x = function (index) {
return index % this.w;
};
battleship.prototype.y = function (index) {
return Math.floor(index / this.w);
};
battleship.prototype.toggleCell = function (x, y) {
var b = this.boardIndex(x, y);
//this.board[b] = !this.board[b]
};
battleship.prototype.isAlive = function (x, y) {
var b = this.boardIndex(x, y);
return (x >= 0) && (y >= 0) && (x < this.w) && (y < this.h)
&& this.board[b] == 1;
};
return battleship;
}());
!function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e){t.exports=React},function(t,e){t.exports=ReactDOM},function(t,e,n){"use strict";n.r(e);var i=function(){function t(t,e){void 0===t&&(t=10),void 0===e&&(e=10),this.w=t,this.h=e,this.destroyer=new r(2,0,"Destroyer",3),this.cruiser=new r(3,0,"Cruiser",4),this.submarine=new r(3,0,"Submarine",5),this.battle=new r(4,0,"Battleship",6),this.carrier=new r(5,0,"Carrier",7),this.ships=[this.destroyer,this.cruiser,this.submarine,this.battle,this.carrier],this.board=this.emptyBoard()}return t.prototype.emptyBoard=function(){for(var t=[],e=0;e<this.h*this.w;e++)t.push(0);return t},t.prototype.boardIndex=function(t,e){return e*this.w+t},t.prototype.x=function(t){return t%this.w},t.prototype.y=function(t){return Math.floor(t/this.w)},t.prototype.setHit=function(t,e){var n=this.boardIndex(t,e),i=this.board;return i[n]=1,i},t.prototype.setMiss=function(t,e){var n=this.boardIndex(t,e),i=this.board;return i[n]=2,i},t.prototype.setShip=function(t,e,n,i){var r=this.boardIndex(t,e),o=this.board;if(1==this.isValidPlacement(t,e,n.size,i)){if(0==i)for(var s=0;s<n.size;s++)o[r+s]=n.id;else for(s=0;s<n.size;s++){o[this.boardIndex(t,e+s)]=n.id}n.placed=!0}return o},t.prototype.isValidPlacement=function(t,e,n,i){var r=this.boardIndex(t,e),o=0;if(i){console.log("insideb"),this.h-e>=n&&(o=1);for(a=0;a<n;a++){var s=this.boardIndex(t,e+a);s<100&&2==this.board[s]&&(o=0)}}else{this.w-t>=n&&(o=1);for(var a=0;a<n;a++)2==this.board[r+a]&&(o=0)}return o},t}(),r=function(){return function(t,e,n,i){this.size=t,this.rotation=e,this.name=n,this.placed=!1,this.id=i}}(),o=n(0),s=function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();function a(t){return o.createElement("rect",{className:t.cell,onClick:t.onClick,x:t.x,y:t.y,width:t.width,height:t.height})}var l=function(t){function e(e){var n=t.call(this,e)||this;return n.state={battleship:e.battleship,board:e.battleship.board,cellSize:e.cellSize,turnCount:0,turn:0},n}return s(e,t),e.prototype.renderSwitch=function(t){switch(t){case 0:return"cell attack";case 1:return"cell hit";case 2:return"cell miss";default:return"cell attack"}},e.prototype.renderCell=function(t){var e=this;return o.createElement(a,{cell:this.renderSwitch(this.state.board[t]),onClick:function(){return e.setMiss(t)},x:this.state.battleship.x(t)*this.state.cellSize,y:this.state.battleship.y(t)*this.state.cellSize,width:this.state.cellSize,height:this.state.cellSize,key:t})},e.prototype.renderGrid=function(){for(var t=[],e=0;e<this.state.battleship.board.length;e++)t.push(this.renderCell(e));return t},e.prototype.setHit=function(t){var e=this.state.battleship.x(t),n=this.state.battleship.y(t),i=this.state.battleship.setHit(e,n);this.setState({board:i})},e.prototype.setMiss=function(t){var e=this.state.battleship.x(t),n=this.state.battleship.y(t),i=this.state.battleship.setMiss(e,n);this.setState({board:i})},e.prototype.handleClick=function(t){},e.prototype.render=function(){return o.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"300",height:"300"},o.createElement("g",null,this.renderGrid()))},e}(o.Component),c=function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();function h(t){return o.createElement("rect",{className:t.cell,onClick:t.onClick,x:t.x,y:t.y,width:t.width,height:t.height})}var u=function(t){function e(e){var n=t.call(this,e)||this;return console.log("called",e.shipIndex),n.state={battleship:e.battleship,board:e.battleship.board,cellSize:e.cellSize,shipIndex:e.shipIndex,rotation:e.rotation},n}return c(e,t),e.prototype.renderSwitch=function(t){switch(t){case 0:return"cell defend";case 1:return"cell hit";case 2:return"cell miss";default:return"cell ship"}},e.prototype.updateRotation=function(t){this.setState({rotation:t})},e.prototype.updateShipIndex=function(t){this.setState({shipIndex:t})},e.prototype.deleteShip=function(){var t=this.state.board,e=this.state.battleship.ships[this.state.shipIndex];e.placed=!1;for(var n=0;n<this.state.board.length;n++)t[n]==e.id&&(t[n]=0);this.setState({board:t})},e.prototype.renderCell=function(t){var e=this;return o.createElement(h,{cell:this.renderSwitch(this.state.board[t]),onClick:function(){return e.setShip(t)},x:this.state.battleship.x(t)*this.state.cellSize,y:this.state.battleship.y(t)*this.state.cellSize,width:this.state.cellSize,height:this.state.cellSize,key:t})},e.prototype.renderGrid=function(){for(var t=[],e=0;e<this.state.battleship.board.length;e++)t.push(this.renderCell(e));return t},e.prototype.setHit=function(t){var e=this.state.battleship.x(t),n=this.state.battleship.y(t),i=this.state.battleship.setHit(e,n);this.setState({board:i})},e.prototype.setMiss=function(t){var e=this.state.battleship.x(t),n=this.state.battleship.y(t),i=this.state.battleship.setMiss(e,n);this.setState({board:i})},e.prototype.setShip=function(t){var e=this.state.battleship.x(t),n=this.state.battleship.y(t),i=this.state.battleship.ships[this.state.shipIndex];if(!i.placed){var r=this.state.battleship.setShip(e,n,i,this.state.rotation);this.setState({board:r})}},e.prototype.handleClick=function(t){},e.prototype.render=function(){return o.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"300",height:"300"},o.createElement("g",null,this.renderGrid()))},e}(o.Component),p=function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),d=new i;d.board=d.emptyBoard();var f=function(t){function e(e){var n=t.call(this,e)||this;return n.setRotation=n.setRotation.bind(n),n.state={index:0,rotation:0},n}return p(e,t),e.prototype.setIndex=function(t){this.setState({index:t}),this.props.setIndex(t)},e.prototype.setRotation=function(){this.setState({rotation:this.state.rotation?0:1}),this.props.setRotation()},e.prototype.deleteShip=function(){this.props.deleteShip()},e.prototype.beginGame=function(){this.props.beginGame()},e.prototype.render=function(){var t=this;return o.createElement("div",null,o.createElement("div",null,o.createElement("button",{type:"button",className:"shipButton",onClick:function(){return t.setIndex(0)},id:"destroyer"},"Destoyer")),o.createElement("div",null,o.createElement("button",{type:"button",className:"shipButton",onClick:function(){return t.setIndex(1)},id:"cruiser"},"Cruiser")),o.createElement("div",null,o.createElement("button",{type:"button",className:"shipButton",onClick:function(){return t.setIndex(2)},id:"submarine"},"Submarine")),o.createElement("div",null,o.createElement("button",{type:"button",className:"shipButton",onClick:function(){return t.setIndex(3)},id:"battleship"},"Battleship")),o.createElement("div",null,o.createElement("button",{type:"button",className:"shipButton",onClick:function(){return t.setIndex(4)},id:"carrier"},"Carrier")),o.createElement("div",null,o.createElement("button",{type:"button",className:"shipButton",onClick:function(){return t.setRotation()},id:"rotate"},"Rotate")),o.createElement("div",null,o.createElement("button",{type:"button",className:"shipButton",onClick:function(){return t.deleteShip()},id:"delete"},"Delete")),o.createElement("div",null,o.createElement("button",{type:"button",className:"shipButton",onClick:function(){return t.beginGame()},id:"begin"},"Begin")),o.createElement("div",null,"Rotation: ",this.state.rotation),o.createElement("div",null,"Ship: ",this.state.index))},e}(o.Component),b=function(t){function e(e){var n=t.call(this,e)||this;return n.dboardRef=o.createRef(),n.setRotation=n.setRotation.bind(n),n.setIndex=n.setIndex.bind(n),n.deleteShip=n.deleteShip.bind(n),n.beginGame=n.beginGame.bind(n),n.state={rotation:0,index:0,gameBegin:!1},n}return p(e,t),e.prototype.renderGame=function(){return o.createElement("div",null,o.createElement("div",{className:"leftDiv"},o.createElement(l,{cellSize:30,board:d.board,battleship:d})),o.createElement("div",{className:"rightDiv"},o.createElement(u,{cellSize:30,board:d.board,battleship:d,rotation:this.state.rotation,shipIndex:this.state.index})))},e.prototype.setRotation=function(){this.setState({rotation:this.state.rotation?0:1}),this.dboardRef.current.updateRotation(this.state.rotation?0:1)},e.prototype.setIndex=function(t){this.setState({index:t}),this.dboardRef.current.updateShipIndex(t)},e.prototype.deleteShip=function(){this.dboardRef.current.deleteShip()},e.prototype.beginGame=function(){this.setState({gameBegin:!0})},e.prototype.renderPlace=function(){return o.createElement("div",null,o.createElement("div",{className:"leftDiv"},o.createElement(u,{ref:this.dboardRef,cellSize:30,board:d.board,battleship:d,rotation:this.state.rotation,shipIndex:this.state.index})),o.createElement("div",{className:"centreDiv"},o.createElement(f,{setRotation:this.setRotation,setIndex:this.setIndex,deleteShip:this.deleteShip,beginGame:this.beginGame})))},e.prototype.render=function(){return this.state.gameBegin?this.renderGame():this.renderPlace()},e}(o.Component);n(1).render(o.createElement(b,null),document.querySelector("#root"))}]);
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css"
integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<title>COSC360 A2</title>
</head>
<body>
<div class="container">
<h1>Battleship</h1>
<p>
Place your ships then hit begin to match
</p>
<div class="root" id="root"></div>
<div class="chat"><input type="text" class="input"><br><button>Send</button></div>
</div>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="./node_modules/react/umd/react.development.js"></script>
<script src="./node_modules/react-dom/umd/react-dom.development.js"></script>
<script src="dist/bundle.js"></script>
<link rel="stylesheet" href="style.css" />
</body>
</html>
../acorn/bin/acorn
\ No newline at end of file
../atob/bin/atob.js
\ No newline at end of file
../babylon/bin/babylon.js
\ No newline at end of file
../browserslist/cli.js
\ No newline at end of file
../cssesc/bin/cssesc
\ No newline at end of file
../csso/bin/csso
\ No newline at end of file
../d3-dsv/bin/dsv2json
\ No newline at end of file
../d3-dsv/bin/dsv2dsv
\ No newline at end of file
../d3-dsv/bin/dsv2dsv
\ No newline at end of file
../d3-dsv/bin/dsv2json
\ No newline at end of file
../errno/cli.js
\ No newline at end of file
../esprima/bin/esparse.js
\ No newline at end of file
../esprima/bin/esvalidate.js
\ No newline at end of file
../he/bin/he
\ No newline at end of file
../import-local/fixtures/cli.js
\ No newline at end of file
../js-yaml/bin/js-yaml.js
\ No newline at end of file
../jsesc/bin/jsesc
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment