diff --git a/index.html b/index.html index f973302..fa515a6 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,7 @@ Battleship | EECS 448 +

Battleship - EECS 448 Project 1

diff --git a/src/components.js b/src/components.js index fd21d69..6baaa34 100644 --- a/src/components.js +++ b/src/components.js @@ -1,9 +1,11 @@ import GameBoardComponent from './components/GameBoard.component.js' +import GridCellComponent from './components/GridCell.component.js' /* * This is where various components we define should be registered. * Once they are listed here, they will be automatically loaded by Vue.js. */ export default { - GameBoardComponent + GameBoardComponent, + GridCellComponent, } diff --git a/src/components/GameBoard.component.js b/src/components/GameBoard.component.js index 2f0eba8..9668446 100644 --- a/src/components/GameBoard.component.js +++ b/src/components/GameBoard.component.js @@ -1,4 +1,5 @@ import {Component} from '../../lib/vues6.js' +import {GridCellState} from '../module/util.js' /* * This is the HTML/JavaScript for the game board component. @@ -15,10 +16,19 @@ import {Component} from '../../lib/vues6.js' * * We can also use components w/in components, to keep code clean. For example, we could have * a battleship component that we reference inside this game board component. + * + * Battleship grid is 14x14. */ const template = ` -
-

The game board will go here. {{ greeting }}

+
+
+
+ +
+
` export default class GameBoardComponent extends Component { @@ -26,9 +36,42 @@ export default class GameBoardComponent extends Component { static get template() { return template } static get props() { return [] } - greeting = 'Hello, world.' + /** + * If true, the grid is ready to be rendered. If false, + * the grid will be hidden. + * @type {boolean} + */ + ready = false + + /** + * Array of grid rows. Each element in this array is itself + * an array of grid cell values. + * @type {Array>} + */ + rows = [] + + /** + * The number of rows in the grid. + * @type {number} + */ + n_rows = 14 + + /** + * The number of columns in a row. + * @type {number} + */ + n_cols = 14 async vue_on_create() { - console.log('The game board has been created!') + // Generate the data structure for the grid + this.rows = Array(this.n_rows).fill('').map(_ => { + return Array(this.n_cols).fill('').map(_ => { + return { + render: GridCellState.Available, + } + }) + }) + + this.ready = true } } diff --git a/src/components/GridCell.component.js b/src/components/GridCell.component.js new file mode 100644 index 0000000..f9b88bf --- /dev/null +++ b/src/components/GridCell.component.js @@ -0,0 +1,25 @@ +import {Component} from '../../lib/vues6.js' +import {GridCellState} from '../module/util.js' + +const template = ` +
+ +
+` +export default class GridCellComponent extends Component { + static get selector() { return 'app-game-cell' } + static get template() { return template } + + /** Properties that can be passed into this component. */ + static get props() { + return [ + 'render', + ] + } + + /** Make the "GridCellState" enum available in the template. */ + GridCellState = GridCellState +} diff --git a/src/module/util.js b/src/module/util.js new file mode 100644 index 0000000..8f66827 --- /dev/null +++ b/src/module/util.js @@ -0,0 +1,5 @@ + +export const GridCellState = { + Available: 'available', + Disabled: 'disabled', +} diff --git a/src/style/components.css b/src/style/components.css new file mode 100644 index 0000000..bccf08a --- /dev/null +++ b/src/style/components.css @@ -0,0 +1,27 @@ +.game-board-component .grid-container .grid-row { + display: flex; +} + +/* Styles for the various grid cell states. */ + +.game-board-cell-component { + width: 40px; + height: 40px; + border: 1px solid grey; +} + +.game-board-cell-component.available { + background: #eeeeee; +} + +.game-board-cell-component.available:hover { + background: #cccccc; +} + +.game-board-cell-component.disabled { + background: #cccccc; +} + +.game-board-cell-component.disabled:hover { + background: #bbbbbb; +}