Exemplo n.º 1
0
def test_diagonal_shot():
    field_2_by_2 = [0, 1, 1, 0]
    g = Game()
    g.start_new_game(size=2, field=field_2_by_2)

    for position in g.diagonal_positions(field_size=2):
        assert g.handle_enemy_shot(position=position) == 'kill'

    field_4_by_4 = [
        0,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        0,
    ]
    g.start_new_game(size=4, field=field_4_by_4)

    for position in g.diagonal_positions(field_size=4):
        assert g.handle_enemy_shot(position=position) == 'kill'
Exemplo n.º 2
0
def game():
    g = Game()
    g.start_new_game()

    return g
Exemplo n.º 3
0
def test_diagonal_shots():
    field_size = 10
    field_with_step_4 = [
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
    ]

    g = Game()
    g.start_new_game(size=field_size, field=field_with_step_4)
    for position in g.diagonal_shots(step=4):
        assert g.handle_enemy_shot(position=position) == 'kill'

    field_with_step_2 = [
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
    ]

    g = Game()
    g.start_new_game(size=field_size, field=field_with_step_2)
    for position in g.diagonal_shots(step=2):
        assert g.handle_enemy_shot(position=position) == 'kill'
Exemplo n.º 4
0
def small_game():
    g = Game()
    g.start_new_game(size=3, field=[0] * 9)

    return g