Intro to C#: 29 - Making a Fancy Keyboard-Controlled Console Menu

  Рет қаралды 67,097

Michael Hadley

Michael Hadley

4 жыл бұрын

In this video, we learn how to create a re-usable menu class that is controlled via the keyboard. We can use this to build out our choose your own adventure C# console games.
=== Relevant Links ===
Playlist: • Intro to Programming i...
Next video: • Intro to C#: 30 - Adve...

Пікірлер: 89
@branislavzivanovic4775
@branislavzivanovic4775 3 жыл бұрын
Why do you have only 100 subscribers? Your a diamond in this KZbin mine!
@johanrecaman
@johanrecaman 3 жыл бұрын
I really liked the way you don't only show how to code. You show how to think to come to this code. Thank you for this
@shadilios
@shadilios 2 жыл бұрын
You're amazing, thank you a lot, literally every aspect of your video is amazing, the way you opened the documentation to see what to do is rarely done in tutorials nowadays where they just give you the answer.
@RuairiOTuathail
@RuairiOTuathail 3 жыл бұрын
This was really great. You explain things very clearly. Thanks a lot.
@gameaudioshaman
@gameaudioshaman 3 ай бұрын
This is really well made. I like that you start with a conceptualisation first.
@TheDoberwomann
@TheDoberwomann 2 жыл бұрын
I am sooo happy I came across this. I am taking my first C# course and in this video you explained everything so well, that I understood everything in detail and finally managed to complete an assignment I´ve been struggling with for 3 days!! THANK YOU :) !!
@adriankozakiewicz8248
@adriankozakiewicz8248 Жыл бұрын
Thank you so much. I searched for a explenation of intaractive terminal in c# for so long and couldn't understand it by myself with c# docs. You are amazing.
@CreeperShorts
@CreeperShorts 9 ай бұрын
Absolute goat! Thank you very much! Your explanations were extremely clear and you made a whole lot of sense compared to my teacher at school. You managed to keep it simple.
@aleswirt4033
@aleswirt4033 3 жыл бұрын
Step by step... Just beautiful!
@carlosavila6047
@carlosavila6047 2 жыл бұрын
I am very grateful, it will be useful to me for a university project. Good tutorial, great explanation. Thank you so much.
@shi76b
@shi76b 3 жыл бұрын
good tutorial, you sir, are a great explainer!
@josuerolandonaranjosieiro761
@josuerolandonaranjosieiro761 Жыл бұрын
This was the most helpful video i'd ever found!!! thanks a lot!!!!!
@niklasmartinsson3719
@niklasmartinsson3719 Жыл бұрын
This is so god damn amazing. Thank you for this!
@rounak3811
@rounak3811 3 жыл бұрын
You deserve more subscribers
@fcdarjan
@fcdarjan 3 жыл бұрын
very slick if i only watched this before my school assignment.... this is way easier than what we did... :D very , very slick!
@kito8088
@kito8088 Жыл бұрын
Great video I learned a lot from it, thank you! The only thing I miss is a file or text in the discription to copy paste the code ;)
@a1t0rmenta
@a1t0rmenta 10 ай бұрын
This is good material man! Thanx
@jonny5_
@jonny5_ 2 жыл бұрын
Aaahhh…so satisfying to see some .NET Core Console app love! Good stuff!
@deprimat666
@deprimat666 2 жыл бұрын
I didn't even read the title I was just like oh cool python. Then realised after seeing title and other recommended videos that it's c# lol. Wow didn't realise its so similiar :o
@sksamassa95
@sksamassa95 3 жыл бұрын
Thank you very for videos! спасибо!
@alinavevel9522
@alinavevel9522 3 жыл бұрын
I'm studying CS and our professor isn't very good...thank you for your video, I hope you will post more videos.
@0L3H.
@0L3H. 3 жыл бұрын
Hello from Ukraine! Thank you so much for the detailed explanation in your video lessons!) Besides, I want to say that all your videos are incredibly cool! 👍🏻
@momobit2143
@momobit2143 3 жыл бұрын
I wish I had access to someone like you to be my mentor for my deliberate practice, please teach me how to get better in problem solving and writing actual logic for my features, how to think like a professional programmer. we all can learn the programming language but I think the key problem is the deliberate practice which need someone who can guide and make some exercises to solve in a right order. please do something like this. I will be your first follower.
@javlonbekfayzullaev3448
@javlonbekfayzullaev3448 Жыл бұрын
Thank you so much it really helped
@jmeadeio4347
@jmeadeio4347 4 жыл бұрын
Great Video, It helped a lot of my game. What was the website you used to put the "Paint Drying" in VS?
@mikewesthad
@mikewesthad 4 жыл бұрын
Glad it helped. Here's the ASCII text generator site: patorjk.com/software/taag/#p=display&f=Bloody&t=Paint%20Drying
@jmeadeio4347
@jmeadeio4347 4 жыл бұрын
@@mikewesthad Thank You! You have helped my classmates and I so much with these videos!!
@ijeanpierrebp
@ijeanpierrebp 2 жыл бұрын
great video!
@solr4cc
@solr4cc Жыл бұрын
What color theme for vs do you use? Great vid!
@LebaneseNostalgia
@LebaneseNostalgia 2 жыл бұрын
Please do one with the clear I couldn't find much on this. thank you!
@Skrowley
@Skrowley 3 жыл бұрын
Боже, прекрасное видео. Большое спасибо!
@jonathanandersson3999
@jonathanandersson3999 2 жыл бұрын
I know this video was posted a while ago but I followed this tutorial to the point where you make the selected index to be white, but when I test mine it turns all of the menu options white instead of just the selected one. Do you have any clue what could be wrong, I'm working in vs community on .net 5.0 could that be the problem ?
@maroxcore
@maroxcore 3 жыл бұрын
MAN I LOVE YOUR CHANNEL, I recently started studying programming and I only practice c# console. So your videos are perfection for me... Is there any posibility to do this without Clear(); inside of the Run(); ? I mean, i don't want to clear everything on console, but if i don't use that method the menu is going to be repeated everytime :( Thanks!!
@mikewesthad
@mikewesthad 3 жыл бұрын
Glad you've found it helpful! If you want to refactor the menu system so that it doesn't Clear, you need to 1) remove the Clear and 2) use SetCursorPosition when you redraw the options when things change. If your menus are always at the top left of the screen, then you can probably get away with a simple solution of using SetCursorPosition(0, 0) when you redraw the options after a key is pressed. If you are looking for a more advanced, general purpose way to handle the menu, I would do something like this: - Pass in an X and Y coordinate to Run that controls where the menu is drawn to the screen. - Split the prompt into lines and draw them starting at (X, Y) when the menu is run. Since the prompt doesn't change, you only need to draw this once. - Draw the options, and redraw them any time the selection changes. You need to draw them starting at (X, Y + numPromptLines).
@maroxcore
@maroxcore 3 жыл бұрын
​@@mikewesthad Thanks for your reply. Yesterday I found a solution using SetCursorPosition and Options.Length to reset the place in each different menu. It is very difficult to find good videos about interesting and well explained projects, keep doing this amazing job!
@KieuThuy-wh6zf
@KieuThuy-wh6zf 3 жыл бұрын
great tutorial ! :D i was wondering where i could get the source code for this project
@hexahedron74
@hexahedron74 2 жыл бұрын
thanks for the tutorial! But i want to make Back functions but I dont know how to do it... How can i make back function? when we go to aboutdisplay, program just finished so i want to fix this
@yz.21
@yz.21 3 жыл бұрын
Hello, your videos really helped me a lot. I have a question, what is the theme you are using in Visual Studio?
@mikewesthad
@mikewesthad 3 жыл бұрын
I have a custom Visual Studio theme installed: marketplace.visualstudio.com/items?itemName=adrianwilczynski.one-dark-pro. If you want some more color options, I recommend: marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.ColorThemesforVisualStudio
@yz.21
@yz.21 3 жыл бұрын
@@mikewesthad Thank you!
@juandanielubieramendez8180
@juandanielubieramendez8180 2 жыл бұрын
There is an error, when you maximize the window, a white line apear all cross the menu, in what the selection was. How can i fix that?
@emreyuksel8053
@emreyuksel8053 3 жыл бұрын
Why does my c# not showing console for the menu.cs and game.cs, but only for the program.cs. Please help me
@DKaldes
@DKaldes 2 жыл бұрын
Your C# programming series is great for learning more about the console and how to use Object oriented programming to it's fullest extent, but I must say creating a Menu class is a kinda useless, you can do the same with a single function.
@mr.banana5627
@mr.banana5627 2 жыл бұрын
How do you put on squares like at 33:10 but just the squares?
@juegosretro1042
@juegosretro1042 2 жыл бұрын
Hello very good, how could I remove the scrollbar from console c #? Thank you very much!
@zyrhusmc3490
@zyrhusmc3490 7 ай бұрын
Can you put it all in one class, i know it more cleaner but for me im more comfortable seeing everybody in one class, plus its make it easier for me to debug it since im not really that smart or good in coding Can someone give me something like this but only in one class? My code is getting ruined, becase in the last part where is the "private void RunFirstChoice()" i cant put may codes there because it already have a method and i think you can't put a method inside of a method
@untaleddy7475
@untaleddy7475 3 жыл бұрын
Great video! How did you manage to put the "Paint Drying" thing on VS? I just cannot manage to put the ascii art on it without getting 99 errors
@mikewesthad
@mikewesthad 3 жыл бұрын
Thanks. A couple of things: - This is the text generator: patorjk.com/software/taag/#p=display&f=Bloody&t=Paint%20Drying - Check out the first ~11 minutes of my other video on displaying ASCII art. It talks about what ASCII is, why some characters may not show up, how to use verbatim strings and how to avoid a common error folks hit with verbatim strings. I suspect you are hitting that error. kzbin.info/www/bejne/b4WsqqKgj8x5epo
@untaleddy7475
@untaleddy7475 3 жыл бұрын
@@mikewesthad Thank you so much!! It really helped A LOT. Keep up the good work, your content is awesome.
@AirshipTodayEmailAddress
@AirshipTodayEmailAddress 3 жыл бұрын
Thanks
@maxjustmax521
@maxjustmax521 3 жыл бұрын
how are you having so little amount of subs? you are a legend! can you try to slow things down a bit! it takes some time for beginners!
@mikewesthad
@mikewesthad 3 жыл бұрын
Thanks! This is actually part of a course where students are 10+ weeks in to programming, so I suspect it'll be fast for some folks who land on it outside of that course. One tip that I usually give to folks that might be helpful here: watch tutorials once without doing any coding, then watch it again and code along. The first time through, you just want to pay attention to the big picture concepts as much as possible. Then, the second time through, you can focus on the details of coding along. That second time, you can also watch it at 1.5x speed and pause as needed. This is two-part process is what I use myself when learning something new. (If you are tackling a long video, you can also break it into chunks - watch the first 15 minute chunk, then start at the beginning and code along, watch the next chunk, etc.)
@oltomcat2106
@oltomcat2106 3 жыл бұрын
For me, english is not my motherlanguage and me is a beginner learning basics in C#. What is helping me, is to slow down the playback speed, beside whatching it more then a single time.
@sabernationtv
@sabernationtv 8 ай бұрын
How could I convert this into an executable?
@dxrk81
@dxrk81 2 жыл бұрын
I think this video's signature is "WriteLIne();" 😂
@ayaanm0min
@ayaanm0min 3 жыл бұрын
Thank y
@captainufo4587
@captainufo4587 3 жыл бұрын
I have a question about the inner workings of the menu... given that when we select "credits" in the end we call RunMainMenu() again, inside the function DisplayAboutInfo() which was itself called by a previous execution of RunMainMenu(), what is happening here? Is the program re-setting RunMainMenu and starting from zero? Is it creating a second instance of the menu? If so, does it mean that if I create a whole game based around this menu system, the more the player plays and backs and forwards between menus, the more system resources the program is hogging?
@mikewesthad
@mikewesthad 3 жыл бұрын
Every time RunMainMenu is called, a new instance of the Menu class is created as a local variable ("mainMenu"). When mainMenu goes out of scope, the Menu instance is destroyed and the memory is available for garbage collection, which is handled for you by the common language runtime. So yes, you are creating new instances of the Menu every time you go back to RunMainMenu from DisplayAboutInfo, but realistically, you shouldn't hit any issues from doing this here. That said, you *could* create some cool added features by moving the menus from local variables to fields/properties. E.g. if the same Menu instance is re-used, that means that when you re-visit the main menu after checking out the about screen, your "selectedIndex" is saved.
@captainufo4587
@captainufo4587 3 жыл бұрын
@@mikewesthad Thanks for the answer. I had some understanding of the garbage collection, however I guess it's not clear to me IF any of the various mainMenu-s ever goes out of scope at all: the RunMainMenu method never ends doing its thing for what I can see. It starts new methods inside itself, which in turn call new RunMainMenu-s, which, you confirmed, each create a new instance of the menu. Hence, are the instances of the menu created by all the other calls of RunMainMenu ever destroyed while the program is running? It seems to me that they sit there, unused, undestroyed until the program runs because the methods that create them never actually complete their lifecycle until the whole thing closes. Or am I wrong?
@mikewesthad
@mikewesthad 3 жыл бұрын
​@@captainufo4587 You've got the right intuition re: scope! But the garbage collector is pretty smart. The tl;dr is that those mainMenu instances within each RunMainMenu will be cleaned up eventually* because they are no longer accessible. Nothing can interact with the mainMenu local variable after we leave the RunMainMenu where it was created. The "*" here is that we need to use a fair bit of memory before the GC will kick in - these menus are tiny in terms of memory. More detailed response follows. Technically, I shouldn't have said "when mainMenu goes out of scope" - I should have said "when mainMenu is unreachable." You can read about the details here: docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals#memory-release. You can see the conditions for garbage collection in the next section, along with a way to manually trigger the GC which can be useful in testing situations. If you open up the Performance Profiler (under the top toolbar under Debug) and select the memory allocation option, you can run your app in Release mode (important to not be in Debug mode) and watch the memory usage live. This tool allows you to take memory snapshots and force GC. If you run it on the current version of the app and cycle through the Main Menu => About => Main Menu => About => etc. hundreds of times, the memory will stay pretty flat (mine starts and stays at ~6mb). Re: conditions for garbage collection from earlier, I suspect the memory footprint here is so low that the GC never even needs to kick in. See the discussion here, since it is a similar question: stackoverflow.com/a/6066311. You can apply a similar approach to force the GC to kick in. If you add a massive byte array as a private field to Menu, along with a finalizer that simply prints out a message that the Menu was destroyed, you can re-run the memory performance profiler. Now the memory will start at ~1gig and swift jump each time you cycle through main menu to about and back again. At a certain point, the GC will kick in and you'll see menus get cleaned up (console message) and the memory usage will drop a bit. You can also force that by hitting the GC button in the memory performance profiler.
@mikewesthad
@mikewesthad 3 жыл бұрын
To follow up on that with a few big picture thoughts: The memory usage in this situation is pretty low, so I wouldn't spend much time worrying. That said, if you want to go into game dev, this is an important issue when it comes to performance. If you've got a slow part of your game / game engine that needs to be optimized, then you do want to write your code in a way where you aren't trigging the allocation and deallocation of memory constantly (along with other optimizations). If you get into more advanced situations like a particle system, there are some patterns that help solve that, e.g. the object pool: gameprogrammingpatterns.com/object-pool.html.
@captainufo4587
@captainufo4587 3 жыл бұрын
@@mikewesthad Thank you very much for the detailed answer and the links!
@Rex-em2qg
@Rex-em2qg 2 жыл бұрын
Hi, is there a way to change the tranparency of the background? I've seen other peoples work and their background on the console app is a lot less.. dark?, Thanks!
@reneborgmann5575
@reneborgmann5575 2 жыл бұрын
u can rightclick the top of the console to change the properties of it.
@nicosiasoco9336
@nicosiasoco9336 3 жыл бұрын
hello do you know how to center the prompt and options? and even if the prompt is ascii art? thanks sir! you really are a God
@mikewesthad
@mikewesthad 3 жыл бұрын
You can center a single line of text via SetCursorPosition or PadLeft. E.g. see stackoverflow.com/a/21917650 for the set cursor approach or programmingisfun.com/c-sharp-console-center-text-padleft/ for the padleft approach. Careful - for that to work, you need to make sure your line of text is not wider than your console window. To center multiple lines (like the prompt + ASCII art), you need to take your multi-line string, split it into lines (www.techiedelight.com/split-string-on-newlines-csharp/) and then draw each line centered.
@aaronchen643
@aaronchen643 3 жыл бұрын
How do I implement the string.Format method? For example string prompt = "HP: {0}, hp";
@mikewesthad
@mikewesthad 3 жыл бұрын
docs.microsoft.com/en-us/dotnet/api/system.string.format?view=net-5.0#get-started-with-the-stringformat-method
@norpanmekk
@norpanmekk 3 жыл бұрын
Hello! I got confused at a very simple spot... when you decide to clean up and do "Title = "paint blabla"" But you never specified what "Title" was before this? did you create a string for it or?
@mikewesthad
@mikewesthad 3 жыл бұрын
It's a property on the Console class. We can use it without specifying the fully qualified path (System.Console.Title) because of the using statement at the top of the file
@trentontyee2552
@trentontyee2552 3 жыл бұрын
How did you implement paint drying into c# from the generator
@mikewesthad
@mikewesthad 3 жыл бұрын
A couple of things: - This is the text generator site: patorjk.com/software/taag/#p=display&f=Bloody&t=Paint%20Drying - Check out the first ~11 minutes of my other video on displaying ASCII art. It talks about what ASCII is, why some characters may not show up, how to use verbatim strings and how to avoid a common error folks hit with verbatim strings: kzbin.info/www/bejne/b4WsqqKgj8x5epo
@aleswirt4033
@aleswirt4033 3 жыл бұрын
May I ask about task in the end of the video? If it possible, to change menu without clear() method, should I use rewrite all text on console panel? P.S. Sorry for my english, I`m solving this issue))
@mikewesthad
@mikewesthad 3 жыл бұрын
If you want to refactor the menu system so that it doesn't Clear, you need to 1) remove the Clear and 2) use SetCursorPosition when you redraw the options when things change. If your menu are always at the top left of the screen, then you can probably get away with a simple solution of using SetCursorPosition(0, 0) when you redraw the options. If you are looking for a more advanced, general purpose way to handle the menu, I would do something like this: - Pass in an X and Y coordinate to Run that controls where the menu is drawn to the screen. - Split the prompt into lines and draw them starting at (X, Y) when the menu is run. Since the prompt doesn't change, you only need to draw this once. - Draw the options, and redraw them any time the selection changes. You need to draw them starting at (X, Y + numPromptLines).
@aleswirt4033
@aleswirt4033 3 жыл бұрын
@@mikewesthad Oh, ok... I think about to make an array of strings, and after choosing options use escape-sequence " ' for each element of array. How about this?
@kossonkosab5513
@kossonkosab5513 Жыл бұрын
any way to contact you?
@CanadianMang
@CanadianMang 2 жыл бұрын
Vocal fryyyyy
@RekkeEU
@RekkeEU 3 жыл бұрын
I don't see the Projects tab, how do I find it?
@mikewesthad
@mikewesthad 3 жыл бұрын
Are you talking about the "Project" menu at the top of the screen? On Windows, that will only show up if you have a solution opened. E.g. you created a new project or you opened up a .sln file. If you are trying to add a class to a project, you can also do that via right clicking on your project in the Solution Explorer sidebar and going through the "Add" option there
@RekkeEU
@RekkeEU 3 жыл бұрын
@@mikewesthad Thankyou!
@mercy7534
@mercy7534 3 жыл бұрын
for me please a big mac
@jhappysemall2269
@jhappysemall2269 2 жыл бұрын
Using FFVII =D
@pizza.3322
@pizza.3322 2 жыл бұрын
29:51
@alexandrareyes8543
@alexandrareyes8543 7 ай бұрын
33:15
@gtl5568
@gtl5568 3 жыл бұрын
As of right now this tutorial doesent work
@mikewesthad
@mikewesthad 3 жыл бұрын
Howdy - this does indeed work. Many of my students have completed it this month. If you are hitting an error, take a look at the error message. That's your clue has to what has gone wrong in your code. I would also recommend watching any technical tutorial twice - once without coding where you pay attention to the concept & take notes, and then a second time where you try to build along. That helps you learn and build a mental model of what is supposed to happen, which then helps you debug when things go wrong when coding.
@gtl5568
@gtl5568 3 жыл бұрын
@@mikewesthad i went through it after i wrote this and forgot to delete it. I was hung up because alot of the commands for me werent working i figured out the issues which were minor inconsistencies in it
@mikewesthad
@mikewesthad 3 жыл бұрын
@@gtl5568 👍🏽 glad you got it working
Intro to C#: 30 - Adventure Game Architecture Walkthrough
38:24
Michael Hadley
Рет қаралды 7 М.
Building beautiful console applications - Patrik Svensson
45:57
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 11 МЛН
🤔Какой Орган самый длинный ? #shorts
00:42
THEY made a RAINBOW M&M 🤩😳 LeoNata family #shorts
00:49
LeoNata Family
Рет қаралды 43 МЛН
Iron Chin ✅ Isaih made this look too easy
00:13
Power Slap
Рет қаралды 34 МЛН
Fastest Way to Learn ANY Programming Language: 80-20 rule
8:24
Sahil & Sarra
Рет қаралды 794 М.
Learn C Language In 10 Minutes!! C Language Tutorial
10:36
AmanBytes
Рет қаралды 195 М.
Create UML diagrams using CHAT GPT & PlantUML Step by Step Tutorial
6:54
Create Your Future with Tariq Aziz
Рет қаралды 26 М.
Primary Constructors in C# 12 Explained!
9:39
James Montemagno
Рет қаралды 23 М.
C# - Como animar un texto en consola (Efecto maquina de escribir)
9:37
DevraYa Oficial
Рет қаралды 2,2 М.
ASMR Programming - Spinning Cube - No Talking
20:45
Servet Gulnaroglu
Рет қаралды 3,7 МЛН
Intro to C#: 21 - Making, Finding and Remixing ASCII Art
36:54
Michael Hadley
Рет қаралды 16 М.
CLI-интерфейсы по-человечески @PodlodkaShow
49:49
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 11 МЛН