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