mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-06-28 04:45:36 -04:00
Battleship (#16)
* project: testing * feat: updated testing configs * feat: ship class and test * feat: more testing * feat: gameboard logic/tests complete * feat: add player methods * feat: add main app * sync: pushing latest code to repo * feat: add some basic styling and stuff * feat: added UI logic * feat: basic game is finished * feat: add adjacent rules * feat: basic game complete
This commit is contained in:
parent
d899a773bd
commit
099e6b13e7
23 changed files with 10431 additions and 9218 deletions
43
battleship/src/app.js
Normal file
43
battleship/src/app.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
export default class Game {
|
||||
constructor(players) {
|
||||
this.player1 = players.player1;
|
||||
this.player2 = players.player2;
|
||||
// this.main();
|
||||
}
|
||||
|
||||
main() {
|
||||
// TODO take turns picking points to shoot a ship
|
||||
let count = 0;
|
||||
|
||||
// Main Game Loop
|
||||
while (count < 100) {
|
||||
this.handleUserMove();
|
||||
this.handleCPUMove();
|
||||
|
||||
// console.log(
|
||||
// this.player1.gameboard.scoreboard,
|
||||
// this.player1.gameboard.sunkShipCount,
|
||||
// this.player2.gameboard.scoreboard,
|
||||
// );
|
||||
if (this.player1.gameboard.sunkShipCount === 5) return;
|
||||
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
handleUserMove(move = null) {
|
||||
// let move = window.prompt('Enter your move in array fashion');
|
||||
if (move) {
|
||||
this.player2.gameboard.receiveAttack(JSON.parse(move));
|
||||
}
|
||||
this.player2.gameboard.shipStatus();
|
||||
}
|
||||
|
||||
handleCPUMove() {
|
||||
let move = this.player2.computerMoves(
|
||||
this.player1.gameboard.scoreboard,
|
||||
);
|
||||
this.player1.gameboard.receiveAttack(move);
|
||||
this.player1.gameboard.shipStatus();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue