mirror of
https://github.com/TheAlgorithms/C
synced 2024-12-11 14:23:59 +03:00
592 lines
48 KiB
HTML
592 lines
48 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.6"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Algorithms_in_C: games/hangman.c File Reference</title>
|
|
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../jquery.js"></script>
|
|
<script type="text/javascript" src="../../dynsections.js"></script>
|
|
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../resize.js"></script>
|
|
<script type="text/javascript" src="../../navtreedata.js"></script>
|
|
<script type="text/javascript" src="../../navtree.js"></script>
|
|
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
|
<script type="text/javascript" src="../../search/search.js"></script>
|
|
<script type="text/x-mathjax-config">
|
|
MathJax.Hub.Config({
|
|
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
|
jax: ["input/TeX","output/HTML-CSS"],
|
|
});
|
|
</script>
|
|
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
|
|
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr id="projectrow">
|
|
<td id="projectalign">
|
|
<div id="projectname">Algorithms_in_C<span id="projectnumber"> 1.0.0</span>
|
|
</div>
|
|
<div id="projectbrief">Set of algorithms implemented in C.</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.6 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="../../menudata.js"></script>
|
|
<script type="text/javascript" src="../../menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(function() {
|
|
initMenu('../../',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(document).ready(function(){initNavTree('dc/dc5/hangman_8c.html','../../'); initResizable(); });
|
|
/* @license-end */
|
|
</script>
|
|
<div id="doc-content">
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<div id="MSearchResults">
|
|
<div class="SRPage">
|
|
<div id="SRIndex">
|
|
<div id="SRResults"></div>
|
|
<div class="SRStatus" id="Loading">Loading...</div>
|
|
<div class="SRStatus" id="Searching">Searching...</div>
|
|
<div class="SRStatus" id="NoMatches">No Matches</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#nested-classes">Data Structures</a> |
|
|
<a href="#func-members">Functions</a> </div>
|
|
<div class="headertitle"><div class="title">hangman.c File Reference</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p>C implementation of <a href="https://en.wikipedia.org/wiki/Hangman_(game)" target="_blank">Hangman Game</a>
|
|
<a href="#details">More...</a></p>
|
|
<div class="textblock"><code>#include <ctype.h></code><br />
|
|
<code>#include <stdio.h></code><br />
|
|
<code>#include <stdlib.h></code><br />
|
|
<code>#include <string.h></code><br />
|
|
<code>#include <time.h></code><br />
|
|
</div><div class="textblock"><div class="dynheader">
|
|
Include dependency graph for hangman.c:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d7/d43/hangman_8c__incl.svg" width="418" height="111"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
</div><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
|
|
Data Structures</h2></td></tr>
|
|
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d01/structgame__instance.html">game_instance</a></td></tr>
|
|
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">for <a class="el" href="../../d8/daf/affine_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4" title="main function">main()</a> - tolower() for <a class="el" href="../../d8/daf/affine_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4" title="main function">main()</a>, new_word(), <a class="el" href="../../dc/dc5/hangman_8c.html#a9611b43141ac2e6ba245487c493599fc" title="checks if letter has been guessed before">new_guess()</a>, <a class="el" href="../../dc/dc5/hangman_8c.html#a669e745d87eb1740ab9b1f3b73bb7336" title="checks if player has won or lost">won()</a> - I/O operations for all functions - exit(), rand() and file functions for <a class="el" href="../../d8/daf/affine_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4" title="main function">main()</a> - for string operations strlen, strchr, strcpy for <a class="el" href="../../dc/dc5/hangman_8c.html#ad4130a1d1092d32dcfa4a46019e27d45" title="creates a new game - generates a random word and stores in global variable current_word">new_game()</a> - used with srand() for declaring new game instance <a href="../../d1/d01/structgame__instance.html#details">More...</a><br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:ad4130a1d1092d32dcfa4a46019e27d45"><td class="memItemLeft" align="right" valign="top">struct <a class="el" href="../../d1/d01/structgame__instance.html">game_instance</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/dc5/hangman_8c.html#ad4130a1d1092d32dcfa4a46019e27d45">new_game</a> ()</td></tr>
|
|
<tr class="memdesc:ad4130a1d1092d32dcfa4a46019e27d45"><td class="mdescLeft"> </td><td class="mdescRight">creates a new game - generates a random word and stores in global variable current_word <br /></td></tr>
|
|
<tr class="separator:ad4130a1d1092d32dcfa4a46019e27d45"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a9611b43141ac2e6ba245487c493599fc"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/dc5/hangman_8c.html#a9611b43141ac2e6ba245487c493599fc">new_guess</a> (char new_guess, const char guesses[], int size)</td></tr>
|
|
<tr class="memdesc:a9611b43141ac2e6ba245487c493599fc"><td class="mdescLeft"> </td><td class="mdescRight">checks if letter has been guessed before <br /></td></tr>
|
|
<tr class="separator:a9611b43141ac2e6ba245487c493599fc"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a6f5bb35e025e731286ce890c90286d2e"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/dc5/hangman_8c.html#a6f5bb35e025e731286ce890c90286d2e">in_word</a> (char letter, const char word[], unsigned int size)</td></tr>
|
|
<tr class="memdesc:a6f5bb35e025e731286ce890c90286d2e"><td class="mdescLeft"> </td><td class="mdescRight">checks if letter is in current word <br /></td></tr>
|
|
<tr class="separator:a6f5bb35e025e731286ce890c90286d2e"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ac0b992734d26b13f1d09345ed87f30e8"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/dc5/hangman_8c.html#ac0b992734d26b13f1d09345ed87f30e8">picture</a> (int score)</td></tr>
|
|
<tr class="separator:ac0b992734d26b13f1d09345ed87f30e8"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a669e745d87eb1740ab9b1f3b73bb7336"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/dc5/hangman_8c.html#a669e745d87eb1740ab9b1f3b73bb7336">won</a> (const char word[], int score)</td></tr>
|
|
<tr class="memdesc:a669e745d87eb1740ab9b1f3b73bb7336"><td class="mdescLeft"> </td><td class="mdescRight">checks if player has won or lost <br /></td></tr>
|
|
<tr class="separator:a669e745d87eb1740ab9b1f3b73bb7336"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/dc5/hangman_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
|
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">Main Function. <br /></td></tr>
|
|
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p>C implementation of <a href="https://en.wikipedia.org/wiki/Hangman_(game)" target="_blank">Hangman Game</a> </p>
|
|
<p>Simple, readable version of hangman. Changed graphic to duck instead of traditional stick figure (same number of guesses). </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/AtlantaEmrys2002" target="_blank">AtlantaEmrys2002</a> </dd></dl>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="a6f5bb35e025e731286ce890c90286d2e" name="a6f5bb35e025e731286ce890c90286d2e"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a6f5bb35e025e731286ce890c90286d2e">◆ </a></span>in_word()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int in_word </td>
|
|
<td>(</td>
|
|
<td class="paramtype">char </td>
|
|
<td class="paramname"><em>letter</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const char </td>
|
|
<td class="paramname"><em>word</em>[], </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">unsigned int </td>
|
|
<td class="paramname"><em>size</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>checks if letter is in current word </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">letter</td><td>letter guessed by player </td></tr>
|
|
<tr><td class="paramname">word</td><td>current word </td></tr>
|
|
<tr><td class="paramname">size</td><td>length of word </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>1 if letter is in word </dd>
|
|
<dd>
|
|
-1 if letter is not in word </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 119</span> {</div>
|
|
<div class="line"><span class="lineno"> 120</span> </div>
|
|
<div class="line"><span class="lineno"> 121</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < size; i++) {</div>
|
|
<div class="line"><span class="lineno"> 122</span> <span class="keywordflow">if</span> ((word[i]) == letter) {</div>
|
|
<div class="line"><span class="lineno"> 123</span> <span class="keywordflow">return</span> 1;</div>
|
|
<div class="line"><span class="lineno"> 124</span> }</div>
|
|
<div class="line"><span class="lineno"> 125</span> }</div>
|
|
<div class="line"><span class="lineno"> 126</span> </div>
|
|
<div class="line"><span class="lineno"> 127</span> <span class="keywordflow">return</span> -1;</div>
|
|
<div class="line"><span class="lineno"> 128</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">◆ </a></span>main()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int main </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Main Function. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 41</span> {</div>
|
|
<div class="line"><span class="lineno"> 42</span> </div>
|
|
<div class="line"><span class="lineno"> 43</span> <span class="keyword">struct </span><a class="code hl_struct" href="../../d1/d01/structgame__instance.html">game_instance</a> game = <a class="code hl_function" href="../../dc/dc5/hangman_8c.html#ad4130a1d1092d32dcfa4a46019e27d45">new_game</a>(); <span class="comment">// new game created</span></div>
|
|
<div class="line"><span class="lineno"> 44</span> <span class="keywordtype">char</span> guess; <span class="comment">// current letter guessed by player</span></div>
|
|
<div class="line"><span class="lineno"> 45</span> </div>
|
|
<div class="line"><span class="lineno"> 46</span> <span class="comment">// main loop - asks player for guesses</span></div>
|
|
<div class="line"><span class="lineno"> 47</span> <span class="keywordflow">while</span> ((strchr(game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#aabb340e08e8ab73df250a6fe3b6f532d">hidden</a>, <span class="charliteral">'_'</span>) != NULL) && game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#a89731a7d5b4676db9ccc4b0db2cd8f24">incorrect</a> <= 12) {</div>
|
|
<div class="line"><span class="lineno"> 48</span> <span class="keywordflow">do</span> {</div>
|
|
<div class="line"><span class="lineno"> 49</span> printf(<span class="stringliteral">"\n****************************\n"</span>);</div>
|
|
<div class="line"><span class="lineno"> 50</span> printf(<span class="stringliteral">"Your word: "</span>);</div>
|
|
<div class="line"><span class="lineno"> 51</span> </div>
|
|
<div class="line"><span class="lineno"> 52</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#ae7d4369a86942792c809a51965764094">size</a>; i++) {</div>
|
|
<div class="line"><span class="lineno"> 53</span> printf(<span class="stringliteral">"%c "</span>, game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#aabb340e08e8ab73df250a6fe3b6f532d">hidden</a>[i]);</div>
|
|
<div class="line"><span class="lineno"> 54</span> }</div>
|
|
<div class="line"><span class="lineno"> 55</span> </div>
|
|
<div class="line"><span class="lineno"> 56</span> <span class="keywordflow">if</span> (game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#affc18c8be0e07b6b19914458ed853aa7">guesses_size</a> > 0) {</div>
|
|
<div class="line"><span class="lineno"> 57</span> printf(<span class="stringliteral">"\nSo far, you have guessed: "</span>);</div>
|
|
<div class="line"><span class="lineno"> 58</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#affc18c8be0e07b6b19914458ed853aa7">guesses_size</a>; i++) {</div>
|
|
<div class="line"><span class="lineno"> 59</span> printf(<span class="stringliteral">"%c "</span>, game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#a742506bd6e2e03ce63e504ef6abdf643">guesses</a>[i]);</div>
|
|
<div class="line"><span class="lineno"> 60</span> }</div>
|
|
<div class="line"><span class="lineno"> 61</span> }</div>
|
|
<div class="line"><span class="lineno"> 62</span> </div>
|
|
<div class="line"><span class="lineno"> 63</span> printf(<span class="stringliteral">"\nYou have %d guesses left."</span>, (12 - game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#a89731a7d5b4676db9ccc4b0db2cd8f24">incorrect</a>));</div>
|
|
<div class="line"><span class="lineno"> 64</span> printf(<span class="stringliteral">"\nPlease enter a letter: "</span>);</div>
|
|
<div class="line"><span class="lineno"> 65</span> scanf(<span class="stringliteral">" %c"</span>, &guess);</div>
|
|
<div class="line"><span class="lineno"> 66</span> guess = tolower(guess);</div>
|
|
<div class="line"><span class="lineno"> 67</span> </div>
|
|
<div class="line"><span class="lineno"> 68</span> } <span class="keywordflow">while</span> (<a class="code hl_function" href="../../dc/dc5/hangman_8c.html#a9611b43141ac2e6ba245487c493599fc">new_guess</a>(guess, game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#a742506bd6e2e03ce63e504ef6abdf643">guesses</a>, game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#affc18c8be0e07b6b19914458ed853aa7">guesses_size</a>) != -1);</div>
|
|
<div class="line"><span class="lineno"> 69</span> </div>
|
|
<div class="line"><span class="lineno"> 70</span> game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#a742506bd6e2e03ce63e504ef6abdf643">guesses</a>[game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#affc18c8be0e07b6b19914458ed853aa7">guesses_size</a>] = guess; <span class="comment">// adds new letter to guesses array</span></div>
|
|
<div class="line"><span class="lineno"> 71</span> game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#affc18c8be0e07b6b19914458ed853aa7">guesses_size</a>++; <span class="comment">// updates size of guesses array</span></div>
|
|
<div class="line"><span class="lineno"> 72</span> </div>
|
|
<div class="line"><span class="lineno"> 73</span> <span class="keywordflow">if</span> (<a class="code hl_function" href="../../dc/dc5/hangman_8c.html#a6f5bb35e025e731286ce890c90286d2e">in_word</a>(guess, game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#ad3caed9fb908aa7dba2aa25e8debdfdf">current_word</a>, game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#ae7d4369a86942792c809a51965764094">size</a>) == 1) {</div>
|
|
<div class="line"><span class="lineno"> 74</span> printf(<span class="stringliteral">"That letter is in the word!"</span>);</div>
|
|
<div class="line"><span class="lineno"> 75</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#ae7d4369a86942792c809a51965764094">size</a>; i++) {</div>
|
|
<div class="line"><span class="lineno"> 76</span> <span class="keywordflow">if</span> ((game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#ad3caed9fb908aa7dba2aa25e8debdfdf">current_word</a>[i]) == guess) {</div>
|
|
<div class="line"><span class="lineno"> 77</span> game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#aabb340e08e8ab73df250a6fe3b6f532d">hidden</a>[i] = guess;</div>
|
|
<div class="line"><span class="lineno"> 78</span> }</div>
|
|
<div class="line"><span class="lineno"> 79</span> }</div>
|
|
<div class="line"><span class="lineno"> 80</span> } <span class="keywordflow">else</span> {</div>
|
|
<div class="line"><span class="lineno"> 81</span> printf(<span class="stringliteral">"That letter is not in the word.\n"</span>);</div>
|
|
<div class="line"><span class="lineno"> 82</span> (game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#a89731a7d5b4676db9ccc4b0db2cd8f24">incorrect</a>)++;</div>
|
|
<div class="line"><span class="lineno"> 83</span> }</div>
|
|
<div class="line"><span class="lineno"> 84</span> picture(game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#a89731a7d5b4676db9ccc4b0db2cd8f24">incorrect</a>);</div>
|
|
<div class="line"><span class="lineno"> 85</span> }</div>
|
|
<div class="line"><span class="lineno"> 86</span> </div>
|
|
<div class="line"><span class="lineno"> 87</span> <a class="code hl_function" href="../../dc/dc5/hangman_8c.html#a669e745d87eb1740ab9b1f3b73bb7336">won</a>(game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#ad3caed9fb908aa7dba2aa25e8debdfdf">current_word</a>, game.<a class="code hl_variable" href="../../d1/d01/structgame__instance.html#a89731a7d5b4676db9ccc4b0db2cd8f24">incorrect</a>);</div>
|
|
<div class="line"><span class="lineno"> 88</span> <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><span class="lineno"> 89</span>}</div>
|
|
<div class="ttc" id="ahangman_8c_html_a669e745d87eb1740ab9b1f3b73bb7336"><div class="ttname"><a href="../../dc/dc5/hangman_8c.html#a669e745d87eb1740ab9b1f3b73bb7336">won</a></div><div class="ttdeci">void won(const char word[], int score)</div><div class="ttdoc">checks if player has won or lost</div><div class="ttdef"><b>Definition:</b> hangman.c:192</div></div>
|
|
<div class="ttc" id="ahangman_8c_html_a6f5bb35e025e731286ce890c90286d2e"><div class="ttname"><a href="../../dc/dc5/hangman_8c.html#a6f5bb35e025e731286ce890c90286d2e">in_word</a></div><div class="ttdeci">int in_word(char, const char word[], unsigned int size)</div><div class="ttdoc">checks if letter is in current word</div><div class="ttdef"><b>Definition:</b> hangman.c:119</div></div>
|
|
<div class="ttc" id="ahangman_8c_html_a9611b43141ac2e6ba245487c493599fc"><div class="ttname"><a href="../../dc/dc5/hangman_8c.html#a9611b43141ac2e6ba245487c493599fc">new_guess</a></div><div class="ttdeci">int new_guess(char, const char guesses[], int size)</div><div class="ttdoc">checks if letter has been guessed before</div><div class="ttdef"><b>Definition:</b> hangman.c:99</div></div>
|
|
<div class="ttc" id="ahangman_8c_html_ad4130a1d1092d32dcfa4a46019e27d45"><div class="ttname"><a href="../../dc/dc5/hangman_8c.html#ad4130a1d1092d32dcfa4a46019e27d45">new_game</a></div><div class="ttdeci">struct game_instance new_game(void)</div><div class="ttdoc">creates a new game - generates a random word and stores in global variable current_word</div><div class="ttdef"><b>Definition:</b> hangman.c:134</div></div>
|
|
<div class="ttc" id="astructgame__instance_html"><div class="ttname"><a href="../../d1/d01/structgame__instance.html">game_instance</a></div><div class="ttdoc">for main() - tolower() for main(), new_word(), new_guess(), won() - I/O operations for all functions ...</div><div class="ttdef"><b>Definition:</b> hangman.c:19</div></div>
|
|
<div class="ttc" id="astructgame__instance_html_a742506bd6e2e03ce63e504ef6abdf643"><div class="ttname"><a href="../../d1/d01/structgame__instance.html#a742506bd6e2e03ce63e504ef6abdf643">game_instance::guesses</a></div><div class="ttdeci">char guesses[25]</div><div class="ttdoc">previous guesses</div><div class="ttdef"><b>Definition:</b> hangman.c:25</div></div>
|
|
<div class="ttc" id="astructgame__instance_html_a89731a7d5b4676db9ccc4b0db2cd8f24"><div class="ttname"><a href="../../d1/d01/structgame__instance.html#a89731a7d5b4676db9ccc4b0db2cd8f24">game_instance::incorrect</a></div><div class="ttdeci">int incorrect</div><div class="ttdoc">number of incorrect guesses</div><div class="ttdef"><b>Definition:</b> hangman.c:24</div></div>
|
|
<div class="ttc" id="astructgame__instance_html_aabb340e08e8ab73df250a6fe3b6f532d"><div class="ttname"><a href="../../d1/d01/structgame__instance.html#aabb340e08e8ab73df250a6fe3b6f532d">game_instance::hidden</a></div><div class="ttdeci">char hidden[30]</div><div class="ttdoc">hidden version of word that is displayed to player</div><div class="ttdef"><b>Definition:</b> hangman.c:22</div></div>
|
|
<div class="ttc" id="astructgame__instance_html_ad3caed9fb908aa7dba2aa25e8debdfdf"><div class="ttname"><a href="../../d1/d01/structgame__instance.html#ad3caed9fb908aa7dba2aa25e8debdfdf">game_instance::current_word</a></div><div class="ttdeci">char current_word[30]</div><div class="ttdoc">word to be guessed by player</div><div class="ttdef"><b>Definition:</b> hangman.c:21</div></div>
|
|
<div class="ttc" id="astructgame__instance_html_ae7d4369a86942792c809a51965764094"><div class="ttname"><a href="../../d1/d01/structgame__instance.html#ae7d4369a86942792c809a51965764094">game_instance::size</a></div><div class="ttdeci">int size</div><div class="ttdoc">size of word</div><div class="ttdef"><b>Definition:</b> hangman.c:23</div></div>
|
|
<div class="ttc" id="astructgame__instance_html_affc18c8be0e07b6b19914458ed853aa7"><div class="ttname"><a href="../../d1/d01/structgame__instance.html#affc18c8be0e07b6b19914458ed853aa7">game_instance::guesses_size</a></div><div class="ttdeci">int guesses_size</div><div class="ttdoc">size of guesses array</div><div class="ttdef"><b>Definition:</b> hangman.c:26</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dc/dc5/hangman_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="196" height="208"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ad4130a1d1092d32dcfa4a46019e27d45" name="ad4130a1d1092d32dcfa4a46019e27d45"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ad4130a1d1092d32dcfa4a46019e27d45">◆ </a></span>new_game()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">struct <a class="el" href="../../d1/d01/structgame__instance.html">game_instance</a> new_game </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>creates a new game - generates a random word and stores in global variable current_word </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>current_game - a new game instance containing randomly selected word, its length and hidden version of word </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 134</span> {</div>
|
|
<div class="line"><span class="lineno"> 135</span> </div>
|
|
<div class="line"><span class="lineno"> 136</span> <span class="keywordtype">char</span> word[30]; <span class="comment">// used throughout function</span></div>
|
|
<div class="line"><span class="lineno"> 137</span> </div>
|
|
<div class="line"><span class="lineno"> 138</span> FILE *fptr;</div>
|
|
<div class="line"><span class="lineno"> 139</span> fptr = fopen(<span class="stringliteral">"games/words.txt"</span>, <span class="stringliteral">"r"</span>);</div>
|
|
<div class="line"><span class="lineno"> 140</span> </div>
|
|
<div class="line"><span class="lineno"> 141</span> <span class="keywordflow">if</span> (fptr == NULL){</div>
|
|
<div class="line"><span class="lineno"> 142</span> fprintf(stderr, <span class="stringliteral">"File not found.\n"</span>);</div>
|
|
<div class="line"><span class="lineno"> 143</span> exit(EXIT_FAILURE);</div>
|
|
<div class="line"><span class="lineno"> 144</span> }</div>
|
|
<div class="line"><span class="lineno"> 145</span> </div>
|
|
<div class="line"><span class="lineno"> 146</span> <span class="comment">// counts number of words in file - assumes each word on new line</span></div>
|
|
<div class="line"><span class="lineno"> 147</span> <span class="keywordtype">int</span> line_number = 0;</div>
|
|
<div class="line"><span class="lineno"> 148</span> <span class="keywordflow">while</span> (fgets(word, 30, fptr) != NULL) {</div>
|
|
<div class="line"><span class="lineno"> 149</span> line_number++;</div>
|
|
<div class="line"><span class="lineno"> 150</span> }</div>
|
|
<div class="line"><span class="lineno"> 151</span> </div>
|
|
<div class="line"><span class="lineno"> 152</span> rewind(fptr);</div>
|
|
<div class="line"><span class="lineno"> 153</span> </div>
|
|
<div class="line"><span class="lineno"> 154</span> <span class="comment">// generates random number</span></div>
|
|
<div class="line"><span class="lineno"> 155</span> <span class="keywordtype">int</span> random_num;</div>
|
|
<div class="line"><span class="lineno"> 156</span> srand(time(NULL));</div>
|
|
<div class="line"><span class="lineno"> 157</span> random_num = rand() % line_number;</div>
|
|
<div class="line"><span class="lineno"> 158</span> </div>
|
|
<div class="line"><span class="lineno"> 159</span> <span class="comment">// selects randomly generated word</span></div>
|
|
<div class="line"><span class="lineno"> 160</span> <span class="keywordtype">int</span> s = 0;</div>
|
|
<div class="line"><span class="lineno"> 161</span> <span class="keywordflow">while</span> (s <= random_num){</div>
|
|
<div class="line"><span class="lineno"> 162</span> fgets(word, 30, fptr);</div>
|
|
<div class="line"><span class="lineno"> 163</span> s++;</div>
|
|
<div class="line"><span class="lineno"> 164</span> }</div>
|
|
<div class="line"><span class="lineno"> 165</span> </div>
|
|
<div class="line"><span class="lineno"> 166</span> <span class="comment">// formats string correctly</span></div>
|
|
<div class="line"><span class="lineno"> 167</span> <span class="keywordflow">if</span> (strchr(word, <span class="charliteral">'\n'</span>) != NULL){</div>
|
|
<div class="line"><span class="lineno"> 168</span> word[strlen(word) - 1] = <span class="charliteral">'\0'</span>;</div>
|
|
<div class="line"><span class="lineno"> 169</span> }</div>
|
|
<div class="line"><span class="lineno"> 170</span> </div>
|
|
<div class="line"><span class="lineno"> 171</span> fclose(fptr);</div>
|
|
<div class="line"><span class="lineno"> 172</span> </div>
|
|
<div class="line"><span class="lineno"> 173</span> <span class="comment">// creates new game instance</span></div>
|
|
<div class="line"><span class="lineno"> 174</span> <span class="keyword">struct </span><a class="code hl_struct" href="../../d1/d01/structgame__instance.html">game_instance</a> current_game;</div>
|
|
<div class="line"><span class="lineno"> 175</span> strcpy(current_game.current_word, word);</div>
|
|
<div class="line"><span class="lineno"> 176</span> current_game.size = strlen(word);</div>
|
|
<div class="line"><span class="lineno"> 177</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < (strlen(word)); i++) {</div>
|
|
<div class="line"><span class="lineno"> 178</span> current_game.hidden[i] = <span class="charliteral">'_'</span>;</div>
|
|
<div class="line"><span class="lineno"> 179</span> }</div>
|
|
<div class="line"><span class="lineno"> 180</span> current_game.incorrect = 0;</div>
|
|
<div class="line"><span class="lineno"> 181</span> current_game.guesses_size = 0;</div>
|
|
<div class="line"><span class="lineno"> 182</span> </div>
|
|
<div class="line"><span class="lineno"> 183</span> <span class="keywordflow">return</span> current_game;</div>
|
|
<div class="line"><span class="lineno"> 184</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a9611b43141ac2e6ba245487c493599fc" name="a9611b43141ac2e6ba245487c493599fc"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a9611b43141ac2e6ba245487c493599fc">◆ </a></span>new_guess()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int new_guess </td>
|
|
<td>(</td>
|
|
<td class="paramtype">char </td>
|
|
<td class="paramname"><em>new_guess</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const char </td>
|
|
<td class="paramname"><em>guesses</em>[], </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>size</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>checks if letter has been guessed before </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">new_guess</td><td>letter that has been guessed by player </td></tr>
|
|
<tr><td class="paramname">guesses</td><td>array of player's previous guesses </td></tr>
|
|
<tr><td class="paramname">size</td><td>size of guesses[] array </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>1 if letter has been guessed before </dd>
|
|
<dd>
|
|
-1 if letter has not been guessed before </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 99</span> {</div>
|
|
<div class="line"><span class="lineno"> 100</span> </div>
|
|
<div class="line"><span class="lineno"> 101</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < size; j++) {</div>
|
|
<div class="line"><span class="lineno"> 102</span> <span class="keywordflow">if</span> (guesses[j] == <a class="code hl_function" href="../../dc/dc5/hangman_8c.html#a9611b43141ac2e6ba245487c493599fc">new_guess</a>) {</div>
|
|
<div class="line"><span class="lineno"> 103</span> printf(<span class="stringliteral">"\nYou have already guessed that letter."</span>);</div>
|
|
<div class="line"><span class="lineno"> 104</span> <span class="keywordflow">return</span> 1;</div>
|
|
<div class="line"><span class="lineno"> 105</span> }</div>
|
|
<div class="line"><span class="lineno"> 106</span> }</div>
|
|
<div class="line"><span class="lineno"> 107</span> </div>
|
|
<div class="line"><span class="lineno"> 108</span> <span class="keywordflow">return</span> -1;</div>
|
|
<div class="line"><span class="lineno"> 109</span>}</div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dc/dc5/hangman_8c_a9611b43141ac2e6ba245487c493599fc_cgraph.svg" width="99" height="60"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ac0b992734d26b13f1d09345ed87f30e8" name="ac0b992734d26b13f1d09345ed87f30e8"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ac0b992734d26b13f1d09345ed87f30e8">◆ </a></span>picture()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void picture </td>
|
|
<td>(</td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>score</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
<div class="fragment"><div class="line"><span class="lineno"> 206</span> {</div>
|
|
<div class="line"><span class="lineno"> 207</span> </div>
|
|
<div class="line"><span class="lineno"> 208</span> <span class="keywordflow">switch</span>(score) {</div>
|
|
<div class="line"><span class="lineno"> 209</span> </div>
|
|
<div class="line"><span class="lineno"> 210</span> <span class="keywordflow">case</span> 12:</div>
|
|
<div class="line"><span class="lineno"> 211</span> printf(<span class="stringliteral">"\n _\n"</span></div>
|
|
<div class="line"><span class="lineno"> 212</span> <span class="stringliteral">" __( ' )> \n"</span></div>
|
|
<div class="line"><span class="lineno"> 213</span> <span class="stringliteral">" \\_ < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 214</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 215</span> </div>
|
|
<div class="line"><span class="lineno"> 216</span> <span class="keywordflow">case</span> 11:</div>
|
|
<div class="line"><span class="lineno"> 217</span> printf(<span class="stringliteral">"\n _\n"</span></div>
|
|
<div class="line"><span class="lineno"> 218</span> <span class="stringliteral">" __( ' )\n"</span></div>
|
|
<div class="line"><span class="lineno"> 219</span> <span class="stringliteral">" \\_ < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 220</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 221</span> </div>
|
|
<div class="line"><span class="lineno"> 222</span> <span class="keywordflow">case</span> 10:</div>
|
|
<div class="line"><span class="lineno"> 223</span> printf(<span class="stringliteral">"\n _\n"</span></div>
|
|
<div class="line"><span class="lineno"> 224</span> <span class="stringliteral">" __( )\n"</span></div>
|
|
<div class="line"><span class="lineno"> 225</span> <span class="stringliteral">" \\_ < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 226</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 227</span> </div>
|
|
<div class="line"><span class="lineno"> 228</span> <span class="keywordflow">case</span> 9:</div>
|
|
<div class="line"><span class="lineno"> 229</span> printf(<span class="stringliteral">"\n \n"</span></div>
|
|
<div class="line"><span class="lineno"> 230</span> <span class="stringliteral">" __( )\n"</span></div>
|
|
<div class="line"><span class="lineno"> 231</span> <span class="stringliteral">" \\_ < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 232</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 233</span> </div>
|
|
<div class="line"><span class="lineno"> 234</span> <span class="keywordflow">case</span> 8:</div>
|
|
<div class="line"><span class="lineno"> 235</span> printf(<span class="stringliteral">"\n \n"</span></div>
|
|
<div class="line"><span class="lineno"> 236</span> <span class="stringliteral">" __( \n"</span></div>
|
|
<div class="line"><span class="lineno"> 237</span> <span class="stringliteral">" \\_ < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 238</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 239</span> </div>
|
|
<div class="line"><span class="lineno"> 240</span> <span class="keywordflow">case</span> 7:</div>
|
|
<div class="line"><span class="lineno"> 241</span> printf(<span class="stringliteral">"\n \n"</span></div>
|
|
<div class="line"><span class="lineno"> 242</span> <span class="stringliteral">" __ \n"</span></div>
|
|
<div class="line"><span class="lineno"> 243</span> <span class="stringliteral">" \\_ < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 244</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 245</span> </div>
|
|
<div class="line"><span class="lineno"> 246</span> <span class="keywordflow">case</span> 6:</div>
|
|
<div class="line"><span class="lineno"> 247</span> printf(<span class="stringliteral">"\n \n"</span></div>
|
|
<div class="line"><span class="lineno"> 248</span> <span class="stringliteral">" _ \n"</span></div>
|
|
<div class="line"><span class="lineno"> 249</span> <span class="stringliteral">" \\_ < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 250</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 251</span> </div>
|
|
<div class="line"><span class="lineno"> 252</span> <span class="keywordflow">case</span> 5:</div>
|
|
<div class="line"><span class="lineno"> 253</span> printf(<span class="stringliteral">"\n \n"</span></div>
|
|
<div class="line"><span class="lineno"> 254</span> <span class="stringliteral">" _ \n"</span></div>
|
|
<div class="line"><span class="lineno"> 255</span> <span class="stringliteral">" _ < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 256</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 257</span> </div>
|
|
<div class="line"><span class="lineno"> 258</span> <span class="keywordflow">case</span> 4:</div>
|
|
<div class="line"><span class="lineno"> 259</span> printf(<span class="stringliteral">"\n \n"</span></div>
|
|
<div class="line"><span class="lineno"> 260</span> <span class="stringliteral">" \n"</span></div>
|
|
<div class="line"><span class="lineno"> 261</span> <span class="stringliteral">" _ < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 262</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 263</span> </div>
|
|
<div class="line"><span class="lineno"> 264</span> <span class="keywordflow">case</span> 3:</div>
|
|
<div class="line"><span class="lineno"> 265</span> printf(<span class="stringliteral">"\n \n"</span></div>
|
|
<div class="line"><span class="lineno"> 266</span> <span class="stringliteral">" \n"</span></div>
|
|
<div class="line"><span class="lineno"> 267</span> <span class="stringliteral">" < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 268</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 269</span> </div>
|
|
<div class="line"><span class="lineno"> 270</span> <span class="keywordflow">case</span> 2:</div>
|
|
<div class="line"><span class="lineno"> 271</span> printf(<span class="stringliteral">"\n \n"</span></div>
|
|
<div class="line"><span class="lineno"> 272</span> <span class="stringliteral">" \n"</span></div>
|
|
<div class="line"><span class="lineno"> 273</span> <span class="stringliteral">" _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 274</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 275</span> </div>
|
|
<div class="line"><span class="lineno"> 276</span> <span class="keywordflow">case</span> 1:</div>
|
|
<div class="line"><span class="lineno"> 277</span> printf(<span class="stringliteral">"\n \n"</span></div>
|
|
<div class="line"><span class="lineno"> 278</span> <span class="stringliteral">" \n"</span></div>
|
|
<div class="line"><span class="lineno"> 279</span> <span class="stringliteral">" ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 280</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 281</span> </div>
|
|
<div class="line"><span class="lineno"> 282</span> <span class="keywordflow">case</span> 0:</div>
|
|
<div class="line"><span class="lineno"> 283</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 284</span> </div>
|
|
<div class="line"><span class="lineno"> 285</span> <span class="keywordflow">default</span>:</div>
|
|
<div class="line"><span class="lineno"> 286</span> printf(<span class="stringliteral">"\n _\n"</span></div>
|
|
<div class="line"><span class="lineno"> 287</span> <span class="stringliteral">" __( ' )> QUACK!\n"</span></div>
|
|
<div class="line"><span class="lineno"> 288</span> <span class="stringliteral">" \\_ < _ ) "</span>);</div>
|
|
<div class="line"><span class="lineno"> 289</span> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><span class="lineno"> 290</span> }</div>
|
|
<div class="line"><span class="lineno"> 291</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a669e745d87eb1740ab9b1f3b73bb7336" name="a669e745d87eb1740ab9b1f3b73bb7336"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a669e745d87eb1740ab9b1f3b73bb7336">◆ </a></span>won()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void won </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const char </td>
|
|
<td class="paramname"><em>word</em>[], </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>score</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>checks if player has won or lost </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">word</td><td>the word player has attempted to guess </td></tr>
|
|
<tr><td class="paramname">score</td><td>how many incorrect guesses player has made </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 192</span> {</div>
|
|
<div class="line"><span class="lineno"> 193</span> <span class="keywordflow">if</span> (score > 12) {</div>
|
|
<div class="line"><span class="lineno"> 194</span> printf(<span class="stringliteral">"\nYou lost! The word was: %s.\n"</span>, word);</div>
|
|
<div class="line"><span class="lineno"> 195</span> }</div>
|
|
<div class="line"><span class="lineno"> 196</span> <span class="keywordflow">else</span> {</div>
|
|
<div class="line"><span class="lineno"> 197</span> printf(<span class="stringliteral">"\nYou won! You had %d guesses left.\n"</span>, (12 - score));</div>
|
|
<div class="line"><span class="lineno"> 198</span> }</div>
|
|
<div class="line"><span class="lineno"> 199</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
</div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="../../dir_4b6f782e158b0b98da980a0e11a23a15.html">games</a></li><li class="navelem"><a class="el" href="../../dc/dc5/hangman_8c.html">hangman.c</a></li>
|
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|