C# Tutorial 8 OOP Game

[ad_1]
Get the Code Here :
Best C# Book :
Support me on Patreon :
If you can’t donate a Like is Greatly Appreciated 🙂

In this part of my C# tutorial series we will make a fun little game. I’m going to show how to create 2 warriors that will fight to the death in a simulated battle. More complex video games follow many of the techniques we cover in this video. It also will show how awesome object oriented programming is in that it gives you the ability to model just about any real world object, or interaction.

For best results take notes on the cheat sheet provided above as you watch and leave any questions you have.

Thank you to Patreon supporters like the following for helping me make this video

facebook.com/cottageindustriesbuild/
jaryd remillard : instagram: @distant_admiration
bugreplay.com
@kyleaisho
@thetwistedhat
vjFaLk
jaryd remillard :


Posted

in

by

Tags:

Comments

43 responses to “C# Tutorial 8 OOP Game”

  1. T Riddle Avatar

    Thanks Derek. Do you think it would have been simpler to make GetAttackResult a boolean instead of a string?

  2. Maaz Shaikh Avatar

    dammit i figured the battle class all wrong, i thought this will be a piece of cake but oh noooo.
    i think this is going to require a whole lot of more time than i thought.

  3. Abrar Iqbal Avatar

    Surely Bob Wins 😀

    I really now have a bit understanding of OOP concepts. All I now have to do is practice a lot. Thanks to you! Really hats of to you for your remarkable tutorials. My plan is after finishing and learning from your C# playlist, I will jump into gaming tutorials you've made.

    Moreover I would like to know if you are planning to make tutorials of making andriod or ios app in VS with C#? Because you really explains a lot with legit information and of course with examples to learn with fun! 😀

  4. Andrew Ignatov Avatar

    Hi, Derek! Thanks for your video, now i know how to start creating games:) There is a question here. In the end of the class "Battle" we write " else return "Fight Again" ". But is't it a mistake cause it doesn't work? And I also can't understand why.

  5. RandomSilly Avatar

    Spending my free time before uni starts again with more knowledge. Thanks for this tutorial, really helpful with improving my programming!

  6. Yasser Osama Avatar

    hey derek i wanted to ask something , why didn't we pass the warrios by reference in getAttackresults method ? is it method taking them by value the way you're doing it in the video ?

  7. N3RDZ0MBI3 Avatar

    "Good for Bob and good for you!"

  8. Patient Ndlovu Avatar

    derek thanks a lot man keep up the good work

  9. Fellipe Freire Avatar

    Random randomNumber = new Random(DateTime.Now.Millisecond);
    Hope it helps. =]

  10. Chris Avatar

    Thanks so much for taking the time to do these tutorials.. I'm sure you've helped an awful lot of people to help themselves 🙂
    – great work, great tutorials 🙂

  11. Maarten Roozendaal Avatar

    Hi Derek, I just finished coding the game and it works perfect. Thank you for the toturials. Just one thing, in order the get the code to fully function I had to create an instance of Random() in the main function and pass this to the warrior() constructor. When i create the instance in the warrior class the Attack() and Block() methods return the same value. I was just wondering why this does work for you and not for me?

  12. TheBinaryGuy Avatar

    Hey Derek, thanks for these amazing tutorials and ofc "Bob Wins" ! xD

    A little out of the point as this tutorial was meant for understanding OOP and it also cleared my OOP doubts:

    I spotted that this game is a little bias and most of the time Warrior A wins as he always gets to attacks first!

    Work Around I tried: Generate a "Random" integer with "min 0" and "max 2" in while loop of battle class and if it is 0 "Warrior A" will get to attack first and if it is 1 than "Warrior B" will get to attack first and this way attacks will also get randomized, atleast I hoped so! but still Warrior B wins most of the time, can you please explain why?

  13. Martin Viles Avatar

    Thank you so much for all the great work you do. Is there some way I can dontate a one off payment via Patreon or something similar ? I am not really a fan of monthly payments. But I would love to fund your great work !

  14. Paul Stroud Avatar

    Great tutorial(s)! Thanks so much for all the effort.
    Ignore the trolls – "Change your voice…" ?? Really?? Just keep doing what you do.

  15. allasar Avatar

    Love these kind of vids. Did start without watching the entire intro, so I let the random attack and blockvalues be handled by the battle class. It makes more sense to me(not saying my way is better or more efficient or superior in any way, just that it makes more sense in my messed up head), since the randomness is part of the battle, not of the warriors. In the end warrior is just a wrapper class for the "qualities" of every warrior and the calculations are handled by the battle class.

  16. Kunal Trivedi Avatar

    Great video. Please do more this type of (exercise) videos . Thanks

  17. Rafał Boguszewski Avatar

    This is great content. I went through a lot of theory in a short period of time, but never had to chance to properly test my skills with some hands-on work. I think self-learners like myself would immensely appreciate more of these types of videos every once in a while.
    While there are tons of "project ideas" out there to help with getting some practice, I do believe that it is great to have someone experienced walk through step by step from setting requirements to implementation.

    Thanks for the great vid!

  18. Almarghulani Avatar

    Should I be upset about doing the exact same thing without using getters and setters?? I did something like this:

    class Battle
    {
    Warrior _warrior1; Warrior _warrior2;

    public Battle(Warrior warrior1, Warrior warrior2)
    {
    _warrior1 = warrior1;
    _warrior2 = warrior2;
    }
    }

    are there any advantages of using getters and setters that I have to look into?

  19. Disciplined Coding Avatar

    Derek I really enjoy ur tutorials greatly, thank you for not only making them but for having the patients and good nature to respond to everyone's questions. I am learning C#- ASP.net, at school, any plans for maybe doing a tut on it?

  20. Alpine Mobile Avatar

    So I got the code from the link and made a new project. The first warrior has these values: 1000, 100, 50. The second warrior has these values: 1000, 50, 100. Put aside the fact that the warriors are equally strong now, my question is: Why does the program act differently when ran using the Start button (loops forever), compared to pressing F10 three times (the program ends with one of the fighters winning)?

  21. Ian Pedlar Avatar

    no offence but you are harsh to listen to

  22. Ian Pedlar Avatar

    like, take a breath man. imagine that you are teaching little kids type of minds
    because you are 🙂

  23. Ian Pedlar Avatar

    and a really annoying voice, I know you love the sound of your own voice but could you soften it up a bit?

  24. Ian Pedlar Avatar

    You are using the zoom too much, we can't see the code

    just keep it simple, one screen size

  25. Raven Claw Avatar

    Dude, you know what the most required programming languages to work at NASA?

  26. PushMyCarr Avatar

    Thank you for another amazing tutorial!!! And I really mean it, this one was amazing!!!
    I just keep getting more and more pumped for what is yet to come in this series.

  27. Andrew Lerion Avatar

    Nice stuff. Derek! Keep it up! I have a question: Will you be covering ASP.NET Web APIs?
    I would like to watch some good REST API ASP.NET tutorial. 😉

  28. General Knowledge Avatar

    These are some nice tutorials.Subbed long back.Now we need a tutorial on how to get some freelance work using these skills.Know there are a ton of such videos on youtube but the actual situation is bit different and worrying. There are very less projects that utilize only C# as the primary skill.We need to add some other supporting skills too. Need some pointers on that.

  29. Angelina Jolie Avatar

    Hi Derek ! the GetAttackResult method only takes care of the B warrior being attacked by A there's no warrior B attacking A? Am I missing something?
    Thanks In Advance !

  30. Jeff Schreiner Avatar

    Great video! I used little games like this to learn to solve problems using design patterns.

  31. João Alves Avatar

    Excellent example. Can you make a tutorial using the keyword 'surprise' for implicity variables ?

  32. mnelson10000 Avatar

    Why do you not use private fields behind the public properties…? I thought that was the point behind properties… to protect the private field

  33. fera fera Avatar

    bob wins and you toooo thanks from my heart

  34. QuebecSquad Avatar

    Love this c# serie. Thanks you very much. Any plan to make a video of c# with MonoGame framework?

  35. Huzaifa Al-sharaami Avatar

    Thanks bro for this useful tutorialsHow about making a tutorials about c# but for unity engine

  36. Bryan Purdy Avatar

    Great stuff. Really appreciate the effort here! Thanks again!

  37. Indrit Bulica Avatar

    Great stuff Derek! Thank you for your effort! Would love to see some WPF using the MVVM architecture. All the best!

  38. Masoud Rousta Avatar

    Amazing
    I love your tutorials Derek
    Thanks

  39. stillww Avatar

    Thank you for these tutorials, I'm really enjoying the series!

Leave a Reply

Your email address will not be published. Required fields are marked *