示例#1
0
def your_attack_response(msg: Message) -> None:
    global enemy_matrix
    if msg.info.startswith('wounded'):
        print("You wound enemy")
        msg = msg.info.split('_')[1]
        wounded_coord = Coordinate(msg.split(':')[0], msg.split(':')[1])
        enemy_matrix.matrix[wounded_coord.number][
            wounded_coord.letter_like_number] = '-'
        enemy_matrix.print_matrix()
    elif msg.info.startswith('missed'):
        print("You missed")
        msg = msg.info.split('_')[1]
        wounded_coord = Coordinate(msg.split(':')[0], msg.split(':')[1])
        enemy_matrix.matrix[wounded_coord.number][
            wounded_coord.letter_like_number] = '+'
        enemy_matrix.print_matrix()
    elif msg.info == 'you win':
        print("You win")
示例#2
0
def get_coordinate(ship_length: int, type_coordinate: str) -> Coordinate:
    coord = input("Input {} coord (a:2) with length {}\n".format(
        type_coordinate, ship_length))
    while coord[0] not in 'abcdefgh' or coord[1] != ':' or coord[
            2] not in '1234567890' or len(coord) != 3:
        print("Enter correct coordinate")
        coord = input("Input {} coord (a:2) with length {}\n".format(
            type_coordinate, ship_length))
    return Coordinate(*coord.split(':'))
示例#3
0
def test_init_ship2():
    ship2 = Ship(Coordinate('a', 5), Coordinate('a', 3))
    assert len(ship2) == 3
示例#4
0
def test_init_ship():
    ship = Ship(Coordinate('c', 2), Coordinate('a', 2))
    assert len(ship) == 3
示例#5
0
def test_init_coord():
    c = Coordinate('a', 2)
    assert c.number == 2
示例#6
0
def test_add_ship():
    matrix = Matrix()
    matrix.add_ship(Ship(Coordinate('a', 2), Coordinate('a', 3)))
    matrix.add_ship(Ship(Coordinate('b', 4), Coordinate('c', 4)))
    assert not matrix.all_ships_are_dead()