Pattern finder [duplicate]

0

I return to a question I asked a few days ago. The intention is to create a program that generates a template like the one shown below in an "intelligent" way. That is, a sequence generator that will vary according to the values for S, E or A. I would like to ask you for help so that you could guide me as to approach the subject to start programming it. The truth is that I have little experience programming and I do not know where to start.

    
asked by Skakimat 21.06.2018 в 13:07
source

1 answer

0

Let's see if this guides you to start. Although you can do it in a thousand different ways and on any platform I focus it on .Net with C # language.

Sequence

To generate the sequence, I propose that you create an object that encapsulates the processing of your S, E and A data. For example:

// Enumerado con los tipos posibles
public enum TipoDato
{
    S,
    E,
    A
}

// Clase que trata los datos S, E y A
public class SEAData
{
    private int  S { get; set; }
    private int E { get; set; }
    private int A { get; set; }

    public SEAData(int s, int e, int a)
    {
        S = s;
        E = e;
        A = a;
    }

    public List<TipoDato> GetSEAList()
    {
        List<TipoDato> seaList = new List<TipoDato>();
        for (int i = 0; i < S; i++)
        {
            seaList.Add(TipoDato.S);
        }
        for (int i = 0; i < E; i++)
        {
            seaList.Add(TipoDato.E);
        }
        for (int i = 0; i < A; i++)
        {
            seaList.Add(TipoDato.A);
        }
        return seaList;
    }

    public List<TipoDato> GetSEAListRandom()
    {
        Random random = new Random();
        List<TipoDato> seaList = GetSEAList();
        return seaList.OrderBy(x => random.Next()).ToList();
    }
}

For its use we could do it like this:

private void Test()
{
    SEAData sea = new SEAData(74, 39, 71);
    List<TipoDato> sequence = sea.GetSEAListRandom();
}

The sequence variable creates a randomly altered list the way you wanted.

You can do the tests that you create at this point.

UI

Continuing with .Net I suggest you create a new Windows Forms project and to start you create a new form (or use the one created automatically when creating a new project) to test. Later and when you control more I would create a user control (user control) to which we pass an object of our type SEAData and be able to paint the necessary UI.

For the tests I would add directly in your form a flowLayoutPanel type control that acts as a container for other controls and that allows you to organize controls automatically. Make sure to set the Dock property of this control in Fill so that the entire window will fill you. In this way we can dynamically create controls based on the size of our list of SEAData .

The following example creates an array of controls with the value S, E, or A in the Load event of a form:

private void Form1_Load(object sender, EventArgs e)
{
    SEAData seaData = new SEAData(74, 39, 71);
    List<TipoDato> seaListRandom = seaData.GetSEAListRandom();

    foreach (TipoDato tipo in seaListRandom)
    {
        flowLayoutPanel1.Controls.Add(new TextBox { Text = tipo.ToString() });
    }
}

The next step would be to paint a color according to S, E or A, center the text ....

I hope it serves as your first approach.

This is what the example that I have proposed paints you:

    
answered by 22.06.2018 / 17:54
source