| File: | src/games/backgammon/teachgammon/ttext2.c |
| Warning: | line 125, column 2 Value stored to 'begin' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* $OpenBSD: ttext2.c,v 1.8 2015/11/30 08:19:25 tb 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. Neither the name of the University nor the names of its contributors |
| 16 | * may be used to endorse or promote products derived from this software |
| 17 | * without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 29 | * SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | #include "back.h" |
| 33 | #include "tutor.h" |
| 34 | |
| 35 | const char *const doubl[] = { |
| 36 | "\nDoubling:", |
| 37 | "\n If a player thinks he is in a good position, he may double the", |
| 38 | "value of the game. However, his opponent may not accept the proposal", |
| 39 | "and can forfeit the game before the price gets too high. A player", |
| 40 | "must double before he rolls, and once his double has been accepted,", |
| 41 | "he cannot double again until his opponent has doubled. Thus, unless", |
| 42 | "the game swings back and forth in advantage between the two players", |
| 43 | "a great deal, the value of the game should be low. At any rate,", |
| 44 | "the value of the game can never go above 64, or six doubles.", |
| 45 | "However, if a player wins a backgammon at 64 points, he wins 192", |
| 46 | "points!", |
| 47 | "", |
| 48 | 0}; |
| 49 | |
| 50 | const char *const stragy[] = { |
| 51 | "\nStrategy:", |
| 52 | "\n Some general hints when playing: Try not to leave men open:", |
| 53 | "it is good to make as many points as possible. Often, two men", |
| 54 | "from different positions can be brought together to form a new", |
| 55 | "point. Although walls (six points in a row) are difficult to form,", |
| 56 | "many points nestled closely together still produce a formidable", |
| 57 | "barrier. Also, while it is good to move back men forward, doing", |
| 58 | "so lessens the opportunity for you to hit the opponent's blots.", |
| 59 | "Finally, remember that once the two player's men have passed each other", |
| 60 | "on the board, there is no chance of either side being hit, so the", |
| 61 | "game reduces to a race off the board. Additional hints on strategy", |
| 62 | "are presented in the practice game.", |
| 63 | "", |
| 64 | 0}; |
| 65 | |
| 66 | const char *const prog[] = { |
| 67 | "\nThe Program and How It Works:", |
| 68 | "\n A general rule of thumb is to type a question mark if you", |
| 69 | "don't know what to do: you should get some help. When it is your", |
| 70 | "turn, only your color will be printed out, with nothing after it.", |
| 71 | "You may double by typing `d', but if you type a space or newline,", |
| 72 | "you will get your roll. (Remember, you must double before you", |
| 73 | "roll.) Also, typing `r' will reprint the board, and typing `q'", |
| 74 | "will quit the game. The program will print 'Move:' when it wants", |
| 75 | "your move. You may indicate each die's move with <s>-<f>, where", |
| 76 | "<s> is the starting position and <f> is the finishing position, or", |
| 77 | "<s>/<r> where <r> is the roll made. <s>-<f1>-<f2> is short for", |
| 78 | "<s>-<f1>,<f1>-<f2> and <s>/<r1><r2> is short for <s>/<r1>,<s>/<r2>.", |
| 79 | "Moves may be separated by a comma or a space.", |
| 80 | "", |
| 81 | "\n Any input which does not make sense will not be echoed; instead,", |
| 82 | "a bell will sound. Backspacing and killing lines may echo differently", |
| 83 | "than usual. You may examine the board by typing `r' if you have", |
| 84 | "made a partial move or before you type a newline to see what the", |
| 85 | "board will look like. You must end your move with a newline. If", |
| 86 | "you cannot double, your roll will be printed and you will not be", |
| 87 | "given the opportunity to double. Home and bar can be represented", |
| 88 | "by the appropriate number, 0 or 25 as the case may be, or by the", |
| 89 | "letters `h' or `b' as appropriate. You may also type `r' or `q'", |
| 90 | "when the program prints 'Move:' to redraw the screen or quit the", |
| 91 | "game. At the beginning of the session, you will get to decide if", |
| 92 | "you want to play red or white (or both if you want to play a friend),", |
| 93 | "and you will not get to change your mind later, since the computer", |
| 94 | "keeps a running score.", |
| 95 | "", |
| 96 | 0}; |
| 97 | |
| 98 | const char *const lastch[] = { |
| 99 | "\nTutorial (Practice Game):", |
| 100 | "\n This tutorial, for simplicity's sake, will let you play one", |
| 101 | "predetermined game. All the rolls have been pre-arranged, and", |
| 102 | "only one response will let you advance to the next move. Although", |
| 103 | "a given roll will may have several legal moves, the tutorial will", |
| 104 | "only accept one (not including the same moves in a different order),", |
| 105 | "claiming that that move is 'best'--obviously, a subjective statement.", |
| 106 | "At any rate, be patient with it and have fun learning about", |
| 107 | "backgammon. To speed things up a little, doubling will not", |
| 108 | "take place in the tutorial. Quitting the tutorial leaves only", |
| 109 | "the tutorial; you will still be able to play a real backgammon", |
| 110 | "game after quitting.", |
| 111 | "\n This is your last chance to look over the rules before the", |
| 112 | "tutorial starts.", |
| 113 | "", |
| 114 | 0}; |
| 115 | |
| 116 | int |
| 117 | text(const char *const *txt) |
| 118 | { |
| 119 | const char *const *begin; |
| 120 | const char *a; |
| 121 | char b; |
| 122 | const char *c; |
| 123 | int i; |
| 124 | |
| 125 | begin = txt; |
Value stored to 'begin' is never read | |
| 126 | while (*txt) { |
| 127 | a = *(txt++); |
| 128 | if (*a != '\0') { |
| 129 | c = a; |
| 130 | for (i = 0; *(c++) != '\0'; i--); |
| 131 | printw("%s\n", a); |
| 132 | } else { |
| 133 | addstr(prompt)waddnstr(stdscr,prompt,-1); |
| 134 | /* if begscr is set we're past the rules screens */ |
| 135 | if (!begscr) { |
| 136 | for (;;) { |
| 137 | if ((b = readc()) == '?') { |
| 138 | clear()wclear(stdscr); |
| 139 | text(list); |
| 140 | addstr(prompt)waddnstr(stdscr,prompt,-1); |
| 141 | continue; |
| 142 | } |
| 143 | i = 0; |
| 144 | if (b == '\n') |
| 145 | break; |
| 146 | while (i < 11) { |
| 147 | if (b == opts[i]) |
| 148 | break; |
| 149 | i++; |
| 150 | } |
| 151 | if (i == 11) |
| 152 | beep(); |
| 153 | else |
| 154 | break; |
| 155 | } |
| 156 | } else { |
| 157 | b = readc(); |
| 158 | i = 0; |
| 159 | } |
| 160 | if (begscr) { |
| 161 | move(18, 0)wmove(stdscr,18,0); |
| 162 | clrtobot()wclrtobot(stdscr); |
| 163 | } else |
| 164 | clear()wclear(stdscr); |
| 165 | if (i) |
| 166 | return(i); |
| 167 | /* move to start of current line? */ |
| 168 | begin = txt; |
| 169 | } |
| 170 | } |
| 171 | return(0); |
| 172 | } |