Using Method to create score

When using method to create score for rock,paper and scissors game.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//would I need to include these variable into set?
int player = 0;
int computer = 0;
int win,tie,lose;

class Score
{
private:
   int score;
public:
   void setScore(int s){
      score = s;
   }
   int getScore(){
      return score;
   }
};


Would this be the right method on create a score for rock,paper and scissors game for the player and computer?

1
2
3
4
5
6
7
8
9
10
11
12
switch(score)
{
case 'win':
    player = win+1;
    computer = win+1;
case 'tie':
    player = tie+1;
    computer = tie+1;
case 'lose':
    player = lose+1;
    computer = lose+1;
}

1
2
3
4
5
6
7
8
9
10
11
12
switch(score)
{
case 'win':
    player = win+1;
    computer = win+1;
case 'tie':
    player = tie+1;
    computer = tie+1;
case 'lose':
    player = lose+1;
    computer = lose+1;
}


In this code, if the outcome is 'win', the computer's score and the player's score goes up by three.
If the outcome is 'tie', the computer's score and the player's score goes up by two.
If the outcome is 'lose', the computer's score and the player's score goes up by one.

As such, nobody will ever have a higher score, and also you need to look up break;
Thanks moschops you have been great help.
I fix the problem. would I been able to put the code into set and calling it into main or do I have to put it into function and calling to main but either way will work.
if so how would you call the set & get method so it output the score for player and computer.
example
1
2
3
4
5
6
7
8
9
10
11
class scoresheet
{
   void setScore(int s){score = s;
   //code goes here......
   }
   int getScore(){return score;}
};
int main()
{
   scoresheet Score;
}
The design seems to be a bit off to me here. I don't think 'score' really lends itself to being an object.

Why not create a player object that contains a score (amongst other things, for example you could store player names and functions to handle the players choices) and create a couple of instances of that object; one for the player, one for the CPU?
Last edited on
Topic archived. No new replies allowed.