Skip to content

Commit

Permalink
visual characater no se sale de los limites (#209)
Browse files Browse the repository at this point in the history
* no se sale de los limites el visual char

* Update src/wollok/game.wlk

---------

Co-authored-by: Fernando Dodino <[email protected]>
  • Loading branch information
lspigariol and fdodino authored Oct 8, 2024
1 parent 22ba1c1 commit 25a0763
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/wollok/game.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ object game {
*/
method addVisualCharacter(visual) {
self.addVisual(visual)
keyboard.up().onPressDo({ visual.position(visual.position().up(1)) })
keyboard.down().onPressDo({ visual.position(visual.position().down(1)) })
keyboard.left().onPressDo({ visual.position(visual.position().left(1)) })
keyboard.right().onPressDo({ visual.position(visual.position().right(1)) })
keyboard.up().onPressDo({
if(visual.position().y() < game.height()-1) visual.position(visual.position().up(1)) })
keyboard.down().onPressDo({
if(visual.position().y() > 0) visual.position(visual.position().down(1)) })
keyboard.right().onPressDo({
if (visual.position().x() < game.width()-1) visual.position(visual.position().right(1)) })
keyboard.left().onPressDo({
if (visual.position().x() > 0) visual.position(visual.position().left(1)) })
}

/**
* Removes an object from the board for stop drawing it.
*
Expand Down
10 changes: 10 additions & 0 deletions test/sanity/game/game.wtest
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,14 @@ describe "Game" {

assert.equals(game.at(0, 1), character.position())
}

test 'addVisualCharacter no exceed limits' {
const character = new Visual()
game.addVisualCharacter(character)
// Simulate
io.queueEvent(["keypress", "ArrowDown"])
game.flushEvents(0)

assert.equals(game.at(0, 0), character.position())
}
}

0 comments on commit 25a0763

Please sign in to comment.