1 /*
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)ttext2.c	8.1 (Berkeley) 05/31/93";
10 #endif /* not lint */
11 
12 #include "back.h"
13 
14 char *prompt, *list, *opts;
15 
16 char	*doubl[] = {
17     "\nDoubling:",
18     "\n   If a player thinks he is in a good position, he may double the",
19     "value of the game.  However, his opponent may not accept the pro-",
20     "posal and forfeit the game before the price gets too high.  A",
21     "player must double before he rolls, and once his double has been",
22     "accepted, he cannot double again, until his opponent has doubled.",
23     "Thus, unless the game swings back and forth in advantage between",
24     "the two players a great deal, the value of the game should be",
25     "low.  At any rate, the value of the game will never go above 64,",
26     "or six doubles.  However, if a player wins a backgammon at 64",
27     "points, he wins 192 points!",
28     "",
29     0};
30 
31 char	*stragy[] = {
32     "\nStrategy:",
33     "\n   Some general hints when playing:  Try not to leave men open",
34     "unless absolutely necessary.  Also, it is good to make as many",
35     "points as possible.  Often, two men from different positions can",
36     "be brought together to form a new point.  Although walls (six",
37     "points in a row) are difficult to form, many points nestled close-",
38     "ly together produce a formidable barrier.  Also, while it is good",
39     "to move back men forward, doing so lessens the opportunity for you",
40     "to hit men.  Finally, remember that once the two player's have",
41     "passed each other on the board, there is no chance of either team",
42     "being hit, so the game reduces to a race off the board.  Addi-",
43     "tional hints on strategy are presented in the practice game.",
44     "",
45     0};
46 
47 char	*prog[] = {
48    "\nThe Program and How It Works:",
49    "\n   A general rule of thumb is when you don't know what to do,",
50    "type a question mark, and you should get some help.  When it is",
51    "your turn, only your color will be printed out, with nothing",
52    "after it.  You may double by typing a 'd', but if you type a",
53    "space or newline, you will get your roll.  (Remember, you must",
54    "double before you roll.)  Also, typing a 'r' will reprint the",
55    "board, and a 'q' will quit the game.  The program will type",
56    "'Move:' when it wants your move, and you may indicate each die's",
57    "move with <s>-<f>, where <s> is the starting position and <f> is",
58    "the finishing position, or <s>/<r> where <r> is the roll made.",
59    "<s>-<f1>-<f2> is short for <s>-<f1>,<f1>-<f2> and <s>/<r1><r2> is",
60    "short for <s>/<r1>,<s>/<r2>.  Moves may be separated by a comma",
61    "or a space.",
62    "",
63    "\n   While typing, any input which does not make sense will not be",
64    "echoed, and a bell will sound instead.  Also, backspacing and",
65    "killing lines will echo differently than normal.  You may examine",
66    "the board by typing a 'r' if you have made a partial move, or be-",
67    "fore you type a newline, to see what the board looks like.  You",
68    "must end your move with a newline.  If you cannot double, your",
69    "roll will always be printed, and you will not be given the oppor-",
70    "tunity to double.  Home and bar are represented by the appropri-",
71    "ate number, 0 or 25 as the case may be, or by the letters 'h' or",
72    "'b' as appropriate.  You may also type 'r' or 'q' when the program",
73    "types 'Move:', which has the same effect as above.  Finally, you",
74    "will get to decide if you want to play red or white (or both if you",
75    "want to play a friend) at the beginning of the session, and you",
76    "will not get to change your mind later, since the computer keeps",
77    "score.",
78    "",
79    0};
80 
81 char	*lastch[] = {
82    "\nTutorial (Practice Game):",
83    "\n   This tutorial, for simplicity's sake, will let you play one",
84    "predetermined game.  All the rolls have been pre-arranged, and",
85    "only one response will let you advance to the next move.",
86    "Although a given roll will may have several legal moves, the tu-",
87    "torial will only accept one (not including the same moves in a",
88    "different order), claiming that that move is 'best.'  Obviously,",
89    "a subjective statement.  At any rate, be patient with it and have",
90    "fun learning about backgammon.  Also, to speed things up a lit-",
91    "tle, doubling will not take place in the tutorial, so you will",
92    "never get that opportunity, and quitting only leaves the tutori-",
93    "al, not the game.  You will still be able to play backgammon",
94    "after quitting.",
95    "\n   This is your last chance to look over the rules before the tu-",
96    "torial starts.",
97    "",
98    0};
99 
100 text (txt)
101 char	**txt;
102 
103 {
104 	char	**begin;
105 	char	*a;
106 	char	b;
107 	char	*c;
108 	int	i;
109 
110 	fixtty (noech);
111 	begin = txt;
112 	while (*txt)  {
113 		a = *(txt++);
114 		if (*a != '\0')  {
115 			c = a;
116 			for (i = 0; *(c++) != '\0'; i--);
117 			writel (a);
118 			writec ('\n');
119 		} else  {
120 			fixtty (raw);
121 			writel (prompt);
122 			for (;;)  {
123 				if ((b = readc()) == '?')  {
124 					if (tflag)  {
125 						if (begscr)  {
126 							curmove (18,0);
127 							clend();
128 						} else
129 							clear();
130 					} else
131 						writec ('\n');
132 					text (list);
133 					writel (prompt);
134 					continue;
135 				}
136 				i = 0;
137 				if (b == '\n')
138 					break;
139 				while (i < 11)  {
140 					if (b == opts[i])
141 						break;
142 					i++;
143 				}
144 				if (i == 11)
145 					writec ('\007');
146 				else
147 					break;
148 			}
149 			if (tflag)  {
150 				if (begscr)  {
151 					curmove (18,0);
152 					clend();
153 				} else
154 					clear();
155 			} else
156 				writec ('\n');
157 			if (i)
158 				return(i);
159 			fixtty (noech);
160 			if (tflag)
161 				curmove (curr,0);
162 			begin = txt;
163 		}
164 	}
165 	fixtty (raw);
166 	return (0);
167 }
168