Esempio n. 1
0
def test_sinked():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    cords = (2, 6)
    fleet = sinked(fleet, cords)
    assert not fleet.get_ship(cords)
Esempio n. 2
0
def test_fleet_fleet_is_not():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    fleet.remove_ship_from_fleet(ship1)
    fleet.remove_ship_from_fleet(ship2)
    assert not fleet.if_fleet_is()
Esempio n. 3
0
def test_f_continue():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(1, [(2, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    cords = (2, 6)
    shot_list = [(2, 2)]
    shot_list, fleet_object = f_continue(fleet, cords, shot_list)
    assert shot_list[1] == cords
Esempio n. 4
0
def test_fleet_setter():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    ship3 = Ship(3, [(5, 2), (5, 3), (5, 4)], 'poziom')
    ship4 = Ship(2, [(2, 6), (2, 7)], 'poziom')
    fleet.set_ships_list([ship3, ship4])
    assert fleet.get_ships_list() == [ship3, ship4]
Esempio n. 5
0
def generate_ships():
    ships = []
    for i in range(4):
        ships.append(Ship(1, random.randint(VERTICAL, HORIZONTAL)))
    for i in range(3):
        ships.append(Ship(2, random.randint(VERTICAL, HORIZONTAL)))
    for i in range(2):
        ships.append(Ship(3, random.randint(VERTICAL, HORIZONTAL)))
    ships.append(Ship(4, random.randint(VERTICAL, HORIZONTAL)))
    return ships
Esempio n. 6
0
def test_fleet_get_list_of_cords():
    ship1 = Ship(
        4,
        [(3, 2), (3, 3), (3, 4), (3, 5)],
        'poziom',
    )
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    assert fleet.get_list_of_cords() == [[(3, 2), (3, 3), (3, 4), (3, 5)],
                                         [(2, 6), (3, 6)]]
Esempio n. 7
0
def test_hit():
    dim = 8
    matrix = np.zeros((dim, dim), dtype=int)
    m_obj = Matrix(matrix)
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    size = ship1.get_size()
    ship2 = Ship(3, [(2, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    cords = (3, 2)
    lifes, m_obj, fleet = hit(m_obj, cords, fleet, dim)
    assert lifes < size
def make_list_of_ships(list_of_infos):
    '''
    Creates and returns list of ships
    to make fleet (list of ships is basic
    fleet object attribute).
    '''
    list_of_ships = []
    infos = list_of_infos
    i = 0
    for items in infos:
        ship = Ship(infos[i][0], infos[i][1], infos[i][2])
        list_of_ships.append(ship)
        i += 1
    return list_of_ships
Esempio n. 9
0
def escape(moves, belt, blast_time=2):
    """
    Takes an array of moves and an array of Asteroid objects and attempts to
    send ship through the asteroid belt to escape from Planet.
    """
    ship = Ship()
    belt.reset()
    print 'Trying {0}'.format(moves)
    for turn, direction in enumerate(moves):
        ship.thrust(direction)  # Change velocity accordingly
        ship.move()             # Move the ship accordingly
        belt.move()             # Move all the asteroids
        if ship.position > len(belt):
            print 'Congratulations, you have escaped the asteroid belt!'
            print 'Moves: {0}'.format(moves)
            return True
        elif belt.asteroids[ship.position].blocking:
            print 'Oh no! You have crashed'
            return False
        elif turn / blast_time > ship.position:
            print 'Oh no! You have been consumed by the planet'
            return False
    print 'Need more directions!'
    return None
Esempio n. 10
0
def set_singledecker(enemy_bf):
    ship_set = False
    while not ship_set:

        a = random.choice(L)
        row = a[0]
        col = a[1]

        try:
            nassau = Ship(row, col)
            check_position(nassau, 1, enemy_bf)
        except ValueError:
            pass
        else:
            enemy_bf.add_ship(nassau)
            try:
                delete_from_list(nassau)
            except ValueError:
                pass
            finally:
                ship_set = True
Esempio n. 11
0
    else:
        ship_type = "однопалубного"
        decks = 1

    print("Расстановка кораблей: введите координаты без пробела. Последовательность расстановки палуб: сверху-вниз "
          "или слева-направо")

    if decks > 1:

        ship_set = False

        while not ship_set:
            try:
                bf.show_field()
                index_1 = input(f"Расположите первую палубу {ship_type} корабля: ")
                battleship_1 = Ship(index_1[0], index_1[1])
                check_position(battleship_1, decks, bf)
            except ValueError:
                print("Координаты введены неверно. Попробуйте еще раз.")
            else:
                try:
                    bf.show_field()
                    index_2 = input(f"Расположите вторую палубу {ship_type} корабля: ")
                    battleship_2 = Ship(index_2[0], index_2[1])
                    check_order()
                    check_position(battleship_2, decks - 1, bf)
                except ValueError:
                    print("Координаты введены неверно. Попробуйте еще раз.")
                else:
                    if decks == 3:
                        if index_1[0] == index_2[0]:
Esempio n. 12
0
def set_trippledecker(enemy_bf):
    # ставим трехпалубник
    a = random.choice(L)
    row = a[0]
    col = a[1]
    konig_1 = Ship(row, col)
    direction = random.randint(1, 2)

    if direction == 1:
        ship_set = False
        while not ship_set:
            try:
                konig_2 = Ship(row + 1, col)
                konig_3 = Ship(row + 2, col)

            except ValueError:
                try:
                    konig_2 = Ship(row - 1, col)
                    konig_3 = Ship(row - 2, col)

                except ValueError:
                    pass
                else:
                    enemy_bf.add_ship(konig_1)
                    enemy_bf.add_ship(konig_2)
                    enemy_bf.add_ship(konig_3)
                    try:
                        delete_from_list(konig_1)
                        delete_from_list(konig_2)
                        delete_from_list(konig_3)
                    except ValueError:
                        pass
                    finally:

                        ship_set = True

            else:
                enemy_bf.add_ship(konig_1)
                enemy_bf.add_ship(konig_2)
                enemy_bf.add_ship(konig_3)
                try:
                    delete_from_list(konig_1)
                    delete_from_list(konig_2)
                    delete_from_list(konig_3)
                except ValueError:
                    pass
                finally:
                    ship_set = True

    elif direction == 2:

        ship_set = False
        while not ship_set:
            try:
                konig_2 = Ship(row, col + 1)
                konig_3 = Ship(row, col + 2)

            except ValueError:
                try:
                    konig_2 = Ship(row, col - 1)
                    konig_3 = Ship(row, col - 2)

                except ValueError:
                    pass
                else:
                    enemy_bf.add_ship(konig_1)
                    enemy_bf.add_ship(konig_2)
                    enemy_bf.add_ship(konig_3)
                    try:
                        delete_from_list(konig_1)
                        delete_from_list(konig_2)
                        delete_from_list(konig_3)
                    except ValueError:
                        pass
                    finally:
                        ship_set = True

            else:
                enemy_bf.add_ship(konig_1)
                enemy_bf.add_ship(konig_2)
                enemy_bf.add_ship(konig_3)
                try:
                    delete_from_list(konig_1)
                    delete_from_list(konig_2)
                    delete_from_list(konig_3)

                except ValueError:
                    pass
                finally:
                    ship_set = True
Esempio n. 13
0
def test_ship_setters():
    ship = Ship(4, [(3, 2), (3, 3), (3, ), (3, 5)], 'poziom')
    ship.set_location([(2, 5), (2, 6), (2, 7)])
    ship.set_size(3)
    ship.set_direction('pion')
    assert ship.get_location() == [(2, 5), (2, 6), (2, 7)]
    assert ship.get_size() == 3
    assert ship.get_direction() == 'pion'
Esempio n. 14
0
def set_doubledecker(enemy_bf):
    ship_set = False
    while not ship_set:
        direction = random.randint(1, 2)
        a = random.choice(L)
        row = a[0]
        col = a[1]

        if direction == 1:
            try:
                kaiser_1 = Ship(row, col)
                kaiser_2 = Ship(row + 1, col)
                check_position(kaiser_1, 2, enemy_bf)
                check_position(kaiser_2, 1, enemy_bf)
            except ValueError:
                try:
                    kaiser_1 = Ship(row, col)
                    kaiser_2 = Ship(row - 1, col)
                    check_position(kaiser_1, 2, enemy_bf)
                    check_position(kaiser_2, 1, enemy_bf)
                except ValueError:
                    pass
                else:
                    enemy_bf.add_ship(kaiser_1)
                    enemy_bf.add_ship(kaiser_2)
                    try:
                        delete_from_list(kaiser_2)
                        delete_from_list(kaiser_1)
                    except ValueError:
                        pass
                    finally:
                        ship_set = True

            else:
                enemy_bf.add_ship(kaiser_1)
                enemy_bf.add_ship(kaiser_2)
                try:
                    delete_from_list(kaiser_2)
                    delete_from_list(kaiser_1)
                except ValueError:
                    pass
                finally:
                    ship_set = True

        elif direction == 2:

            try:
                kaiser_1 = Ship(row, col)
                kaiser_2 = Ship(row, col + 1)
                check_position(kaiser_1, 2, enemy_bf)
                check_position(kaiser_2, 1, enemy_bf)
            except ValueError:
                try:
                    kaiser_1 = Ship(row, col)
                    kaiser_2 = Ship(row, col - 1)
                    check_position(kaiser_1, 2, enemy_bf)
                    check_position(kaiser_2, 1, enemy_bf)
                except ValueError:
                    pass
                else:
                    enemy_bf.add_ship(kaiser_1)
                    enemy_bf.add_ship(kaiser_2)
                    try:

                        delete_from_list(kaiser_2)
                        delete_from_list(kaiser_1)
                    except ValueError:
                        pass
                    finally:
                        ship_set = True

            else:
                enemy_bf.add_ship(kaiser_1)
                enemy_bf.add_ship(kaiser_2)
                try:
                    delete_from_list(kaiser_2)
                    delete_from_list(kaiser_1)
                except ValueError:
                    pass
                finally:
                    ship_set = True
Esempio n. 15
0
def test_ship_remove_cord():
    ship = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship.remove_cord((3, 4))
    assert ship.get_location() == [(3, 2), (3, 3), (3, 5)]
Esempio n. 16
0
from screen_func import *
from classes import Ship
from classes import Shot
from classes import Asteroid


num_asteroids = 0
asteroid_reload = 30


#makes sprite containers and initializes the sprites

ship_container = pygame.sprite.Group()
Ship.containers = ship_container
ship = Ship()

shot_container = pygame.sprite.Group()
Shot.containers = shot_container

asteroid_container = pygame.sprite.Group()
Asteroid.containers = asteroid_container
asteroid_reload = 30

pygame.init()
pygame.mixer.init()


ret = screen_func.intro_screen()
stop = 1
while stop != 0:
Esempio n. 17
0
def test_ship_hurt():
    ship = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship.hurt()
    ship.hurt()
    assert ship.get_size() == 2
Esempio n. 18
0
def test_fleet_fleet_is():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    assert fleet.if_fleet_is()
Esempio n. 19
0
def test_fleet_remove_ship_from_fleet():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    fleet.remove_ship_from_fleet(ship2)
    assert fleet.get_ships_list() == [ship1]
Esempio n. 20
0
def test_fleet_getter():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    assert fleet.get_ships_list() == [ship1, ship2]
Esempio n. 21
0
def test_ship_getters():
    ship = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    assert ship.get_location() == [(3, 2), (3, 3), (3, 4), (3, 5)]
    assert ship.get_size() == 4
    assert ship.get_direction() == 'poziom'