Simple Dice Game - C# Beginner Project

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 พ.ย. 2024

ความคิดเห็น • 42

  • @richardlew3667
    @richardlew3667 3 ปีที่แล้ว +27

    This is superbly done. I hope you keep making more C# walkthroughs for beginner, intermediate, and advanced levels!

  • @guykensdale710
    @guykensdale710 3 หลายเดือนก่อน +3

    moving from JS to C# this playlist is perfect - not a repeat of the basics but gets me stuck in with easy and comfortable projects many thanks!

  • @badboyb00gie
    @badboyb00gie 3 ปีที่แล้ว +16

    You should make more videos! You are very good at explaining things! Thank you.

  • @mrts0
    @mrts0 2 ปีที่แล้ว +3

    Holy crap ive been up all night and i have really similar homework. thanks for tutorial i can finally get some sleep. Subbed!

  • @mev6524
    @mev6524 25 วันที่ผ่านมา

    Good video! Keep making them!

  • @benedictcherlet8583
    @benedictcherlet8583 ปีที่แล้ว +1

    The Quality is extremely good

  • @saudsiddiqui4297
    @saudsiddiqui4297 3 ปีที่แล้ว +3

    great video really appreciate your work,hope you keep making more C# projects for beginner.

  • @gemellimusic931
    @gemellimusic931 2 ปีที่แล้ว +3

    Nicely done, but remember - the generator is pseudo-random, you're need to add seed while you're creating an object of Random class :)

  • @quennti4687
    @quennti4687 2 ปีที่แล้ว +1

    I love your British accent ;) and I love your Unity tutorials!

  • @itsme-rl7zt
    @itsme-rl7zt 2 ปีที่แล้ว +1

    superb ...
    I am very happy with this video ...
    pls make more c# videos

  • @alperen_101
    @alperen_101 2 หลายเดือนก่อน +1

    Keep going, great content :)

  • @johnshmoe147
    @johnshmoe147 2 ปีที่แล้ว +2

    Great video and well explained. Thanks!

  • @tonipaffel3357
    @tonipaffel3357 2 ปีที่แล้ว +1

    This is great, You are very easy to listing to

  • @jaaferelsadig
    @jaaferelsadig 8 หลายเดือนก่อน +1

    Fun and useful, thank you!

  • @keatonhatch6213
    @keatonhatch6213 2 ปีที่แล้ว +3

    I get it’s a simple project and it’s done well but I’d probably create a Player object with randomNum and Points variables with get ; set to show the fundamentals of OOP.

  • @speghetti_goblin5264
    @speghetti_goblin5264 2 ปีที่แล้ว +1

    Super awesome! Thanks!

  • @paulpopSignatur
    @paulpopSignatur 2 ปีที่แล้ว +1

    Great video Thank you. 😊

  • @grebetriplex
    @grebetriplex 2 ปีที่แล้ว +1

    Amazing video.

  • @celinaindhur3286
    @celinaindhur3286 6 หลายเดือนก่อน

    i hope youre still creating videos !!!!

  • @horaciovc
    @horaciovc 3 ปีที่แล้ว +1

    good videos! wish you success!

  • @danialshahzad842
    @danialshahzad842 2 ปีที่แล้ว +1

    How do I do this with Windows Form Application on c#?

  • @Starfallfantasy
    @Starfallfantasy 2 ปีที่แล้ว +1

    Thank you so much for this, it was very well explained ^_^

  • @fraadem3849
    @fraadem3849 ปีที่แล้ว

    if i want refactor this code, how am i able to count the points and first to get 100 points wins?

  • @jkahdjbek
    @jkahdjbek 2 ปีที่แล้ว

    any idea how to do this but with the interface with multiple forms?

  • @your_daily_duas
    @your_daily_duas 2 ปีที่แล้ว +1

    Amazing video but my enemy points is never increasing could you please give a bit of help on that

  • @MickMush
    @MickMush 3 ปีที่แล้ว +1

    Thanks for the video

  • @danialshahzad842
    @danialshahzad842 2 ปีที่แล้ว

    What´s the front side suposed to look like

  • @non-eggwhites6328
    @non-eggwhites6328 3 ปีที่แล้ว +3

    Nice Video! I have a question tho, what if i want to count the points, from the random dice number has generated.

    • @TheCodersCat
      @TheCodersCat  3 ปีที่แล้ว +4

      Instead of playerPoints++, it'd be playerPoints += playerRandomNum.
      And for the enemy, instead of enemyPoints++, you'd need to change it to enemyPoints += enemyRandomNum.
      This will add on the points the player or enemy have rolled, instead of just increasing their points by 1.
      Does that answer your question?

    • @non-eggwhites6328
      @non-eggwhites6328 3 ปีที่แล้ว +2

      yup, I just tried it and it works. Thank you so much!

  • @emansza
    @emansza 3 ปีที่แล้ว +2

    Quick question. I recently learned C# so I understand all of this but when you call Random() maybe explaining what Random is would be a bit better. Like saying it's a built-in function. had to go thru the docs to figure out what it was.

    • @nishanthk1648
      @nishanthk1648 2 ปีที่แล้ว

      yes, you can even find it even when you hover cursor on Random it will show meaning of it , you can also find it in the Docs

  • @celinaindhur3286
    @celinaindhur3286 6 หลายเดือนก่อน

    great video

  • @piterovvv7959
    @piterovvv7959 3 ปีที่แล้ว +1

    How do you make this into a 3 player game? I tried doing it myself but only player 1 and player 2 works, if player 3 gets a higher number than the other two he still doesn't get a point

    • @TheCodersCat
      @TheCodersCat  3 ปีที่แล้ว +6

      You need to change the if statements to accommodate for more than 2 players. To find out who has won a round you could firstly find out the highest score rolled from all players and store it inside an int. Then you could check which player(s) scored this number and then assign them a point. (Don't forget to check for the case that all players roll the same number and thus no one would score a point at all!)
      All of this would be easier to achieve if the scores were held in an array.
      Firstly, set up two arrays of size 3 to hold the numbers rolled for each player and the total points for all players -
      int playerCount = 3; // Used to represent the number of players wanted in game
      int[] numbersRolled = new int[playerCount];
      int[] playerPoints = new int[playerCount];
      numbersRolled[0] would represent the number player 1 has rolled.
      numbersRolled[1] would represent the number player 2 has rolled,
      and numbersRolled[2] would represent the number player 3 has rolled.
      Then playerPoints[0] would represent player 1's current score,
      playerPoints[1] would be player 2's current score
      and playerPoints[2] would be player 3's current score.
      In the game loop, create a new for loop (using j instead of i) with it's condition being
      j < playerCount
      This for loop will then repeat for each player.
      for(int j = 0; j < playerCount; j++)
      {
      Console.WriteLine("Player " + (j + 1) + ", press any key to roll the dice.");
      Console.ReadKey();
      numbersRolled[j] = random.Next(1, 7);
      Console.WriteLine("Player " + (j + 1) + " rolled a " + numbersRolled[j]);
      Console.WriteLine();
      }
      The number each player has rolled is stored inside the numbersRolled array.
      We can use this later on to check who has rolled the highest and therefore scores a point.
      Now, let's check the case that all player's have rolled the same number -
      if(numbersRolled[0] == numbersRolled[1] && numbersRolled[1] == numbersRolled[2])
      {
      Console.WriteLine("It's a draw!");
      }
      So, here we check if player1's score is the same as player2's score and if player's 2 score is the same as player3's score.
      If this is true, then we can just print out a message saying it's a draw.
      Else, then we want to calculate the highest score out of all the rolls. We can do this using another loop.
      else
      {
      // Calculate highest number rolled
      int highestScore = 0;
      for(int j = 0; j < playerCount; j++)
      {
      if(numbersRolled[j] > highestScore)
      {
      highestScore = numbersRolled[j];
      }
      }
      // Assign points to player(s) with the highest number rolled
      for (int j = 0; j < playerCount; j++)
      {
      if(numbersRolled[j] == highestScore)
      {
      playerPoints[j]++;
      }
      }
      }
      The first part here loops through all the scores and records the highest.
      The second part then loops through all the players. If the player has achieved the highest score recorded, then they score a point.
      Finally, let's display the scores -
      Console.WriteLine("The score is now - Player 1 : " + playerPoints[0] +
      ". Player 2 : " + playerPoints[1] +
      ". Player 3 : " + playerPoints[2]);
      Console.WriteLine();
      Finally, outside the main for loop, let's display the final results on who is the final winner.
      Once again, let's account for the case that all player's score the same amount and cause a tie, first. Else, we'll use similar logic as before to calculate who has the highest score and thus who has won.
      if(playerPoints[0] == playerPoints[1] && playerPoints[1] == playerPoints[2])
      {
      Console.WriteLine("It's a draw!");
      }
      else
      {
      // Calculate highest score
      int highestScore = 0;
      for (int i = 0; i < playerCount; i++)
      {
      if (playerPoints[i] > highestScore)
      {
      highestScore = playerPoints[i];
      }
      }
      // Display winners
      for (int i = 0; i < playerCount; i++)
      {
      if (numbersRolled[i] == highestScore)
      {
      Console.WriteLine("Player " + i + " is the winner!");
      }
      }
      }
      And that should be it! Sorry for the long reply, it turned out to be a lot more complicated than I initially thought and needed a lot of code refactoring. But it should do the trick!
      As some of the code is repetitive and to stop Main from getting too convoluted and overpacked, I'd really recommend splitting the different sections into methods. :)
      If you try it, let me know if you run into any issues or whether you need any help.
      Thanks very much for watching the video too! :)

  • @muhammetfurkanallaberdiyev6734
    @muhammetfurkanallaberdiyev6734 2 ปีที่แล้ว +1

    it seems a little like java script i = i + 1 is the same for Java Script

  • @Nadeneris
    @Nadeneris 2 ปีที่แล้ว +2

    👌

  • @upscale24
    @upscale24 3 ปีที่แล้ว +2

    Thank you so much for the video. Could you be my tutor xD? Subscribed.

  • @tenebrae1191
    @tenebrae1191 ปีที่แล้ว

    👍