Oppure

Loading
02/07/12 11:26
ht-never
sto implementando in un videogioco in C#, Framework XNA un sistema di custom levels basato su plain text. Esempio:
10
10
100
10
10
10
10
100

questo codice genera due rettangoli di qualche sorta, composti da quattro numeri, appunto che andranno ad essere gli argomenti del costruttore della classe Rectangle.

questo è il codice:
la funzione DrawWall disegna un singolo rettangolo

private void DrawLevel(string file)
        {
            int[] buffer = new int[500];
            int[] the_buffer = new int[4];
            int count=0;

            string[] lines = System.IO.File.ReadAllLines(file);
            foreach (string line in lines)
            {
                buffer[count] = Convert.ToInt32(line);
                count++;
            }
            count = 0;
            foreach (int i in buffer)
            {
                if (count == 4)
                {
                    count = 0;
                    DrawWall(the_buffer[0],
                             the_buffer[1],
                             the_buffer[2],
                             the_buffer[3]);
                }
                the_buffer[count] = i;
            }
        }
aaa
02/07/12 11:45
ampeg
mi sa che il problema è che non fai avanzare la variabile count nella seconda iterazione quindi non arriverà mai ad avere il valore uguale a 4
aaa
02/07/12 12:05
ht-never
Grazie, era quello il problema
aaa