locked
Set values for a 2 dimensional array RRS feed

  • Question

  • User-761596968 posted

    Hey! I've got stuck in my Bingo project.

     class Spelplan
        { 
            
            public Stack bollar = new Stack();      
            ArrayList arrayen = new ArrayList();
            Random boll = new Random();
            int c = 0;
            public Spelplan() { bollar = new Stack(); }
    
            public Rectangle[,] rutor = new Rectangle[5,5];
    
            public void rakna()
            {
                for (int x = 0; x < 5; x++)
                {
                    for (int y = 0; y < 5; y++)
                    {
                        rutor[x, y] = new Rectangle(x * 100, y * 100, 100, 100);
                    }
                }
           }
            public void raknasystem()
            {
                for (int i = 0; i < 25; i++)
    			{
                    arrayen.Add(i);
                    
    			}
              
                for (int i = 0; i < 25; i++)
                {
                    c = boll.Next(1, 25);
                    while (arrayen[c] != null)
                    {
                        bollar.Push(arrayen[c]);
                        arrayen[c] = null;
                    }
                }
             
            }
        }W

    As you can see i got a 2 dimensional array to keep track of a 5x5 grid. What i want to do is to give each of the positions in my grid a value in my arraylist ("arrayen"). 

    So basicly i want:

    position 0 in "arrayen" to have the value 0,0

    position 1 in "arrayen" to have the value 0,1

    position 2 in "arrayen" to have the value 0,2 

    position 3 in "arrayen" to have the value 0,3

    position 4 in "arrayen" to have the value 0,4

    position 6 in "arrayen" to have the value 1,0

    .......

    position 24 in "arrayen" to have the value 4,4

    How can i proceed to get this working?

    Thanks in advance!

    Wednesday, May 15, 2013 3:58 AM

Answers

  • User-1716253493 posted

    try use %

    a. 7 / 5 = 1

    b. 7 % 5 =2

    position 7 = arr(1,2)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 15, 2013 4:21 AM