RSokoban 0.71 → 0.73
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +22 -0
- data/README.rdoc +19 -19
- data/RSokoban-0.73.gem +0 -0
- data/TODO +25 -18
- data/VERSION +1 -0
- data/bin/rsokoban +65 -1
- data/lib/rsokoban/exception.rb +4 -0
- data/lib/rsokoban/game.rb +42 -29
- data/lib/rsokoban/level.rb +67 -30
- data/lib/rsokoban/level_loader.rb +4 -4
- data/lib/rsokoban/level_set.rb +20 -10
- data/lib/rsokoban/map.rb +51 -0
- data/lib/rsokoban/move_recorder.rb +38 -0
- data/lib/rsokoban/option.rb +29 -12
- data/lib/rsokoban/raw_level.rb +15 -4
- data/lib/rsokoban/ui/base_ui.rb +37 -0
- data/lib/rsokoban/ui/console.rb +43 -33
- data/lib/rsokoban/ui/curses_console.rb +45 -36
- data/lib/rsokoban/ui/player_action.rb +74 -0
- data/lib/rsokoban/ui/tk_ui.rb +474 -0
- data/lib/rsokoban/ui.rb +10 -0
- data/lib/rsokoban.rb +4 -5
- data/skins/default/crate.bmp +0 -0
- data/skins/default/crate_store.bmp +0 -0
- data/skins/default/floor.bmp +0 -0
- data/skins/default/man_down.bmp +0 -0
- data/skins/default/man_left.bmp +0 -0
- data/skins/default/man_right.bmp +0 -0
- data/skins/default/man_store_down.bmp +0 -0
- data/skins/default/man_store_left.bmp +0 -0
- data/skins/default/man_store_right.bmp +0 -0
- data/skins/default/man_store_up.bmp +0 -0
- data/skins/default/man_up.bmp +0 -0
- data/skins/default/outside.bmp +0 -0
- data/skins/default/readme +1 -0
- data/skins/default/store.bmp +0 -0
- data/skins/default/wall.bmp +0 -0
- data/test/original.xsb +0 -2
- data/test/tc_level.rb +37 -37
- data/test/tc_level_loader.rb +14 -2
- data/test/tc_level_set.rb +8 -0
- data/test/tc_map.rb +40 -0
- data/test/tc_move_recorder.rb +100 -0
- data/test/tc_raw_level.rb +5 -5
- data/test/test.rb +3 -1
- data/test/test_file2.xsb +2 -0
- data/test/ui/tc_console.rb +27 -13
- data/test/ui/tc_player_action.rb +156 -0
- metadata +38 -25
- data/lib/rsokoban/ui/ui.rb +0 -44
data/test/tc_level.rb
CHANGED
@@ -148,7 +148,7 @@ class TC_Level < Test::Unit::TestCase
|
|
148
148
|
|
149
149
|
def test_rawLevel
|
150
150
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Level1))
|
151
|
-
assert_equal Level1, ins.
|
151
|
+
assert_equal Level1, ins.map
|
152
152
|
end
|
153
153
|
|
154
154
|
Level1_u = [' #####',
|
@@ -166,7 +166,7 @@ class TC_Level < Test::Unit::TestCase
|
|
166
166
|
def test_rawLevel_after_move_up
|
167
167
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Level1))
|
168
168
|
ins.move :up
|
169
|
-
assert_equal Level1_u, ins.
|
169
|
+
assert_equal Level1_u, ins.map
|
170
170
|
end
|
171
171
|
|
172
172
|
Text4 = [ '####',
|
@@ -202,7 +202,7 @@ class TC_Level < Test::Unit::TestCase
|
|
202
202
|
def test_AfterMoveUp1
|
203
203
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp1))
|
204
204
|
ins.moveUp
|
205
|
-
assert_equal AfterMoveUp1, ins.
|
205
|
+
assert_equal AfterMoveUp1, ins.map
|
206
206
|
end
|
207
207
|
|
208
208
|
CanMoveUp2 = ['###',
|
@@ -225,7 +225,7 @@ class TC_Level < Test::Unit::TestCase
|
|
225
225
|
def test_AfterMoveUp2
|
226
226
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp2))
|
227
227
|
ins.moveUp
|
228
|
-
assert_equal AfterMoveUp2, ins.
|
228
|
+
assert_equal AfterMoveUp2, ins.map
|
229
229
|
end
|
230
230
|
|
231
231
|
CanMoveUp3 = ['###',
|
@@ -250,7 +250,7 @@ class TC_Level < Test::Unit::TestCase
|
|
250
250
|
def test_AfterMoveUp3
|
251
251
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp3))
|
252
252
|
ins.moveUp
|
253
|
-
assert_equal AfterMoveUp3, ins.
|
253
|
+
assert_equal AfterMoveUp3, ins.map
|
254
254
|
end
|
255
255
|
|
256
256
|
CanMoveUp4 = ['###',
|
@@ -275,7 +275,7 @@ class TC_Level < Test::Unit::TestCase
|
|
275
275
|
def test_AfterMoveUp4
|
276
276
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp4))
|
277
277
|
ins.moveUp
|
278
|
-
assert_equal AfterMoveUp4, ins.
|
278
|
+
assert_equal AfterMoveUp4, ins.map
|
279
279
|
end
|
280
280
|
|
281
281
|
CannotMoveUp1 = ['###',
|
@@ -285,7 +285,7 @@ class TC_Level < Test::Unit::TestCase
|
|
285
285
|
def test_CannotMoveUp1
|
286
286
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp1))
|
287
287
|
assert_equal 'ERROR wall', ins.moveUp
|
288
|
-
assert_equal CannotMoveUp1, ins.
|
288
|
+
assert_equal CannotMoveUp1, ins.map
|
289
289
|
end
|
290
290
|
|
291
291
|
CannotMoveUp2 = ['###',
|
@@ -296,7 +296,7 @@ class TC_Level < Test::Unit::TestCase
|
|
296
296
|
def test_CannotMoveUp2
|
297
297
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp2))
|
298
298
|
assert_equal 'ERROR wall behind crate', ins.moveUp
|
299
|
-
assert_equal CannotMoveUp2, ins.
|
299
|
+
assert_equal CannotMoveUp2, ins.map
|
300
300
|
end
|
301
301
|
|
302
302
|
CannotMoveUp3 = ['###',
|
@@ -309,7 +309,7 @@ class TC_Level < Test::Unit::TestCase
|
|
309
309
|
def test_CannotMoveUp3
|
310
310
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp3))
|
311
311
|
assert_equal 'ERROR double crate', ins.moveUp
|
312
|
-
assert_equal CannotMoveUp3, ins.
|
312
|
+
assert_equal CannotMoveUp3, ins.map
|
313
313
|
end
|
314
314
|
|
315
315
|
CannotMoveUp4 = ['###',
|
@@ -322,7 +322,7 @@ class TC_Level < Test::Unit::TestCase
|
|
322
322
|
def test_CannotMoveUp4
|
323
323
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp4))
|
324
324
|
assert_equal 'ERROR double crate', ins.moveUp
|
325
|
-
assert_equal CannotMoveUp4, ins.
|
325
|
+
assert_equal CannotMoveUp4, ins.map
|
326
326
|
end
|
327
327
|
|
328
328
|
CannotMoveUp5 = ['###',
|
@@ -335,7 +335,7 @@ class TC_Level < Test::Unit::TestCase
|
|
335
335
|
def test_CannotMoveUp5
|
336
336
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp5))
|
337
337
|
assert_equal 'ERROR double crate', ins.moveUp
|
338
|
-
assert_equal CannotMoveUp5, ins.
|
338
|
+
assert_equal CannotMoveUp5, ins.map
|
339
339
|
end
|
340
340
|
|
341
341
|
CannotMoveUp6 = ['###',
|
@@ -348,7 +348,7 @@ class TC_Level < Test::Unit::TestCase
|
|
348
348
|
def test_CannotMoveUp6
|
349
349
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp6))
|
350
350
|
assert_equal 'ERROR double crate', ins.moveUp
|
351
|
-
assert_equal CannotMoveUp6, ins.
|
351
|
+
assert_equal CannotMoveUp6, ins.map
|
352
352
|
end
|
353
353
|
|
354
354
|
### Move down ##############################################
|
@@ -371,7 +371,7 @@ class TC_Level < Test::Unit::TestCase
|
|
371
371
|
def test_AfterMoveDown1
|
372
372
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown1))
|
373
373
|
ins.moveDown
|
374
|
-
assert_equal AfterMoveDown1, ins.
|
374
|
+
assert_equal AfterMoveDown1, ins.map
|
375
375
|
end
|
376
376
|
|
377
377
|
CanMoveDown2 = ['###',
|
@@ -392,7 +392,7 @@ class TC_Level < Test::Unit::TestCase
|
|
392
392
|
def test_AfterMoveDown2
|
393
393
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown2))
|
394
394
|
ins.moveDown
|
395
|
-
assert_equal AfterMoveDown2, ins.
|
395
|
+
assert_equal AfterMoveDown2, ins.map
|
396
396
|
end
|
397
397
|
|
398
398
|
CanMoveDown3 = ['###',
|
@@ -415,7 +415,7 @@ class TC_Level < Test::Unit::TestCase
|
|
415
415
|
def test_AfterMoveDown3
|
416
416
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown3))
|
417
417
|
ins.moveDown
|
418
|
-
assert_equal AfterMoveDown3, ins.
|
418
|
+
assert_equal AfterMoveDown3, ins.map
|
419
419
|
end
|
420
420
|
|
421
421
|
CanMoveDown4 = ['###',
|
@@ -438,7 +438,7 @@ class TC_Level < Test::Unit::TestCase
|
|
438
438
|
def test_AfterMoveDown4
|
439
439
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown4))
|
440
440
|
ins.moveDown
|
441
|
-
assert_equal AfterMoveDown4, ins.
|
441
|
+
assert_equal AfterMoveDown4, ins.map
|
442
442
|
end
|
443
443
|
|
444
444
|
CannotMoveDown1 = ['###',
|
@@ -448,7 +448,7 @@ class TC_Level < Test::Unit::TestCase
|
|
448
448
|
def test_CannotMoveDown1
|
449
449
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown1))
|
450
450
|
assert_equal 'ERROR wall', ins.moveDown
|
451
|
-
assert_equal CannotMoveDown1, ins.
|
451
|
+
assert_equal CannotMoveDown1, ins.map
|
452
452
|
end
|
453
453
|
|
454
454
|
CannotMoveDown2 = ['###',
|
@@ -459,7 +459,7 @@ class TC_Level < Test::Unit::TestCase
|
|
459
459
|
def test_CannotMoveDown2
|
460
460
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown2))
|
461
461
|
assert_equal 'ERROR wall behind crate', ins.moveDown
|
462
|
-
assert_equal CannotMoveDown2, ins.
|
462
|
+
assert_equal CannotMoveDown2, ins.map
|
463
463
|
end
|
464
464
|
|
465
465
|
CannotMoveDown3 = ['###',
|
@@ -472,7 +472,7 @@ class TC_Level < Test::Unit::TestCase
|
|
472
472
|
def test_CannotMoveDown3
|
473
473
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown3))
|
474
474
|
assert_equal 'ERROR double crate', ins.moveDown
|
475
|
-
assert_equal CannotMoveDown3, ins.
|
475
|
+
assert_equal CannotMoveDown3, ins.map
|
476
476
|
end
|
477
477
|
|
478
478
|
CannotMoveDown4 = ['###',
|
@@ -485,7 +485,7 @@ class TC_Level < Test::Unit::TestCase
|
|
485
485
|
def test_CannotMoveDown4
|
486
486
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown4))
|
487
487
|
assert_equal 'ERROR double crate', ins.moveDown
|
488
|
-
assert_equal CannotMoveDown4, ins.
|
488
|
+
assert_equal CannotMoveDown4, ins.map
|
489
489
|
end
|
490
490
|
|
491
491
|
CannotMoveDown5 = ['###',
|
@@ -498,7 +498,7 @@ class TC_Level < Test::Unit::TestCase
|
|
498
498
|
def test_CannotMoveDown5
|
499
499
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown5))
|
500
500
|
assert_equal 'ERROR double crate', ins.moveDown
|
501
|
-
assert_equal CannotMoveDown5, ins.
|
501
|
+
assert_equal CannotMoveDown5, ins.map
|
502
502
|
end
|
503
503
|
|
504
504
|
CannotMoveDown6 = ['###',
|
@@ -511,7 +511,7 @@ class TC_Level < Test::Unit::TestCase
|
|
511
511
|
def test_CannotMoveDown6
|
512
512
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown6))
|
513
513
|
assert_equal 'ERROR double crate', ins.moveDown
|
514
|
-
assert_equal CannotMoveDown6, ins.
|
514
|
+
assert_equal CannotMoveDown6, ins.map
|
515
515
|
end
|
516
516
|
|
517
517
|
### Move left ##############################################
|
@@ -532,7 +532,7 @@ class TC_Level < Test::Unit::TestCase
|
|
532
532
|
def test_AfterMoveLeft1
|
533
533
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft1))
|
534
534
|
ins.moveLeft
|
535
|
-
assert_equal AfterMoveLeft1, ins.
|
535
|
+
assert_equal AfterMoveLeft1, ins.map
|
536
536
|
end
|
537
537
|
|
538
538
|
CanMoveLeft2 = ['####',
|
@@ -551,7 +551,7 @@ class TC_Level < Test::Unit::TestCase
|
|
551
551
|
def test_AfterMoveLeft2
|
552
552
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft2))
|
553
553
|
ins.moveLeft
|
554
|
-
assert_equal AfterMoveLeft2, ins.
|
554
|
+
assert_equal AfterMoveLeft2, ins.map
|
555
555
|
end
|
556
556
|
|
557
557
|
CanMoveLeft3 = ['#####',
|
@@ -570,7 +570,7 @@ class TC_Level < Test::Unit::TestCase
|
|
570
570
|
def test_AfterMoveLeft3
|
571
571
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft3))
|
572
572
|
ins.moveLeft
|
573
|
-
assert_equal AfterMoveLeft3, ins.
|
573
|
+
assert_equal AfterMoveLeft3, ins.map
|
574
574
|
end
|
575
575
|
|
576
576
|
CanMoveLeft4 = ['#####',
|
@@ -589,7 +589,7 @@ class TC_Level < Test::Unit::TestCase
|
|
589
589
|
def test_AfterMoveLeft4
|
590
590
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft4))
|
591
591
|
ins.moveLeft
|
592
|
-
assert_equal AfterMoveLeft4, ins.
|
592
|
+
assert_equal AfterMoveLeft4, ins.map
|
593
593
|
end
|
594
594
|
|
595
595
|
CannotMoveLeft1 = ['###',
|
@@ -599,7 +599,7 @@ class TC_Level < Test::Unit::TestCase
|
|
599
599
|
def test_CannotMoveLeft1
|
600
600
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveLeft1))
|
601
601
|
assert_equal 'ERROR wall', ins.moveLeft
|
602
|
-
assert_equal CannotMoveLeft1, ins.
|
602
|
+
assert_equal CannotMoveLeft1, ins.map
|
603
603
|
end
|
604
604
|
|
605
605
|
CannotMoveLeft2 = ['####',
|
@@ -609,7 +609,7 @@ class TC_Level < Test::Unit::TestCase
|
|
609
609
|
def test_CannotMoveLeft2
|
610
610
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveLeft2))
|
611
611
|
assert_equal 'ERROR wall behind crate', ins.moveLeft
|
612
|
-
assert_equal CannotMoveLeft2, ins.
|
612
|
+
assert_equal CannotMoveLeft2, ins.map
|
613
613
|
end
|
614
614
|
|
615
615
|
CannotMoveLeft3 = ['######',
|
@@ -619,7 +619,7 @@ class TC_Level < Test::Unit::TestCase
|
|
619
619
|
def test_CannotMoveLeft3
|
620
620
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveLeft3))
|
621
621
|
assert_equal 'ERROR double crate', ins.moveLeft
|
622
|
-
assert_equal CannotMoveLeft3, ins.
|
622
|
+
assert_equal CannotMoveLeft3, ins.map
|
623
623
|
end
|
624
624
|
|
625
625
|
### Move right ##############################################
|
@@ -640,7 +640,7 @@ class TC_Level < Test::Unit::TestCase
|
|
640
640
|
def test_AfterMoveRight1
|
641
641
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight1))
|
642
642
|
ins.moveRight
|
643
|
-
assert_equal AfterMoveRight1, ins.
|
643
|
+
assert_equal AfterMoveRight1, ins.map
|
644
644
|
end
|
645
645
|
|
646
646
|
CanMoveRight2 = ['####',
|
@@ -659,7 +659,7 @@ class TC_Level < Test::Unit::TestCase
|
|
659
659
|
def test_AfterMoveRight2
|
660
660
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight2))
|
661
661
|
ins.moveRight
|
662
|
-
assert_equal AfterMoveRight2, ins.
|
662
|
+
assert_equal AfterMoveRight2, ins.map
|
663
663
|
end
|
664
664
|
|
665
665
|
CanMoveRight3 = ['#####',
|
@@ -678,7 +678,7 @@ class TC_Level < Test::Unit::TestCase
|
|
678
678
|
def test_AfterMoveRight3
|
679
679
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight3))
|
680
680
|
ins.moveRight
|
681
|
-
assert_equal AfterMoveRight3, ins.
|
681
|
+
assert_equal AfterMoveRight3, ins.map
|
682
682
|
end
|
683
683
|
|
684
684
|
CanMoveRight4 = ['#####',
|
@@ -697,7 +697,7 @@ class TC_Level < Test::Unit::TestCase
|
|
697
697
|
def test_AfterMoveRight4
|
698
698
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight4))
|
699
699
|
ins.moveRight
|
700
|
-
assert_equal AfterMoveRight4, ins.
|
700
|
+
assert_equal AfterMoveRight4, ins.map
|
701
701
|
end
|
702
702
|
|
703
703
|
CannotMoveRight1 = ['###',
|
@@ -707,7 +707,7 @@ class TC_Level < Test::Unit::TestCase
|
|
707
707
|
def test_CannotMoveRight1
|
708
708
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveRight1))
|
709
709
|
assert_equal 'ERROR wall', ins.moveRight
|
710
|
-
assert_equal CannotMoveRight1, ins.
|
710
|
+
assert_equal CannotMoveRight1, ins.map
|
711
711
|
end
|
712
712
|
|
713
713
|
CannotMoveRight2 = ['####',
|
@@ -717,7 +717,7 @@ class TC_Level < Test::Unit::TestCase
|
|
717
717
|
def test_CannotMoveRight2
|
718
718
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveRight2))
|
719
719
|
assert_equal 'ERROR wall behind crate', ins.moveRight
|
720
|
-
assert_equal CannotMoveRight2, ins.
|
720
|
+
assert_equal CannotMoveRight2, ins.map
|
721
721
|
end
|
722
722
|
|
723
723
|
CannotMoveRight3 = ['######',
|
@@ -727,7 +727,7 @@ class TC_Level < Test::Unit::TestCase
|
|
727
727
|
def test_CannotMoveRight3
|
728
728
|
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveRight3))
|
729
729
|
assert_equal 'ERROR double crate', ins.moveRight
|
730
|
-
assert_equal CannotMoveRight3, ins.
|
730
|
+
assert_equal CannotMoveRight3, ins.map
|
731
731
|
end
|
732
732
|
|
733
733
|
### WIN ########################################################
|
@@ -766,7 +766,7 @@ class TC_Level < Test::Unit::TestCase
|
|
766
766
|
ins.addStorage
|
767
767
|
|
768
768
|
# I need to be sure that coord 1, 1 is '*'
|
769
|
-
assert_equal '#*#', ins.
|
769
|
+
assert_equal '#*#', ins.map[1]
|
770
770
|
|
771
771
|
assert_equal 'ERROR wall behind crate', ins.moveUp
|
772
772
|
end
|
data/test/tc_level_loader.rb
CHANGED
@@ -26,12 +26,12 @@ class TC_LevelLoader < Test::Unit::TestCase
|
|
26
26
|
assert_equal "one simple level to test\n", ins.set.description
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def test_map
|
30
30
|
ins = RSokoban::LevelLoader.new "test_file1.xsb"
|
31
31
|
expected = [ '#####',
|
32
32
|
'#.$@#',
|
33
33
|
'#####']
|
34
|
-
assert_equal expected, ins.set.rawLevels[0].
|
34
|
+
assert_equal expected, ins.set.rawLevels[0].map
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_title_of_level
|
@@ -85,4 +85,16 @@ class TC_LevelLoader < Test::Unit::TestCase
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
def test_get_size_of_set
|
89
|
+
ins = RSokoban::LevelLoader.new "original.xsb"
|
90
|
+
assert_equal 90, ins.set.size
|
91
|
+
end
|
92
|
+
|
93
|
+
# There was a bug where size was majored by one when the xsb file
|
94
|
+
# finish by several blank lines.
|
95
|
+
def test_get_size_of_set_buggy
|
96
|
+
ins = RSokoban::LevelLoader.new "test_file2.xsb"
|
97
|
+
assert_equal 6, ins.set.size
|
98
|
+
end
|
99
|
+
|
88
100
|
end
|
data/test/tc_level_set.rb
CHANGED
@@ -39,4 +39,12 @@ class TC_LevelSet < Test::Unit::TestCase
|
|
39
39
|
ins = RSokoban::LevelSet.new
|
40
40
|
assert_equal [], ins.rawLevels
|
41
41
|
end
|
42
|
+
|
43
|
+
def test_get_size
|
44
|
+
ins = RSokoban::LevelSet.new
|
45
|
+
list = [].push(RSokoban::RawLevel.new('title', ['###']))
|
46
|
+
ins.rawLevels = list
|
47
|
+
assert_equal 1, ins.size
|
48
|
+
end
|
49
|
+
|
42
50
|
end
|
data/test/tc_map.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class TC_Map < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@map = RSokoban::Map.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_default_picture_is_empy
|
8
|
+
assert_equal [], RSokoban::Map.new.rows
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_assigning_rows
|
12
|
+
@map.rows = ['###', '# #', '###']
|
13
|
+
assert_equal ['###', '# #', '###'], @map.rows
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_get_height
|
17
|
+
@map.rows = ['###', '# #', '###']
|
18
|
+
assert_equal 3, @map.height
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_get_width
|
22
|
+
@map.rows = ['###', '####', '##']
|
23
|
+
assert_equal 4, @map.width
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_get_a_row
|
27
|
+
@map.rows = ['###', '# #', '###']
|
28
|
+
assert_equal '# #', @map[1]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_each_row
|
32
|
+
@map.rows = ['#', '##', '###']
|
33
|
+
expected = '#'
|
34
|
+
@map.each {|row|
|
35
|
+
assert_equal expected, row
|
36
|
+
expected += '#'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
class TC_MoveRecorder < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@mr = RSokoban::MoveRecorder.new
|
5
|
+
|
6
|
+
# For testing purpose, add a method to reset the queue of moves.
|
7
|
+
def @mr.empty_for_testing
|
8
|
+
@queue = []
|
9
|
+
end
|
10
|
+
|
11
|
+
# For testing purpose, add a method to fill the queue of moves with known values.
|
12
|
+
def @mr.fill_for_testing list
|
13
|
+
@queue = list
|
14
|
+
end
|
15
|
+
|
16
|
+
# For testing purpose, add a method to get the queue of moves.
|
17
|
+
def @mr.get_for_testing
|
18
|
+
@queue
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_create_instance
|
23
|
+
assert @mr.instance_of?(RSokoban::MoveRecorder)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_raise_exception_if_we_undo_an_empty_queue
|
27
|
+
@mr.empty_for_testing
|
28
|
+
assert_raise(RSokoban::EmptyMoveQueueError) do
|
29
|
+
@mr.undo
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_record_up
|
34
|
+
@mr.empty_for_testing
|
35
|
+
@mr.record :up
|
36
|
+
assert_equal [:up], @mr.get_for_testing
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_record_down
|
40
|
+
@mr.empty_for_testing
|
41
|
+
@mr.record :down
|
42
|
+
assert_equal [:down], @mr.get_for_testing
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_record_left
|
46
|
+
@mr.empty_for_testing
|
47
|
+
@mr.record :left
|
48
|
+
assert_equal [:left], @mr.get_for_testing
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_record_right
|
52
|
+
@mr.empty_for_testing
|
53
|
+
@mr.record :right
|
54
|
+
assert_equal [:right], @mr.get_for_testing
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def test_record_up_and_push
|
59
|
+
@mr.empty_for_testing
|
60
|
+
@mr.record :up, :push
|
61
|
+
assert_equal [:UP], @mr.get_for_testing
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_record_down_and_push
|
65
|
+
@mr.empty_for_testing
|
66
|
+
@mr.record :down, :push
|
67
|
+
assert_equal [:DOWN], @mr.get_for_testing
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_record_left_and_push
|
71
|
+
@mr.empty_for_testing
|
72
|
+
@mr.record :left, :push
|
73
|
+
assert_equal [:LEFT], @mr.get_for_testing
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_record_right_and_push
|
77
|
+
@mr.empty_for_testing
|
78
|
+
@mr.record :right, :push
|
79
|
+
assert_equal [:RIGHT], @mr.get_for_testing
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def test_record_nothing_else_than_direction
|
84
|
+
assert_raise(ArgumentError) do
|
85
|
+
@mr.record :north
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_undo_give_the_last_move
|
90
|
+
@mr.fill_for_testing [:up, :up, :left]
|
91
|
+
assert_equal :left, @mr.undo
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_undo_diminish_the_queue
|
95
|
+
@mr.fill_for_testing [:up, :up, :left]
|
96
|
+
@mr.undo
|
97
|
+
assert_equal [:up, :up], @mr.get_for_testing
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
data/test/tc_raw_level.rb
CHANGED
@@ -21,15 +21,15 @@ class TC_RawLevel < Test::Unit::TestCase
|
|
21
21
|
'#.$@#',
|
22
22
|
'#####']
|
23
23
|
|
24
|
-
def
|
24
|
+
def test_map_accessors
|
25
25
|
ins = RSokoban::RawLevel.new
|
26
|
-
ins.
|
27
|
-
assert_equal Picture1, ins.
|
26
|
+
ins.map = Picture1
|
27
|
+
assert_equal Picture1, ins.map.rows
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def test_default_map
|
31
31
|
ins = RSokoban::RawLevel.new
|
32
|
-
assert_equal
|
32
|
+
assert_equal RSokoban::Map.new, ins.map
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
data/test/test.rb
CHANGED
@@ -12,5 +12,7 @@ require "../test/tc_raw_level"
|
|
12
12
|
require "../test/tc_position"
|
13
13
|
require "../test/tc_moveable"
|
14
14
|
require "../test/tc_man"
|
15
|
+
require "../test/tc_move_recorder"
|
16
|
+
require "../test/tc_map"
|
15
17
|
require "../test/ui/tc_console"
|
16
|
-
|
18
|
+
require "../test/ui/tc_player_action"
|
data/test/ui/tc_console.rb
CHANGED
@@ -7,10 +7,13 @@ class TC_Console < Test::Unit::TestCase
|
|
7
7
|
def @console.public_parse(*args)
|
8
8
|
parse(*args)
|
9
9
|
end
|
10
|
+
|
11
|
+
@pa = RSokoban::UI::PlayerAction.new
|
10
12
|
end
|
11
13
|
|
12
14
|
def test_string_quit_must_returns_symbol_quit
|
13
|
-
|
15
|
+
@pa.action = :quit
|
16
|
+
assert_equal @pa, @console.public_parse('quit')
|
14
17
|
end
|
15
18
|
|
16
19
|
def test_string_help_must_returns_symbol_help
|
@@ -18,43 +21,53 @@ class TC_Console < Test::Unit::TestCase
|
|
18
21
|
end
|
19
22
|
|
20
23
|
def test_string_retry_must_returns_symbol_retry
|
21
|
-
|
24
|
+
@pa.action = :retry
|
25
|
+
assert_equal @pa, @console.public_parse('retry')
|
22
26
|
end
|
23
27
|
|
24
28
|
def test_string_up_must_returns_symbol_up
|
25
|
-
|
29
|
+
@pa.action = :up
|
30
|
+
assert_equal @pa, @console.public_parse('up')
|
26
31
|
end
|
27
32
|
|
28
33
|
def test_string_down_must_returns_symbol_down
|
29
|
-
|
34
|
+
@pa.action = :down
|
35
|
+
assert_equal @pa, @console.public_parse('down')
|
30
36
|
end
|
31
37
|
|
32
38
|
def test_string_right_must_returns_symbol_right
|
33
|
-
|
39
|
+
@pa.action = :right
|
40
|
+
assert_equal @pa, @console.public_parse('right')
|
34
41
|
end
|
35
42
|
|
36
43
|
def test_string_left_must_returns_symbol_left
|
37
|
-
|
44
|
+
@pa.action = :left
|
45
|
+
assert_equal @pa, @console.public_parse('left')
|
38
46
|
end
|
39
47
|
|
40
48
|
def test_string_z_must_returns_symbol_up
|
41
|
-
|
49
|
+
@pa.action = :up
|
50
|
+
assert_equal @pa, @console.public_parse('z')
|
42
51
|
end
|
43
52
|
|
44
53
|
def test_string_s_must_returns_symbol_down
|
45
|
-
|
54
|
+
@pa.action = :down
|
55
|
+
assert_equal @pa, @console.public_parse('s')
|
46
56
|
end
|
47
57
|
|
48
|
-
def
|
49
|
-
|
58
|
+
def test_string_q_must_returns_action_left
|
59
|
+
@pa.action = :left
|
60
|
+
assert_equal @pa, @console.public_parse('q')
|
50
61
|
end
|
51
62
|
|
52
63
|
def test_string_d_must_returns_symbol_right
|
53
|
-
|
64
|
+
@pa.action = :right
|
65
|
+
assert_equal @pa, @console.public_parse('d')
|
54
66
|
end
|
55
67
|
|
56
68
|
def test_string_representing_a_number_must_returns_this_number
|
57
|
-
|
69
|
+
@pa.action = 12
|
70
|
+
assert_equal @pa, @console.public_parse("12")
|
58
71
|
end
|
59
72
|
|
60
73
|
def test_must_return_nil_if_number_is_negative
|
@@ -66,7 +79,8 @@ class TC_Console < Test::Unit::TestCase
|
|
66
79
|
end
|
67
80
|
|
68
81
|
def test_xsb_filename_must_returns_itself
|
69
|
-
|
82
|
+
@pa.action = 'some_levels.xsb'
|
83
|
+
assert_equal @pa, @console.public_parse("some_levels.xsb")
|
70
84
|
end
|
71
85
|
|
72
86
|
def test_anything_else_must_returns_nil
|