If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Need help designing my craps program.

This will be my first program in C++ and it will be a crap game with every possible bet, just like on a Vegas crap table. I'm using SFML to display half of a crap table and to display the bets (chips) for up to 4 players on the crap table.

Every bet will be positioned in the proper place in each bet box just like on a Vegas crap table. This means there will be 4 positions on the passline (for 4 players), 4 positions for passline backup bets, 4 positions for each "place bet", etc.

To give you an idea of what I need, here's some sample bets in a struct:

1. When displaying the chips on the table using SFML, I need to scan all of the "betAmount" values. If zero, don't display. If greater than zero, display the proper amount of chips at the coordinates given.

2. When a player makes a bet, I need to update "betAmount" easily.

3. When a player loses a bet, I need to zero "betAmount" easily.

QUESTION:

1. To display the bets (chips) on the table, I need a for loop to scan every bet position to see if the "betAmount" is greater than zero. But the way I showed the code above does not seem to be a good way to do that.

2. When a player clicks in a bet box to make a bet, I need to translate the mouse coordinates to know which bet box was clicked in, and then update the "betAmount" for that player.

Any suggestions on how to store all of the bet info that will allow easy updating of the "betAmount" when bets are made or lost, and yet allow scanning with a for loop to display the bets made.

Re: Need help designing my craps program.

Originally Posted by raptor88

This will be my first program in C++ and it will be a crap game with every possible bet, just like on a Vegas crap table. I'm using SFML to display half of a crap table and to display the bets (chips) for up to 4 players on the crap table.

I don't know this game, but your overall approach of combining the UI with the logic of the game has many drawbacks. Just the struct you have of having the bet amount coupled with UI information is a source of these issues. What does a bet amount have to do with a coordinate position? What if you now want to create a text based version of the game, or you want to change the UI in some other way?

I would suggest you read up on the MVC (Model-View-Controller) design pattern. This is where the logic (rules) of the game is separated from the UI (or view). For example, the bet would be placed, and then the code that placed the bet sends a message, calls a function, etc. to the view, and then the view does whatever it needs to do to update itself given the information passed.

1. The four pass line bets (chips) would be shown on the horizontal row labeled "PASS LINE".

2. The four "Place4Pn" bets would be above and below the block containing the big yellow 4 in the bet area labeled "PLACE BETS". Something like this, where P1 is actually the chips bet for Player1, etc.

P4 P3
= 4 =
P1 P2

(Ignore the equals signs. They are just used to space the '4' in the center.)

I was considering using a vector which would be easy to push_back when a bet is made. But I need a "data" table to hold the coordinates for EVERY bet position on the craps table. So I don't think a vector would work for that, or would it?

Re: Need help designing my craps program.

Originally Posted by Paul McKenzie

I don't know this game, but your overall approach of combining the UI with the logic of the game has many drawbacks. Just the struct you have of having the bet amount coupled with UI information is a source of these issues. What does a bet amount have to do with a coordinate position? What if you now want to create a text based version of the game, or you want to change the UI in some other way?

I would suggest you read up on the MVC (Model-View-Controller) design pattern. This is where the logic (rules) of the game is separated from the UI (or view). For example, the bet would be placed, and then the code that placed the bet sends a message, calls a function, etc. to the view, and then the view does whatever it needs to do to update itself given the information passed.

If you go down the road you're going now, you will eventually have an intertwining of UI code with game rules, making the application harder to change, debug, and maintain.

Regards,

Paul McKenzie

Very good points and thanks for pointing them out. I'll use your suggestions in future projects.

But since this will be my first C++ project, I want to keep the code as simple as possible. My current idea is to have a global table that contains the bets made and the respective coordinates where the chips should be shown on the table. I know global items are not recommended in C++ but I just want to use this method for my first project.

- My GetBets class would get bets from each player and update the corresponding bet amount in the table.
- Then my display class would just scan that table and display chips for any bets made in their proper positions.

I'm not sure how to make that table which would be easy to scan using a "for" loop in my display class. Any suggestions?

Re: Need help designing my craps program.

Very good points and thanks for pointing them out. I'll use your suggestions in future projects.

But since this will be my first C++ project, I want to keep the code as simple as possible.

What is to say that using MVC is not simpler? Do you have the rules of the game coded? What good is the UI if the game doesn't properly implement the rules? It seems you're making the mistake that many beginner coders make, and that is concentrating and coding nice or "cool" looking output, and neglecting the most important parts of the program (the calculations required, in your case the rules of the game, etc.).

Assume there is no UI. Do you have the individual functions coded to handle bets, randomly "throw dice", react to the number thrown, handle multiple persons playing the game? None of these require a user interface. At most, you would have a console main() app that randomly places bets, rolls dice, etc. thereby exercising the rules of the game to see if the rules are implemented correctly. Once that is done, then you go from there. Or maybe there is an input file that has a simulated game -- you read the file and see if the rules are implemented correctly. Again, no UI is required.

Re: Need help designing my craps program.

Originally Posted by Paul McKenzie

What is to say that using MVC is not simpler? Do you have the rules of the game coded? What good is the UI if the game doesn't properly implement the rules? It seems you're making the mistake that many beginner coders make, and that is concentrating and coding nice or "cool" looking output, and neglecting the most important parts of the program (the calculations required, in your case the rules of the game, etc.).

Assume there is no UI. Do you have the individual functions coded to handle bets, randomly "throw dice", react to the number thrown, handle multiple persons playing the game? None of these require a user interface. At most, you would have a console main() app that randomly places bets, rolls dice, etc. thereby exercising the rules of the game to see if the rules are implemented correctly. Once that is done, then you go from there. Or maybe there is an input file that has a simulated game -- you read the file and see if the rules are implemented correctly. Again, no UI is required.

Thanks for your helpful advice Paul. I appreciate your pointing me in the right direction.

For now, I think I might have figured out a way to implement my "betInfo" table. I was thinking about how a database for employees works. One method might be to have a structure containing the employee's name, address, phone numbers, wages, etc. Then there could be an array of the structures. The key is to have the employee's name "in the structure" to identify each record. I think my initial thought of just having the bet amount and chip coordinates in the structure without an identifying name in the structure was the problem.

With the name of the bet "in the structure", (like passP1 passP2, place4P1, place4P2, etc.), I can search for the name when updating the bet amount. For displaying the chips bet, since the structures are in an array, I could use a for loop and increment the array index to scan the array of structures for bet amounts greater than zero. When a bet amount greater than zero is found, draw the sprite for the chips using the coordinates in that structure.