I was messing around with a simple Rock Paper Scissor game, I have came to a problem, my game simply has no classes, as it works without classes I don't see the need to have them, but I really need to know how to 'fix' it so that the Rock, Paper and Scissor all have their own separate class.
Even with that I had no idea how to use the class, I know I am pretty terrible for the fact I can't do this (it's probably really easy for some of you out there) but I am trying to self teach myself and if I could see what the end result should look like I will be able to study it against what I had originally and hopefully gain an understanding.
Thankyou for your time.
You chose a bad program to try classes on, as they provide no advantage here. As such, using classes properly means not to use them in this case.
There's two ways you can improve the program: move the image printing stuff into functions and use symbolic constants for rock, paper, scissors instead of using 1-3 literally.
@Athar: the classes don't need to provide an advantage of any kind, they just need to be there, but please remember I have small to little knowledge of C++ coding, so I don't know what most terms mean.
I understand that the image printing is like my ASCII of rock, paper and scissor.
But I don't really know what you mean by 'move the image printing stuff into functions'.
And I really don't understand what you mean by 'use symbolic constants', so I will do a little research on this.
If this is for a school assignment, then they could not have given you a worse assignment. Classes will make this code WORSE, and it will not teach you anything helpful, good, or important about classes other than their syntax, which is completely useless.
@ L B: It's not a school/college project it is just something I was trying to build in a form of self teaching, so that I know a bit if i ever decide to take programming at college.
I'm detecting that this code is basically very useless and not worth adding classes too as it is pretty useless?
Well if this code is just going to get worse and become not very useful to me, can someone direct me to a good example I can look over?
But I don't really know what you mean by 'move the image printing stuff into functions'.
There's no hidden meaning, you can take it literally. The printing diverts from the important parts when reading the code, so it should happen outside of main().
And I really don't understand what you mean by 'use symbolic constants'
That's the process of giving your numbers and strings proper names, e.g. enum Gesture {Rock=1,Paper,Scissors};
//or constint Rock=1,Paper=2,Scissors=3;
Well if this code is just going to get worse and become not very useful to me, can someone direct me to a good example I can look over?
Good examples include more complex games that feature a variety of objects and hierarchies in a game world, as it is easy to understand the benefits that classes, inheritance and polymorphism give you in such a situation. Pretty much any type of program works that involves lots of things that you can easily classify as "objects" even without any programming experience.
Even though in practice this isn't the prime example of when to use classes, this code could definitely be put into classes.
If you had classes you could:
Overload the ostream operator instead of using your print function.
Every single one of your if else if else would be gone by using polymorphism.
At the very least it would be good practice for you.
Instead of print function overload the << operator: