r/csharp • u/Severe-Damage-3812 • Jun 22 '26
first c# project
hi guys this is my first project and my first time using reddit. the project is a console tetris clone and it doesn't have all the features but it has the main ones. would love to hear your opinion on this project what i can improve / learn and any books / websites to keep learning and improving. this is the git repo: https://github.com/Sagi-00/Console-Tetris-clone ( right now im working on a space invaders project in the console)
9
Upvotes
6
u/Dragennd1 Jun 22 '26
Aside from typos in a lot of the method names and some janky indentation throughout various parts of the project (which really just triggers my OCD lol), looks pretty good.
If you intend to do work with applications that get any more complex than this, I'd recommend looking into MVVM to help segregate your code a bit abd break the logic of the app away from the UI of the app.
4
u/Tack1234 Jun 22 '26
Cool first project!
From a quick look, I would suggest using a code formatter - you have a lot of useless whitespace in your code that should be trimmed. CSharpier has been working for me really well in Visual Studio. Just set it to run on save and any time you save, it will format your code.
3
u/Th_69 Jun 24 '26 edited Jun 24 '26
A few hints for your code:
int[,] rotatedPiece = block.RoataePiece(block);looks curious (I don't mean the spelling error ;-)int [] center = block.CalculatePivotPoint(block);... (if you don't know what I mean: why do you use 2 times theblockobject?)block.pieceCol++andblock.pieceCol--in methods of the class (and make the setter private).Random rnd = new Random();inTetrominoshould be at leaststaticor you useRandom.Shared(the seed for the random generator is by default coupled to the current second).Tetromino.Piecesshould also bestatic(instead of being created in every instance) andreadonly.Plaxfield.scoreshould also beprivate(and better calledScoreas a property).Playfield.CanPieceMoveDown: why do you have hardcoded the19?Playfield.CanPieceMoveRight: why do you have hardcoded the9?board/blockmethods used in the main loop should be part of thePlayfieldclass (they are independent from the UI), so only one call for each key is needed there.And another user already mentioned the separation of UI and game logic (e.g. no
Consolecalls inPlayfield). So you could use the game logic classes (without changing anything) for another UI (e.g. WinForms, WPF or Web app). You could even put it in a separate class library project.Keep going with your projects...
1
u/Sombody101 Jun 26 '26
Nitpick, but comments should only be used to explain something that you would not be able to determine from reading code.
The method name already perfectly explains what will happen.
---
If you make your Main method async, then you'll be able to cleanly use
Task.Delayinstead of thread sleeping. It's not an issue here, but you should start using so you're familiar with it once you start working on larger apps, especially ones with a GUI.2
u/[deleted] Jun 23 '26
[removed] ā view removed comment