Problem z przeniesieniem zmiennej konstruktora do konstruktora

0

Cześć,
Mam problem z przeniesieniem zmiennej pole konstruktora z klasy PozycjaF.cs do konstruktora Krol z klasy Krol.cs, który dziedziczy z klasy PozycjaF.cs oraz IFigura.cs, następnie wypisuję to w Program.cs.Czy istnieje jakis sposób by dodac konstruktor public PozycjaF(string pole) ,którego chciałbym użyć jako zmienną pozycja do pobrania w konstruktorze Krol
public Krol(string kolor,string symbol,string pozycja,string nazwa = nameof(Krol)) ?

Pozdrawiam

IFigura.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SzachyRoLa.Klasy
{
    public interface IFigura
    {
        string Nazwa { get; }
        string Kolor { get; }
        string Symbol { get; }
        void PokazDetale();
    }
}

PozycjaF.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SzachyRoLa.Klasy
{
   public class PozycjaF
    {
        int x;
        int y;
        string pole;

        public string Pole
        {
            get
            {
                return pole;
            }

            set
            {
                pole = value;
                x = PrzeliczX(pole);
                y = PrzeliczY(pole);
            }
        }

        public int X
        {
            get
            {
                return x;
            }
        }

        public int Y
        {
            get
            {
                return y;
            }
        }

        internal static int PrzeliczX(string pole)
        {
            return pole[0] - 'A' + 1;
        }
        internal static int PrzeliczY(string pole)
        {
            return Int32.Parse(pole.Substring(1));
        }

        public PozycjaF()
        {
            pole = null;
            x = 0;
            y = 0;
        }
        public PozycjaF(string pole) // tego konstruktora chcialbym użyć 
        {
            this.Pole = pole;

        }
    }
}

Krol.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SzachyRoLa.Klasy.Figury
{
    class Krol : PozycjaF,IFigura   //Dziedziczenie z Interfejsu oraz Pozycji
    {      
        public string Nazwa { get; private set; }
        public string Kolor { get; private set; }
        public string Symbol { get; private set; }
        


        public Krol(string kolor,string symbol,string pozycja,string nazwa = nameof(Krol))    //Konstruktor tutaj chcialbym dodac konstruktor PozycjaF
        {
           Nazwa = nazwa;
           Kolor = kolor;
           Symbol = symbol;
           Pozycja = pozycja;
           


        }

        public void PokazDetale()   //Wyświetla detale 
        {       
            Console.WriteLine(string.Format("+-----------------------------------------+\n" +
                                             "Figura : {0}{1} Kolor : {2} Pozycja : {3}\n" +
                                            "+-----------------------------------------+\n", Symbol, Nazwa, Kolor,Pozycja));
        }
    }

}

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SzachyRoLa.Klasy.Figury;
using SzachyRoLa.Klasy;

namespace SzachyRoLa
{
    class Program
    {
        static void Main(string[] args)
        {  
            //Króle
            IFigura bialyKrol = new Krol("Biały", "♔", ""); 
            bialyKrol.ToString();
            bialyKrol.PokazDetale();
            IFigura czarnyKrol = new Krol("Czarny", "♔", "");
            czarnyKrol.PokazDetale();

            Console.WriteLine(przyklad.Pole);

            Console.ReadKey(true);
        }
    }
}
0

Okej dałem rade zmienić klase Krol.cs tak jak chciałem.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SzachyRoLa.Klasy.Figury
{
    class Krol : PozycjaF,IFigura   //Dziedziczenie z Interfejsu oraz Pozycji
    {      
        public string Nazwa { get; private set; }
        public string Kolor { get; private set; }
        public string Symbol { get; private set; }

        public string PoleFig(string pole)
        {
            return Pole;
        }
       


        public Krol(string kolor,string symbol,string pole,string nazwa = nameof(Krol))    //Konstruktor 
        {
           Nazwa = nazwa;
           Kolor = kolor;
           Symbol = symbol;
           Pole = pole;
        }

1 użytkowników online, w tym zalogowanych: 0, gości: 1