Ask coding questions

← Back to all posts
Need help with designing a Game
Shaheen_Fathima (7)

Hi! I need help designing a Game called Pig in C++11, It's a dice game, but I really have no idea on how to start. It would be great if anyone can help me out.

Comments
hotnewtop
PYer (3946)

Your game sounds interesting

JoshDaBosh (81)

assuming the game will be local and will have 2 human players, it's relatively simple (pseudocode below):

#include <cstdlib> (for random numbers)
create the two score counters for player1 and player2, set both to 0
create a turn counter and set to 0.

make a while loop that runs only if no players have exceeded 100 points and put this inside:
if the turn counter is 0 then player 1 goes. the dice will be declared with "((rand())%6)+1". if the dice ends up as 1 then you increment the turn counter by 1 and end the turn. otherwise increment player 1's score counter by the dice variable amount, increment the score counter by 1. ask the player if they want to hold. if not then keep running the code above in another while loop until the player either gets a 1 or decides to hold. each time, increment the player's score by the dice amount. when the turn ends increment the turn counter by 1, and end the turn.
if the turn counter is 1 then player 2 goes. same logic as player 1, but instead of incrementing the turn counter by 1 as in player 1, set it back to 0 or add 1 and apply a modulus of 2 to it.

break out of the first while loop when any player gets more than 100 points.

(you might want to include something like a congrats message or something!)

Have fun, I'll be working on a version of this and I'll probably post it to GitHub gists.

Shaheen_Fathima (7)

@JoshDaBosh Here's something that I did, however, I am getting compiler errors, although the program seems to compile. How do I fix it? Here's the link to what I tried: https://repl.it/@Shaheen_Fathima/RoundedRaggedAmoebas

JoshDaBosh (81)

@Shaheen_Fathima it seems to be working just fine, what's the issue?

Shaheen_Fathima (7)

@JoshDaBosh yes I just figured it out that it initially had compiler warnings but I fixed it now. Thank you anyways! I still think I might need help, this project is actually part of my college assignment, since it's the final assignment and the most important one, I am kind of nervous. I have the file attached and what I have done so far from my part (split into two REPLS). I got stuck in between and I really see no way on how to proceed further, in fact, I am so very confused. It would be great if I at least get even a slight idea of what I am supposed to do next. Here are two repls of what I tried on my part so far; Link 1: https://repl.it/@Shaheen_Fathima/YellowgreenSuddenQuadrilateral
Link 2: https://repl.it/@Shaheen_Fathima/RoundedRaggedAmoebas
Link to the assignment that I was given: https://drive.google.com/file/d/1h9jxjs63g_Ib3C7OiQ4QAOCrH11_Vvab/view?usp=sharing

JoshDaBosh (81)

@Shaheen_Fathima your first repl contains the welcome screen but none of the features are actually necessary as they're almost all contained in your second repl. One thing to note is that you never call menuInput() so your bulletproof menu does not apply.

JoshDaBosh (81)

@Shaheen_Fathima just make a bulletproof menu in your second repl and make sure your code checks out.

Shaheen_Fathima (7)

@JoshDaBosh ok! Thank you! So do I have to make it like pure Alpha Menu or just the regular menu?

JoshDaBosh (81)

@Shaheen_Fathima im not sure what you mean by pure Alpha Menu but I would recommend looking at your professor's guidelines

Shaheen_Fathima (7)

@JoshDaBosh ok. Anyway's thank you for helping me out! and yes ur pseudocode idea was super helpful! :-)

Shaheen_Fathima (7)

@JoshDaBosh I am almost done, but I am totally confused on how to set a tracker to keep track of the number of turns, the second confusion is that in main(), I want only the Roll option to work when the user types R and only the Hold option to work when the user types H, the third confusion is with the resign option: what its supposed to do is this: if the user chooses to resign in between, the game should end immediately and ask the user if they would like to restart. I am in desperate need of help. Totally confused. I request to please help me out. Here's the link to the program: https://repl.it/@Shaheen_Fathima/RoundedRaggedAmoebas