From ee2a1f7e16272d19eb5a2dc03355ce8b851a441e Mon Sep 17 00:00:00 2001 From: adrianna Date: Fri, 16 May 2014 17:47:44 +0200 Subject: [PATCH] rotation action --- data/images/glyphs/anticlockwise.png | Bin 0 -> 204 bytes data/images/glyphs/clockwise.png | Bin 0 -> 204 bytes data/location_decks/standard.yaml | 23 ++++++++++++ naja/actions.py | 5 ++- naja/gameboard.py | 16 ++++----- naja/tests/test_gameboard.py | 51 +++++++++++++++++++++++++-- naja/widgets/text.py | 2 ++ sources/images/glyph.xcf | Bin 4536 -> 4896 bytes 8 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 data/images/glyphs/anticlockwise.png create mode 100644 data/images/glyphs/clockwise.png diff --git a/data/images/glyphs/anticlockwise.png b/data/images/glyphs/anticlockwise.png new file mode 100644 index 0000000000000000000000000000000000000000..b8f93e952565ae627533a8197c6d077694c5bcbf GIT binary patch literal 204 zcmeAS@N?(olHy`uVBq!ia0vp^93VCa8<3oGNZ$fTu_bxCyDx`7I;J! zGca%qgD@k*tT_@uLG}_)Usv{ftOEReywl4i<$ywxC9V-A&iT2ysd*&~&PAz-C8;S2 z<(VZJ3hti10pX2&;y^_vo-U3d5|@(`7Kj)a85sO=Uv%-Qgv0`&{~I&@oo{eeS7!dp qsH}JV;FFmjD*0!AmiPY=z`+o9iHn8H>X9l?KZB>MpUXO@geCyDx;iZY literal 0 HcmV?d00001 diff --git a/data/images/glyphs/clockwise.png b/data/images/glyphs/clockwise.png new file mode 100644 index 0000000000000000000000000000000000000000..bc6f077d0c199703855b2c8605e710986cb4b797 GIT binary patch literal 204 zcmeAS@N?(olHy`uVBq!ia0vp^93VCa8<3oGNZ$fTu_bxCyDx`7I;J! zGca%qgD@k*tT_@uLG}_)Usv{ftOERe3@?wRE(QuombgZgIOpf)rskC}I2WZRmZYXA zlxLP?D7bt2281{Ai31gxc)B=-NL)@%SRi8H^zwhik^hIE{7=64LtgD%hqKUKwkRey pr!u356aSn)00d2kRkVIFFkGzW 0: - locations_to_rotate.append((px - 1, py)) - if px < 4: locations_to_rotate.append((px + 1, py)) if py < 4: - for i in range(max(0, px -1), min(5, px + 2)): + for i in reversed(range(max(0, px -1), min(5, px + 2))): locations_to_rotate.append((i, py + 1)) - if direction == ROTATION.CLOCKWISE: - new_positions = locations_to_rotate[1:] + locations_to_rotate[0] - elif direction == ROTATION.ANTICLOCKWISE: - new_positions = locations_to_rotate[-1] + locations_to_rotate[:-1] + if px > 0: + locations_to_rotate.append((px - 1, py)) + + if ROTATION[direction] == ROTATION.CLOCKWISE: + new_positions = locations_to_rotate[1:] + [locations_to_rotate[0]] + elif ROTATION[direction] == ROTATION.ANTICLOCKWISE: + new_positions = [locations_to_rotate[-1]] + locations_to_rotate[:-1] for old, new in zip(locations_to_rotate, new_positions): rotated_locations[old] = self.board_locations[new] diff --git a/naja/tests/test_gameboard.py b/naja/tests/test_gameboard.py index 6231ac7..d843c7e 100644 --- a/naja/tests/test_gameboard.py +++ b/naja/tests/test_gameboard.py @@ -124,21 +124,66 @@ class TestGameBoard(TestCase): (0, 2): '12', (1, 2): '32', (3, 2): '42', (4, 2): '02', })) - def test_allow_chess_move_knight(self): + def test_rotate_locations_clockwise(self): board = GameBoard.new_game([{'actions': []}]) board.board_locations = self.generate_locations() + board.rotate_locations('CLOCKWISE') + self.assertEqual(board.board_locations, self.generate_locations({ + (1, 1): '21', (2, 1): '31', (3, 1): '32', + (1, 2): '11', (3, 2): '33', + (1, 3): '12', (2, 3): '13', (3, 3): '23', + })) + + def test_rotate_locations_clockwise_top(self): + board = GameBoard.new_game([{'actions': []}], initial_pos=(2, 0)) + board.board_locations = self.generate_locations() + board.rotate_locations('CLOCKWISE') + self.assertEqual(board.board_locations, self.generate_locations({ + (1, 0): '30', (3, 0): '31', + (1, 1): '10', (2, 1): '11', (3, 1): '21', + })) + + def test_rotate_locations_clockwise_right(self): + board = GameBoard.new_game([{'actions': []}], initial_pos=(0, 2)) + board.board_locations = self.generate_locations() + board.rotate_locations('CLOCKWISE') + self.assertEqual(board.board_locations, self.generate_locations({ + (0, 1): '11', (1, 1): '12', + (1, 2): '13', + (0, 3): '01', (1, 3): '03', + })) + + def test_rotate_locations_clockwise_corner(self): + board = GameBoard.new_game([{'actions': []}], initial_pos=(0, 4)) + board.board_locations = self.generate_locations() + board.rotate_locations('CLOCKWISE') + self.assertEqual(board.board_locations, self.generate_locations({ + (0, 3): '13', (1, 3): '14', + (1, 4): '03', + })) + + def test_rotate_locations_anticlockwise(self): + board = GameBoard.new_game([{'actions': []}]) + board.board_locations = self.generate_locations() + board.rotate_locations('ANTICLOCKWISE') + self.assertEqual(board.board_locations, self.generate_locations({ + (1, 1): '12', (2, 1): '11', (3, 1): '21', + (1, 2): '13', (3, 2): '31', + (1, 3): '23', (2, 3): '33', (3, 3): '32', + })) + + def test_allow_chess_move_knight(self): + board = GameBoard.new_game([{'actions': []}]) board.allow_chess_move(MOVES.KNIGHT) self.assertEqual(board.player.movement_mode, MOVES.KNIGHT) def test_allow_chess_move_bishop(self): board = GameBoard.new_game([{'actions': []}]) - board.board_locations = self.generate_locations() board.allow_chess_move(MOVES.BISHOP) self.assertEqual(board.player.movement_mode, MOVES.BISHOP) def test_allow_chess_move_castle(self): board = GameBoard.new_game([{'actions': []}]) - board.board_locations = self.generate_locations() board.allow_chess_move(MOVES.CASTLE) self.assertEqual(board.player.movement_mode, MOVES.CASTLE) diff --git a/naja/widgets/text.py b/naja/widgets/text.py index d8d2d47..e4eecaa 100644 --- a/naja/widgets/text.py +++ b/naja/widgets/text.py @@ -19,6 +19,8 @@ MARKUP_MAP = { 'RED': ('glyphs/key.png', PALETTE.ORANGE), 'GREEN': ('glyphs/key.png', PALETTE.GREEN), 'BLUE': ('glyphs/key.png', PALETTE.BLUE), + 'CLOCKWISE': ('glyphs/clockwise.png', None), + 'ANTICLOCKWISE': ('glyphs/anticlockwise.png', None), } diff --git a/sources/images/glyph.xcf b/sources/images/glyph.xcf index 596119b1285d1464c7b2e17dd5424ca87b943398..003c7eaea7de7861be462943f00d7ea401b96f7a 100644 GIT binary patch delta 897 zcmZvZyJ}TY5QhJ~_Wgc|MHDn%$N~$&fK@6h>l9X6NiY%=4JcUJ_yEGZK;FQlv+`2d zL{!8aG2l5GH)82LR^? z;GP7$Gk`w^1mi$>4v0mS+Wa^Xozta11?AEANZNaMTUTxJ!q3T`KP|PgY zy*f9Rrl(mY8ms|2rbcMOnX&HELwkI*V9O5M`wbj!Hq7bt2J9Hj<4SVbbKbv8b1J51 z&T0Ch+S=`yDICopUf$j8qlS5k*6p_TmL&#Dy)DUnmo}Uw?SGKiNd2FZ1rB|8S9P#1 zv5|&Kvaq5*URQ_P5*uk`-pRz?{?TCygGW00&$Xg`*NXXC!Gelk(35zm{Mc{P^ocjA z6Sh_IisqA{vMUdhEn1E`I&Dd8_DRTFX-&4#73GeNtUfqEBU7Lw-Os^{#CO4 wH?5{EUA&gqNQ=*s6~AaDTh!%qiH)?}_n_qlwexqndik%kT9K^!LGO#Pzxim1#Q*>R delta 790 zcmZvaODjcD6vx+j+;jGMpK~z~LbL})_fAXkAkeDg!d%x=CG> zx1>-WH*UG)RVE&LAMRkus@2--_y6y`Yqe(ia>I1DGQZF>ptKnPS|xzq2#}};Fq#0& zW&lq8od_NS~a$+Hz97 zWojOu^jpknDP+bWZtE#@%w3+?qc(XpaYI?+b%xz>zMV+q7y3mxA+ns@nD5w`AM)( zS#XKP=!}OMilsF?q%6F~$7H%iz|w96UHv2deUn3Dqjl}Q6T{Lj?!_UNGd@p=D(#Xh q*r8W-%JqvoQRND1B1M#oEa4acL^I-0`b!c0+^_J