Пример #1
0
    //Jбработка попадания в ячейку
    public void Treatment_Shot()
    {
        switch (type_unit)
        {
        case unit_type.sea:
        {
            type_unit  = unit_type.hit_sea;
            this.image = new BitmapImage(new Uri("dot.png", UriKind.Relative));
            break;
        }

        case unit_type.ship:
        {
            type_unit  = unit_type.hit_ship;
            this.image = new BitmapImage(new Uri("cross.png", UriKind.Relative));
            break;
        }

        default:
        {
            throw new InvalidOperationException("Trying to change a modified cell");
        }
        }
        //Обработка попадания и соответсвующее изменение картинки для ячейки.
    }
Пример #2
0
    //Установка типа ячейки
    public void Set_Unit_Type(unit_type type_unit)
    {
        switch (type_unit)
        {
        case unit_type.hit_sea:
            Set_Image(new Uri("dot.png", UriKind.Relative));
            break;

        case unit_type.hit_ship:
            Set_Image(new Uri("cross.png", UriKind.Relative));
            break;

        case unit_type.sea:
            Set_Image(new Uri("sea.jpg", UriKind.Relative));
            break;

        case unit_type.ship:
            Set_Image(new Uri("ship.png", UriKind.Relative));
            break;
        }
        this.type_unit = type_unit;
    }
Пример #3
0
    private int position_j;      //Позиция ячейки в стольбце матрице


    //Конструкторы:

    public Unit(unit_type type_unit, int position_i, int position_j)
    {
        try
        {
            this.type_unit  = type_unit;
            this.position_i = position_i;
            this.position_j = position_j;
        }
        catch (Exception)
        {
            throw new ArgumentException("Invalid argument");
        }
        try
        {
            switch (type_unit) //В свитче устанавливаем ячейке картинку в зависимости от переданного аргумента type_unit
            {
            case unit_type.sea:
                this.image = new BitmapImage(new Uri("sea.jpg", UriKind.Relative));     //Используем относитьельные пути к картинкам (т.е. они должны рядом с экзешником лежать)
                break;

            case unit_type.ship:
                this.image = new BitmapImage(new Uri("ship.png", UriKind.Relative));     //Добавить картинку с кораблем
                break;

            case unit_type.hit_sea:
                this.image = new BitmapImage(new Uri("dot.png", UriKind.Relative));     //Добавить картинку с попаданием в море
                break;

            case unit_type.hit_ship:
                this.image = new BitmapImage(new Uri("cross.png", UriKind.Relative));     //Добавить картинку с попаданием в корабль
                break;
            }
        }
        catch (Exception)
        {
            throw new UriFormatException("Missing image of the unit");
        }
    }
Пример #4
0
 public void Set_Unit_Type(unit_type type_unit)
 {
     this.type_unit = type_unit;
 }