GAME: Petals around the Rose (2004)

This commit is contained in:
kougyokugentou 2021-10-24 16:17:01 -07:00
parent 6953a62612
commit 6ff439ccff
1 changed files with 90 additions and 0 deletions

90
demos/petals.c Normal file
View File

@ -0,0 +1,90 @@
/* petals - Old dice game called "Petals Around the Rose"
Copyright (C) 2004 Shaun Marquardt
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* Petals Around the Rose */
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include "header/random.h"
void rolldice(void);
int num_petals = 0;
void main()
{
int started;
int guess;
char tmp[3];
clrscr();
if( !started )
{
printf("Welcome to the dice game \"Petals Around the Rose\".\n\r");
printf("There are three hints which I may give you.\n\rYou may type H at any time to recieve them.\n\r");
printf("Press any key to continue, and start the game.\n\r");
started = 1;
getch();
clrscr();
}
num_petals = 0;
rolldice();
printf("\n\rHow many petals are around the rose? ");
gets(tmp);
if('H' == toupper(tmp[0]) )
{
printf("Hint 1: The name of the game \"Petals Around the Rose\" is important.\n\r");
printf("Hint 2: Every answer will be zero or a even number.\n\r");
printf("Hint 3: You will be told the answer of every roll once you guess.\n\r"); printf("\n\rI cannot give you any more hints. It is up to you to figure it out. Good luck.\n\r");
getch();
main();
}
else guess = atoi(tmp);
if(guess == num_petals)
printf("Correct! There are %d petals.\n\r",num_petals);
else
printf("Incorrect. There are %d petals.\n\r",num_petals);
exit(0);
}
void rolldice(void)
{ /* 0,1,2,3,4,5,6 */
const int petals[] = { 0,0,0,2,0,4,0 };
int dice;
int number;
/* seed the randomizer */
seedrnd();
/* Roll dice and see if they have any petals. */
for(dice = 0; dice < 5; dice++)
{
number = rnd(6)+1; /* numbers 1-6 */
num_petals += petals[number];
printf("%-2d",number);
}
return;
}