4 <title>Hangman (again)
</title>
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8"/>
6 <style type=
"text/css">
15 h1 { font-size:
3em; }
16 h2 { font-size:
2em; }
17 h3 { font-size:
1.6em; }
19 text-decoration: none;
22 -moz-border-radius:
5px;
23 -web-border-radius:
5px;
31 text-shadow:
0 0 20px #
333;
37 text-shadow:
0 0 20px #
333;
51 <textarea id=
"source">
55 1. **Set a puzzle**
<== here
64 .indexlink[[Index](index.html)]
70 * 'List' of words to choose from
78 <th> </th>
86 * In order in the word
95 * Update discovered letters
97 * Show discovered word
98 * Detect game end, report
99 * Detect game win or loss, report
109 We've got a list of valid words.
112 * look in the `random` module
114 * Once we have a word, how to represent what's been guessed?
118 # Representing the game state
122 * `target`, the target word: a `string`
123 * `discovered`, what's been found so far: a `list` of letters (each a length-one `string`)
124 * unguessed letters are `_`
125 * `guess`, the letter that's just been guessed: a length-one `string`
126 * `lives`, the lives remaining: an `int`
127 * `wrong_letters`, the incorrect guesses: a `list` (optional)
128 * (but it makes the automated players easier if they don't have to track wrong guesses and therefore be made stateless)
134 1. Print a `discovered` word
136 3. Check if the `guess`ed letter is in the `target`
137 4. Update `discovered` word with the newly-`guess`ed letter
138 5. Update `lives` and `wrong_letters` if the guess is wrong
142 1. Remember `
<string>.join(
<list>)` ?
143 2. `input('prompt')` (or `input('prompt').strip().lower()[
0]` )
144 3. Walk over `target`, looking for `guess`. Explicit iteration (`for letter in target:`) or with a comprehension (`enumerate(target)`)
145 4. `target[n] = guess`. Note that you need the numerical position, and you need all the positions for repeated words.
146 5. How do you know the guess is wrong?
150 <script src=
"http://gnab.github.io/remark/downloads/remark-0.6.0.min.js" type=
"text/javascript">
153 <script type=
"text/javascript"
154 src=
"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&delayStartupUntil=configured"></script>
156 <script type=
"text/javascript">
157 var slideshow = remark.create({ ratio:
"16:9" });
162 skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
165 MathJax.Hub.Queue(function() {
166 $(MathJax.Hub.getAllJax()).map(function(index, elem) {
167 return(elem.SourceElement());
168 }).parent().addClass('has-jax');
170 MathJax.Hub.Configured();