Programming a Tetris Game in C# - Full Guide

preview_player
Показать описание
Learn how to program a Tetris game in C# using WPF.

Download the assets here:

Source code is available here:

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!
Рекомендации по теме
Комментарии
Автор

*Source code*

If you don't want to write the code yourself, it's available here for 3$ (and free for Patreon supporters):
Your support would be a massive help for me and my channel! 🤩

OttoBotCode
Автор

I love how simple this way of creating Tetris is compared to other examples. Keep up the good work!

vstom
Автор

I love how you took the time to talk about designing the application. Much appreciated after browsing other C# videos.

shanep
Автор

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.

joevaghn
Автор

I'm from Belarus, studying at university and starting to make games. Your tutorial was very helpful, the code is very beautiful. Thank you ♥♥♥

chipolinchikaloe
Автор

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

gurbanaarongulman
Автор

this video and channel are SOOO underrated you deserved my sub!

TeamROsky
Автор

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.

nikolaoskonstantinidis
Автор

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 ..

sumugu
Автор

Very clean! Don't know how i stumbled upon this video, but well done :)

tbpotn
Автор

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 <3

mrjelk
Автор

This would be my weekend challenge for this Saturday. Thanks for the great tutorial!

daeyoungkim
Автор

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.

solomareds
Автор

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.

andergarcia
Автор

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.

remigiuszobrycki
Автор

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!!

kallismb
Автор

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.

TinyMaths
Автор

Seriously well done and thank you for this.

mariousranasinghe
Автор

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.

cobrakilla
Автор

Very good explanations, it helped me a lot in learning object oriented programming in C#. thanks a lot!!! :-)

DennisRitchie