From 718fdf63b137d9f576a6ba2c65a9b51a90ca1293 Mon Sep 17 00:00:00 2001 From: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Fri, 15 Mar 2024 20:49:39 -0400 Subject: [PATCH] feat: add player methods --- battleship/src/components/gameboard.js | 1 - battleship/src/components/player.js | 9 +++++++++ battleship/src/index.js | 7 +++++++ battleship/tests/player.test.js | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 battleship/src/components/player.js create mode 100644 battleship/tests/player.test.js diff --git a/battleship/src/components/gameboard.js b/battleship/src/components/gameboard.js index 750aa89..5b614e7 100644 --- a/battleship/src/components/gameboard.js +++ b/battleship/src/components/gameboard.js @@ -1,5 +1,4 @@ import { Ship } from './ship'; -let _ = require('lodash'); class Gameboard { constructor() { diff --git a/battleship/src/components/player.js b/battleship/src/components/player.js new file mode 100644 index 0000000..3970185 --- /dev/null +++ b/battleship/src/components/player.js @@ -0,0 +1,9 @@ +import { Gameboard } from './gameboard'; +class Player { + constructor(name) { + this.gameboard = new Gameboard(); + this.playerName = name; + } +} + +export { Player }; diff --git a/battleship/src/index.js b/battleship/src/index.js index e69de29..938f857 100644 --- a/battleship/src/index.js +++ b/battleship/src/index.js @@ -0,0 +1,7 @@ +import { Player } from './components/player'; + +const player1 = new Player('Player 1'); +const player2 = new Player('CPU'); + +console.log(player1.gameboard); +console.log(player2.gameboard); diff --git a/battleship/tests/player.test.js b/battleship/tests/player.test.js new file mode 100644 index 0000000..65cefa8 --- /dev/null +++ b/battleship/tests/player.test.js @@ -0,0 +1,18 @@ +import { Gameboard } from '../src/components/gameboard'; +class Player { + constructor(name) { + this.gameboard = new Gameboard(); + this.playerName = name; + } +} + +let p = new Player('Player1'); + +it('should contain a gameboard', () => { + expect(p.gameboard).toHaveProperty( + 'ships', + 'scoreboard', + 'shipCount', + 'sunkShipCount', + ); +});