11

Does anyone want to criticize my c# code for a quiz game I made in like 10 minutes?

Comments
  • 5
    You could have done the exact same thing in any functional language
  • 4
    @RazorSh4rk yea and I chose C# I'm not a C# wizard I just started and wanted to practice?
  • 4
    Look up "exception handling"
  • 1
    @RazorSh4rk isn't that kind of like a switch statement?
  • 2
    *you're ready to play
  • 1
    @jlave215 I guess that's good for my C# skills but bad for my English skills...
  • 7
    Console.Writeline("Text" + Environment.NewLine);

    It will be easier to read.
  • 4
    Use common c# code styling.
    The braces should be on new lines.

    The if with a do..While where you count down attempts and then taunt the player. Compare with IgnoreCase if you don't care for about the case.

    Encapsulate questions and answers in a separate class, then you'll be able to load all questions using Assembly, it will simplify the insertion of new questions.

    Create a taunt factory with good taunts.
  • 1
    That is most definitely NOT a global variable...
  • 1
    I do code reviews everyday but I can't do a short reply here. There is too much wrong with your code. Not bad for a beginner though but it needs a lot of work.

    Make yourself familiar with object orientation, exception handling, SOLID principles. Separate concerns.

    I do like your coding style which looks good so I would say you are on the right track.
  • 0
    @MightyNerd meh kinda, but it will save you a lot of if()s
  • 1
    Or do an array of questions and correct answers, then loop though them. Look up Dictionary, then have an array of possible answers as the value, the key could be the question. Probably a horrible idea but that's how I'd do it xD
  • 0
    @RhysOC write a method with a Question object as the parameter, then create a Question object linked list (so you can add more to it), read qouestion-answer pairs from a txt to the constructors of the objects, randomly choose questions to appear
  • 2
    Also dont forget to alias your input, so it accepts y, yes, true, etc
  • 3
    Use \n instead of Console.WriteLine("");

    Also if you want to write Console.WriteLine("");
    You could omit [""].
  • 2
    I think you should check for strings equality like this
    StringVariableName.Equals("START", StringComparsion.OrdinalIgnoreCase);
  • 1
    Use \n for a new line instead of Console.WriteLine(); and maybe add a while loop around it so the player can play again. Otherwise it's good!
  • 3
    Not enough jQuery
  • 1
    No functions, no OOP, no structure and no reusability. What if you want to use something other than logging to console?
  • 0
    @michalpiekarski stupid question but what is inverting ifs?
  • 0
    @negative-byte yea I was aware it's kind of pointless I just thought I start somewhere.
  • 2
    I would have created a Question class with a string for the question a book for the answer and created a List with questions and keep going from there, and yeah, in 10 mints. But what you did is good.
  • 1
    @michalpiekarski whats inverting ifs good for?
  • 1
    bikeshead opinion = new bikeshead();

    @michalpiekarski not logic gets confusing; I set the if condition based on either 1) the most common path or 2) the correct path.
    if (bool run_A)
    {
    // A
    }
    else
    {
    // B
    }

    Or

    if (bool run_B)
    {
    // B
    }
    else
    {
    // A
    }

    When you use a method it can get confusing
    if (GetSomeString().Length > 0)

    For "fall through" code it's fine, but with additional classes and methods the structure will have to be reworked.
  • 1
    Is a binary tree quiz game a bad idea? I just thought of that and i wanna implement it
  • 2
    @RazorSh4rk No it isn't I did one for a friend's homework last year.
  • 0
    Console.WriteLine();
    is just cleaner than
    Console.WriteLine("");
Add Comment