*Source code* If you don't want to write the code yourself, it's available here for 3$ (and free for Patreon supporters): www.patreon.com/OttoBotCode/shop/78691 Your support would be a massive help for me and my channel! 🤩
@@norbertabone9157 That's a shame. It works just fine on my end. Could you try again and see if it works now? Alternatively, try to go straight to www.patreon.com/OttoBotCode. You can find the Tetris code in the shop 😊
Bro I can't stress this enough : if you keep making C++ , C# tutorials your channel is going to skyrocket ,and hold on hold on before you say that people are more into py and js now yeah yeah I’ve done it all ppl in the comments have done it all, BUT because C# and C++ tutorials are FREAKING rare . I figured that learning the universal concepts and principles of programming languages and their special features are best served with a pinch of tutorials before you go out there and create your own apps. It can be very frustrating just sitting there and creating stuff without seeing how to make them in the first place. You are freaking life savior with this I swear to God. PLEASE make more videos !!!n
Thanks, I hear you. There will be more videos, this is just the beginning! At the moment, it's hard for me to find time for my videos, but that will change in 2 months time 😉
Very good for showing a completed project! Can't say many have ever actually shown a project as finished, or even so much as _declared_ their project as finished. So that gets bonus points! Kudos, bro.
@@OttoBotCode For real this is one of the best tutorial video's I've ever seen in my programming career love to see a new big channel at it's early stages of growing! I will do my best to share this content with everyone I know that loves this! I hope the best for you and wishes your channel a great growth in the near future :)
I'm a beginner at C# and unfortunately this is very hard for me to follow for some reason. Something about the explanations don't "click" with me. Maybe I'll try it again at a future time. Appreciate all the hard work you put in it though and the fact that you answer all your comments. Much respect.
For a beginner, this is too hard. It's more helpful for people who know properties, inheritance, basic collections, etc. If you know such things, following a tutorial like this one can help you get to the next level. I don't speed up the typing like I did for this video anymore, that's probably another reason why it's a bit hard to follow. Once you get more familiar with C# and you want to create a small project, definetely come back here (or perhaps check out my Snake tutorial) and give that a try. Thanks for your comment! 😊
thank you for showing the complete guide from programming to developing and testing everything in real world. it helps me a lot to understand the various use of method and functions too ..keep it up.. one subscriber ..
Otto, this tutorial helped me a lot. Thank you for a clear and simple explanation. Keep making such amazing and interesting videos. Well done and good luck
This is one of the best programming videos I've seen. Everything very well explained but simple at same time. Btw loved the edit too. Keep up the amazing work! Thank youu!!
This is amazing. How did you learn to program, so simple yet so efficiently? It's like you are so perfect at this, when I program I just go with the flow, and although I would love my code to be as flexible and simple as yours, it never turns out like this. You are extremely talented, thanks for this amazing tutorial.
Thank you so much for the kind words! When I program, I try my best to write clean and efficient code that's as easy to understand as possible. I have a masters degree in computer science, which is where I have a lot of my knowledge from. My coding style comes from a lot of hard work and passion for the field! 😊
Well, I'm still in the 'learning to code phase' but I just finished my first iteration of Tetris which I coded with JavaScript. Wow, at a certain point I thought I was going to lose my mind because I ran into so many issues, but somehow it's 95% finished now. So, seeing your vid thumbnail, I thought I'd come and learn something. My code is about 4 times the size of yours. I've got a thing or two to learn as yet. It's fascinating to see how you handled the dropping of non-full rows after clearing 'x' amount of rows. That whole process gave me massive headaches.
Thanks for making this video. I believe it is the best way to learn how to transform theory into true code. You have been very clear and I would not be able to do many things.
Master... thank you very much for the quality of your content. It is a great contribution to make the knowledge available to everyone. Someday i want to be like you.
Hello! What a great video! I haven't made the project yet but have a quick question, I notice that you use individual tile pictures to make a whole block, can I use the entire png of the block instead of using this method? I wish to make my own fun spin on Tetris with a different style to the blocks, maybe something like animals! Thanks!
It is possible but you would have to change the code to display your blocks correctly. Also keep in mind that your blocks will be chopped up when the player clears a row.
First off fantastic video. Secondly I see there's code so that the same block cannot be called twice in a row. What would be the best way to make this happen call all 7 blocks before repeating the same block?
You don't need to make it public, that's just how I was taught programming. Using "abstract" does make a lot of sense because we don't want the Block class to be instantiated directly (only the subclasses).
'MainWindow' does not contain a definition for 'Window_KeyDown' and no accessible extension method 'Window_KeyDown' accepting a first argument of type 'MainWindow' could be found (are you missing a using directive or an assembly reference?)😣
Can I make the same project using the .NET Framework? And if so, then what can be the changes made? Thank You for this video, going to make this for my college project!❤❤
This tutorial is great, but for some reason I couldn't get the game to run fully. While debugging, the game goes to GameOver state after a split second. After pressing "PlayAgine" it is the same. VisualStudio shows no errors.
Hey, where you learned programming like that? Any Books or only tutorials from yt, maybe some studies(I ask out of curiosity). About same game, this is really simple explain and coding, good work.
Hello! I have a bachelor's degree in "Software Development" and a master's degree in "Computer Science" 😊 Whenever I find something that interests me, I like to try it myself and create some small project 😉 Great that you like this one!
Very cool game, it was fun to make at times, other times it was a pain in the back because of the errors I got, but overall, I got'em fixed and the game itself is pretty well done. Thank you for the experience
I am glad that it helped you. Many games are easiest to implement using some kind of grid. Unfortunately, I am not familiar with dr.Mario, but best of luck with your project 😀
I also want to ask about how can you think about what function to create and how would you create it.. for example create a basic function that can be called later inside another function .. how do you think about it? Does this comes from experience and you just instinctively create all the functions in one go? is there a mathematics that can help us create the desired function? Does math function is really important in programming? for example a composite function is that necessary to learn for programming.. i honestly dont know what function to create but you just seamlessly code that without any troubles..
What you don't see in the video is the process of planning everything and structured the code to be as easy to understand as possible. There are design principles and standard patterns you can follow to some extent. That being said, there is no substitute for practice. With time you will develop a feel for what "good" code and "bad" code is. How important is math? That really depends on what you want to do. For most projects it's not so important in my opinion. It's more important to think logically and keep the code as simple as possible. BUT the really impressive programs like ray tracers, machine learning algorithms and game engines require a lot of math! 😉
Sorry I completely missed your comment! The easiest way to add a pause feature would probably be to add a bool isGamePaused to MainWindow.xaml.cs. When the user presses P (or some other key) we set isGamePaused to true if it's currently false and vice versa. You also want to show something on the screen that indicates that the game is paused. When isGamePaused is true, we must make sure that: a) Pressing any key (except P) won't do anything. b) The current block doesn't move down. Stopping the current block from moving down can be a bit tricky, it requires modifying the game loop a bit. The easiest (but maybe not the prettiest) way would be to add a condition like this: if (!isGamePaused) { gameState.MoveBlockDown(); Draw(gameState); } That way each iteration of the game loop doesn't manipulate the GameState when the game is paused. Hope this makes sense and thank you for the kind words 😊
aw i was hoping you'd do 7-bag instead of random with double protection 7-bag is like, you get the tetrominos in groups, or bags, of 7. all tetrominos in one bag are different. then you get a new bag, and the cycle repeats. 7-bag is the standard in modern guideline Tetris
I hope i get an answer after all the time :D The .Reset(); method at 14:38 is red underlined because its not defined and either am blind or you didn't shown it. What to write in it if i create the method?
Thanks much for your answer I joined your patreon club(lol) as I need all the help I can get. Curious though, I wrote a message in the OttoBot not sure how that works to receive a reply?.
Hello! This type of content is amazing!! One question I have: how do you do your visualizations? For instance, at 0:47 you have a game grid representation that is animated well and with smooth transitions. I want to do things like that when I make content for my channel. Thank you so much for reading! Definitely gained a sub from me :)
@@EchosongVV In some of my more recent videos I've been experimenting with programming the animations instead. Then I start the program and sceen record the animation. You can certaintly do something like that in Unity, but it also takes some work 😊
This video is super awesome! I'm following along and trying to code the same thing, but in java, which is posing some fun challenges. Do you have any suggestions for how to approach coding the UI in java?
Thank you! Cool that you are trying to make it in Java. You should be able to write the game logic in a very similar way to what is in the video. I don't have much experience with UI in Java, but I wish you the best of luck 😀
Hey i ran into this issue what should i do 'MainWindow' does not contain a definition for 'GameCanvas_Loaded' and no accessible extension method 'GameCanvas_Loaded' accepting a first argument of type 'MainWindow' could be found (are you missing a using directive or an assembly reference?
I would guess that your Position class is "internal" or "private". Make sure the Position class is "public". Inside Position.cs, the code should be: public class Position 😀
I have a question. What should i do if i want to tetris 3d? How should i set the positions and change 'Block' class? I am not sure honestly how many position state.
Hello! I am having some trouble with the game after play again is clicked. The DropBlock method is not being invoked but all the other buttons work. When I do the dropblock method, the game speed up. Any ideas? Thank you!
@@OttoBotCode great thank you, ill try to convert it any particular advice on what i could do? also great video btw i like how each function ,method and class is explained very helpful
I'm up to GameStateBlock and I'm a little concerned as I have several underlined code words in this block (like GameState and BlockFits) and others that you do not. I've followed you perfectly down to the exact line number on every block....... I'm using VS 17.9.3 ease my mind please?? thanks
My guess would be that the warnings disappear if you disable the "nullable" feature under project settings. It is a newer feature which is now enabled by default when you create a project. Its purpose is to help you avoid null reference exceptions by imposing additional constraints on your code. I did not follow these constraints. Don't worry about those warnings, the code will work just fine! For this project, I recommend disabling nullable under project settings. That should get rid of those annoying warnings! Best of luck with the tutorial 😊
I am very new to c#, it's honestly the first ever language I want to start learning and this is pretty hard for me. Imma still try and understand what things you are doing but I just dont get the arrays. For example grid[r + numRows, c] or grid[r, c]. Does that just change the values of the row and column to 0?
Hello and sorry for the late reply! The grid array is a 2-Dimensional rectangular array (containing integers in our case). You can think of it as a grid or table of numbers. To access a specific element we must provide two indices - a row and a column. *r* and *c* are integer variables. When your code is running, they will store some integer value. *grid[r, c]* accesses the element at row *r* and column *c*. We can also change an entry like this: *grid[r, c] = 0* *grid[r + numRows, c]* is similar. Here we access the element at row (*r + numRows*) and column *c*. We just do a little addition inside the square brackets. I hope this helps and good luck with your programming journey 😀
I have problem here the block it doesn't move. When I press the keys for rotating is ok but when I press right, left and down button it doesn't move please help me 29:07
First, thanks for the tutorial. I have an Issue that is only one tetrominos spawns I can move him around and place but after that they spawn no one more
i would like to ask question @3:05 does declaring /*Rows=rows; /*is the same as */ this.Rows=rows; /*Columns=columns; /*is the same as */ this.Columns=colums; what does that imply?.. is that mean the class can only have one instance or object?
In this case *Rows = rows* and *Columns = columns* is the same as *this.Rows = rows* and *this.Columns = columns* *this* just refers to the current instance of the class. In the case above you don't have to add it explicitly but it is sometimes necessary. If the parameters in the constructor were also called *Rows* and *Columns* then we would have to do this: *this.Rows = Rows* and *this.Columns = Columns*. It does not imply that you can only create one instance of the class. We don't need it but you could create multiple instances of GameGrid. I hope this helps 😊
Good afternoon! I have a problem in the code. I am writing on Visual stusio 2017. Everything is clearly written in code, but the O-block is not displayed. It is displayed transparent on the playing field, although it is displayed in the HOLD and NEXT fields.
The hold and next fields display the Block-O.png image. On the playing field, an O-block is displayed using four instances of TileYellow.png. I suspect that Tile-Yellow.png is not loaded correctly in your project. Make sure that Tile-Yellow.png has build action set to "Resource" and double check that you have written the filename correctly in MainWindow.xaml.cs. Let me know if this resolves the issue! 😊
SetupGameCanvas populates a Canvas with Image controls, one for each cell in the GameGrid. If there is nothing in a given a cell (gameGrid[r, c] == 0), the source of the corresponding image is set to "Assets/TileEmpty.png". This image is just a dark gray border, with a transparent fill color. To give the cells a different color use one of these options: 1) Change the background color of the Canvas in the xaml code. 2) Change the TileEmpty.png image (this way will also allow you to change the color of the grid lines)
@@OttoBotCode Thank you very much , I understood . I have one more question that is the id variable in the Drawgrid method, it will always default to 0 right?
@@NguyenMinh-th2li The "IDs" are stored in an int array in the GameGrid class. The default value for int is 0. So yes, initially all IDs will be 0 by default.
It's hard for me to guess what the issue is. The source code for the project is available here for 3$: www.patreon.com/OttoBotCode/shop. If that doesn't help you locate the mistake, then I can take a look at your project 😊
I am trying to learn from this video and i keep running into the same problem in the Block.cs class When i create the constructor i get an error saying this: 'Position[][]' does not contain a definition for 'Row' and no accessible extension method 'Row' accepting a first argument of type 'Position[][]' could be found (are you missing a using directive or an assembly reference?) Same error goes for Column. I have tried your your git project and i get same error.
Hi, I'm not sure if you'll see this, but I have a question. I want to figure out all the technical stuff myself, so I kind of just skimmed through the video. I can't figure out how to draw the graphical parts, how did you do that? I didn't see it in the vid. Whenever I move a block, there's a shutter I can see, where it's being repainted. I can't get it to not have that shutter.
I use a grid of image controls. When a block moves, the image sources are updated to reflect the new state of the game. It's all in the video if you ever feel like checking it out in depth 😉 I can't say why your program stutters without seeing your code.
@@OttoBotCode Is it possible to add tetris song to this app? I know how to do it in Windows Forms app, but here the same code doesn't work :sob: I added the mp3 file to the Assets folder and changed the Build Action to Resource as for the images, but what do I do next? Thank you so much for your assistance. :hugging_face:
@@elenatrifonova5286 For the mp3 file. You have to set "Build Action" to "Content" and "Copy to Output Directory" to "Copy always". You can play the sound with the MediaPlayer class. MediaPlayer player = new MediaPlayer(); player.Open(new Uri("Assets/your_sound.mp3", UriKind.Relative)); player.Play();
hi OttoBotCode i need help with the protected abstrasct tiles and start offset the Error is: incosistent accesbilitiy property Type 'Position' is less accesible than Blockscs.Startoffset: the 2 error is: incosistent accesbilitiy property Type 'Position' is less accesible than Blockscs.Tiles
I can't get the keys to work, I can't find anything I haven't followed perfectly as I re watch the video. The only thing that sticks out is I have a "Non-nullable field 'currentBlock' must contain a non-null value when exiting the constructor....." So I'm not sure if that has anything to do with it.
Does nothing happen when you press the arrow keys? Try setting a breakpoint in Window_KeyDown and then run the program in Debug mode. Then let me know if that breakpoint is hit when you press the arrow keys.
@@OttoBotCode tried that. And that is about the extent of my knowledge with debugging using visual studio features. And it did not trigger the breakpoint.
@@chadgessner4412 Okay so it seems like the event handler is not registered. I think the problem is in MainWindow.xaml. Do you have this property "KeyDown="Window_KeyDown" on the Window?
@@OttoBotCode I may have found something useful... My Window_KeyDown shows '0 references' above it, but yours shows 1. Maybe I missed a line of code somewhere?
Thanks for buying the code. You should unzip the compressed file first and then open Tetris.sln with Visual Studio. Once opened, you can start the game by clicking the run button (green arrow) or pressing CTRL + F5. If that does not work, let me know what kind of error message you get! ☺
Hey bro, Finished the tutorial but the O block keeps spawning as every other block and all but the 0 block are cyan. Any idea what I might have done? The BitMapImages look correct for colors. Not even sure where to look for the logic that keeps spawning the O block though.
Sorry for the late reply. If you are interested I can help you out. Send your entire project to me at ottobotcodehelp@gmail.com (zip or github link). I'll figure out what the problem is for you 😉
Im having an issue where no blocks will spawn for like 20 seconds and then when it finally does theres a invisible layer a few squares above the current blocks, any idea of what it could be?
One more thing: at 19:40 it says that KeyDown="Window_KeyDown"> is an error because it can be declared only on the left side of += or -= I'm using Visual Studio 2022
I am not a Tetris expert but from what I can tell "lock delay" is the time it takes for a block to lock in place when it is on the ground (or on top of another block). The lock delay can be reset by moving/rotating the block but only a certain number of times. Correct me if that is wrong. There is a problem with the Game Loop used in this video. It's simplistic which makes it easy to implement but not very flexible. We could easily detect when a block is on the ground (or on top of another block) and do something like. await Task.Delay(lockDelay); Instead of the usual delay for moving the block down, but how would we change this delay when the user moves the block? I don't think there is an easy way to change the duration of Task.Delay after it has been started. For more advanced features like lock delay I recommend using a "proper" game loop that runs a certain number of times per second. With that, you can create variables for time based events like moving the block down (and locking it in place). Every time the loop runs (at each frame) you subtract the elapsed time from these variables and check if they are