date and time created 82/05/11 14:54:31 by rrh
[unix-history] / usr / src / games / backgammon / teachgammon / teach.c
CommitLineData
7b90fd84
RH
1static char sccsid[] = " teach.c 1.1 82/05/11 ";
2
3#include "back.h"
4
5char *hello[];
6char *list[];
7char *intro1[];
8char *intro2[];
9char *moves[];
10char *remove[];
11char *hits[];
12char *endgame[];
13char *doubl[];
14char *stragy[];
15char *prog[];
16char *lastch[];
17
18extern char ospeed; /* tty output speed for termlib */
19
20char *helpm[] = {
21 "\nEnter a space or newline to roll, or",
22 " b to display the board",
23 " d to double",
24 " q to quit\n",
25 0
26};
27
28char *contin[] = {
29 "",
30 0
31};
32
33main (argc,argv)
34int argc;
35char **argv;
36
37{
38 register char *s, *ts[];
39 register int i;
40
41 signal (2,getout);
42 if (gtty (0,&tty) == -1) /* get old tty mode */
43 errexit ("teachgammon(gtty)");
44 old = tty.sg_flags;
45#ifdef V7
46 raw = ((noech = old & ~ECHO) | CBREAK); /* set up modes */
47#else
48 raw = ((noech = old & ~ECHO) | RAW); /* set up modes */
49#endif
50 ospeed = old.sg_ospeed; /* for termlib */
51 tflag = getcaps (getenv ("TERM"));
52#ifdef V7
53 while (*++argv != 0)
54#else
55 while (*++argv != -1)
56#endif
57 getarg (&argv);
58 if (tflag) {
59 noech &= ~(CRMOD|XTABS);
60 raw &= ~(CRMOD|XTABS);
61 clear();
62 }
63 text (hello);
64 text (list);
65 i = text (contin);
66 if (i == 0)
67 i = 2;
68 init();
69 while (i)
70 switch (i) {
71
72 case 1:
73 leave();
74
75 case 2:
76 if (i = text(intro1))
77 break;
78 wrboard();
79 if (i = text(intro2))
80 break;
81
82 case 3:
83 if (i = text(moves))
84 break;
85
86 case 4:
87 if (i = text(remove))
88 break;
89
90 case 5:
91 if (i = text(hits))
92 break;
93
94 case 6:
95 if (i = text(endgame))
96 break;
97
98 case 7:
99 if (i = text(doubl))
100 break;
101
102 case 8:
103 if (i = text(stragy))
104 break;
105
106 case 9:
107 if (i = text(prog))
108 break;
109
110 case 10:
111 if (i = text(lastch))
112 break;
113 }
114 tutor();
115}
116
117leave() {
118 if (tflag)
119 clear();
120 else
121 writec ('\n');
122 fixtty(old);
123 execl (EXEC,"backgammon",args,"n",0);
124 writel ("Help! Backgammon program is missing\007!!\n");
125 exit (-1);
126}