6years later and you are still helping people! Thank you so much for this very helpful video!
@michaelartsmedia6 ай бұрын
That's great to hear. Thanks for watching!
@emiliatakkinen52534 жыл бұрын
Thank you for saving my grade in programming at school :)
@michaelartsmedia4 жыл бұрын
Haha that's awesome to hear! You're welcome!
@saltypepper33402 жыл бұрын
@@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?
@teacherinthailan64413 жыл бұрын
Excellent! My first C# experience plus Forms too! You are an amazing teacher. Thank you so much.
@michaelartsmedia3 жыл бұрын
Thanks for watching!
@mittamaka5 жыл бұрын
Great tutorial, I understood everything you said. It was all nice and clear, great job dude.
@michaelartsmedia5 жыл бұрын
That's great to hear! Thanks for watching!
@dindocastrogamis4 жыл бұрын
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!
@johnvenn37744 жыл бұрын
One of the best tutorials I've ever done. Thank you so much
@michaelartsmedia4 жыл бұрын
Thanks for watching!!
@ctcrosby01 Жыл бұрын
Dude, this was fantastic. Definitely going to incorporate some of your ideas into my project.
@csanadczanik97103 жыл бұрын
I actually tried racing you at the end. You won, cant beat the creator I guess. Thanks for the help!
@luiskeller28953 жыл бұрын
Thank you my man. This Video helped me and my friend to safe our grade in IT Class.
@naTure-vs2ef3 жыл бұрын
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
@fayadtaleb44173 жыл бұрын
K,
@freekynoname28853 жыл бұрын
dude in 2021 u saved my coursework on c#))) Thx buddy)))
@madness56902 жыл бұрын
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
@tidzej54004 ай бұрын
Hey, i have the same exercise with those buttons, can you write how did you manage to do them?
@xauchino88792 жыл бұрын
Nice and easy tutorial, thanks for the help, it was useful and easy to understand.
@amirhosseinzarei25973 жыл бұрын
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 ;)!!!
@michaelartsmedia3 жыл бұрын
haha so glad to hear you enjoyed it! Thanks for watching!
@Eneken646 жыл бұрын
Amazing game Michael! Thank you very much!
@michaelartsmedia6 жыл бұрын
No problem, thanks for watching!
@marcfrancecabiles23546 жыл бұрын
You deserve a thousand likes!
@michaelartsmedia6 жыл бұрын
Thanks! Hopefully someday I'll get there haha
@aleksd32634 жыл бұрын
Great tutorial! Thank you!
@jnelson167014 жыл бұрын
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. :)
@michaelartsmedia4 жыл бұрын
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 Жыл бұрын
I was getting the same error, but saw that I forgot to put a "N" in the list. After adding that, it fixed it.
@szabinakralik22677 жыл бұрын
I like it very much. Thanks Michael!
@michaelartsmedia7 жыл бұрын
Awesome to hear, thanks for watching!
@rue-n9l3 жыл бұрын
if i want to use pictures instead of letters, can i use picture box?
@arrxwy3 ай бұрын
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?
@shandrickdeguzman51824 жыл бұрын
can I use picture box if I want to set the picture instead of label???
@ayushtyagi38952 жыл бұрын
I have to do the same thing but instead of labels in each of the boxes, I need to use picture boxes, any suggestions?
@fuxu2175 ай бұрын
Thank you for your teaching
@omersar75445 жыл бұрын
nice and very explanatory. thanks for your tutorial
@michaelartsmedia5 жыл бұрын
Thanks for watching!
@filipebraz99823 жыл бұрын
@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?
@shina63775 ай бұрын
is it possible to use images or pictures instead of icons?
@ellathermaenius84882 жыл бұрын
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?
@michaelartsmedia2 жыл бұрын
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!
@simo54656 жыл бұрын
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 :)
@darkosimic4861 Жыл бұрын
Each time i try always match first 2. all cards match and shows only SQUARE.
@guybrush33184 жыл бұрын
Dude, AMAZING thankyou!
@migsteele4 жыл бұрын
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?
@ledschmidt14416 ай бұрын
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!!
@simonwong79692 жыл бұрын
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?
@aaryannavare491111 ай бұрын
How can I add levels into this game please give some ideas
@abbeyharobed6602 жыл бұрын
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?
@michaelartsmedia2 жыл бұрын
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!
@sideral09Ай бұрын
thank you for the big help!
@deandregriffin32483 жыл бұрын
how do I insert picture files instead of icons?
@bimbon12310 ай бұрын
did you figured out how?? i would like to know
@Chavyyy5 жыл бұрын
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.
@michaelartsmedia5 жыл бұрын
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!
@lew18842 жыл бұрын
hi man ,do you have tutorial how to add timer to the game like 1 min to win?
@sreealekyatellabati81083 жыл бұрын
Iam getting warning like the field'form1.firstclicked'is never used and also the field 'form1.second clicked is never used
@AlkNA5 жыл бұрын
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 :/
@michaelartsmedia5 жыл бұрын
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!
@marcusmanning86534 жыл бұрын
nice tutorial thank you you helped me out a lot!
@michaelartsmedia4 жыл бұрын
Great to hear! Thanks for watching!
@cccddd8823 жыл бұрын
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.
@michaelartsmedia3 жыл бұрын
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!
@cccddd8823 жыл бұрын
@@michaelartsmedia oh I understand. Ty!
@technercom55024 жыл бұрын
it gives me the error property not found when ever i want to type c in gridcharset
@ibraheemalhunaidi22282 жыл бұрын
Hey what version of visual studio did you use?
@jobot47803 жыл бұрын
Thank you a lot !! great tutorial
@serhiimamedov6 жыл бұрын
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!
@michaelartsmedia5 жыл бұрын
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.
@adinanicolau276 жыл бұрын
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!
@michaelartsmedia6 жыл бұрын
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!
@adinanicolau276 жыл бұрын
Michael Hicks thank you a lot!
@brahm21573 жыл бұрын
Dude seriosly thank you !
@migalesch18392 жыл бұрын
thanks dude
@Tim_Linkel6 жыл бұрын
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?
@michaelartsmedia6 жыл бұрын
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_Linkel6 жыл бұрын
@@michaelartsmedia sure there is. The question is how to refer to that image variable . And what is the variable it is.
@michaelartsmedia6 жыл бұрын
@@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_Linkel6 жыл бұрын
thank you so much. I've just now found a solution to make it works.
@TheStreeterCZ4 жыл бұрын
What if I wanted to program a bot to play against me? E.g. it would just pick random cards (no intelligence)
@kc98685 жыл бұрын
Great video!
@amitnachmias49784 жыл бұрын
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
@michaelartsmedia4 жыл бұрын
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!
@viktortaylor45052 жыл бұрын
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.
@imeiprezime832710 ай бұрын
Druze, volim te
@User-ww3oj4 жыл бұрын
How long did it take you to get to this point? In terms of time how did you personally learn?
@michaelartsmedia4 жыл бұрын
I taught myself by making small games. If you have a passion for coding you will learn the more you dive in!
@User-ww3oj4 жыл бұрын
@@michaelartsmedia Thanks Michael.
@petersusan77436 жыл бұрын
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.
@michaelartsmedia6 жыл бұрын
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!
@petersusan77436 жыл бұрын
Thanks so much for responding quickly!!! this is a great idea am getting on it right away. Cheers to you sir
@petersusan77436 жыл бұрын
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
@michaelartsmedia6 жыл бұрын
+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!
@petersusan77436 жыл бұрын
Thanks Sir. I'll start from here and do it. I appreciate you responding even on your old videos
@HassanYasser-qv2ri18 күн бұрын
Thanks you pro your are great
@zaoplayz80215 жыл бұрын
How can I change it into mathematical icons?
@michaelartsmedia5 жыл бұрын
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!
@zaoplayz80215 жыл бұрын
@@michaelartsmedia thank you for your answer :>
@Codworld3606 жыл бұрын
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!!
@michaelartsmedia6 жыл бұрын
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!
@onigumo5 жыл бұрын
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.
@tanjimashraf8035 жыл бұрын
didnt understand the line 38 in the video. Why the Labels of tableLayoutPanel.Controls are stored in the local variable label?
@tanjimashraf8035 жыл бұрын
Why did you use the if condition on line 38? Kindly explain it explicitly.
@michaelartsmedia5 жыл бұрын
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.
@FYLTV4 жыл бұрын
Thanks!
@TheLifeWithJoy3 жыл бұрын
I couldn’t help my daughter, but this tutorial DID 😊😊😊😊🍾🤓🤓🙏🙏🙏🙏🙏🙏🙏🎖🎖🎖🎖🎖🎖🎖
@TheMakcswell6 жыл бұрын
Ty dude!
@janielletulloch47615 жыл бұрын
I am getting an error message for this. for (int i = 0; i
@michaelartsmedia5 жыл бұрын
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!
@janielletulloch47615 жыл бұрын
@@michaelartsmedia thanks.
@onigumo5 жыл бұрын
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.
@janielletulloch47615 жыл бұрын
How do you edit it so it will ask you if you want to start a new game instead of closing it?
@michaelartsmedia5 жыл бұрын
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!
@janielletulloch47615 жыл бұрын
@@michaelartsmedia Thank you.
@amaltalibe88546 жыл бұрын
You didn’t tell us how you got that empty form set up. Doesn’t help beginners like me
@michaelartsmedia6 жыл бұрын
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.
@StefanKo12245 жыл бұрын
I dont understant how when program run,it shows pictures,not letters that are on list
@michaelartsmedia5 жыл бұрын
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.
@StefanKo12245 жыл бұрын
@@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
@michaelartsmedia5 жыл бұрын
@@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!
@tomealexandre23456 жыл бұрын
Nice
@kerfuritogonzales5 жыл бұрын
I probably won't get an answer, but how do I check the pairs by index of the elements in the list?
@michaelartsmedia5 жыл бұрын
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!
@kerfuritogonzales5 жыл бұрын
@@michaelartsmedia thanks for the answer, basically I want to pair labels even though they have different text (for like matching definitions and stuff)
@michaelartsmedia5 жыл бұрын
@@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!
@kerfuritogonzales5 жыл бұрын
@@michaelartsmedia you understand it quite well, that's basically what I'm trying to do. I just don't exactly know how
@michaelartsmedia5 жыл бұрын
@@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!
@TheDrop2.03 жыл бұрын
Can you do this in Visual Basic ?
@Banoffeenyx3 жыл бұрын
it is visual basic lol
@johngeronimo88215 жыл бұрын
I used Community Version of VS (2015) I can't find TablePanel is there any alternative toolbox?
@michaelartsmedia5 жыл бұрын
2015 should have a TablePanel, try looking under the "All" category of the toolbox!
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?
@michaelartsmedia6 жыл бұрын
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!
@michaelartsmedia6 жыл бұрын
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.
@michaelartsmedia6 жыл бұрын
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.
@rushermabilis13876 жыл бұрын
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" };
@rushermabilis13876 жыл бұрын
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?
@457Deniz4576 жыл бұрын
*ty nice tut ! :)*
@michaelartsmedia6 жыл бұрын
No problem thanks for watching!
@cosminadrian84846 жыл бұрын
Is mutiplayer?
@Savage_Gamer7776 жыл бұрын
when im putting the code for (int i = 0, i < tableLayoutPanel1.Controls.Count; i++) i'm getting errors,):
@michaelartsmedia6 жыл бұрын
What is the error you're getting? If you can provide some more details I'll see if I can help!
@Savage_Gamer7776 жыл бұрын
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
@michaelartsmedia6 жыл бұрын
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_Gamer7776 жыл бұрын
i fixed it man, it was autocorrecting me , instead of putting Private Void AssignIconstoSquares() it was Putting Private Void AssignIconstpSquares()
@Savage_Gamer7776 жыл бұрын
thank you man,
@WanderingHighlander5 жыл бұрын
Больше 20 картинок пишет нельзя. Индекс не может быть больше 20. Почему? Как сделать больше 20?
@michaelartsmedia5 жыл бұрын
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!
@WanderingHighlander5 жыл бұрын
@@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 :)
@michaelartsmedia5 жыл бұрын
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.
@ludj55005 жыл бұрын
CAN YOU GIVE ME SOURCE CODE , PRORGAM , I WANT IT, PLEASE !!!
@ImDippinIn3 жыл бұрын
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(); } } }
@TheIsolatedGamerz6 жыл бұрын
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.
@michaelartsmedia6 жыл бұрын
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!
@TheIsolatedGamerz6 жыл бұрын
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 KZbin. Watching your videos, and learning this morning. I look forward to your future content. And you have my full support. Regards, Lais
@saxik974 жыл бұрын
Heya boss.. Could you upload somewhere the main code please ? Thank youu
@sarveshbhavsar50426 жыл бұрын
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
@michaelartsmedia6 жыл бұрын
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!
@jhk17026 жыл бұрын
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??
@SLEEPYTIMENOW Жыл бұрын
I did not like this video, my code just does not work.
@brunomachado99855 жыл бұрын
i ly
@michaelartsmedia5 жыл бұрын
@glim72604 жыл бұрын
17:25
@makaiyotube4 жыл бұрын
Where can I download the source code? I'm lazy :D
@michaelartsmedia4 жыл бұрын
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!
@luckyjim373 жыл бұрын
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?
@michaelartsmedia3 жыл бұрын
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!
@luckyjim373 жыл бұрын
@@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
@michaelartsmedia3 жыл бұрын
@@luckyjim37 What exactly do you mean by that? You can't find the timer variable when you type it in the code?
@luckyjim373 жыл бұрын
@@michaelartsmedia exactly
@michaelartsmedia3 жыл бұрын
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!