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