10. Memory Game with Windows Forms! | Intro To C# Programming

Поделиться
HTML-код
  • Опубликовано: 25 авг 2024

Комментарии • 196

  • @emiliatakkinen5253
    @emiliatakkinen5253 4 года назад +39

    Thank you for saving my grade in programming at school :)

    • @michaelartsmedia
      @michaelartsmedia  3 года назад +1

      Haha that's awesome to hear! You're welcome!

    • @saltypepper3340
      @saltypepper3340 2 года назад +2

      @@michaelartsmedia uisng the newest version of visual studio also using c# windows form.
      For me, on random, icons, firstclicked and secondclicked
      It says that "A namespace cannot directly contain members such as fields or methods"
      And because of this the program does not work
      Do you maybe know how to fix these errors?

  • @eyyjj1533
    @eyyjj1533 5 месяцев назад +1

    6years later and you are still helping people! Thank you so much for this very helpful video!

    • @michaelartsmedia
      @michaelartsmedia  5 месяцев назад

      That's great to hear. Thanks for watching!

  • @mittamaka
    @mittamaka 5 лет назад +21

    Great tutorial, I understood everything you said. It was all nice and clear, great job dude.

  • @teacherinthailan6441
    @teacherinthailan6441 3 года назад +5

    Excellent! My first C# experience plus Forms too! You are an amazing teacher. Thank you so much.

  • @dindocastrogamis
    @dindocastrogamis 4 года назад +8

    Thank you it's a big help for my case study this midterm for my subject "Game Development" ! Make more game using C# in VB please!

  • @johnvenn3774
    @johnvenn3774 3 года назад +4

    One of the best tutorials I've ever done. Thank you so much

  • @ctcrosby01
    @ctcrosby01 Год назад +2

    Dude, this was fantastic. Definitely going to incorporate some of your ideas into my project.

  • @csanadczanik9710
    @csanadczanik9710 3 года назад +2

    I actually tried racing you at the end. You won, cant beat the creator I guess. Thanks for the help!

  • @freekynoname2885
    @freekynoname2885 3 года назад +1

    dude in 2021 u saved my coursework on c#))) Thx buddy)))

  • @luiskeller2895
    @luiskeller2895 3 года назад +1

    Thank you my man. This Video helped me and my friend to safe our grade in IT Class.

  • @amirhosseinzarei2597
    @amirhosseinzarei2597 3 года назад +4

    Thank you so much Nice and clear. That was great. step by step. You are a great teacher I have learned all of them. especially "oops!" between codes were great ;)!!!

    • @michaelartsmedia
      @michaelartsmedia  3 года назад +1

      haha so glad to hear you enjoyed it! Thanks for watching!

  • @xauchino8879
    @xauchino8879 2 года назад +1

    Nice and easy tutorial, thanks for the help, it was useful and easy to understand.

  • @Eneken64
    @Eneken64 6 лет назад +4

    Amazing game Michael! Thank you very much!

  • @madness5690
    @madness5690 2 года назад

    thanks mate, great tutorial i had to do this for my school with extra reset, start, stop and exit buttons and this here pretty much made it possible without any problems

    • @tidzej5400
      @tidzej5400 3 месяца назад

      Hey, i have the same exercise with those buttons, can you write how did you manage to do them?

  • @marcfrancecabiles2354
    @marcfrancecabiles2354 6 лет назад +6

    You deserve a thousand likes!

  • @fuxu217
    @fuxu217 4 месяца назад

    Thank you for your teaching

  • @omersar7544
    @omersar7544 5 лет назад +2

    nice and very explanatory. thanks for your tutorial

  • @szabinakralik2267
    @szabinakralik2267 6 лет назад +3

    I like it very much. Thanks Michael!

  • @aleksd3263
    @aleksd3263 4 года назад +2

    Great tutorial! Thank you!

  • @naTure-vs2ef
    @naTure-vs2ef 3 года назад +2

    It tells me error on the label.Text= icons[randomNumber];
    It says "index was out of range",Must be non-nevative and less than the size of the collection...
    Help pleaseee Michael

  • @sideral09
    @sideral09 16 дней назад

    thank you for the big help!

  • @guybrush3318
    @guybrush3318 4 года назад +1

    Dude, AMAZING thankyou!

  • @jnelson16701
    @jnelson16701 4 года назад +6

    Excellent tutorial, however I'm getting an error in the AssignIconsToSquares method. The error occurs on the line that reads: "label.Text = icons[randomnumber];" The error says, "Use of unassigned local variable 'label'.
    I don't understand why this error occurs. I typed in the same code you showed here. I'm using VS 2019, so I don't know if that makes a difference or not. I don't see how it would, but you never know with Microsoft.
    Thanks. :)

    • @michaelartsmedia
      @michaelartsmedia  4 года назад +1

      That error means you're trying to use a variable that hasn't been assigned. A lot of times just assigning the variable to an empty value where you declare it initially will fix this.
      So instead of
      ClassName class;
      ClassName class = null; would fix the error.
      Try comparing your declaration with what's in the video and look for things like that. Thanks for watching!

    • @benchmarking6875
      @benchmarking6875 Год назад

      I was getting the same error, but saw that I forgot to put a "N" in the list. After adding that, it fixed it.

  • @marcusmanning8653
    @marcusmanning8653 4 года назад +1

    nice tutorial thank you you helped me out a lot!

  • @ledschmidt1441
    @ledschmidt1441 5 месяцев назад

    Great game and thanks much for teaching the code as well..... hope you still monitor the site because another feature for this would be... should someone guess 3 times and NOT match, then the game penalizes them and resets the entire game, regardless of how far along you are. So if you can, help me with the code that would do this...... i'm real new to c...... Also for me personally, I will play with it and add more cols and rows and make it really tough!!

  • @shandrickdeguzman5182
    @shandrickdeguzman5182 4 года назад +2

    can I use picture box if I want to set the picture instead of label???

  • @user-hj4rb9mv7l
    @user-hj4rb9mv7l 3 года назад +1

    if i want to use pictures instead of letters, can i use picture box?

  • @arrxwy
    @arrxwy 2 месяца назад

    Hello, I'm having trouble at 17:50. For me, just one image shows up and the rest are just the squares, does anyone know what's wrong please?

  • @jobot4780
    @jobot4780 3 года назад

    Thank you a lot !! great tutorial

  • @ayushtyagi3895
    @ayushtyagi3895 2 года назад +1

    I have to do the same thing but instead of labels in each of the boxes, I need to use picture boxes, any suggestions?

  • @simo5465
    @simo5465 6 лет назад +4

    is someone here who knows how to show images in Wpf with style "Webbedigns"? I finished the game, but i don't know how to show images instead of letters..
    P.S.: Thank you for your great video. Very nice :)

  • @migalesch1839
    @migalesch1839 2 года назад

    thanks dude

  • @filipebraz9982
    @filipebraz9982 3 года назад +1

    ​ @Michael Hicks I'm kind replicating this exercice with visual basic code. I'm having trouble with hiding the images (as I'm using pictureboxes) and creating an event for when the images clicked match. Any tips?

  • @ellathermaenius8488
    @ellathermaenius8488 2 года назад +1

    This is the video that saved my grad, but the pictures won’t random they are just next to each outer. What am I doing wrong?

    • @michaelartsmedia
      @michaelartsmedia  2 года назад

      It's hard to say without looking at code, but I would make sure the line that uses the "random" function is written correctly. Good luck!

  • @shina6377
    @shina6377 4 месяца назад

    is it possible to use images or pictures instead of icons?

  • @brahm2157
    @brahm2157 3 года назад

    Dude seriosly thank you !

  • @darkosimic4861
    @darkosimic4861 Год назад

    Each time i try always match first 2. all cards match and shows only SQUARE.

  • @Chavyyy
    @Chavyyy 5 лет назад +1

    Nice video! Very well explained I am trying to add a new feature to it. I am trying to connect a trackbar to the game. The trackbar minimum value is 4 and max is 10. If the track bar is value 4 it should be 4*4 if it’s 5 it should be 5*5 but i am not having success.

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      Thanks for watching! What exactly is the issue? The track bar is supposed to change the grid of the game but it's not somehow? The more details you give the better!

  • @migsteele
    @migsteele 4 года назад +1

    Hello, tableLayoutPanel.Controls is an empty collection for me? Am I supposed to intialise that collection somewhere, I can't see you do it at any point in your video?

  • @aaryannavare4911
    @aaryannavare4911 10 месяцев назад

    How can I add levels into this game please give some ideas

  • @kc9868
    @kc9868 5 лет назад

    Great video!

  • @abbeyharobed660
    @abbeyharobed660 2 года назад +1

    Great Tutorial! I've got a question, if at the end of the game you want to restart it instead of the "close();" at the end, what would we run instead?

    • @michaelartsmedia
      @michaelartsmedia  2 года назад +1

      Thanks for watching! You'll need to reinitialize all of the variables and form info to their initial state. That means resetting the draw colors to the invisible color, and also resetting the variables we declare at the top. Good luck!

  • @ImDippinIn
    @ImDippinIn 3 года назад

    Thanks man

  • @serhiimamedov
    @serhiimamedov 5 лет назад +1

    Damn... I gotta be stupid or something... I don't understand null and return in the code. When the form initialized all labels are null right?
    So there is a code:
    if (clickedLabel == null)
    return;
    return to what? click function is a void so it does not return value!
    And there is this thing:
    if (firstClicked.Text == secondClicked.Text)
    {
    firstClicked = null;
    secondClicked = null;
    }
    What is that suppose to mean? So you successfully matched 2 labels so... What does it mean? You set them both to null... Why and what does it do?
    Great video by the way! We all need more of these and you need much more likes and subs!

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      Hey, sorry I just saw this comment. When a function is void and you want to immedietely exit the function you simply call return. Like you said void means nothing so you don't type anything after return.
      Null basically means "no value" or empty. You could think of it as setting those variables to 0.
      Hope that helps and sorry again.

  • @cccddd882
    @cccddd882 3 года назад +1

    Thank you! It helped me a lot! But I have one problem, I have no “tablelayout” in toolbox. What should I do? I would love an answer quickly because I need it for a project for this week.

    • @michaelartsmedia
      @michaelartsmedia  3 года назад

      Unfortunately I probably can't be much help with that. Possibly it didn't come with your install of visual studio? You'll probably have better luck googling that... sorry!

    • @cccddd882
      @cccddd882 3 года назад

      @@michaelartsmedia oh I understand. Ty!

  • @simonwong7969
    @simonwong7969 2 года назад

    Hi Micheal Hicks. I following the skip but on the line 32 if(firstClicked ! = null && secondClicked ! = null) return; , it is still error. Can i know what happens?

  • @imeiprezime8327
    @imeiprezime8327 9 месяцев назад

    Druze, volim te

  • @FYLTV
    @FYLTV 3 года назад

    Thanks!

  • @deandregriffin3248
    @deandregriffin3248 3 года назад +1

    how do I insert picture files instead of icons?

    • @bimbon123
      @bimbon123 9 месяцев назад +1

      did you figured out how?? i would like to know

  • @Tim_Linkel
    @Tim_Linkel 6 лет назад +2

    Hi Michael. This is the best tutorial that I've ever seen.
    I do my memo game with pictureboxes. I did almost everything as you did. But I have List of the pictures, not the labels ... and at the last step when I need to compare 2 "icons" I dont know how to compare them. Could you help me please?

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад

      Haha thanks a lot, you're too kind! There is likely an Image variable in the picture box that you can compare. If the images are equal then you know they are matching!

    • @Tim_Linkel
      @Tim_Linkel 6 лет назад

      @@michaelartsmedia sure there is. The question is how to refer to that image variable . And what is the variable it is.

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад

      @@Tim_Linkel You should be able to just compare that variable. If not, you can create a string variable that stores the name or path of the image. When you set the image make sure you set this variable appropriately and you can compare the name of the images later on.

    • @Tim_Linkel
      @Tim_Linkel 6 лет назад

      thank you so much. I've just now found a solution to make it works.

  • @sreealekyatellabati8108
    @sreealekyatellabati8108 3 года назад

    Iam getting warning like the field'form1.firstclicked'is never used and also the field 'form1.second clicked is never used

  • @AlkNA
    @AlkNA 5 лет назад +1

    Nice video!
    I don't have any errors but my program doesn't functions after I have clicked 3 images. So, when I click on two images and if they are not the same they disappear after 750 ms but after that, I click again and the program freezes and does not respond to my clicks :/

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      It's like an issue with the timer freezing or not being reset maybe. Maybe take a look at that section of the video and double check everything matches up. Good luck!

  • @lew1884
    @lew1884 2 года назад

    hi man ,do you have tutorial how to add timer to the game like 1 min to win?

  • @amitnachmias4978
    @amitnachmias4978 4 года назад +1

    Hello, Michael, your video help me a lot and I think your one of the greatest when I doing the right match between two labels I get an error message which says:
    System.NullReferenceException: Reference to object not set to an instance of an object. it's happened in this line:
    firstClick.ForeColor = firstClick.BackColor;
    secondClick.ForeColor = secondClick.BackColor;
    I hope you could help me

    • @michaelartsmedia
      @michaelartsmedia  4 года назад

      If you hover over those variables you'll see that one of them is null... anything that you try to access that is null will throw that error. If something is null that means it's an empty variable that has nothing inside. Usually this means you're missing a line of code where you call "new" on a class. Good luck and thanks for watching!

    • @viktortaylor4505
      @viktortaylor4505 2 года назад

      The same code as here, or on with the original Microsoft tutorial, and always System.NullReferenceException;
      ps: Ok, works fine. The issue: Time enabled was true, and it works only with false.

  • @technercom5502
    @technercom5502 4 года назад

    it gives me the error property not found when ever i want to type c in gridcharset

  • @TheMakcswell
    @TheMakcswell 6 лет назад

    Ty dude!

  • @adinanicolau27
    @adinanicolau27 6 лет назад +1

    Hi. This video helped me a lot. I want to ask you a question, is possible when 2 of them matched another image to show up in the 2 icons? For example: when the spiders match, they will be replaced with "x" image. Can you help me to fix this issue?
    Thank you!

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад +1

      Very glad to hear the video was useful. In regards to your question: do you know the function where we randomly set the panel text to various letters from the Webdings font? You would do something similar... find the character in the font that is the X you want, then set the text of the matching panels to that character once you detect the match! This should be pretty easy as we've already detected when two images match.... good luck!

    • @adinanicolau27
      @adinanicolau27 6 лет назад +1

      Michael Hicks thank you a lot!

  • @ibraheemalhunaidi2228
    @ibraheemalhunaidi2228 2 года назад

    Hey what version of visual studio did you use?

  • @petersusan7743
    @petersusan7743 6 лет назад +1

    Thanks so much for the video.
    Can you please write a function for counting how many times each label clicked at the end of the game.

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад +3

      Hey you're very welcome! Unfortunately I'm super busy right now trying to ship my new video game, but I can lead you in the right direction. You could create a list of ints and each int in the list can correspond to one of the grids. For example...
      List timesClicked = new List ();
      Then in initialize or somewhere at the beginning of the program you could call timesClicked.Add (0); to add a number for each grid. You could put that line in a for loop that iterates for as many grids there are.
      Then once one of the grids are clicked you could say timesClicked[0]++ to add one to the count. Replace 0 with whatever grid is clicked, you would only use 0 if the very first grid was clicked.
      Hopefully that helps! Good luck!

    • @petersusan7743
      @petersusan7743 6 лет назад +1

      Thanks so much for responding quickly!!!
      this is a great idea am getting on it right away.
      Cheers to you sir

    • @petersusan7743
      @petersusan7743 6 лет назад

      Hi, am failing to do this because every time is 'int' to the grids its not compatible to the System.Windows.forms .
      Do you have a simpler way of doing it?
      or maybe you can write a simple code in the comments

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад

      +Peter susan The code I posted is the simplest way I can think of. Don't set anything to the form, it sounds like you're trying to set something that's not an int to the int. Maybe start with only one int that counts how many total times all the grids are clicked. Then once you get that working you can expand to having a counter for each grid. To do this just make an int called counter at the top and then increase it each time a grid's color is set to the visible color!

    • @petersusan7743
      @petersusan7743 6 лет назад

      Thanks Sir. I'll start from here and do it.
      I appreciate you responding even on your old videos

  • @User-ww3oj
    @User-ww3oj 4 года назад +1

    How long did it take you to get to this point? In terms of time how did you personally learn?

    • @michaelartsmedia
      @michaelartsmedia  4 года назад +1

      I taught myself by making small games. If you have a passion for coding you will learn the more you dive in!

    • @User-ww3oj
      @User-ww3oj 4 года назад

      @@michaelartsmedia Thanks Michael.

  • @tomealexandre2345
    @tomealexandre2345 6 лет назад +1

    Nice

  • @TheStreeterCZ
    @TheStreeterCZ 4 года назад

    What if I wanted to program a bot to play against me? E.g. it would just pick random cards (no intelligence)

  • @TheLifeWithJoy
    @TheLifeWithJoy 3 года назад

    I couldn’t help my daughter, but this tutorial DID 😊😊😊😊🍾🤓🤓🙏🙏🙏🙏🙏🙏🙏🎖🎖🎖🎖🎖🎖🎖

  • @zaoplayz8021
    @zaoplayz8021 5 лет назад +1

    How can I change it into mathematical icons?

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад +1

      You could change fonts and just use the + - x / signs... or you could implement a picture box (see the comments below for links on this) to use whatever pictures you want. Depending on what symbols you're using, I'd just use a different font! Good luck!

    • @zaoplayz8021
      @zaoplayz8021 5 лет назад

      @@michaelartsmedia thank you for your answer :>

  • @457Deniz457
    @457Deniz457 6 лет назад +1

    *ty nice tut ! :)*

  • @tanjimashraf803
    @tanjimashraf803 5 лет назад

    didnt understand the line 38 in the video. Why the Labels of tableLayoutPanel.Controls are stored in the local variable label?

    • @tanjimashraf803
      @tanjimashraf803 5 лет назад

      Why did you use the if condition on line 38? Kindly explain it explicitly.

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад +1

      There could be many different types of controls in that list, so we use the if check to confirm the current item we're looking at in the list is a Label.

  • @Codworld360
    @Codworld360 6 лет назад

    I must have missed something in the video because I'm getting an error of "Object reference not set to an instance of an object" for the following code in the timer1_Tick function
    firstClicked.ForeColor = firstClicked.BackColor;
    Please help!!

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад

      When it breaks, hover over the line it highlight and see which variable is set to null. This is the variable that needs set... at this point you can reference the video to find the line that sets the variable you missed. Good luck!

    • @onigumo
      @onigumo 5 лет назад

      i was getting the same thing but i checked a lot times somehow my code "timer1.Start(); " wrote two times, just delete one and it works fine.

  • @amaltalibe8854
    @amaltalibe8854 5 лет назад +1

    You didn’t tell us how you got that empty form set up. Doesn’t help beginners like me

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад +1

      This is part of a series of videos. We cover making empty projects in earlier videos! Basically you just need to go to New Project and choose Windows Form project.

  • @janielletulloch4761
    @janielletulloch4761 5 лет назад

    I am getting an error message for this. for (int i = 0; i

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      Somewhere that variable isn't being set, try looking through the code in the video and see if you're missing any lines related to that variable. Also, if that doesnt help try creating a whole new table Layout Panel and using the variable it gives you. Sometimes the variables don't get linked up to the form stuff properly. Good luck!

    • @janielletulloch4761
      @janielletulloch4761 5 лет назад

      @@michaelartsmedia thanks.

    • @onigumo
      @onigumo 5 лет назад

      i was getting the same thing but i checked a lot times somehow my code "timer1.Start(); " wrote two times, just delete one and it works fine.

  • @janielletulloch4761
    @janielletulloch4761 5 лет назад

    How do you edit it so it will ask you if you want to start a new game instead of closing it?

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      You can display a message box that asks that question and then respond to it accordingly. Google C# message box yes or no and there should be code samples. If they say yes you just need to reset all of the game variables by setting them to the default values for the new round. Good luck!

    • @janielletulloch4761
      @janielletulloch4761 5 лет назад

      @@michaelartsmedia Thank you.

  • @TheDrop2.0
    @TheDrop2.0 3 года назад

    Can you do this in Visual Basic ?

  • @StefanKo1224
    @StefanKo1224 5 лет назад

    I dont understant how when program run,it shows pictures,not letters that are on list

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      The Webdings font uses pictures not letters. If you open up Wordpad and start typing with the Webding font you'll see the same images.

    • @StefanKo1224
      @StefanKo1224 5 лет назад +1

      @@michaelartsmedia Thanks man,i have exam today,exam was similar to this game,only we can use some pictures that we must use on game,i didnt know how can i use it,and make program.Ur tutorial is so good.How can i use images form resources,and make array from it and do similar game like this??Sorry for my bad englsh

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      @@StefanKo1224 That's no problem! Unfortunately, I haven't made this using actual pictures but it shouldn't be too hard. You would use a PictureBox, which is a form you can drag and drop from the Toolbox. Here's an article that shows the basics: www.c-sharpcorner.com/uploadfile/mahesh/picturebox-in-C-Sharp/ Good luck!

  • @kerfuritogonzales
    @kerfuritogonzales 5 лет назад

    I probably won't get an answer, but how do I check the pairs by index of the elements in the list?

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      Can you be more specific? What is the variable you want to look at the index of and what type of variable is it? I haven't watched this video in a while so if you can tell me that I can help you quicker. Thanks!

    • @kerfuritogonzales
      @kerfuritogonzales 5 лет назад

      @@michaelartsmedia thanks for the answer, basically I want to pair labels even though they have different text (for like matching definitions and stuff)

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад +1

      @@kerfuritogonzales Maybe I'm dumb but I'm not sure I understand Haha. We check for matches in the video. You can use that method of looking at the labels for any type of checks you want to make! It sounds like you're wanting to alter the rules of the game a bit, you can do that and check the data the same way. Let me know if I'm misunderstanding!

    • @kerfuritogonzales
      @kerfuritogonzales 5 лет назад

      @@michaelartsmedia you understand it quite well, that's basically what I'm trying to do. I just don't exactly know how

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      @@kerfuritogonzales at 30:15 we check the text in the two labels that were clicked. You can use firstClicked.Text and secondClicked.Text to check for whatever logic you want the game to have. Hopefully that helps!

  • @johngeronimo8821
    @johngeronimo8821 5 лет назад

    I used Community Version of VS (2015) I can't find TablePanel is there any alternative toolbox?

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      2015 should have a TablePanel, try looking under the "All" category of the toolbox!

    • @johngeronimo8821
      @johngeronimo8821 5 лет назад

      Sorry but I cant find it 😔

    • @johngeronimo8821
      @johngeronimo8821 5 лет назад

      Is there a guide to find it

    • @johngeronimo8821
      @johngeronimo8821 5 лет назад

      ???

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад

      Try this: docs.microsoft.com/en-us/visualstudio/ide/step-4-lay-out-your-form-with-a-tablelayoutpanel-control?view=vs-2019

  • @rushermabilis1387
    @rushermabilis1387 6 лет назад

    DialogResult di = MessageBox.Show("You won!
    Another Game?", "Another?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    if (di == DialogResult.Yes)
    {
    assign();
    }
    I'm getting errors like index was out of range must be non negative and less than the size of the collection
    It is good for one game only? How can I play another game without restarting the program?

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад

      Where exactly is it breaking? The code you posted doesn't have a place where the index can be out of range. I'd recommend setting a break point and debugging your code line by line to figure out where the issue is stemming from. I have a video in this series where I show how to debug like this. You should be able to re start this game and play another round if the variables are reset correctly. Good luck!

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад

      How are you assigning the random number? Most likely the range of that number is outside of the limit of the variable. For example if we have 9 items in the list and your random number is picking a random number between 0 and 15, anything over 8 will crash the code.

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад

      Sorry I just saw the full function you posted, I'm on mobile so it wasn't showing up right. The issue is you're removing an icon from the list then using the random number as an index into the list after removing something. Think about it like this... there are 8 items in the list and we get a random number of 7 (the last item in the list). After you remove the icon from the list the number of the items in the list is now 7. Your original random number of 7 is no longer valid and will cause the code to crash.

    • @rushermabilis1387
      @rushermabilis1387 6 лет назад

      I assign the random number like this
      List icons = new List()
      {
      "a","a","b","b","c","c","d","d","e","e","f","f","h","h","i","i"
      };

    • @rushermabilis1387
      @rushermabilis1387 6 лет назад

      Yes, that's what happened when I called again the method of assign that code crashes because the icon index is 0. My problem how can I restore the number of icons?

  • @Savage_Gamer777
    @Savage_Gamer777 6 лет назад

    when im putting the code for (int i = 0, i < tableLayoutPanel1.Controls.Count; i++) i'm getting errors,):

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад

      What is the error you're getting? If you can provide some more details I'll see if I can help!

    • @Savage_Gamer777
      @Savage_Gamer777 6 лет назад

      Michael Hicks (local variable) int I A local variable or function named “i” is already defined in this scope the variable “i” is declared but never used

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад

      Somewhere you've defined i two times. Is this part of the code in a double for loop where I is defined in the first loop? I'd try and find the other place it's defined. You could also reference the code in the video line for line in this function and see where things don't add up. Hope that helps!

    • @Savage_Gamer777
      @Savage_Gamer777 6 лет назад +1

      i fixed it man, it was autocorrecting me , instead of putting Private Void AssignIconstoSquares() it was Putting Private Void AssignIconstpSquares()

    • @Savage_Gamer777
      @Savage_Gamer777 6 лет назад +1

      thank you man,

  • @SLEEPYTIMENOW
    @SLEEPYTIMENOW Год назад +1

    I did not like this video, my code just does not work.

  • @WanderingHighlander
    @WanderingHighlander 5 лет назад

    Больше 20 картинок пишет нельзя. Индекс не может быть больше 20. Почему? Как сделать больше 20?

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад +1

      Hey I don't speak Russian so I can't really help you much. I used Google Translate and I think you're asking about expanding the array to hold more than 20 pictures? Yes, you'll need to expand the array to hold 20 (or however many you want). In programming you need to define how many items are stored in an array. If the index goes over how many items the array can store you'll get a crash. Same thing with Lists... if you try to access the 21st item in a list and there's only 20 items, it will crash. Hopefully that helps!

    • @WanderingHighlander
      @WanderingHighlander 5 лет назад +1

      @@michaelartsmedia спасибо. Я сделал вот так
      List icons = new List()
      {
      "я", "я", "N", "N", "O", "O", "k", "k","S", "S","U","U","Y","Y","e","e","J","J",
      "b", "b", "v", "v", "ц", "ц", "I", "I", "Z", "Z","!","!","ы","ы","т","т","j","j"
      };
      36 items. it will be more difficult :)

    • @michaelartsmedia
      @michaelartsmedia  5 лет назад +1

      haha true! Ok so, whenever you iterate through this array you need to make sure the index never goes over 35... that may be the issue. In programming we start counting at 0, so if you try to access the array at index 36 it will crash.

  • @ludj5500
    @ludj5500 5 лет назад +1

    CAN YOU GIVE ME SOURCE CODE , PRORGAM , I WANT IT, PLEASE !!!

    • @ImDippinIn
      @ImDippinIn 3 года назад

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows.Forms;
      namespace WindowsFormsApp1
      {
      public partial class Form1 : Form
      {
      Random random = new Random();
      List icons = new List()
      {
      "!", "!", "N", "N", ",", ",", "k", "k",
      "b", "b", "v", "v", "w", "w", "z", "z"
      };
      Label firstClicked, secondClicked;
      public Form1()
      {
      InitializeComponent();
      AssignIconsToSquares();
      }
      private void AssignIconsToSquares()
      {
      Label label;
      int randomNumber;
      for (int i = 0; i < tableLayoutPanel1.Controls.Count; i++)
      {
      if (tableLayoutPanel1.Controls[i] is Label)
      label = (Label)tableLayoutPanel1.Controls[i];
      else
      continue;
      randomNumber = random.Next(0, icons.Count);
      string v = icons[randomNumber];
      label.Text = v;
      icons.RemoveAt(randomNumber);
      }
      }
      private void timer1_Tick(object sender, EventArgs e)
      {
      timer1.Stop();
      firstClicked.ForeColor = firstClicked.BackColor;
      secondClicked.ForeColor = secondClicked.BackColor;
      firstClicked = null;
      secondClicked = null;
      }
      private void label1_Click(object sender, EventArgs e)
      {
      if (firstClicked != null && secondClicked != null)
      return;
      Label clickedLabel = sender as Label;
      if (clickedLabel == null)
      return;
      if (clickedLabel.ForeColor == Color.Black)
      return;
      if (firstClicked == null)
      {
      firstClicked = clickedLabel;
      firstClicked.ForeColor = Color.Black;
      return;
      }
      secondClicked = clickedLabel;
      secondClicked.ForeColor = Color.Black;
      CheckForWinner();
      if (firstClicked.Text == secondClicked.Text)
      {
      firstClicked = null;
      secondClicked = null;
      }
      else
      timer1.Start();
      }
      private void CheckForWinner()
      {
      Label label;
      for (int i = 0; i < tableLayoutPanel1.Controls.Count; i++)
      {
      label = tableLayoutPanel1.Controls[i] as Label;
      if (label != null && label.ForeColor == label.BackColor)
      return;
      }
      MessageBox.Show("You matches the icons!");
      Close();
      }
      }
      }

  • @TheIsolatedGamerz
    @TheIsolatedGamerz 6 лет назад +2

    Thank you for your content. Im looking forward to more videos. I have subbed :)
    I really want to get a job as junior unity dev. I find myself going back and forth between unity and wpf/wpa(games such as above).
    I've been coding for like 7-8 months now man. But i feel like i cant write code like the abov(yet)e, but i can read it, and understand it. I was told once, just stick to game or app dev, rarely developers do both. What can i do bro?
    p.s. I not used to seeing null used so often.
    if (firstClicked.Text == secondClicked.Text)
    {
    firstClicked = null;
    secondClicked = null;
    }
    //i tired, but it didnt work.
    icons.Remove(firstClicked.Text);
    icons.Remove(secondClicked.Text);
    by making it null are we removing it from the icons?
    null means empty. yea.

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад +1

      Hey thanks for the sub, hopefully you find the channel useful. I'm currently in the middle of the next programming series... hoping to get it out early next year.
      null means "nothing". When the data you're working with is a class, you can set the variable to nothing by setting it to null. null doesn't work on data types such as string or int, only on classes.
      If you have a null item in a list C# will not automatically remove it from the list... you'll have to manually remove it. It's possible for lists to contain null items. There are some scenarios where you actually would want this... but not in this video!
      Hope that helps!

    • @TheIsolatedGamerz
      @TheIsolatedGamerz 6 лет назад

      Thanks Micheal. You explained null very well. I learned list can contain nulls, yet keep there length. And we can only set class objects to null and not data types.
      I'm back on RUclips. Watching your videos, and learning this morning.
      I look forward to your future content. And you have my full support.
      Regards,
      Lais

  • @jhk1702
    @jhk1702 6 лет назад

    sir very good lesson
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    namespace 카드짝_맞추기_게임
    {
    public partial class Form1 : Form
    {
    Random random = new Random();
    List icons = new List()
    {
    "!", "!", "N", "N", ",", ",", "k", "k",
    "b", "b", "v", "v", "w", "w", "z", "z"
    };
    Label firstclicked, secondclicked;
    public Form1()
    {
    InitializeComponent();
    AssignIconsToSquares();
    }
    private void AssignIconsToSquares()
    {
    Label label;
    int randomnumder;
    for (int i = 0; i < tableLayoutPanel1.Controls.Count; i++)
    {
    if (tableLayoutPanel1.Controls[i] is Label)
    label = (Label)tableLayoutPanel1.Controls[i];
    else
    continue;
    randomnumder = random.Next(0, icons.Count);
    label.Text = icons[randomnumder];
    icons.RemoveAt(randomnumder);
    }
    }
    private void label_Click(object sender, EventArgs e)
    {
    if (firstclicked! = null && secondClicked ! = null)
    return;
    Label clickedLabel = sender as Label;
    if (clickedLabel == null)
    return;
    if (clickedLabel.ForeColor == Color.Black)
    return;
    if (firstclicked == null)
    {
    firstclicked = clickedLabel;
    firstclicked.ForeColor = Color.Black;
    return;
    }
    secondclicked = clickedLabel;
    secondclicked.ForeColor = Color.Black;
    CheckForwinner();
    if (firstclicked.Text == secondclicked.Text)
    {
    firstclicked = null;
    secondclicked = null;
    }
    else
    timer1.Start();
    }
    private void CheckForwinner()
    {
    Label label;
    for (int i = 0; i < tableLayoutPanel1.Controls.Count; i++)
    {
    Label = tableLayoutPanel1.Controls[i] as Label;
    if (Label! = null && Label.DefaultForeColor == Label.backcolor)
    return;
    }
    MessageBox.show("You matched all the icons! ");
    close();
    }
    private void timer1_Tick(object sender, EventArgs e)
    {
    timer1.Stop();
    firstclicked.ForeColor = firstclicked.BackColor;
    secondclicked.ForeColor = secondclicked.BackColor;
    firstclicked = null;
    secondclicked = null;
    }
    private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
    {
    }
    }
    }
    i've some issues
    is there anything wrong i typed??

  • @sarveshbhavsar5042
    @sarveshbhavsar5042 6 лет назад

    An unhandled exception of type 'System.NullReferenceException' occurred in project.exe
    Additional information: Object reference not set to an instance of an object.
    getting this error after first match.Please,help

    • @michaelartsmedia
      @michaelartsmedia  6 лет назад

      When your game crashes, hover over the variables on the line it highlights. One of them will be null, this variable is not being set correctly. Once you know which variable is null, look back on the video to find the line of code that is setting that variable. For example if the null variable is "pizza", find the line in the video that says "pizza =". Either this line is not in your program or something else is not causing it to be hit. Good luck!

  • @glim7260
    @glim7260 4 года назад

    17:25

  • @saxik97
    @saxik97 4 года назад

    Heya boss.. Could you upload somewhere the main code please ? Thank youu

  • @brunomachado9985
    @brunomachado9985 5 лет назад +1

    i ly

  • @makaiyotube
    @makaiyotube 4 года назад

    Where can I download the source code? I'm lazy :D

    • @michaelartsmedia
      @michaelartsmedia  4 года назад +3

      I didn't upload it for that exact reason :p Learning how to debug and problem solve makes people better coders and human beings! Too many people just copy and paste these things lol. If you're having problems I'll try my best to walk you through debugging. Just let me know what your issue is!

  • @luckyjim37
    @luckyjim37 3 года назад +1

    I’ve been following along with the tutorial and I’ve been having a few issues at the end. Can I dm you on Twitter to show you the issues?

    • @michaelartsmedia
      @michaelartsmedia  3 года назад

      I'd prefer to do it here in case other people have the same problem. Also, I'm super busy this month so it may be hard for me to reply. But I'll try my best to help!

    • @luckyjim37
      @luckyjim37 3 года назад

      @@michaelartsmedia i'll explain my issue. I can't link the timer from the game into the code and I've tried turning it into an object which was unsuccessful

    • @michaelartsmedia
      @michaelartsmedia  3 года назад

      @@luckyjim37 What exactly do you mean by that? You can't find the timer variable when you type it in the code?

    • @luckyjim37
      @luckyjim37 3 года назад

      @@michaelartsmedia exactly

    • @michaelartsmedia
      @michaelartsmedia  3 года назад

      Try clicking the timer icon at the bottom of the form view. Next look at the properties window and look for the "Name" property. Whatever is listed here is what you'll type in the code view. Hope that helps!

  • @user-dv3dr4dq8d
    @user-dv3dr4dq8d 2 года назад

    Thank you bro 🤙

  • @youngblood3205
    @youngblood3205 5 лет назад +1

    What means null