C++ Darts Simulation help!

Hello,

My name is Hannah. I am currently studying game design and am in the middle of being taught C++.

We've asked for our first assignment to write dart simulation program which lets player's Joe and Cid take 3 turns each at a non-depicted dart board and play a game of '301'- didn't even know what that was till recently lol.

I have to do the program in two ways: using functions i.e. in C style, and using classes i.e. in C++ style.

I have a little code when I was trying to write a program which would have calculated how many times it took "Joe" to hit the bull in ten turns etc, but other than that, I am thoroughly confused, and will take any help or suggestions I can get.

Thanks everyone.

Hannah x
Do you mean you have to write one program incorporating both functions and classes?

Or two programs; one with functions, one with classes?
Hey,

I need one program incorporating both functions and classes.

Hannah x
I would start by looking at your classes then.

It'd probably be a good idea to create a player class, each with it's own score. You can give the class a function, something like ThrowDart(), where you can write the logic that deducts the score from the remaining total. You can then create two instances of that player class within your code, one called Cid and one called Joe.

It'd then be a case of looping through and calling the ThrowDart() function of each player three times, until someone wins. You'll have to put some kind of check in the function to see if they've won or gone bust.

The random logic is potentially difficult, depending on how smart/skilled you want your players to be. At the lowest level, you can randomly pick a number between 0 and 60 for each thrown dart, logic which would be calculated in your ThrowDart() function. If you wanted to implement some intelligence, I would work out some sort of system where you work out the desired target and then, depending on the AI player's skill, assign probabilities for the likelihood of hitting that target. That'll work out better when you get near the end of the game and the player is trying to hit specific values, rather than flowing blindly.

As I've mentioned, I'd implement a check to see if the player has one in the ThrowDart() function. It could call a HasWon() function that checks to see if the score is equal to zero. If the score is less than zero, you can assume the player has thrown a dart that's too high for the remaining value and gone bust, ceasing their turn.


1
2
3
4
5
6
// Declare players
// Start while loop (while nobody has won)
// -- Iterate a for loop 3 times, throwing Cid's darts
// -- Iterate a for loop 3 times, throwing Joe's darts
// End while loop (someone has one)
// Output name of winner 
Last edited on
Why is using functions "c style"? Do we not use functions in c++...?
Topic archived. No new replies allowed.