主题:本人准备开始用BCB编程了,今天遇到第一个问题望高手指点
编了一个赌博游戏,有几个bug大家帮忙看一下:
/*
author : euclid
data: 6-22-05
name: gambling ver 1.0.0
*/
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "time.h"
#pragma hdrstop
#include "conio.h"
#pragma argsused
#define Esc 27
#define INITMONEY 2000
void delay (float sec)
{
time_t bg = clock(), ed = clock ();
while ((ed - bg)/18.2 < sec) ed = clock ();
}
int play (long *money)
{
long betmoney;
int r1, r2, c; //r1,r2是筛子点数, c是临时量
char stone, tstone[3]; //stone是大小对, tstone是真点
printf ("要玩吗?[!Esc]\n");
if (*money <= 0) printf ("大哥你钱好多!还敢玩吗?~\n");
if (getch() == Esc) exit (1);
printf ("请下注[你有现金%ld元]\n", *money);
do {
scanf ("%d", &betmoney);
if (betmoney > 0 || betmoney <= *money) break;
else printf ("重新下注\n");
betmoney = 0;
} while (1);
printf ("押宝(大[b] 小[s] 对[d])\n");
while (1) {
scanf ("%c", &stone);
if (stone == Esc) exit (1);
if (stone == 's' || stone == 'b' || stone == 'd') break;
else printf ("重新押宝\n");
}
printf ("好,开始!\neuclid轻轻地把筛子掷了出去......\n");
printf ("stone is %c\n", stone);
delay (4);
srand ((unsigned)time(NULL));
r1 = rand ()%6 + 1;
delay (2);
r2 = rand ()%6 + 1;
printf ("叮叮,筛子停了!\n");
if (r1 == r2){
strcpy (tstone, "对");
if (stone == 'd') betmoney = betmoney * 4;
}
else if (r1 + r2 > 6) {
strcpy (tstone, "大");
if (stone == 'b') betmoney = betmoney * 2;
}
else if (r1 + r2 < 7) {
strcpy (tstone, "小");
if (stone == 's') betmoney = betmoney * 2;
}
else betmoney = (-1) * betmoney;
textcolor (LIGHTBLUE);
cprintf ("%d - %d%s", r1, r2, tstone);
*money += betmoney;
if (betmoney < 0) {
textcolor (RED);
cprintf ("你赔了!庄家赢.");
}
else {
textcolor (LIGHTRED);
cprintf ("你赢了!再来一盘吧..");
}
return 0;
}
int main (void)
{
long money = INITMONEY;
while (1) play (&money);
return 0;
}
bug list:
1.首先delay ()没有起到延时作用?
2.不管我压什么,最后总是赢,按说没问题啊?
我想问题出在 else betmoney = (-1) * betmoney;这句。
/*
author : euclid
data: 6-22-05
name: gambling ver 1.0.0
*/
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "time.h"
#pragma hdrstop
#include "conio.h"
#pragma argsused
#define Esc 27
#define INITMONEY 2000
void delay (float sec)
{
time_t bg = clock(), ed = clock ();
while ((ed - bg)/18.2 < sec) ed = clock ();
}
int play (long *money)
{
long betmoney;
int r1, r2, c; //r1,r2是筛子点数, c是临时量
char stone, tstone[3]; //stone是大小对, tstone是真点
printf ("要玩吗?[!Esc]\n");
if (*money <= 0) printf ("大哥你钱好多!还敢玩吗?~\n");
if (getch() == Esc) exit (1);
printf ("请下注[你有现金%ld元]\n", *money);
do {
scanf ("%d", &betmoney);
if (betmoney > 0 || betmoney <= *money) break;
else printf ("重新下注\n");
betmoney = 0;
} while (1);
printf ("押宝(大[b] 小[s] 对[d])\n");
while (1) {
scanf ("%c", &stone);
if (stone == Esc) exit (1);
if (stone == 's' || stone == 'b' || stone == 'd') break;
else printf ("重新押宝\n");
}
printf ("好,开始!\neuclid轻轻地把筛子掷了出去......\n");
printf ("stone is %c\n", stone);
delay (4);
srand ((unsigned)time(NULL));
r1 = rand ()%6 + 1;
delay (2);
r2 = rand ()%6 + 1;
printf ("叮叮,筛子停了!\n");
if (r1 == r2){
strcpy (tstone, "对");
if (stone == 'd') betmoney = betmoney * 4;
}
else if (r1 + r2 > 6) {
strcpy (tstone, "大");
if (stone == 'b') betmoney = betmoney * 2;
}
else if (r1 + r2 < 7) {
strcpy (tstone, "小");
if (stone == 's') betmoney = betmoney * 2;
}
else betmoney = (-1) * betmoney;
textcolor (LIGHTBLUE);
cprintf ("%d - %d%s", r1, r2, tstone);
*money += betmoney;
if (betmoney < 0) {
textcolor (RED);
cprintf ("你赔了!庄家赢.");
}
else {
textcolor (LIGHTRED);
cprintf ("你赢了!再来一盘吧..");
}
return 0;
}
int main (void)
{
long money = INITMONEY;
while (1) play (&money);
return 0;
}
bug list:
1.首先delay ()没有起到延时作用?
2.不管我压什么,最后总是赢,按说没问题啊?
我想问题出在 else betmoney = (-1) * betmoney;这句。