0

My array only deploys one image i would like it to display 52 card images each one twice and selected randomly

is anyone able to point me in the right direction

Thanks

Image of grid

namespace FinalPairsGame
{
    public partial class Background : Form
    {
        // global decalrations
        int[,] memoryarray = new int[6, 6];
        GImageArray controlarray;
        string imagepath = Directory.GetCurrentDirectory() + "\\Cards\\";

        public Background()
        {
            InitializeComponent();
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            initgame();
            pictureBox1.Hide();
            Title.Hide();
        }
        private void helpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            inithelp();
        }
        private void inithelp()
        {
            MessageBox.Show("Pairs, the aim of the game is to match 2 cards in the grid, each player will take it in turns to find a pair, once the card pair has been found it will turn blue. The winner is the player who ends with the most pairs");
        }

        public void initgame()
        {
            for (int row = 0; row < 6; row++)
            {
                for (int col = 0; col <6;col++)
                { 
                    memoryarray[row, col] = 1;
                    if (memoryarray[row, col] == 1)
                    {
                        ;
                    }
                }
            }
            controlarray = new GImageArray(this, memoryarray, 35, 200, 10, 200, 10, imagepath);
            controlarray.Which_Element_Clicked += new GImageArray.ImageClickedEventHandler(Which_Element_Clicked);
        }
   




        private void Which_Element_Clicked(object sender, EventArgs e)
        {
            int row = controlarray.Get_Row(sender);
            int col = controlarray.Get_Col(sender);

        }
        private void assigncardstogrid()
        {
            
                
        }

      

    }
}

I tried messing around with it but could never get further than one card and yeah not sure how to fix this would appreciate it if someone could help me out

  • Problem on which part? – MichaelMao Dec 23 '22 at 09:00
  • My grid will only display one card i need it to display 52 (26 pairs) i cant figure out how to do it – Harrison 2904 Dec 23 '22 at 09:05
  • 1
    Try to write in clear sentence what you expect init, game to do, and the step. With a clear definition you will have 99% of your issue solved. If you have issue defining what to do, go back to pen and paper , draw a single row grid. Define the card and pair. and manually pick them. If you are strict in your pick you will have an almost compilable algorythm – Drag and Drop Dec 23 '22 at 09:15
  • @MichaelMao My grid will only display one card i need it to display 52 (26 pairs) i cant figure out how to do it – Harrison 2904 Dec 23 '22 at 09:30
  • Trying to fix, solve, display image could be overwhelming. Allow me to take a step back and do it in console, with a 1d Grig , and no image. Simplify the issue may help you understand what you have to do. https://dotnetfiddle.net/iU4JOk. You may think "that's a bit too mutch, it's not related to my issue". But if you had a int[52] with correct numbers in it, it will be 100% of your solution without any code modification. – Drag and Drop Dec 23 '22 at 09:42
  • The code doesn't do mutch , because for now every thing else is unclear. You keep repeating the same "display the 52". But there is many question that can be raise using the shared code as a base. How many pair do you have, not in the grid, but in total? How do you pick those Pair if you have more than required? If you have exactly the right number then you have one less issue: simply double the card to create pair and shuffle. – Drag and Drop Dec 23 '22 at 09:53
  • so i have a deck of cards (52) i need the grid to display 26 cards out of the 52 twice, also thankyou for helping me – Harrison 2904 Dec 23 '22 at 09:57
  • i have put an image in the chat to further explain – Harrison 2904 Dec 23 '22 at 09:59
  • you have to pick your card first https://stackoverflow.com/questions/48087/select-n-random-elements-from-a-listt-in-c-sharp . Add them twice , and shuffle the result. – Drag and Drop Dec 23 '22 at 10:22
  • @DragandDrop is there any chance you would be able to implement that into my code example i cant get it to work, again thanks for your help. – Harrison 2904 Dec 23 '22 at 10:27

0 Answers0