|
| 1 | +import { game } from '../../Game'; |
| 2 | +import { |
| 3 | + HEAVEN_BOARD_ID, |
| 4 | + HELL_BOARD_ID, |
| 5 | + OVERWORLD_BOARD_ID, |
| 6 | +} from '../../Constants'; |
| 7 | +import { onPlayerAction } from '../PieceLogic'; |
| 8 | +import { Player, PlayerColors } from '../Players'; |
| 9 | +import { Position } from './PiecesUtilities'; |
| 10 | +import { Pawn } from './Pawn'; |
| 11 | +import { DoubleQueen } from './DoubleQueen'; |
| 12 | + |
| 13 | +const whitePlayer = new Player(PlayerColors.WHITE); |
| 14 | +const blackPlayer = new Player(PlayerColors.BLACK); |
| 15 | + |
| 16 | +jest.mock('../../ui/BoardManager.ts', () => ({ |
| 17 | + destroyElementOnBoard: jest.fn(), |
| 18 | + moveElementOnBoard: jest.fn(), |
| 19 | + spawnPieceElementOnBoard: jest.fn(), |
| 20 | + getSquareElementById: jest.fn(), |
| 21 | + getAllSquareElements: jest.fn(), |
| 22 | + highlightLastMove: jest.fn(), |
| 23 | +})); |
| 24 | +jest.mock('../../ui/Screen.ts', () => ({ |
| 25 | + renderPlayersInformation: jest.fn(), |
| 26 | +})); |
| 27 | +jest.mock('../../ui/logs/Logger.ts'); |
| 28 | +jest.mock('../../ui/Events.ts', () => ({})); |
| 29 | +jest.mock('../../ui/InventoriesUI.ts', () => ({ |
| 30 | + initializeInventoryUI: jest.fn(), |
| 31 | + switchShownInventory: jest.fn(), |
| 32 | + showItemOnInventory: jest.fn(), |
| 33 | +})); |
| 34 | +jest.mock('../../ui/ShopUI.ts'); |
| 35 | + |
| 36 | +game.getCurrentPlayer = jest.fn().mockReturnValue(whitePlayer); |
| 37 | + |
| 38 | +describe('Piece movements', () => { |
| 39 | + test('Validating Double Queen movement', () => { |
| 40 | + const initialPosition: Position = { |
| 41 | + coordinates: [2, 5], |
| 42 | + boardId: OVERWORLD_BOARD_ID, |
| 43 | + }; |
| 44 | + const doubleQueen = new DoubleQueen(initialPosition, whitePlayer); |
| 45 | + game.setPieces([doubleQueen]); |
| 46 | + |
| 47 | + const newStraightPosition: Position = { |
| 48 | + coordinates: [2, 2], |
| 49 | + boardId: OVERWORLD_BOARD_ID, |
| 50 | + }; |
| 51 | + let validMoves = doubleQueen.getLegalMoves(); |
| 52 | + expect(validMoves).toContainEqual(newStraightPosition); |
| 53 | + |
| 54 | + const newDiagonalPosition: Position = { |
| 55 | + coordinates: [5, 5], |
| 56 | + boardId: OVERWORLD_BOARD_ID, |
| 57 | + }; |
| 58 | + validMoves = doubleQueen.getLegalMoves(); |
| 59 | + expect(validMoves).toContainEqual(newDiagonalPosition); |
| 60 | + |
| 61 | + const invalidPosition: Position = { |
| 62 | + coordinates: [0, 0], |
| 63 | + boardId: OVERWORLD_BOARD_ID, |
| 64 | + }; |
| 65 | + validMoves = doubleQueen.getLegalMoves(); |
| 66 | + expect(validMoves).not.toContainEqual(invalidPosition); |
| 67 | + }); |
| 68 | +}); |
| 69 | + |
| 70 | +describe('Piece killing', () => { |
| 71 | + test('Validating Queen killing', () => { |
| 72 | + const initialKillerPosition: Position = { |
| 73 | + coordinates: [2, 2], |
| 74 | + boardId: OVERWORLD_BOARD_ID, |
| 75 | + }; |
| 76 | + const killerDoubleQueen = new DoubleQueen(initialKillerPosition, whitePlayer); |
| 77 | + |
| 78 | + const victimPosition: Position = { |
| 79 | + coordinates: [2, 5], |
| 80 | + boardId: OVERWORLD_BOARD_ID, |
| 81 | + }; |
| 82 | + const victimPiece = new Pawn(victimPosition, blackPlayer); |
| 83 | + |
| 84 | + game.initialize(); |
| 85 | + game.setPieces([killerDoubleQueen, victimPiece]); |
| 86 | + onPlayerAction(killerDoubleQueen, victimPiece); |
| 87 | + |
| 88 | + const victimPieceBoardId = victimPiece.position.boardId; |
| 89 | + expect(victimPieceBoardId).toEqual(HEAVEN_BOARD_ID); |
| 90 | + |
| 91 | + let killerNewCoordinates = killerDoubleQueen.position.coordinates; |
| 92 | + expect(killerNewCoordinates).toEqual(victimPosition.coordinates); |
| 93 | + |
| 94 | + // Diagonal kill |
| 95 | + killerDoubleQueen.position = initialKillerPosition; |
| 96 | + |
| 97 | + const otherVictimPosition: Position = { |
| 98 | + coordinates: [6, 6], |
| 99 | + boardId: OVERWORLD_BOARD_ID, |
| 100 | + }; |
| 101 | + const otherVictimPiece = new Pawn(otherVictimPosition, blackPlayer); |
| 102 | + otherVictimPiece.killCount = 1; |
| 103 | + |
| 104 | + game.setPieces([killerDoubleQueen, otherVictimPiece]); |
| 105 | + onPlayerAction(killerDoubleQueen, otherVictimPiece); |
| 106 | + |
| 107 | + const otherVictimPieceBoardId = otherVictimPiece.position.boardId; |
| 108 | + expect(otherVictimPieceBoardId).toEqual(HELL_BOARD_ID); |
| 109 | + |
| 110 | + killerNewCoordinates = killerDoubleQueen.position.coordinates; |
| 111 | + expect(killerNewCoordinates).toEqual(otherVictimPosition.coordinates); |
| 112 | + |
| 113 | + const playerXP = killerDoubleQueen.player.xp; |
| 114 | + expect(playerXP).toBeGreaterThan(0); |
| 115 | + }); |
| 116 | +}); |
0 commit comments