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

Поділитися
Вставка
  • Опубліковано 5 лис 2024

КОМЕНТАРІ • 91

  • @branislavzivanovic4775
    @branislavzivanovic4775 4 роки тому +21

    Why do you have only 100 subscribers? Your a diamond in this UA-cam mine!

  • @zajac4817
    @zajac4817 Місяць тому

    It got recommended to me for some reason and I love it. I grasped the basics and OOP in C#. It I just love the approach, how one should look for docs and utilise stuff. I also love the explanations. Years later, loving it!!!!!

  • @johanrecaman
    @johanrecaman 3 роки тому +7

    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 роки тому +8

    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.

  • @gameaudioshaman
    @gameaudioshaman 6 місяців тому

    This is really well made. I like that you start with a conceptualisation first.

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

  • @TheDoberwomann
    @TheDoberwomann 2 роки тому +4

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

  • @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

  • @rounak3811
    @rounak3811 3 роки тому +5

    You deserve more subscribers

  • @CreeperShorts
    @CreeperShorts Рік тому

    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.

  • @0L3H.
    @0L3H. 3 роки тому +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! 👍🏻

  • @RuairiOTuathail
    @RuairiOTuathail 3 роки тому +3

    This was really great. You explain things very clearly. Thanks a lot.

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

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

  • @jmeadeio4347
    @jmeadeio4347 4 роки тому +11

    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 роки тому +2

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

  • @kito8088
    @kito8088 2 роки тому

    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 ;)

  • @aleswirt4033
    @aleswirt4033 3 роки тому

    Step by step... Just beautiful!

  • @josuerolandonaranjosieiro761

    This was the most helpful video i'd ever found!!! thanks a lot!!!!!

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

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

  • @niklasmartinsson3719
    @niklasmartinsson3719 2 роки тому

    This is so god damn amazing. Thank you for this!

  • @maroxcore
    @maroxcore 3 роки тому +5

    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 роки тому +6

      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 роки тому +1

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

  • @carlosavila6047
    @carlosavila6047 3 роки тому

    I am very grateful, it will be useful to me for a university project. Good tutorial, great explanation. Thank you so much.

  • @jonny5_
    @jonny5_ 3 роки тому

    Aaahhh…so satisfying to see some .NET Core Console app love! Good stuff!

  • @shi76b
    @shi76b 3 роки тому +3

    good tutorial, you sir, are a great explainer!

  • @a1t0rmenta
    @a1t0rmenta Рік тому

    This is good material man! Thanx

  • @dxrk81
    @dxrk81 2 роки тому

    I think this video's signature is "WriteLIne();" 😂

  • @solr4cc
    @solr4cc Рік тому

    What color theme for vs do you use? Great vid!

  • @ijeanpierrebp
    @ijeanpierrebp 2 роки тому

    great video!

  • @untaleddy7475
    @untaleddy7475 4 роки тому +2

    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  4 роки тому

      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. ua-cam.com/video/9TIyojZgFD8/v-deo.html

    • @untaleddy7475
      @untaleddy7475 4 роки тому

      @@mikewesthad Thank you so much!! It really helped A LOT. Keep up the good work, your content is awesome.

  • @0z2ae
    @0z2ae 3 роки тому +1

    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 роки тому +1

      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

    • @0z2ae
      @0z2ae 3 роки тому

      @@mikewesthad Thank you!

  • @maxjustmax521
    @maxjustmax521 3 роки тому +2

    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 роки тому +5

      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.

  • @captainufo4587
    @captainufo4587 3 роки тому +2

    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 роки тому +1

      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 роки тому +1

      @@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 роки тому +2

      ​@@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 роки тому +2

      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 роки тому +1

      @@mikewesthad Thank you very much for the detailed answer and the links!

  • @LebaneseNostalgia
    @LebaneseNostalgia 3 роки тому

    Please do one with the clear I couldn't find much on this. thank you!

  • @javlonbekfayzullaev3448
    @javlonbekfayzullaev3448 2 роки тому

    Thank you so much it really helped

  • @sksamassa95
    @sksamassa95 3 роки тому +2

    Thank you very for videos!
    спасибо!

  • @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?

  • @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?

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

  • @zyrhusmc3490
    @zyrhusmc3490 10 місяців тому

    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

  • @Skrowley
    @Skrowley 4 роки тому +1

    Боже, прекрасное видео. Большое спасибо!

  • @hexahedron74
    @hexahedron74 3 роки тому

    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

  • @OneTrueBIue
    @OneTrueBIue 3 роки тому +1

    Thank y

  • @KieuThuy-wh6zf
    @KieuThuy-wh6zf 3 роки тому

    great tutorial ! :D i was wondering where i could get the source code for this project

  • @juegosretro1042
    @juegosretro1042 2 роки тому

    Hello very good, how could I remove the scrollbar from console c #?
    Thank you very much!

  • @sabernationtv
    @sabernationtv 11 місяців тому

    How could I convert this into an executable?

  • @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

  • @norpanmekk
    @norpanmekk 4 роки тому

    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  4 роки тому +2

      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

  • @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 ?

  • @AirshipTodayEmailAddress
    @AirshipTodayEmailAddress 3 роки тому

    Thanks

  • @CanadianMang
    @CanadianMang 2 роки тому

    Vocal fryyyyy

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

  • @MrBananaPeace
    @MrBananaPeace 2 роки тому

    How do you put on squares like at 33:10 but just the squares?

  • @aaronchen643
    @aaronchen643 3 роки тому

    How do I implement the string.Format method? For example string prompt = "HP: {0}, hp";

    • @mikewesthad
      @mikewesthad  3 роки тому +1

      docs.microsoft.com/en-us/dotnet/api/system.string.format?view=net-5.0#get-started-with-the-stringformat-method

  • @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: ua-cam.com/video/9TIyojZgFD8/v-deo.html

  • @kossonkosab5513
    @kossonkosab5513 Рік тому

    any way to contact you?

  • @Metaconta
    @Metaconta 3 місяці тому

    El menú y submenú que he hecho más complicado es usar solo las teclas de las flechas, Enter y Escape. Nada más. Ya que hice lo mismo en un display gráfico que se comporta como la ventana del MS-DOS por llamarlo de alguna manera. ua-cam.com/video/9HM2CROtuek/v-deo.html

  • @jhappysemall2269
    @jhappysemall2269 2 роки тому

    Using FFVII =D

  • @mercy7534
    @mercy7534 3 роки тому

    for me please a big mac

  • @RekkeEU
    @RekkeEU 3 роки тому

    I don't see the Projects tab, how do I find it?

    • @mikewesthad
      @mikewesthad  3 роки тому +1

      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!

  • @gtl5568
    @gtl5568 3 роки тому

    As of right now this tutorial doesent work

    • @mikewesthad
      @mikewesthad  3 роки тому +1

      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

  • @alexandrareyes8543
    @alexandrareyes8543 10 місяців тому

    33:15

  • @pizza.3322
    @pizza.3322 3 роки тому

    29:51