Hi all, I am a beginner in programming and C++. i have been given a dice game that reads;
In a variation of a dice game, one draws a beetle in parts. The idea is to roll the die, draw the parts of a beetle based on the face value of the die rolls, and continue until the beetle is completed. The traditional rolls for deciding the part drawn are:
Six is for the body, of which there is one. And must be the first one to be drawn.
Five is for the head, of which there is one. The body must be present to draw the head.
Four is for the tail, of which there is one. The body must be present to draw the tail.
Three is for a leg, of which there are six. The body must be present to draw the legs.
Two is for an antenna, of which there are two. The head must be present to draw the antenna.
One is for an eye, of which there are two. The head must be present to draw the eyes.
It is necessary to roll the correct number for the body before any other parts may be drawn.
In a multiplayer game (with N players), each player takes a turn and the game will continue until all but the last player have won. However, the game can be stopped after n numbers of players win the game (n < N). Hence, by default n=N-1.
I don't know how to save the results from the random function and enforce the rules of the game
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 99 100 101 102 103 104 105
|
#include "stdafx.h"
#include<iostream>
#include<time.h>
#include<conio.h>
using namespace std;
void one();
void two();
void three();
void four();
void five();
void six();
void call();
int main()
{
cout << "Press r to roll or q to quit the game " << endl;
char ch;
ch = getch();
xm:
if (ch == 'r'){
system("cls");
call();
}
else
exit(0);
cout << endl << endl << "Press r to roll again q to quit!";
ch = getch();
goto xm;
getch();
}
void call()
{
srand(time(NULL));
int n;
n = rand();
n = 1 + n % 6;
switch (n)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
default:
cout << "NONUM";
}
void one()
{
cout << "draw an eye" << endl;
}
void two()
{
cout <<" draw an antenna"<< endl;
}
void three()
{
cout <<"draw a leg"<< endl;
}
void four()
{
cout << "draw tail" << endl;
}
void five()
{
cout << "draw head" << endl;
}
void six()
{
cout << " draw body" << endl;
}
while (n = 6)
{
}
|