lundi 15 février 2016

c# filling my 2D array with specific characters

I started coding about a week ago in school and got an assignment to make a 20x20 box and fill it randomly with the characters B, V, M, SB, SL, _, F, P, K, L. I also have to code the chance that the character is in the box. For example: B has an 8% chance to be in my 20x20 box. I'm not sure how to get the characters to appear randomly and no clue at all how to code a certain chance for them all.

This is what I have so far:

int[,] objectArray = new int[20, 20];

// Horizontal numbers.
for (int i = 1; i <= 20; i++)
{
    if (i == 1)
        Console.Write("   " + i);
    else if (i < 9)
        Console.Write("  " + i);
    else
        Console.Write(" " + i);

}
Console.WriteLine("");

//Vertical numbers
for (int x = 0; x < 20; x++)
{
    if (x < 9)
        Console.Write((x + 1) + "  ");
    else
        Console.Write((x + 1) + " ");

    for (int y = 0; y < 20; y++)
    {
        Console.Write("_  ");
    }

    Console.WriteLine();
}

Console.Read();

I hope you can give me tips on how to fix this.




Aucun commentaire:

Enregistrer un commentaire