-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43db8d3
commit e72cdb8
Showing
2 changed files
with
111 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,76 @@ | ||
import test from 'ava' | ||
import actions from '../public/game/actions' | ||
import Dungeon, {CampfireRoom, MonsterRoom, Monster} from '../public/game/dungeon' | ||
import {getCurrRoom, isCurrentRoomCompleted, isDungeonCompleted} from '../public/game/utils' | ||
|
||
const a = actions | ||
|
||
test('can create rooms with many monsters', (t) => { | ||
const room = new MonsterRoom(new Monster(), new Monster()) | ||
t.is(room.monsters.length, 2) | ||
}) | ||
|
||
test('can create a dungeon', (t) => { | ||
const d = Dungeon({ | ||
rooms: [MonsterRoom(Monster()), CampfireRoom(), MonsterRoom(Monster())], | ||
}) | ||
t.is(d.rooms.length, 3) | ||
t.is(d.rooms[0].type, 'monster') | ||
t.is(d.rooms[0].monsters.length, 1) | ||
t.is(d.rooms[1].type, 'campfire') | ||
t.is(d.rooms[2].type, 'monster') | ||
}) | ||
|
||
test('can set a dungeon', (t) => { | ||
const dungeon = Dungeon({rooms: [MonsterRoom(Monster())]}) | ||
let state = a.createNewGame() | ||
state = a.setDungeon(state, dungeon) | ||
t.deepEqual(state.dungeon, dungeon, 'setting dungeon works') | ||
}) | ||
|
||
test('we know when a monster room is won', (t) => { | ||
const room = new MonsterRoom(new Monster()) | ||
const state = {dungeon: {rooms: [room]}} | ||
t.false(isCurrentRoomCompleted(state)) | ||
room.monsters[0].currentHealth = 0 | ||
t.true(isCurrentRoomCompleted(state)) | ||
}) | ||
|
||
test('we know when the entire dungeon has been cleared', (t) => { | ||
const dungeon = Dungeon({ | ||
rooms: [MonsterRoom(Monster()), MonsterRoom(Monster())], | ||
}) | ||
const state = {dungeon} | ||
t.false(isDungeonCompleted(state)) | ||
state.dungeon.rooms[0].monsters[0].currentHealth = 0 | ||
t.false(isDungeonCompleted(state)) | ||
state.dungeon.rooms[1].monsters[0].currentHealth = 0 | ||
t.true(isDungeonCompleted(state)) | ||
}) | ||
|
||
test('we know when a monster room with many monsters is won', (t) => { | ||
const room = new MonsterRoom(new Monster(), new Monster()) | ||
const state = {dungeon: {rooms: [room]}} | ||
t.false(isCurrentRoomCompleted(state)) | ||
room.monsters[0].currentHealth = 0 | ||
t.false(isCurrentRoomCompleted(state)) | ||
room.monsters[1].currentHealth = 0 | ||
t.true(isCurrentRoomCompleted(state)) | ||
}) | ||
|
||
test.todo('we know when a campfire has been used') | ||
|
||
test('we can navigate a dungeon', (t) => { | ||
// Prepare a game with a dungeon. | ||
let state = a.createNewGame() | ||
const dungeon = Dungeon({ | ||
rooms: [CampfireRoom(), CampfireRoom(), CampfireRoom()], | ||
}) | ||
state = a.setDungeon(state, dungeon) | ||
// Go through the next rooms. | ||
state = a.goToNextRoom(state) | ||
t.is(getCurrRoom(state).id, dungeon.rooms[1].id) | ||
state = a.goToNextRoom(state) | ||
t.is(getCurrRoom(state).id, dungeon.rooms[2].id) | ||
t.throws(() => a.goToNextRoom(state), null, 'can not go further than last room') | ||
}) | ||
import test from 'ava' | ||
import actions from '../public/game/actions' | ||
import Dungeon, {CampfireRoom, MonsterRoom, Monster} from '../public/game/dungeon' | ||
import {getCurrRoom, isCurrentRoomCompleted, isDungeonCompleted} from '../public/game/utils' | ||
|
||
const a = actions | ||
|
||
test('can create rooms with many monsters', (t) => { | ||
const room = new MonsterRoom(new Monster(), new Monster()) | ||
t.is(room.monsters.length, 2) | ||
}) | ||
|
||
test('can create a dungeon', (t) => { | ||
const d = Dungeon({ | ||
rooms: [MonsterRoom(Monster()), CampfireRoom(), MonsterRoom(Monster())], | ||
}) | ||
t.is(d.rooms.length, 3) | ||
t.is(d.rooms[0].type, 'monster') | ||
t.is(d.rooms[0].monsters.length, 1) | ||
t.is(d.rooms[1].type, 'campfire') | ||
t.is(d.rooms[2].type, 'monster') | ||
}) | ||
|
||
test('can set a dungeon', (t) => { | ||
const dungeon = Dungeon({rooms: [MonsterRoom(Monster())]}) | ||
let state = a.createNewGame() | ||
state = a.setDungeon(state, dungeon) | ||
t.deepEqual(state.dungeon, dungeon, 'setting dungeon works') | ||
}) | ||
|
||
test('we know when a monster room is won', (t) => { | ||
const room = new MonsterRoom(new Monster()) | ||
const state = {dungeon: {rooms: [room]}} | ||
t.false(isCurrentRoomCompleted(state)) | ||
room.monsters[0].currentHealth = 0 | ||
t.true(isCurrentRoomCompleted(state)) | ||
}) | ||
|
||
test('we know when the entire dungeon has been cleared', (t) => { | ||
const dungeon = Dungeon({ | ||
rooms: [MonsterRoom(Monster()), MonsterRoom(Monster())], | ||
}) | ||
const state = {dungeon} | ||
t.false(isDungeonCompleted(state)) | ||
state.dungeon.rooms[0].monsters[0].currentHealth = 0 | ||
t.false(isDungeonCompleted(state)) | ||
state.dungeon.rooms[1].monsters[0].currentHealth = 0 | ||
t.true(isDungeonCompleted(state)) | ||
}) | ||
|
||
test('we know when a monster room with many monsters is won', (t) => { | ||
const room = new MonsterRoom(new Monster(), new Monster()) | ||
const state = {dungeon: {rooms: [room]}} | ||
t.false(isCurrentRoomCompleted(state)) | ||
room.monsters[0].currentHealth = 0 | ||
t.false(isCurrentRoomCompleted(state)) | ||
room.monsters[1].currentHealth = 0 | ||
t.true(isCurrentRoomCompleted(state)) | ||
}) | ||
|
||
test.todo('we know when a campfire has been used') | ||
|
||
test('we can navigate a dungeon', (t) => { | ||
// Prepare a game with a dungeon. | ||
let state = a.createNewGame() | ||
const dungeon = Dungeon({ | ||
rooms: [CampfireRoom(), CampfireRoom(), CampfireRoom()], | ||
}) | ||
state = a.setDungeon(state, dungeon) | ||
// Go through the next rooms. | ||
state = a.goToNextRoom(state) | ||
t.is(getCurrRoom(state).id, dungeon.rooms[1].id) | ||
state = a.goToNextRoom(state) | ||
t.is(getCurrRoom(state).id, dungeon.rooms[2].id) | ||
t.throws(() => a.goToNextRoom(state), null, 'can not go further than last room') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
import test from 'ava' | ||
import createNewGame from '../public/game/index.js' | ||
import {createCard} from '../public/game/cards' | ||
|
||
// We don't want to test too much here, | ||
// since tests/actions.js has most of it. | ||
|
||
test('it all', (t) => { | ||
const game = createNewGame() | ||
t.is(game.state.player.currentHealth, 72) | ||
// can add a card | ||
const strike = createCard('Strike') | ||
game.enqueue({type: 'addCardToHand', card: strike}) | ||
t.is(game.future.list.length, 1) | ||
t.is(game.past.list.length, 0) | ||
game.dequeue() | ||
t.is(game.future.list.length, 0) | ||
t.is(game.past.list.length, 1) | ||
t.is(game.state.hand.length, 6) | ||
t.is(game.state.hand[game.state.hand.length - 1].id, strike.id) | ||
// we can undo | ||
game.undo() | ||
t.is(game.state.hand.length, 5) | ||
// and draw cards again | ||
game.enqueue({type: 'drawCards'}) | ||
game.dequeue() | ||
t.is(game.state.hand.length, 10) | ||
}) | ||
|
||
test('game also contains actions', (t) => { | ||
const game = createNewGame() | ||
game.state.hand = [] | ||
game.state = game.actions.drawCards(game.state) | ||
t.is(game.state.hand.length, 5) | ||
}) | ||
import test from 'ava' | ||
import createNewGame from '../public/game/index.js' | ||
import {createCard} from '../public/game/cards' | ||
|
||
// We don't want to test too much here, | ||
// since tests/actions.js has most of it. | ||
|
||
test('it all', (t) => { | ||
const game = createNewGame() | ||
t.is(game.state.player.currentHealth, 72) | ||
// can add a card | ||
const strike = createCard('Strike') | ||
game.enqueue({type: 'addCardToHand', card: strike}) | ||
t.is(game.future.list.length, 1) | ||
t.is(game.past.list.length, 0) | ||
game.dequeue() | ||
t.is(game.future.list.length, 0) | ||
t.is(game.past.list.length, 1) | ||
t.is(game.state.hand.length, 6) | ||
t.is(game.state.hand[game.state.hand.length - 1].id, strike.id) | ||
// we can undo | ||
game.undo() | ||
t.is(game.state.hand.length, 5) | ||
// and draw cards again | ||
game.enqueue({type: 'drawCards'}) | ||
game.dequeue() | ||
t.is(game.state.hand.length, 10) | ||
}) | ||
|
||
test('game also contains actions', (t) => { | ||
const game = createNewGame() | ||
game.state.hand = [] | ||
game.state = game.actions.drawCards(game.state) | ||
t.is(game.state.hand.length, 5) | ||
}) |