My First Ever C-Sharp Mini Project!
Hey there!
I've invested 6 hours in learning C# so far and cleared the basics overall/got a rough idea of the syntax. I'm a python programmer working with that language for over a year.
After finishing the basics, I just made my first C# minigame, RPS nothing too crazy.
The goal was to achieve a program with the properties:
-> The program takes input from the user
-> Until the input is
rock
, paper
or scissor
, the program asks the user to re-try because invalid input
-> There are aliases for rock
, paper
and scissor
such as r
, p
and s
. So if a user types r
the program should automatically understand that they are picking rock and continue from there.
-> Making computer pick a random choice from RPS
-> Declaring the win/loss with a custom message.
I succeeded in achieving it without external help yippies and here's what the code looks like:
It's working as intended but no doubt that I could make improvements in the code. Anyone whos more experienced with the lang please tell me how would you approach it/what changes would you make to achieve the same thing in much easier/better way or simply put, how can I improve the program7 Replies
It was also my first Python project when I was learning it a year ago, pretty glad of where I stand in terms of py now so I thought I'd recreate the same thing in c# to progress further.
Here's what the py code looked like if anyone is interested xD
I just re-created it in c# and guess it wasn't bad even tho this one has a lot better readablity
More of a fit for #code-review
Suffers a bit from primitive obsession. C# has a rich type system, use it instead of just having string everywhere.
I'd create an
enum
for choices instead of using a string and create methods to break up the long block of code.
I see, I don't get most of this code maybe because I just started but will dive deep into it shortly
:salute:
yeah thats fine, just wanted to show a less string-focused solution would look like
oh yeah 😄