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