Skip to content

Commit

Permalink
Adding Hangman project
Browse files Browse the repository at this point in the history
  • Loading branch information
danfimov committed Aug 15, 2021
1 parent 71d340f commit e43e755
Show file tree
Hide file tree
Showing 11 changed files with 545 additions and 0 deletions.
124 changes: 124 additions & 0 deletions Python Developer/Hangman/Error_/task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<h2>Description</h2>

<p>Now that we are done with the basics, let's work on perfecting some details.</p>

<p>In the previous stage, if the user entered the same letter twice, the program reduced the number of remaining attempts regardless of whether this was a correct letter or not. This doesn’t seem fair to the player, does it? They gain no additional information about the situation on the field yet the program still reduces their remaining attempts. Let's fix it!</p>

<h2>Objectives</h2>

<ol>
<li>If the user enters the same letter twice, then the program should output <code class="java">You've already guessed this letter</code> . This message should also be printed if the user inputs a letter that doesn't appear in the word. The number of attempts shouldn't be decreased in this case. </li>
<li>Also, you should check to make sure the player entered an English lowercase letter. If not, the program should print <code class="java">Please enter a lowercase English letter</code> . </li>
<li>You should also check if the player entered exactly one letter. If not, the program should print <code class="java">You should input a single letter</code> . Remember that zero is also not one!</li>
<li>Note that none of these three errors should reduce the number of remaining attempts!</li>
</ol>

<p><div class="alert alert-warning">Please, make sure that your program's output formatting precisely follows the output formatting in the example. Pay attention to the empty lines between tries and in the end.</div></p>

<h2>Examples</h2>

<p>The greater-than symbol followed by a space (<code class="java">&gt; </code>) represents the user input. Note that it's not part of the output.</p>

<p><strong>Example 1</strong></p>

<pre><code class="language-no-highlight">H A N G M A N

----------
Input a letter: &gt; a

-a-a------
Input a letter: &gt; i

-a-a---i--
Input a letter: &gt; o
That letter doesn't appear in the word

-a-a---i--
Input a letter: &gt; o
You've already guessed this letter

-a-a---i--
Input a letter: &gt; p

-a-a---ip-
Input a letter: &gt; p
You've already guessed this letter

-a-a---ip-
Input a letter: &gt; h
That letter doesn't appear in the word

-a-a---ip-
Input a letter: &gt; k
That letter doesn't appear in the word

-a-a---ip-
Input a letter: &gt; a
You've already guessed this letter

-a-a---ip-
Input a letter: &gt; z
That letter doesn't appear in the word

-a-a---ipt
Input a letter: &gt; t

-a-a---ipt
Input a letter: &gt; x
That letter doesn't appear in the word

-a-a---ipt
Input a letter: &gt; b
That letter doesn't appear in the word

-a-a---ipt
Input a letter: &gt; d
That letter doesn't appear in the word

-a-a---ipt
Input a letter: &gt; w
That letter doesn't appear in the word
You lost!</code></pre>

<p><strong>Example 2</strong></p>

<pre><code class="language-no-highlight">H A N G M A N

----
Input a letter: &gt; j

j---
Input a letter: &gt; i
That letter doesn't appear in the word

j---
Input a letter: &gt; +
Please enter a lowercase English letter

j---
Input a letter: &gt; A
Please enter a lowercase English letter

j---
Input a letter: &gt; ii
You should input a single letter

j---
Input a letter: &gt; ++
You should input a single letter

j---
Input a letter: &gt;
You should input a single letter

j---
Input a letter: &gt; g
That letter doesn't appear in the word

j---
Input a letter: &gt; a

ja-a
Input a letter: &gt; v
You guessed the word java!
You survived!</code></pre>
31 changes: 31 additions & 0 deletions Python Developer/Hangman/Hello, Hangman/task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<h2>Description</h2>

<p><strong>Hangman</strong> is a popular yet grim intellectual game. A cruel computer hides a word from you. Letter by letter you try to guess it. If you fail, you'll be hanged, if you win, you'll survive. See also: <a target="_blank" href="https://en.wikipedia.org/wiki/Hangman_(game)" rel="nofollow noopener noreferrer">Wikipedia</a></p>

<p>You probably played the game at least once in your life; now you can actually create this game yourself!</p>

<p>Let's look at a brief overview of what you are going to build in this project. Here is what the gameplay should look like:</p>

<ol>
<li>In the main menu, a player can choose to either play or exit the game.</li>
<li>If the user chooses to play, the computer picks a word from a list: this will be the answer to the puzzle.</li>
<li>The computer asks the player to enter a letter that they think is in the word.</li>
<li>If that letter does not appear in the word and this letter hasn't already been guessed, the computer counts it as a miss. A player can only afford 8 misses before the game is over.</li>
<li>If the letter does occur in the word, the computer notifies the player. If there are letters left to guess, the computer invites the player to go on.</li>
<li>When the entire word is uncovered, it's a victory! The game calculates the final score and returns to the main menu.</li>
</ol>

<p>This may sound complex, but the project is split into small stages with hints to see you through. The final product is sure to be replayable and quite engaging!</p>

<p>Let's start with an announcement that will greet the player. You already know how to print something using Python. Try to apply that knowledge to entice your friends to play with an announcement for your game!</p>

<h2>Objectives</h2>

<p>In this stage, you should<strong> write a program</strong> that prints the lines shown in the example below.</p>

<h2>Example </h2>

<p>Output:</p>

<pre><code class="language-no-highlight">H A N G M A N
The game will be available soon.</code></pre>
26 changes: 26 additions & 0 deletions Python Developer/Hangman/Help is on the way/task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h2>Description</h2>

<p>Now our game has become quite hard, and your chances of guessing the word depend on the size of the list. When the list has four words, you only have a 25% chance to guess correctly. So let's show a little mercy to the player and add a hint for them.</p>

<h2>Objectives</h2>

<ol>
<li>As in the previous stage, you should use the following word list: <code class="java">'python', 'java', 'kotlin', 'javascript'</code></li>
<li>Once the computer has chosen a word from the list, show its first 3 letters. Hidden letters should be replaced with hyphens (<code class="java">"-"</code>).</li>
</ol>

<h2>Examples</h2>

<p>The greater-than symbol followed by a space (<code class="java">&gt; </code>) represents the user input. Note that it's not part of the output.</p>

<p><strong>Example 1</strong></p>

<pre><code class="language-no-highlight">H A N G M A N
Guess the word jav-: &gt; java
You survived!</code></pre>

<p><strong>Example 2</strong></p>

<pre><code class="language-no-highlight">H A N G M A N
Guess the word pyt---: &gt; pythia
You lost!</code></pre>
92 changes: 92 additions & 0 deletions Python Developer/Hangman/Keep trying/task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<h2>Description</h2>

<p>Let's make the game iterative. Now it's time to make the game resemble the classic version of Hangman a bit more. The player should now guess letters in the word instead of typing the entire word all at once. If the player guesses a letter, it should be uncovered in the word. For now, start by building the defeat condition and add 8 tries to guess a letter that appears in the word. When the player runs out of attempts, the game ends.</p>

<p>Later we will determine the winning conditions, but in this stage, let's just see how well our player guesses the word on each attempt.</p>

<h2>Objectives</h2>

<p>Now your game should work as follows:</p>

<ol>
<li>A player has <strong>exactly 8 tries</strong> and enters letters. Nothing changes if a player has more tries left but they have already guessed the word.</li>
<li>If the letter doesn't appear in the word, the computer takes one try away – even if the user has already guessed this letter.</li>
<li>If the player doesn't have any more attempts, the game should end and the program should show a losing message. Otherwise, the player can continue to input letters.</li>
<li>Also, the word should be selected from our list: <code class="java">'python', 'java', 'kotlin', 'javascript'</code>, so that your program can be tested more reliably.</li>
</ol>

<p><div class="alert alert-warning">Please, make sure that your program's output formatting precisely follows the example. Pay attention to the empty lines between tries and at the end.</div></p>

<h2>Examples</h2>

<p>The greater-than symbol followed by a space (<code class="java">&gt; </code>) represents the user input. Note that it's not part of the output.</p>

<p><strong>Example 1</strong></p>

<pre><code class="language-no-highlight">H A N G M A N

----------
Input a letter: &gt; a

-a-a------
Input a letter: &gt; i

-a-a---i--
Input a letter: &gt; o
That letter doesn't appear in the word

-a-a---i--
Input a letter: &gt; z
That letter doesn't appear in the word

-a-a---i--
Input a letter: &gt; l
That letter doesn't appear in the word

-a-a---ip-
Input a letter: &gt; p

-a-a---ip-
Input a letter: &gt; h
That letter doesn't appear in the word

-a-a---ip-
Input a letter: &gt; k
That letter doesn't appear in the word

Thanks for playing!
We'll see how well you did in the next stage</code></pre>

<p><strong>Example 2</strong></p>

<pre><code class="language-no-highlight">H A N G M A N

----
Input a letter: &gt; j

j---
Input a letter: &gt; i
That letter doesn't appear in the word

j---
Input a letter: &gt; g
That letter doesn't appear in the word

j---
Input a letter: &gt; o
That letter doesn't appear in the word

j---
Input a letter: &gt; a

ja-a
Input a letter: &gt; v

java
Input a letter: &gt; a

java
Input a letter: &gt; j

Thanks for playing!
We'll see how well you did in the next stage</code></pre>
29 changes: 29 additions & 0 deletions Python Developer/Hangman/Let’s play a game/task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<h2>Description</h2>

<p>At this stage, you will create a real game, though it will still be quite simple. There will be two possible outcomes. Let's first print a welcome message and then ask the player to guess the word we set for the game. If our player manages to guess the exact word, the game reports "win"; otherwise it will "hang" the player.</p>

<h2>Objectives</h2>

<ol>
<li>Ask the player for a possible word.</li>
<li>Print <code class="java">You survived!</code> if the user guesses the word.</li>
<li>Print <code class="java">You lost!</code> if the user guesses incorrectly.</li>
</ol>

<p><div class="alert alert-primary">By the way, <code class="java">python</code> should be the word the player needs to guess to win the game.</div></p>

<h2>Examples</h2>

<p>The greater-than symbol followed by a space (<code class="java">&gt; </code>) represents the user input. Note that it's not the part of the output.</p>

<p><strong>Example 1</strong></p>

<pre><code class="language-no-highlight">H A N G M A N
Guess the word: &gt; python
You survived!</code></pre>

<p><strong>Example 2</strong></p>

<pre><code class="language-no-highlight">H A N G M A N
Guess the word: &gt; java
You lost!</code></pre>
32 changes: 32 additions & 0 deletions Python Developer/Hangman/Make your choice/task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<h2>Description</h2>

<p>If there is a predefined word, the game isn't replayable. You already know the word, so there’s no longer any challenge. At this stage, let's make the game more challenging by choosing a word from a special list with a variety of options. This way, our game will have more replay value.</p>

<h2>Objectives</h2>

<ol>
<li>Create the following list of words: <code class="java">'python', 'java', 'kotlin', 'javascript'</code>.</li>
<li>Program the game to choose a word from the list at random. You can enter more words, but let's stick to these four for now.</li>
</ol>

<h2>Examples</h2>

<p>The greater-than symbol followed by a space (<code class="java">&gt; </code>) represents the user input. Note that it's not part of the output.</p>

<p><strong>Example 1. </strong><em>The computer randomly chose <code class="java">python</code> from the list.</em></p>

<pre><code class="language-no-highlight">H A N G M A N
Guess the word: &gt; python
You survived!</code></pre>

<p><strong>Example 2. </strong><em>The computer randomly chose something other than <code class="java">python</code> from the list.</em></p>

<pre><code class="language-no-highlight">H A N G M A N
Guess the word: &gt; python
You lost!</code></pre>

<p><strong>Example 3. </strong><em>The computer randomly chose something other than <code class="java">kotlin</code> from the list.</em></p>

<pre><code class="language-no-highlight">H A N G M A N
Guess the word: &gt; kotlin
You lost!</code></pre>
Loading

0 comments on commit e43e755

Please sign in to comment.