import {Component} from '../../lib/vuetranslit.js' import {GameState, instructions} from '../util/util.js' import app from '../application.js' const template = `

Snake


{{instructions}}
{{instructions.replace('{end}', victory)}}
` class TopComponent extends Component { GameState = GameState static get tag() { return 'top-comp'; } static get template() { return template; } static get props() { return {}; } current_state = GameState.SizeSelect; rowinput = 6; colinput = 6; has_ai = app.hasAI; instructions = instructions[this.current_state]; victory = ""; watch_rowinput() { this.rowinput = parseInt(this.rowinput); app.rowCount = this.rowinput; } watch_colinput() { this.colinput = parseInt(this.colinput); app.colCount = this.colinput; } watch_current_state() { this.instructions = instructions[this.current_state]; } compute_celldim() { let height = parseInt((window.screen.height - 150) / this.rowinput); let width = parseInt(window.screen.width / this.colinput); return Math.min(width, height); } compute_accept_bounds() { return this.rowinput > 5 && this.colinput > 5 && (!(this.rowinput % 2) || !(this.colinput % 2)); } set_game_state(state) { this.current_state = state; app.current_state = state; } set_has_ai() { app.hasAI = !app.hasAI; this.has_ai = app.hasAI; } on_create() { app.rowCount = this.rowinput; app.colCount = this.colinput; this.current_state = app.get_current_state(); app.tester(async (state,victory) => { this.current_state = state; this.instructions = instructions[this.current_state]; if (victory) this.victory = 'win'; else this.victory = 'lose'; }) } } export default TopComponent;