Programming a Tetris Game in C# - Full Guide

  Рет қаралды 194,974

OttoBotCode

OttoBotCode

Күн бұрын

Learn how to program a Tetris game in C# using WPF.
Download the assets here:
ottobotcode.com/tetris/
Source code is available here:
/ 78691
In this video you will learn how to write a Tetris game in C# without any game engine. This video is a step-by-step guide, and contains everything you need to know to write a Tetris game. You will learn about the representation of the game grid and the blocks from animations and code. The code is written in C#, but the ideas and design of the game can also be used in other programming languages like Java and C++. Have fun learning about game development in C#!
Chapters
0:00 - Introduction
0:11 - Project Setup
0:45 - Game Grid Representation
2:00 - Writing a GameGrid class
4:13 - Clearing Rows
6:22 - The 7 Blocks
6:32 - Block Rotation
7:55 - Block Movement
8:34 - Adding a Position class
8:57 - Writing a Block class
10:58 - The IBlock
11:56 - The OBlock
12:33 - Block Data
12:53 - Picking the Next Block
14:15 - The GameState Class
17:59 - Importing Assets
19:04 - The UI
23:36 - Loading Assets
24:50 - Setting Up the Canvas
27:20 - Drawing the Game Grid
27:35 - Drawing the Current Block
27:53 - Drawing the Game State
28:22 - Detecting Key Presses
29:07 - The Game So Far
29:33 - Adding a Game Loop
30:17 - Handling Game Over
30:38 - Restarting the Game
31:04 - Fixing Spawn Position
31:46 - Making Last Block Visible
32:20 - Next Block Preview
32:51 - Score
33:49 - Hold Feature
35:34 - Hard Drop Feature
37:02 - Ghost Block
38:02 - Increasing Difficulty
38:59 - Adding an Icon
39:16 - Thanks!

Пікірлер: 409
@OttoBotCode
@OttoBotCode 7 ай бұрын
*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
@norbertabone9157 7 ай бұрын
The link seems not to be working
@OttoBotCode
@OttoBotCode 7 ай бұрын
@@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 😊
@PMyt007
@PMyt007 Ай бұрын
Brother do you want sail any project of c#
@PMyt007
@PMyt007 Ай бұрын
Bcz i need in emergency
@joevaghn457
@joevaghn457 10 ай бұрын
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.
@shanep2514
@shanep2514 2 жыл бұрын
I love how you took the time to talk about designing the application. Much appreciated after browsing other C# videos.
@OttoBotCode
@OttoBotCode 2 жыл бұрын
I am glad you liked it, thanks for watching!
@tbpotn
@tbpotn 2 жыл бұрын
Very clean! Don't know how i stumbled upon this video, but well done :)
@vstom910
@vstom910 2 жыл бұрын
I love how simple this way of creating Tetris is compared to other examples. Keep up the good work!
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thanks, I appreciate it. More content coming soon😀
@aiksjdijdemlfnewklfn7092
@aiksjdijdemlfnewklfn7092 Жыл бұрын
@@OttoBotCode What is the name of the data structure u used?
@mrjelk8902
@mrjelk8902 Жыл бұрын
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
@OttoBotCode
@OttoBotCode Жыл бұрын
Thank you, that's great to hear! I'm working on the next project (also in C#) 😉
@gurbanaarongulman2505
@gurbanaarongulman2505 4 ай бұрын
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
@OttoBotCode
@OttoBotCode 4 ай бұрын
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 😉
@gurbanaarongulman2505
@gurbanaarongulman2505 4 ай бұрын
@@OttoBotCode Man all thanks to you sure I can't wait to see more !
@daeyoungkim4971
@daeyoungkim4971 2 жыл бұрын
This would be my weekend challenge for this Saturday. Thanks for the great tutorial!
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thank you! 😃
@solomareds
@solomareds 2 жыл бұрын
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.
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thank you for watching. Glad it was helpful
@chipolinchikaloe8447
@chipolinchikaloe8447 3 ай бұрын
I'm from Belarus, studying at university and starting to make games. Your tutorial was very helpful, the code is very beautiful. Thank you ♥♥♥
@OttoBotCode
@OttoBotCode 3 ай бұрын
Thank you! I'm glad you like it 👍
@norbertabone9157
@norbertabone9157 7 ай бұрын
Great video!! the idea flow is simple and easy to understand
@kallismb3015
@kallismb3015 2 жыл бұрын
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!!
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thank you! Awesome to hear 😃
@dadoodooman4928
@dadoodooman4928 2 жыл бұрын
Very clear and good explanation, good animations and entertaining, helped me a lot :) Well done:)
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thank you so much, really glad you like it!
@Gozer
@Gozer 2 жыл бұрын
Thanks mate, this helped me a lot!
@InOutLake
@InOutLake 8 ай бұрын
So simple and clear! I like it Also I noticed how your clead code improves mine, and it feels is amazing! Thank you
@OttoBotCode
@OttoBotCode 8 ай бұрын
Great to hear! Thanks for your comment 👍
@andergarcia1115
@andergarcia1115 Жыл бұрын
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.
@OttoBotCode
@OttoBotCode Жыл бұрын
Glad you enjoyed it and thanks for the kind words!
@melitonolguinmendoza
@melitonolguinmendoza 7 ай бұрын
Great video. It was easy to follow and understand.
@TeamROsky
@TeamROsky 2 жыл бұрын
this video and channel are SOOO underrated you deserved my sub!
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thank you so much!
@TeamROsky
@TeamROsky 2 жыл бұрын
@@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 :)
@OttoBotCode
@OttoBotCode 2 жыл бұрын
@@TeamROsky Awesome to hear. It is greatly appreciated, much more content coming soon!
@TeamROsky
@TeamROsky 2 жыл бұрын
@@OttoBotCode My teacher has send the other classes towards your video so they can do this as a task! Never expected that to happen but here you go :)
@OttoBotCode
@OttoBotCode 2 жыл бұрын
@@TeamROsky Wow super cool! Thanks again :)
@greekz8750
@greekz8750 Жыл бұрын
I've seen that has actually explained it to in a concise way!
@DennisRitchie1978
@DennisRitchie1978 Жыл бұрын
Very good explanations, it helped me a lot in learning object oriented programming in C#. thanks a lot!!! :-)
@OttoBotCode
@OttoBotCode Жыл бұрын
Thanks for your comment 😊
@rawbrwoarry6407
@rawbrwoarry6407 2 жыл бұрын
why is this channel so underrated????
@funtimesans13
@funtimesans13 Жыл бұрын
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
@OttoBotCode
@OttoBotCode Жыл бұрын
Glad to hear you worked out in the end. Thanks for your comment!
@tanm3051
@tanm3051 2 жыл бұрын
I'm surprised you have less than 700 subs! This is great content, keep up the great work
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thank you for the kind words. More content coming soon 😊
@gonzaloalbornoz4128
@gonzaloalbornoz4128 Жыл бұрын
This is awesome. Thank you so much and greetings from Argentina
@OttoBotCode
@OttoBotCode Жыл бұрын
Thanks for your comment and greetings from Denmark 😉
@markharby180
@markharby180 Ай бұрын
Great tutorial Otto, this is a feature-rich game.
@OttoBotCode
@OttoBotCode Ай бұрын
Thanks!
@rickyryannacario1936
@rickyryannacario1936 2 жыл бұрын
OMG, it really worked. Thank you so much!!
@OttoBotCode
@OttoBotCode Жыл бұрын
You're welcome!
@aaronjayzosadelapena8356
@aaronjayzosadelapena8356 2 жыл бұрын
thank you so much. Its easy to understand. it was really helpful
@OttoBotCode
@OttoBotCode 2 жыл бұрын
You're welcome 😃 Glad you liked it!
@dave_s_vids
@dave_s_vids Жыл бұрын
Seriously impressive - thanks!
@OttoBotCode
@OttoBotCode Жыл бұрын
You're welcome 😊
@nikolaoskonstantinidis3505
@nikolaoskonstantinidis3505 10 ай бұрын
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.
@OttoBotCode
@OttoBotCode 10 ай бұрын
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! 😊
@cobrakilla8
@cobrakilla8 Жыл бұрын
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.
@OttoBotCode
@OttoBotCode Жыл бұрын
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! 😊
@elenatrifonova5286
@elenatrifonova5286 2 жыл бұрын
OMG! You are a life saver. Thanks you for clear description of every step of the way; amazing content! Good luck!!!!
@OttoBotCode
@OttoBotCode 2 жыл бұрын
You're welcome 😀
@elenatrifonova5286
@elenatrifonova5286 2 жыл бұрын
@@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:
@OttoBotCode
@OttoBotCode 2 жыл бұрын
@@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();
@elenatrifonova5286
@elenatrifonova5286 2 жыл бұрын
@@OttoBotCode Super Mega LIKE to you, my friend! It can sing now :grin:
@rawbrwoarry6407
@rawbrwoarry6407 2 жыл бұрын
this was so good and simple !!
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thanks and happy new year 😀
@meatgaming1352
@meatgaming1352 Жыл бұрын
utilised and enjoyed wNice tutoriallst increasing in value.
@arthurodelapena-ii4112
@arthurodelapena-ii4112 2 жыл бұрын
thank you sooo much for the torurial.it helps a lot
@OttoBotCode
@OttoBotCode 2 жыл бұрын
You are welcome 😊 Thanks for your comment 👍
@ma.donnabelramos4350
@ma.donnabelramos4350 Жыл бұрын
nice tuto bro, that solved!
@ArtemSerov
@ArtemSerov Жыл бұрын
It's awesome!!! Thank you very, very much!!!!
@OttoBotCode
@OttoBotCode Жыл бұрын
Thanks for the nice comment 😊
@rickyricky4610
@rickyricky4610 Жыл бұрын
Great video 👍🥰❤️
@TinyMaths
@TinyMaths Жыл бұрын
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.
@OttoBotCode
@OttoBotCode Жыл бұрын
Good luck with finishing your project. I'm glad this video was helpful 😊
@benstin2317
@benstin2317 Ай бұрын
Really appreciate it!!!!
@MkStar55
@MkStar55 2 жыл бұрын
Thanks! Good Work!
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thank you 😃
@Smqckd
@Smqckd 2 жыл бұрын
Elsker at jeg kan hører du er dansker!
@TheLolpwnz
@TheLolpwnz Жыл бұрын
Thanky its took me a longer time to write dwn the code. But i like it
@OttoBotCode
@OttoBotCode Жыл бұрын
You're welcome! I sped up the typing in this video and some people don't like that. In more recent videos I've gone away from that. It should now be much easier to code along with 😊
@TheLolpwnz
@TheLolpwnz Жыл бұрын
@@OttoBotCode ah :D that make sense , I just all time worried I'm to slow :D:D
@Genexyz_von_Deus
@Genexyz_von_Deus 2 жыл бұрын
Damn I found a good channel, sub++
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Haha thanks!
@edrobinson8248
@edrobinson8248 Жыл бұрын
simply brilliant
@OttoBotCode
@OttoBotCode Жыл бұрын
Thank you!
@hurmanfåraiallaämnen
@hurmanfåraiallaämnen 2 жыл бұрын
Great vid!
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thanks! 😉
@smpitbaitussalam2cangkring515
@smpitbaitussalam2cangkring515 Жыл бұрын
DUDE, I got so frustrated 'cause of that problem, thanks a lot!
@gvuprise1465
@gvuprise1465 Жыл бұрын
i love this! thank you so much please do mmore
@brunobezzan1169
@brunobezzan1169 Жыл бұрын
It's my first day of soft School, and I can tell I'm going to like my teacher!
@satmat2272
@satmat2272 2 жыл бұрын
thank you youre the best bro
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thank you for watching 😊
@lenguyenquangnamfgwdn2611
@lenguyenquangnamfgwdn2611 Жыл бұрын
Thank you Sir
@TheLyrandana
@TheLyrandana 11 ай бұрын
so cool thanks
@hampus3699
@hampus3699 Жыл бұрын
its beutiful how you animate this to show it. i dont know how you do it but it shows us really well. thanks a lot. im gonna make this on my school computer and im making snake at home
@OttoBotCode
@OttoBotCode Жыл бұрын
Thank you for the kind words! Best of luck with both projects 😀
@DasiyshineAJ
@DasiyshineAJ 2 ай бұрын
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!
@mrstickman6718
@mrstickman6718 2 жыл бұрын
Sir I just watched ur video big fan sir U deserve respect coz u r a very talented person. I'll subscribe u from my all 5 KZfaq accounts 🙂❤️❤️❤️
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Wow, thank you so much! Glad you enjoyed it 🤩 Next video will be out next week 😃
@mrstickman6718
@mrstickman6718 2 жыл бұрын
@@OttoBotCode Job done sir 😌 5 added..
@OttoBotCode
@OttoBotCode 2 жыл бұрын
@@mrstickman6718 Awesome, thanks again!
@A_S0ur
@A_S0ur Жыл бұрын
This tutorial is amazing, i've been trying to expand the game by adding a database to make a register/login feature is there any way you can help??
@panaikran
@panaikran 5 ай бұрын
Hey, I need help at 29:30 I can't get the row to clear is something wrong with it?
@alperenates1165
@alperenates1165 11 ай бұрын
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.
@lancebrixtermendoza3268
@lancebrixtermendoza3268 3 ай бұрын
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
@MIGUELOXI10
@MIGUELOXI10 Жыл бұрын
Nice tutorial, i just cracked soft soft ;)
@OttoBotCode
@OttoBotCode Жыл бұрын
Thank you 😊 What are you guys talking about? "soft soft" I don't get it 😂
@princesarno2652
@princesarno2652 Жыл бұрын
I can’t drag content / sample into my playlist on Mac? Anyone know how to fix
@e.alarcon5322
@e.alarcon5322 Жыл бұрын
what throws off is the step sequencer. i ntally associate it with a soft/clip whether it's being used or not. also when you do
@wootanfall1
@wootanfall1 3 ай бұрын
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?
@OttoBotCode
@OttoBotCode 3 ай бұрын
It's around 10:45
@DasiyshineAJ
@DasiyshineAJ 3 ай бұрын
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!
@OttoBotCode
@OttoBotCode 3 ай бұрын
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.
@KidFlash22898
@KidFlash22898 Ай бұрын
27:58 I'm getting 2 errors under the TilePositions and under the Id in [block.Id]. Both the error codes are CS1061
@abdullahajeebi
@abdullahajeebi Жыл бұрын
pretty good ngl
@MaineMaineJr
@MaineMaineJr 17 күн бұрын
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?
@harryhayfron-benjamin5199
@harryhayfron-benjamin5199 2 жыл бұрын
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?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Hello! It sounds like you are missing the GameCanvas_Loaded method in MainWindow.xaml.cs.
@harryhayfron-benjamin4189
@harryhayfron-benjamin4189 2 жыл бұрын
@@OttoBotCode true I fixed it but the program was just showing the canvas but it was still empty how do I fix that?
@El_kammex
@El_kammex 2 жыл бұрын
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.
@OttoBotCode
@OttoBotCode 2 жыл бұрын
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!
@remigiuszobrycki9098
@remigiuszobrycki9098 6 ай бұрын
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.
@stevengualoto4626
@stevengualoto4626 11 ай бұрын
at what moment does the Hold appear on the screen, that is, when this event occurs
@Avichan_
@Avichan_ 4 ай бұрын
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.
@OttoBotCode
@OttoBotCode 4 ай бұрын
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! 😊
@SlikerEdits
@SlikerEdits Жыл бұрын
Brandony man pls i need to know how can I restore the snare and the hat in the channel rack, I accidentally deleted them.
@josephyang8569
@josephyang8569 Жыл бұрын
are there any other function besides "Children"? cuz im using visual studio 2019
@footballCartoon91
@footballCartoon91 2 жыл бұрын
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?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
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 😊
@itsmrknott2u
@itsmrknott2u Жыл бұрын
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.
@OttoBotCode
@OttoBotCode Жыл бұрын
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 😉
@rul1175
@rul1175 Жыл бұрын
Incredible video. I have a question, why did u use public abstract classes???
@OttoBotCode
@OttoBotCode Жыл бұрын
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).
@cederichiltbrunner421
@cederichiltbrunner421 2 жыл бұрын
I get an error in IBlock at 11:15. Apparently I'm using an older version which doesn't support the notation "new(0,1)". Do you know of a way I can rewrite this so that it works?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
You are right, I have omitted the type after "new" which you can only do in C# 9 or later. For older versions you have to always write the type explicitly like this: new Position(r,c) Hope that helps! 😃
@cederichiltbrunner421
@cederichiltbrunner421 2 жыл бұрын
@@OttoBotCode This resolved my problem, thank you very much! This is a super cool tutorial, thanks!
@Joooooooooooosh
@Joooooooooooosh 5 ай бұрын
​@@OttoBotCodeI kept wanting to reach through the screen and rewrite your code to use the new C#11 collection initializers and then I realized this was 2 years old. 😂 Great video! Subscribed.
@cryptolivetv7276
@cryptolivetv7276 2 жыл бұрын
I have had the hardest ti finding a video on soft that actually made sense to (I'm brand new with literally zero knowledge) and tNice tutorials
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thank you! 😊
@EchosongVV
@EchosongVV Жыл бұрын
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 :)
@OttoBotCode
@OttoBotCode Жыл бұрын
Thanks for the kind words and the sub 😉 I did the animations for this video in After Effects. It was a little painful but it turned out well 😄
@EchosongVV
@EchosongVV Жыл бұрын
@@OttoBotCode Oh god, AFTER EFFECTS Do you think that I could do something like this in Unity?
@OttoBotCode
@OttoBotCode Жыл бұрын
​@@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 😊
@Apep88
@Apep88 9 ай бұрын
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
@firulais9982
@firulais9982 6 ай бұрын
amazing video, do you consider this project as a beginner or intermediate project
@OttoBotCode
@OttoBotCode 6 ай бұрын
Thanks! I'd say this is an intermediate project but on the easy side 😉
@oleggordeev5849
@oleggordeev5849 9 ай бұрын
Is using OOP for such small projects worth it?
@VeryBigDoor
@VeryBigDoor Жыл бұрын
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?
@OttoBotCode
@OttoBotCode Жыл бұрын
I can find out if you send me your code. You can send it to ottobotcodehelp@gmail.com, then I'll take a look 😊
@PhucTran-ql7tq
@PhucTran-ql7tq 6 ай бұрын
how can i add music into the game?
@thesituation5315
@thesituation5315 2 жыл бұрын
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.
@OttoBotCode
@OttoBotCode 2 жыл бұрын
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.
@thesituation5315
@thesituation5315 2 жыл бұрын
@@OttoBotCode Ok thanks. I'll try that. Is there a way I could show you the code?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
@@thesituation5315 You can send it to ottobotcodehelp@gmail.com. Then I'll take a look when I have the time 😃
@ledschmidt1441
@ledschmidt1441 4 ай бұрын
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
@OttoBotCode
@OttoBotCode 4 ай бұрын
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 😊
@frejandsubtolclc7935
@frejandsubtolclc7935 5 ай бұрын
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
@OttoBotCode
@OttoBotCode 5 ай бұрын
It sounds like your Position class is either "internal" or "private". Go to Position.cs and make the class "public" 😊
@Thallane
@Thallane Жыл бұрын
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.
@OttoBotCode
@OttoBotCode Жыл бұрын
Can you send the project with the error to ottobotcodehelp@gmail.com? Then I'll figure out what is wrong 😉
@nghialuongtrong2311
@nghialuongtrong2311 Жыл бұрын
Is there an external interface code for this game?
@bugatti555xd3
@bugatti555xd3 2 ай бұрын
el Id del bloque I Me esta marcando error y lo tengo igual al del minuto 11:28
@0i3ee
@0i3ee Жыл бұрын
i want to know about grid ,but i dont know how to set position becase all position is 0 all omg my head.
@NguyenMinh-th2li
@NguyenMinh-th2li 2 жыл бұрын
Hey , I want to ask you something, how to apply color to cells in grid, canvas? why is your loop giving an empty color grid ?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
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)
@NguyenMinh-th2li
@NguyenMinh-th2li 2 жыл бұрын
@@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?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
@@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.
@NguyenMinh-th2li
@NguyenMinh-th2li 2 жыл бұрын
@@OttoBotCode Thank you, I got it. Your project is very good to learn 😃😃
@code-to-learn
@code-to-learn Жыл бұрын
nice
@jankobylka181
@jankobylka181 6 ай бұрын
Hi, maybe some could help me out. At #29:10 when he start up the program everythik goes well. When i trying to start it up it doesnt show any block and program crush down. Thanks for any help.
@OttoBotCode
@OttoBotCode 6 ай бұрын
Do you get any error message in the output window?
@jankobylka181
@jankobylka181 6 ай бұрын
Untreated exception System.IndexOutOfRangeException: Index was outside the bounds of the array.@@OttoBotCode
@jankobylka181
@jankobylka181 6 ай бұрын
System.IndexOutOfRangeException: Index was outside the bounds of the array. @@OttoBotCode
@johnniegilkerson4724
@johnniegilkerson4724 Жыл бұрын
Sorry found my error: I had private void Window_KeyDown(object sender, KeyboardEventArgs e) instead of Window_KeyDown(object sender, KeyEventArgs e)
@alshick3973
@alshick3973 Ай бұрын
would parts of this code would you be able to use it in the windows forms c# or would you have to change some of it?
@OttoBotCode
@OttoBotCode Ай бұрын
You don't have to change any of the actual Tetris logic. All you have to do is rewrite the UI (the code in MainWindow.xaml and MainWindow.xaml.cs).
@alshick3973
@alshick3973 28 күн бұрын
@@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
@Enderdash3838
@Enderdash3838 4 ай бұрын
Hey, I need a little help: at 14:31 the computer gives me a warning on "currentBlock". Could you explain me why, please?
@OttoBotCode
@OttoBotCode 4 ай бұрын
What does the warning say?
@Enderdash3838
@Enderdash3838 4 ай бұрын
​@@OttoBotCode it says that "currentBlock" can't contain a Null value in the output, because it isn't nullable
@Enderdash3838
@Enderdash3838 4 ай бұрын
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
@ryanatkinson3961
@ryanatkinson3961 6 ай бұрын
Hi, I have used the code exactly how you have but the blocks won't move down I was wondering if you knew why this would be?
@OttoBotCode
@OttoBotCode 6 ай бұрын
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 😊
@only_denis
@only_denis 11 ай бұрын
anyone help me, how he has onened a new file pragram.cs? plss
@footballCartoon91
@footballCartoon91 2 жыл бұрын
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..
@OttoBotCode
@OttoBotCode 2 жыл бұрын
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! 😉
C# GAME ENGINE BY 16-YEAR-OLD! // Code Review
49:06
The Cherno
Рет қаралды 302 М.
Using Image Recognition to DESTROY Fruit Ninja
10:08
CodeNoodles
Рет қаралды 603 М.
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 62 МЛН
A clash of kindness and indifference #shorts
00:17
Fabiosa Best Lifehacks
Рет қаралды 123 МЛН
Женская драка в Кызылорде
00:53
AIRAN
Рет қаралды 465 М.
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 160 МЛН
20 Advanced Coding Tips For Big Unity Projects
22:23
Tesseract
Рет қаралды 168 М.
Learning C# In A Week... Otherwise I Fail University
9:04
What was Coding like 40 years ago?
29:05
The Coding Train
Рет қаралды 1,7 МЛН
Every Programming Language Ever Explained in 15 Minutes
15:29
Flash Bytes
Рет қаралды 297 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 696 М.
CODING MY OWN TETRIS  (Unity)
13:00
Valem
Рет қаралды 126 М.
How To Make A Game Alone
8:11
Thomas Brush
Рет қаралды 1,1 МЛН
Programming a Snake Game in C# - Full Guide
1:22:02
OttoBotCode
Рет қаралды 147 М.
C# in 100 Seconds
2:27
Fireship
Рет қаралды 2 МЛН
ВАЖНО! Не проверяйте на своем iPhone после установки на экран!
0:19
ГЛАЗУРЬ СТЕКЛО для iPhone и аксессуары OTU
Рет қаралды 6 МЛН
НОВЫЕ ФЕЙК iPHONE 🤯 #iphone
0:37
ALSER kz
Рет қаралды 226 М.
Kumanda İle Bilgisayarı Yönetmek #shorts
0:29
Osman Kabadayı
Рет қаралды 1,8 МЛН
iPhone, Galaxy или Pixel? 😎
0:16
serg1us
Рет қаралды 1,3 МЛН
Я купил первый в своей жизни VR! 🤯
1:00
Вэйми
Рет қаралды 2 МЛН