|
|
1.1 root 1: #include <stdlib.h>
2: #include <stdio.h>
3: #include <dos.h>
4: #include <io.h>
5: #include <fcntl.h>
6:
7: int players, player, roller, bet_amt, lose, win, ok;
8:
9: main(int argc, char *argv[])
10: {
11: FILE *fp;
12: char cont='Y', ch;
13:
14:
15: get_game_status(ok);
16: if (ok) { players++; player=players; }
17: if (players>1) request_access();
18: while (!kbhit()) { }
19: randomize();
20: roll();
21:
22:
23: while(cont=='Y') {
24: printf("\n\nWould you like to play again?");cont=toupper(getche());
25: if (cont=='Y')
26: roll();
27: else
28: printf("\n\nThank you for playing, try again soon!");
29: }
30: return;
31: }
32:
33: /* This is the routine to roll the dice */
34:
35: roll()
36: {
37: FILE *fp;
38: char ch;
39: int die1, die2, dice, roll, match, shake, x;
40: die1=die2=dice=roll=match=lose=win=0;
41:
42: clrscr();
43: while (!lose&&!win) { ch='';
44: printf("\n\n[S]end message or [ENTER] to roll!"); ch=toupper(getche());
45: printf("\n\n");
46: for (shake=0; shake<50; shake++) {
47: die1=random(6)+1; die2=random(6)+1;
48: }
49: dice=die1+die2; roll++;
50: printf("You rolled a %d and a %d for a total of %d",die1,die2,dice);
51:
52: if (match==dice) {
53: printf("\n\nBitchin! You matched your first roll! You WIN!"); getche();
54: win=1; return;
55: }
56: if ((dice==7||dice==11) && roll==1) {
57: printf("\n\nHurray! You WIN!"); win=1; getche(); return;
58: }
59: if (((dice==2||dice==12) && roll==1) || ((dice==7||dice==11) && roll>1)) {
60: printf("\n\nBummer dude, You LOST!"); lose=1; getche(); return;
61: } else if (roll==1) {
62: match=dice;
63: printf("\n\nYou've gotta try to match a %d",match);
64: }
65: printf("\n\nWould you like to increase the bet? ");
66: while (ch!='Y' && ch!='N') {
67: ch=toupper(getche()); if (ch=='Y') increase_bet();
68: } ch='';
69: }
70: }
71:
72: /***********************************
73: Gets the current status of the game
74: ************************************/
75: int get_game_status()
76: {
77: FILE *fp;
78:
79: if(!access("GAMESTAT.TXT",0)) {
80: printf("file exists\7");
81: if ((fp=fopen("GAMESTAT.TXT","r"))==NULL)
82: return -1;
83: fscanf(fp,"%d%d%d", &players, &roller, &bet_amt);
84: fclose(fp); return 0;
85: } else {
86: if ((fp=fopen("GAMESTAT.TXT","a+"))==NULL)
87: return -1;
88: players=player=roller=1;bet_amt=0;
89: fprintf(fp,"%d\n%d\n%d", players, roller, bet_amt);
90: fclose(fp); return 1;
91: }
92: }
93:
94: increase_bet()
95: {
96: int add;
97:
98: ok=0;
99:
100: while (!ok) {
101: printf("\n\nEnter amount to increase by (in Kbytes): ");
102: scanf("%d",add);
103: if (add<=100) ok=1;
104: else printf("\n\nMust be less than 100K!!");
105: }
106: return;
107: }
108:
109:
110: /* This function waits till the current bet (if any) is over before
111: giving the new player access to the game */
112:
113: request_access()
114: {
115: FILE *fp;
116: char fname[81];
117: int x;
118:
119: sprintf(fname,"REQUEST.%d",player);
120: if ((fp=fopen(fname,"a+"))==NULL) return;
121: fclose(fp);
122:
123: printf("\n\nHang on! Waiting to enter game!");
124: while (!access(fname,0)) { }
125:
126: sprintf(fname,"PLAYER.%d",player);
127: if ((fp=fopen(fname,"a+"))==NULL) return;
128: fclose(fp);
129:
130: }
131:
132:
133:
134: menu()
135: {
136: char ch;
137:
138: if (roller==player)
139: printf("\n\nCommand (I,P,R,S,Q,?): ");
140: else
141: printf("\n\nCommand (S,Q,?): ");
142: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.