• Forum
  • Lounge
  • Drinking Game. Criticize, suggest, ideas

 
Drinking Game. Criticize, suggest, ideas?

I've completed my first program/game. Any thing I could do to make it more efficient? I don't want to start developing any bad habits now. Like, should I use an array of strings instead of a switch? Also, any idea's on a program I could write that would be harder than this I would be really thankful for!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#define CHOICES 7
#define TIME 10

void drinks();
int rand0toN(int n);

using namespace std;

int main(){

    int p;
    srand(time(NULL));  // Set seed for Randomizing

    //Prompt user with instructions and ask for players
    cout << "~~~~~Welcome to the drinking game!!~~~~~\n\n";
    cout << "Instructions:\n";
    cout << "1: Enter number of players and assign each player a number.\n";
    cout << "2: Each player has 10 seconds to complete drinking task. Start when\n";
    cout << "it says go.\n";
    cout << "3: If can/glass is not on the table before time is up\n";
    cout << "players loses and is out of the game.\n\n";
    cout << "Enter number of players(0 to exit): ";
    cin >> p;

    //Cycle through number of players, 0 to exit.
    while(p!=0){
            for(int i=1;i<=p;i++){
            cout << "Player " << i << endl;
            drinks();
            cout << " Ready... Set...\n";
                Sleep(6000);//Give them some time to read the challenge.
                cout << "GOOOOO!\n";
                //Count down timer.
                for(int s=1;s<=TIME;s++){
                    Sleep(1000);
                    cout << s << endl;
                }
            cout << "Time's up!!!\n\n";
            Sleep(1000);
            }
            cout << "Enter new number of players(0 to exit): ";
            cin >> p;
    }





system("pause");
return 0;
}

//This function makes a random choice for the player.
void drinks(){
    int c = rand0toN(CHOICES);
    switch(c){
        case 1:
            cout << "Take 1 gulps!";
            break;

        case 2:
            cout << "Take 2 gulps!";
            break;

        case 3:
            cout << "Take 3 gulps, or 1 shot!";
            break;

        case 4:
            cout << "Slam your drink!";
            break;

        case 5:
            cout << "Choose someone for 2 gulps! Pick quick!";
            break;

        case 6:
            cout << "Choose someone for 3 gulps or 1 shot! Pick quick!";
            break;

        case 7:
            cout << "Take shots until the clock runs out!(Or slam your drink)";
            break;
        default:
            break;
    }


}
//Random number selection for function "drinks"
int rand0toN(int n){
    return (rand()%n)+1;

}
Last edited on
As far as bad habits go, completing 10 drinking tasks within 100 seconds is definitely one of the worst.
Harder Program... How long have you been at this, what do you know? Interested in learning a Library?
Here is my recent project. http://www.cplusplus.com/forum/beginner/51442/
I'm willing to take a whack at anything. So shoot.

what do you know

Well I've about finished C++ Wihtout fear, only thing I havn't covered there yet is Polymorphism.
Last edited on
As far as bad habits:

- Using "system("pause")" is sort of a bad habit, I'm sure you've heard this from us before. I want to emphasize that this is made worse by your inclusion of windows.h which offers far cooler solutions for holding the window open.

- You seem to be including Windows.h soley for the purpose of using the "Sleep()" funciton even though you are already including the ctime header to seed "srand()". Seriously check out MSDN, this is a waste this header files potential

As far as a next project, why not build off of this one:

- Create an object that will keep track of each player. Be sure to include their Name, Weight and currently estimated BAC. Note that this calculation is dependent on the rate of consumption so you should read up on that ctime header. If you REALLY want to get fancy put in an alarm to warn people when they should stop playing and make the game automatically declare a winner and quit.

- In order to calculate their potential BAC you need to know the Alchohal content AND volume of what ever you are drinking so there's another object.

- Use the information I mentioned above to define what a "shot" would be for each player depending on what they are drinking.
Last edited on
@Computergeek01 Thank you very much! I'll certainly do that!

I know the system pause isn't good, but I can never get cin.get() to work right. I knew there was a better way than using Sleep, thanks for that too!
As a quick and easy way to pause execution on the console I do this:
1
2
3
4
5
void pause()
{
     std::cin.sync();
     std::cin.ignore();
}

Additionally if you are using GCC\MingW then use this forward declaration:
 
void pause() __attribute__((destructor));

This will ensure that this function is called right at the end of your program as long as it quits naturally.
Last edited on
Topic archived. No new replies allowed.