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