GameMoves.js 649 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. class GameMove {
  2. constructor(type, data) {
  3. this.type = type;
  4. this.data = data;
  5. }
  6. verify() {}
  7. performMove() {}
  8. };
  9. GameMove.TYPES = {
  10. PLACE: 1,
  11. PLACE_AND_REVEAL: 2,
  12. SELECT_CARDS: 0
  13. };
  14. class PlaceMove extends GameMove {
  15. constructor(card, position, player) {
  16. super(GameMove.TYPES.PLACE, {});
  17. this.position = position;
  18. this.card = card;
  19. this.player = player;
  20. }
  21. verify(state) {
  22. if (state.board.isEmpty(this.position)) {
  23. throw Error('Not a valid move, there is already a card there!');
  24. }
  25. return true;
  26. }
  27. performMove(board) {
  28. board.putCard(this.card, this.position, this.player);
  29. }
  30. }
  31. module.exports = {
  32. PlaceMove
  33. };