diff options
author | Crystal <crystal@wizard.tower> | 2024-02-14 23:56:29 +0100 |
---|---|---|
committer | Crystal <crystal@wizard.tower> | 2024-02-14 23:56:29 +0100 |
commit | 881ff00e4140350fa74fa256733fdcdf92ef94c4 (patch) | |
tree | f38aedf28507c009961071538b725b2da9a3ebb8 | |
parent | 85f992cd5d04872b3840bb02d4e2dd9473412f79 (diff) | |
download | www-881ff00e4140350fa74fa256733fdcdf92ef94c4.tar.gz |
Add stuff
-rw-r--r-- | blog/c/game.html | 403 | ||||
-rwxr-xr-x | index.html | 84 | ||||
-rw-r--r-- | src/org/blog/c/game.org | 28 | ||||
-rwxr-xr-x | src/org/index.org | 2 |
4 files changed, 255 insertions, 262 deletions
diff --git a/blog/c/game.html b/blog/c/game.html index 3525321..18e530c 100644 --- a/blog/c/game.html +++ b/blog/c/game.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> -<!-- 2024-02-14 Wed 23:43 --> +<!-- 2024-02-14 Wed 23:56 --> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>The loneliness Game</title> @@ -23,164 +23,161 @@ <p> Hello !!, I hope you are doing great you amazing person whoever you are, and I really appreciate you reading my little C programming adventure. Soo basically I wanted to blog about a little game I made when bored, and figured out it would be a great way to optimize it, and learn new stuff too by documenting the process! </p> -<div id="outline-container-orgbdbc704" class="outline-2"> -<h2 id="orgbdbc704">The concept :</h2> -<div class="outline-text-2" id="text-orgbdbc704"> +<div id="outline-container-org4e3dd7a" class="outline-2"> +<h2 id="org4e3dd7a">The concept :</h2> +<div class="outline-text-2" id="text-org4e3dd7a"> <p> Basically the player is faced with a NxM field made up with the sign <b>“-”</b> and the player is denoted by the symbol <b>“+”</b>, there are also Bonuses <b>“B”</b> which add 1 to your score, Traps <b>“T”</b>, that remove one from your score, and Dead <b>“D”</b> which resets the score to 0. I will go into more of the specifics later but for now this is how it works, and the controls are Basic WASD bindings, though i may go for a HJKL style later. </p> </div> </div> -<div id="outline-container-orgb212cc7" class="outline-2"> -<h2 id="orgb212cc7">The code :</h2> -<div class="outline-text-2" id="text-orgb212cc7"> -<div class="org-src-container"> -<pre class="src src-c"><span class="linenr"> 1: </span><span style="color: #f9e2af;">#include</span> <span style="color: #f38ba8;"><</span><span style="color: #a6e3a1;">stdio.h</span><span style="color: #f38ba8;">></span> -<span class="linenr"> 2: </span><span style="color: #f9e2af;">#include</span> <span style="color: #f38ba8;"><</span><span style="color: #a6e3a1;">stdlib.h</span><span style="color: #f38ba8;">></span> -<span class="linenr"> 3: </span><span style="color: #f9e2af;">int</span> <span style="color: #89b4fa;">main</span><span style="color: #f38ba8;">(</span><span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">argc</span>, <span style="color: #f9e2af;">char</span> *<span style="color: #cdd6f4;">argv</span><span style="color: #fab387;">[]</span><span style="color: #f38ba8;">)</span> <span style="color: #f38ba8;">{</span> -<span class="linenr"> 4: </span> <span style="color: #f9e2af;">char</span> <span style="color: #cdd6f4;">input</span>,<span style="color: #cdd6f4;">map</span><span style="color: #fab387;">[</span><span style="color: #fab387;">5</span><span style="color: #fab387;">][</span><span style="color: #fab387;">5</span><span style="color: #fab387;">]</span> = <span style="color: #fab387;">{</span> -<span class="linenr"> 5: </span> <span style="color: #f9e2af;">{</span><span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span><span style="color: #f9e2af;">}</span>, -<span class="linenr"> 6: </span> <span style="color: #f9e2af;">{</span><span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span><span style="color: #f9e2af;">}</span>, -<span class="linenr"> 7: </span> <span style="color: #f9e2af;">{</span><span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span><span style="color: #f9e2af;">}</span>, -<span class="linenr"> 8: </span> <span style="color: #f9e2af;">{</span><span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span><span style="color: #f9e2af;">}</span>, -<span class="linenr"> 9: </span> <span style="color: #f9e2af;">{</span><span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span>, <span style="color: #a6e3a1;">'-'</span><span style="color: #f9e2af;">}</span> -<span class="linenr"> 10: </span> <span style="color: #fab387;">}</span>; -<span class="linenr"> 11: </span> <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">stop</span>=<span style="color: #fab387;">0</span>,<span style="color: #cdd6f4;">i</span>=<span style="color: #fab387;">0</span>,<span style="color: #cdd6f4;">moves</span>=<span style="color: #fab387;">0</span>,<span style="color: #cdd6f4;">score</span>=<span style="color: #fab387;">0</span>,<span style="color: #cdd6f4;">pos</span><span style="color: #fab387;">[</span><span style="color: #fab387;">2</span><span style="color: #fab387;">]</span> = <span style="color: #fab387;">{</span><span style="color: #fab387;">2</span>, <span style="color: #fab387;">2</span><span style="color: #fab387;">}</span>; -<span class="linenr"> 12: </span> <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">bonus</span><span style="color: #fab387;">[</span><span style="color: #fab387;">2</span><span style="color: #fab387;">]</span>; -<span class="linenr"> 13: </span> <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">trap</span><span style="color: #fab387;">[</span><span style="color: #fab387;">2</span><span style="color: #fab387;">]</span> ; -<span class="linenr"> 14: </span> <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">death</span><span style="color: #fab387;">[</span><span style="color: #fab387;">2</span><span style="color: #fab387;">]</span>; -<span class="linenr"> 15: </span> map<span style="color: #fab387;">[</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">][</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">]</span> = <span style="color: #a6e3a1;">'+'</span>; -<span class="linenr"> 16: </span> <span style="color: #cba6f7;">do</span><span style="color: #fab387;">{</span> -<span class="linenr"> 17: </span> bonus<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span> = arc4random_uniform<span style="color: #f9e2af;">(</span><span style="color: #fab387;">5</span><span style="color: #f9e2af;">)</span>; bonus<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span> = arc4random_uniform<span style="color: #f9e2af;">(</span><span style="color: #fab387;">5</span><span style="color: #f9e2af;">)</span>; -<span class="linenr"> 18: </span> trap<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span> = arc4random_uniform<span style="color: #f9e2af;">(</span><span style="color: #fab387;">5</span><span style="color: #f9e2af;">)</span>; trap<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span> = arc4random_uniform<span style="color: #f9e2af;">(</span><span style="color: #fab387;">5</span><span style="color: #f9e2af;">)</span>; -<span class="linenr"> 19: </span> death<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span> = arc4random_uniform<span style="color: #f9e2af;">(</span><span style="color: #fab387;">5</span><span style="color: #f9e2af;">)</span>; death<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span> = arc4random_uniform<span style="color: #f9e2af;">(</span><span style="color: #fab387;">5</span><span style="color: #f9e2af;">)</span>; -<span class="linenr"> 20: </span> <span style="color: #fab387;">}</span><span style="color: #cba6f7;">while</span><span style="color: #fab387;">(</span><span style="color: #f9e2af;">(</span>bonus<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> == trap<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> && bonus<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span> == trap<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span> || <span style="color: #f9e2af;">(</span>bonus<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> == death<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> && bonus<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span> == death<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span> || <span style="color: #f9e2af;">(</span>trap<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> == death<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> && trap<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span> == death<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span> || <span style="color: #f9e2af;">(</span>bonus<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> == pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> && bonus<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span> == pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span> || <span style="color: #f9e2af;">(</span>trap<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> == pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> && trap<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span> == pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span> || <span style="color: #f9e2af;">(</span>death<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> == pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> && death<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span> == pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span><span style="color: #fab387;">)</span>; -<span class="linenr"> 21: </span> map<span style="color: #fab387;">[</span>bonus<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">][</span>bonus<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">]</span> = <span style="color: #a6e3a1;">'B'</span>; -<span class="linenr"> 22: </span> map<span style="color: #fab387;">[</span>trap<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">][</span>trap<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">]</span> = <span style="color: #a6e3a1;">'T'</span>; -<span class="linenr"> 23: </span> map<span style="color: #fab387;">[</span>death<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">][</span>death<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">]</span> = <span style="color: #a6e3a1;">'D'</span>; -<span class="linenr"> 24: </span> <span style="color: #cba6f7;">do</span><span style="color: #fab387;">{</span> -<span class="linenr"> 25: </span> printf<span style="color: #f9e2af;">(</span><span style="color: #a6e3a1;">"Map:\n"</span><span style="color: #f9e2af;">)</span>; -<span class="linenr"> 26: </span> <span style="color: #cba6f7;">for</span> <span style="color: #f9e2af;">(</span><span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">i</span> = <span style="color: #fab387;">0</span>; i < <span style="color: #fab387;">5</span>; i++<span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr"> 27: </span> <span style="color: #cba6f7;">for</span> <span style="color: #a6e3a1;">(</span><span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">j</span> = <span style="color: #fab387;">0</span>; j < <span style="color: #fab387;">5</span>; j++<span style="color: #a6e3a1;">)</span> <span style="color: #a6e3a1;">{</span> -<span class="linenr"> 28: </span> printf<span style="color: #f38ba8;">(</span><span style="color: #a6e3a1;">"%c "</span>, map<span style="color: #fab387;">[</span>i<span style="color: #fab387;">][</span>j<span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span>; -<span class="linenr"> 29: </span> <span style="color: #a6e3a1;">}</span> -<span class="linenr"> 30: </span> printf<span style="color: #a6e3a1;">(</span><span style="color: #a6e3a1;">"\n"</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr"> 31: </span> <span style="color: #f9e2af;">}</span> -<span class="linenr"> 32: </span> printf<span style="color: #f9e2af;">(</span><span style="color: #a6e3a1;">"Score: %d\n"</span>, score<span style="color: #f9e2af;">)</span>; -<span class="linenr"> 33: </span> printf<span style="color: #f9e2af;">(</span><span style="color: #a6e3a1;">"Moves: %d\n"</span>, moves<span style="color: #f9e2af;">)</span>; -<span class="linenr"> 34: </span> printf<span style="color: #f9e2af;">(</span><span style="color: #a6e3a1;">"Enter a direction (w,a,s,d) or c to quit: "</span><span style="color: #f9e2af;">)</span>; -<span class="linenr"> 35: </span> scanf<span style="color: #f9e2af;">(</span><span style="color: #a6e3a1;">" %c"</span>, &input<span style="color: #f9e2af;">)</span>; -<span class="linenr"> 36: </span><span style="color: #6c7086;">// </span><span style="color: #6c7086;">pos[0] updown pos[1] lr</span> -<span class="linenr"> 37: </span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>input == <span style="color: #a6e3a1;">'w'</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr"> 38: </span> printf<span style="color: #a6e3a1;">(</span><span style="color: #a6e3a1;">"Moving up\n"</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr"> 39: </span> map<span style="color: #a6e3a1;">[</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span><span style="color: #a6e3a1;">][</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span><span style="color: #a6e3a1;">]</span> = <span style="color: #a6e3a1;">'-'</span>; -<span class="linenr"> 40: </span> <span style="color: #cba6f7;">if</span> <span style="color: #a6e3a1;">(</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span> == <span style="color: #fab387;">0</span><span style="color: #a6e3a1;">)</span> <span style="color: #a6e3a1;">{</span> -<span class="linenr"> 41: </span> pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span> = <span style="color: #fab387;">4</span>; -<span class="linenr"> 42: </span> <span style="color: #a6e3a1;">}</span> -<span class="linenr"> 43: </span> <span style="color: #cba6f7;">else</span> <span style="color: #a6e3a1;">{</span> -<span class="linenr"> 44: </span> pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span>--; -<span class="linenr"> 45: </span> <span style="color: #a6e3a1;">}</span> -<span class="linenr"> 46: </span> <span style="color: #f9e2af;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>input == <span style="color: #a6e3a1;">'a'</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr"> 47: </span> printf<span style="color: #a6e3a1;">(</span><span style="color: #a6e3a1;">"Moving left\n"</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr"> 48: </span> map<span style="color: #a6e3a1;">[</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span><span style="color: #a6e3a1;">][</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span><span style="color: #a6e3a1;">]</span> = <span style="color: #a6e3a1;">'-'</span>; -<span class="linenr"> 49: </span> <span style="color: #cba6f7;">if</span> <span style="color: #a6e3a1;">(</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span> == <span style="color: #fab387;">0</span><span style="color: #a6e3a1;">)</span> <span style="color: #a6e3a1;">{</span> -<span class="linenr"> 50: </span> pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span> = <span style="color: #fab387;">4</span>; -<span class="linenr"> 51: </span> <span style="color: #a6e3a1;">}</span> -<span class="linenr"> 52: </span> <span style="color: #cba6f7;">else</span> <span style="color: #a6e3a1;">{</span> -<span class="linenr"> 53: </span> pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span>--; -<span class="linenr"> 54: </span> <span style="color: #a6e3a1;">}</span> -<span class="linenr"> 55: </span> <span style="color: #f9e2af;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>input == <span style="color: #a6e3a1;">'s'</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr"> 56: </span> -<span class="linenr"> 57: </span> printf<span style="color: #a6e3a1;">(</span><span style="color: #a6e3a1;">"Moving down\n"</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr"> 58: </span> map<span style="color: #a6e3a1;">[</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span><span style="color: #a6e3a1;">][</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span><span style="color: #a6e3a1;">]</span> = <span style="color: #a6e3a1;">'-'</span>; -<span class="linenr"> 59: </span> <span style="color: #cba6f7;">if</span> <span style="color: #a6e3a1;">(</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span> == <span style="color: #fab387;">4</span><span style="color: #a6e3a1;">)</span> <span style="color: #a6e3a1;">{</span> -<span class="linenr"> 60: </span> pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span> = <span style="color: #fab387;">0</span>; -<span class="linenr"> 61: </span> <span style="color: #a6e3a1;">}</span> -<span class="linenr"> 62: </span> <span style="color: #cba6f7;">else</span> <span style="color: #a6e3a1;">{</span> -<span class="linenr"> 63: </span> pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span>++; -<span class="linenr"> 64: </span> <span style="color: #a6e3a1;">}</span> -<span class="linenr"> 65: </span> <span style="color: #f9e2af;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>input == <span style="color: #a6e3a1;">'d'</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr"> 66: </span> printf<span style="color: #a6e3a1;">(</span><span style="color: #a6e3a1;">"Moving right\n"</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr"> 67: </span> map<span style="color: #a6e3a1;">[</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span><span style="color: #a6e3a1;">][</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span><span style="color: #a6e3a1;">]</span> = <span style="color: #a6e3a1;">'-'</span>; -<span class="linenr"> 68: </span> <span style="color: #cba6f7;">if</span> <span style="color: #a6e3a1;">(</span>pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span> == <span style="color: #fab387;">4</span><span style="color: #a6e3a1;">)</span> <span style="color: #a6e3a1;">{</span> -<span class="linenr"> 69: </span> pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span> = <span style="color: #fab387;">0</span>; -<span class="linenr"> 70: </span> <span style="color: #a6e3a1;">}</span> -<span class="linenr"> 71: </span> <span style="color: #cba6f7;">else</span> <span style="color: #a6e3a1;">{</span> -<span class="linenr"> 72: </span> pos<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span>++; -<span class="linenr"> 73: </span> <span style="color: #a6e3a1;">}</span> -<span class="linenr"> 74: </span> <span style="color: #f9e2af;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>input == <span style="color: #a6e3a1;">'c'</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr"> 75: </span> printf<span style="color: #a6e3a1;">(</span><span style="color: #a6e3a1;">"Quitting\n"</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr"> 76: </span> <span style="color: #f9e2af;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #f9e2af;">{</span> -<span class="linenr"> 77: </span> printf<span style="color: #a6e3a1;">(</span><span style="color: #a6e3a1;">"Invalid input\n"</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr"> 78: </span> <span style="color: #f9e2af;">}</span> -<span class="linenr"> 79: </span> map<span style="color: #f9e2af;">[</span>pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">][</span>pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">]</span> = <span style="color: #a6e3a1;">'+'</span>; -<span class="linenr"> 80: </span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> == bonus<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> && pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span> == bonus<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr"> 81: </span> score++; -<span class="linenr"> 82: </span> <span style="color: #cba6f7;">do</span><span style="color: #a6e3a1;">{</span> -<span class="linenr"> 83: </span> bonus<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span>= arc4random_uniform<span style="color: #f38ba8;">(</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">)</span>; -<span class="linenr"> 84: </span> bonus<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span>= arc4random_uniform<span style="color: #f38ba8;">(</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">)</span>; -<span class="linenr"> 85: </span> <span style="color: #a6e3a1;">}</span><span style="color: #cba6f7;">while</span><span style="color: #a6e3a1;">(</span><span style="color: #f38ba8;">(</span>bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == trap<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == trap<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span> || <span style="color: #f38ba8;">(</span>bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == death<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == death<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span> || <span style="color: #f38ba8;">(</span>bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == pos<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == pos<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr"> 86: </span> <span style="color: #f9e2af;">}</span> -<span class="linenr"> 87: </span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> == trap<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> && pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span> == trap<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr"> 88: </span> score--; -<span class="linenr"> 89: </span> <span style="color: #cba6f7;">do</span><span style="color: #a6e3a1;">{</span> -<span class="linenr"> 90: </span> trap<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span>= arc4random_uniform<span style="color: #f38ba8;">(</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">)</span>; -<span class="linenr"> 91: </span> trap<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span>= arc4random_uniform<span style="color: #f38ba8;">(</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">)</span>; -<span class="linenr"> 92: </span> <span style="color: #a6e3a1;">}</span><span style="color: #cba6f7;">while</span><span style="color: #a6e3a1;">(</span><span style="color: #f38ba8;">(</span>trap<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && trap<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span> || <span style="color: #f38ba8;">(</span>trap<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == death<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && trap<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == death<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span> || <span style="color: #f38ba8;">(</span>trap<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == pos<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && trap<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == pos<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr"> 93: </span> <span style="color: #f9e2af;">}</span> -<span class="linenr"> 94: </span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> == death<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span> && pos<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span> == death<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr"> 95: </span> score = <span style="color: #fab387;">0</span>; -<span class="linenr"> 96: </span> <span style="color: #cba6f7;">do</span><span style="color: #a6e3a1;">{</span> -<span class="linenr"> 97: </span> death<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span>= arc4random_uniform<span style="color: #f38ba8;">(</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">)</span>; -<span class="linenr"> 98: </span> death<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span>= arc4random_uniform<span style="color: #f38ba8;">(</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">)</span>; -<span class="linenr"> 99: </span> <span style="color: #a6e3a1;">}</span><span style="color: #cba6f7;">while</span><span style="color: #a6e3a1;">(</span><span style="color: #f38ba8;">(</span>death<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && death<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span> || <span style="color: #f38ba8;">(</span>death<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == trap<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && death<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == trap<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span> || <span style="color: #f38ba8;">(</span>death<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == pos<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && death<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == pos<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr">100: </span> <span style="color: #f9e2af;">}</span> -<span class="linenr">101: </span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>score % <span style="color: #fab387;">3</span> == <span style="color: #fab387;">0</span> && score != <span style="color: #fab387;">0</span> && stop == <span style="color: #fab387;">0</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr">102: </span> map<span style="color: #a6e3a1;">[</span>death<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span><span style="color: #a6e3a1;">][</span>death<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span><span style="color: #a6e3a1;">]</span> = <span style="color: #a6e3a1;">'-'</span>; -<span class="linenr">103: </span> <span style="color: #cba6f7;">do</span><span style="color: #a6e3a1;">{</span> -<span class="linenr">104: </span> death<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span>= arc4random_uniform<span style="color: #f38ba8;">(</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">)</span>; -<span class="linenr">105: </span> death<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span>= arc4random_uniform<span style="color: #f38ba8;">(</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">)</span>; -<span class="linenr">106: </span> <span style="color: #a6e3a1;">}</span><span style="color: #cba6f7;">while</span><span style="color: #a6e3a1;">(</span><span style="color: #f38ba8;">(</span>death<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && death<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span> || <span style="color: #f38ba8;">(</span>death<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == trap<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && death<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == trap<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span> || <span style="color: #f38ba8;">(</span>death<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == pos<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && death<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == pos<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr">107: </span> stop = <span style="color: #fab387;">1</span>; -<span class="linenr">108: </span> <span style="color: #f9e2af;">}</span> -<span class="linenr">109: </span> <span style="color: #cba6f7;">else</span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>score % <span style="color: #fab387;">3</span> != <span style="color: #fab387;">0</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr">110: </span> stop = <span style="color: #fab387;">0</span>; -<span class="linenr">111: </span> <span style="color: #f9e2af;">}</span> -<span class="linenr">112: </span> <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>moves % <span style="color: #fab387;">5</span> == <span style="color: #fab387;">0</span> && moves != <span style="color: #fab387;">0</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span> -<span class="linenr">113: </span> <span style="color: #cba6f7;">do</span><span style="color: #a6e3a1;">{</span> -<span class="linenr">114: </span> map<span style="color: #f38ba8;">[</span>trap<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">][</span>trap<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">]</span> = <span style="color: #a6e3a1;">'-'</span>; -<span class="linenr">115: </span> trap<span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span>= arc4random_uniform<span style="color: #f38ba8;">(</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">)</span>; -<span class="linenr">116: </span> trap<span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span>= arc4random_uniform<span style="color: #f38ba8;">(</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">)</span>; -<span class="linenr">117: </span> <span style="color: #a6e3a1;">}</span><span style="color: #cba6f7;">while</span><span style="color: #a6e3a1;">(</span><span style="color: #f38ba8;">(</span>trap<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && trap<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == bonus<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span> || <span style="color: #f38ba8;">(</span>trap<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == death<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && trap<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == death<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span> || <span style="color: #f38ba8;">(</span>trap<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> == pos<span style="color: #fab387;">[</span><span style="color: #fab387;">0</span><span style="color: #fab387;">]</span> && trap<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span> == pos<span style="color: #fab387;">[</span><span style="color: #fab387;">1</span><span style="color: #fab387;">]</span><span style="color: #f38ba8;">)</span><span style="color: #a6e3a1;">)</span>; -<span class="linenr">118: </span> -<span class="linenr">119: </span> <span style="color: #f9e2af;">}</span> -<span class="linenr">120: </span> map<span style="color: #f9e2af;">[</span>bonus<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">][</span>bonus<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">]</span> = <span style="color: #a6e3a1;">'B'</span>; -<span class="linenr">121: </span> map<span style="color: #f9e2af;">[</span>trap<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">][</span>trap<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">]</span> = <span style="color: #a6e3a1;">'T'</span>; -<span class="linenr">122: </span> map<span style="color: #f9e2af;">[</span>death<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">0</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">][</span>death<span style="color: #a6e3a1;">[</span><span style="color: #fab387;">1</span><span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">]</span> = <span style="color: #a6e3a1;">'D'</span>; -<span class="linenr">123: </span> moves++; -<span class="linenr">124: </span> <span style="color: #fab387;">}</span><span style="color: #cba6f7;">while</span><span style="color: #fab387;">(</span>input != <span style="color: #a6e3a1;">'c'</span><span style="color: #fab387;">)</span>; -<span class="linenr">125: </span> <span style="color: #cba6f7;">return</span> <span style="color: #fab387;">0</span>; -<span class="linenr">126: </span><span style="color: #f38ba8;">}</span> -<span class="linenr">127: </span> +<div id="outline-container-orgfc70f38" class="outline-2"> +<h2 id="orgfc70f38">The code :</h2> +<div class="outline-text-2" id="text-orgfc70f38"> +<pre class="example" id="org047cb86"> +#include <stdio.h> +#include <stdlib.h> +int main(int argc, char *argv[]) { + char input,map[5][5] = { + {'-', '-', '-', '-', '-'}, + {'-', '-', '-', '-', '-'}, + {'-', '-', '-', '-', '-'}, + {'-', '-', '-', '-', '-'}, + {'-', '-', '-', '-', '-'} + }; + int stop=0,i=0,moves=0,score=0,pos[2] = {2, 2}; + int bonus[2]; + int trap[2] ; + int death[2]; + map[pos[0]][pos[1]] = '+'; + do{ + bonus[0] = arc4random_uniform(5); bonus[1] = arc4random_uniform(5); + trap[0] = arc4random_uniform(5); trap[1] = arc4random_uniform(5); + death[0] = arc4random_uniform(5); death[1] = arc4random_uniform(5); + }while((bonus[0] == trap[0] && bonus[1] == trap[1]) || (bonus[0] == death[0] && bonus[1] == death[1]) || (trap[0] == death[0] && trap[1] == death[1]) || (bonus[0] == pos[0] && bonus[1] == pos[1]) || (trap[0] == pos[0] && trap[1] == pos[1]) || (death[0] == pos[0] && death[1] == pos[1])); + map[bonus[0]][bonus[1]] = 'B'; + map[trap[0]][trap[1]] = 'T'; + map[death[0]][death[1]] = 'D'; + do{ + printf("Map:\n"); + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + printf("%c ", map[i][j]); + } + printf("\n"); + } + printf("Score: %d\n", score); + printf("Moves: %d\n", moves); + printf("Enter a direction (w,a,s,d) or c to quit: "); + scanf(" %c", &input); +// pos[0] updown pos[1] lr + if (input == 'w') { + printf("Moving up\n"); + map[pos[0]][pos[1]] = '-'; + if (pos[0] == 0) { + pos[0] = 4; + } + else { + pos[0]--; + } + } else if (input == 'a') { + printf("Moving left\n"); + map[pos[0]][pos[1]] = '-'; + if (pos[1] == 0) { + pos[1] = 4; + } + else { + pos[1]--; + } + } else if (input == 's') { + + printf("Moving down\n"); + map[pos[0]][pos[1]] = '-'; + if (pos[0] == 4) { + pos[0] = 0; + } + else { + pos[0]++; + } + } else if (input == 'd') { + printf("Moving right\n"); + map[pos[0]][pos[1]] = '-'; + if (pos[1] == 4) { + pos[1] = 0; + } + else { + pos[1]++; + } + } else if (input == 'c') { + printf("Quitting\n"); + } else { + printf("Invalid input\n"); + } + map[pos[0]][pos[1]] = '+'; + if (pos[0] == bonus[0] && pos[1] == bonus[1]) { + score++; + do{ + bonus[0]= arc4random_uniform(5); + bonus[1]= arc4random_uniform(5); + }while((bonus[0] == trap[0] && bonus[1] == trap[1]) || (bonus[0] == death[0] && bonus[1] == death[1]) || (bonus[0] == pos[0] && bonus[1] == pos[1])); + } + if (pos[0] == trap[0] && pos[1] == trap[1]) { + score--; + do{ + trap[0]= arc4random_uniform(5); + trap[1]= arc4random_uniform(5); + }while((trap[0] == bonus[0] && trap[1] == bonus[1]) || (trap[0] == death[0] && trap[1] == death[1]) || (trap[0] == pos[0] && trap[1] == pos[1])); + } + if (pos[0] == death[0] && pos[1] == death[1]) { + score = 0; + do{ + death[0]= arc4random_uniform(5); + death[1]= arc4random_uniform(5); + }while((death[0] == bonus[0] && death[1] == bonus[1]) || (death[0] == trap[0] && death[1] == trap[1]) || (death[0] == pos[0] && death[1] == pos[1])); + } + if (score % 3 == 0 && score != 0 && stop == 0) { + map[death[0]][death[1]] = '-'; + do{ + death[0]= arc4random_uniform(5); + death[1]= arc4random_uniform(5); + }while((death[0] == bonus[0] && death[1] == bonus[1]) || (death[0] == trap[0] && death[1] == trap[1]) || (death[0] == pos[0] && death[1] == pos[1])); + stop = 1; + } + else if (score % 3 != 0) { + stop = 0; + } + if (moves % 5 == 0 && moves != 0) { + do{ + map[trap[0]][trap[1]] = '-'; + trap[0]= arc4random_uniform(5); + trap[1]= arc4random_uniform(5); + }while((trap[0] == bonus[0] && trap[1] == bonus[1]) || (trap[0] == death[0] && trap[1] == death[1]) || (trap[0] == pos[0] && trap[1] == pos[1])); + + } + map[bonus[0]][bonus[1]] = 'B'; + map[trap[0]][trap[1]] = 'T'; + map[death[0]][death[1]] = 'D'; + moves++; + }while(input != 'c'); + return 0; +} + </pre> -</div> <p> Let’s go step by step and see what we can fix or improve, to start off, line 4 to 10 can be reduced to a single line (which will be beneficial later too) </p> -<div class="org-src-container"> -<pre class="src src-c"><span class="linenr">4: </span><span style="color: #f9e2af;">char</span> <span style="color: #cdd6f4;">input</span>,<span style="color: #cdd6f4;">map</span><span style="color: #f38ba8;">[</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">][</span><span style="color: #fab387;">5</span><span style="color: #f38ba8;">]</span> = <span style="color: #f38ba8;">{</span><span style="color: #a6e3a1;">'-'</span><span style="color: #f38ba8;">}</span>; +<pre class="example" id="orgc476b5a"> +char input,map[5][5] = {'-'}; </pre> -</div> <p> Much better…but can be even more better, why stop at 5 when we can give the choice to the user !! </p> -<div class="org-src-container"> -<pre class="src src-c"><span class="linenr">4: </span><span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">n</span>=<span style="color: #fab387;">5</span>,<span style="color: #cdd6f4;">m</span>=<span style="color: #fab387;">5</span>; -<span class="linenr">5: </span><span style="color: #f9e2af;">char</span> <span style="color: #cdd6f4;">input</span>,<span style="color: #cdd6f4;">map</span><span style="color: #f38ba8;">[</span>n<span style="color: #f38ba8;">][</span>m<span style="color: #f38ba8;">]</span>=<span style="color: #f38ba8;">{</span><span style="color: #a6e3a1;">'-'</span><span style="color: #f38ba8;">}</span>; +<pre class="example" id="orgcdc65be"> +int n=5,m=5; +char input,map[n][m]={'-'}; </pre> -</div> <p> For now at least, n and m are hardcoded to 5, but this will change later. @@ -189,10 +186,9 @@ For now at least, n and m are hardcoded to 5, but this will change later. <p> Of course we have the usual inits on line 11, though since we are using variables instead of hardcoding 5, we will have to find the center by ourselves </p> -<div class="org-src-container"> -<pre class="src src-c"><span class="linenr">11: </span> <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">stop</span>=<span style="color: #fab387;">0</span>,<span style="color: #cdd6f4;">i</span>=<span style="color: #fab387;">0</span>,<span style="color: #cdd6f4;">moves</span>=<span style="color: #fab387;">0</span>,<span style="color: #cdd6f4;">score</span>=<span style="color: #fab387;">0</span>,<span style="color: #cdd6f4;">pos</span><span style="color: #f38ba8;">[</span><span style="color: #fab387;">2</span><span style="color: #f38ba8;">]</span> = <span style="color: #f38ba8;">{</span>n/<span style="color: #fab387;">2</span>,m/<span style="color: #fab387;">2</span><span style="color: #f38ba8;">}</span>; +<pre class="example" id="orge2ff0f5"> + int stop=0,i=0,moves=0,score=0,pos[2] = {n/2,m/2}; </pre> -</div> <p> This is getting better, of course we then initialize the coordinates of bonus, trap, and death, and set the player as a <b>’+’</b> in the field. @@ -202,12 +198,11 @@ This is getting better, of course we then initialize the coordinates of bonus, t <p> Here comes the line 17-21, where it generates a random coordinate for the aforementioned pickups, and do that until there is no conflict between eachother and the player) here we will need to change it a tiny bit. </p> -<div class="org-src-container"> -<pre class="src src-c"><span class="linenr">17: </span> <span style="color: #f9e2af;">bonus</span><span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span> = arc4random_uniform<span style="color: #f38ba8;">(</span>n<span style="color: #f38ba8;">)</span>; <span style="color: #f9e2af;">bonus</span><span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span> = arc4random_uniform<span style="color: #f38ba8;">(</span>m<span style="color: #f38ba8;">)</span>; -<span class="linenr">18: </span> <span style="color: #f9e2af;">trap</span><span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span> = arc4random_uniform<span style="color: #f38ba8;">(</span>n<span style="color: #f38ba8;">)</span>; <span style="color: #f9e2af;">trap</span><span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span> = arc4random_uniform<span style="color: #f38ba8;">(</span>m<span style="color: #f38ba8;">)</span>; -<span class="linenr">19: </span> <span style="color: #f9e2af;">death</span><span style="color: #f38ba8;">[</span><span style="color: #fab387;">0</span><span style="color: #f38ba8;">]</span> = arc4random_uniform<span style="color: #f38ba8;">(</span>n<span style="color: #f38ba8;">)</span>; <span style="color: #f9e2af;">death</span><span style="color: #f38ba8;">[</span><span style="color: #fab387;">1</span><span style="color: #f38ba8;">]</span> = arc4random_uniform<span style="color: #f38ba8;">(</span>m<span style="color: #f38ba8;">)</span>; +<pre class="example" id="org75ddb11"> + bonus[0] = arc4random_uniform(n); bonus[1] = arc4random_uniform(m); + trap[0] = arc4random_uniform(n); trap[1] = arc4random_uniform(m); + death[0] = arc4random_uniform(n); death[1] = arc4random_uniform(m); </pre> -</div> <p> Looking good so far!!, We then have line 21-23 which also shows the pickups as their respective symbols in the map. @@ -217,16 +212,15 @@ Looking good so far!!, We then have line 21-23 which also shows the pickups as t <p> The main interactive program starts here, which will learn at least one time and stop if the received input is a <b>’c’</b>, it starts with a nested for loop on line 26 up to 31 to show the content of the map, nothing fancy, just some matrix stuff. we need to change the 5 though! </p> -<div class="org-src-container"> -<pre class="src src-c"><span class="linenr">26: </span> <span style="color: #cba6f7;">for</span> <span style="color: #f38ba8;">(</span><span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">i</span> = <span style="color: #fab387;">0</span>; i < n; i++<span style="color: #f38ba8;">)</span> <span style="color: #f38ba8;">{</span> -<span class="linenr">27: </span> <span style="color: #cba6f7;">for</span> <span style="color: #fab387;">(</span><span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">j</span> = <span style="color: #fab387;">0</span>; j < m; j++<span style="color: #fab387;">)</span> <span style="color: #fab387;">{</span> -<span class="linenr">28: </span> printf<span style="color: #f9e2af;">(</span><span style="color: #a6e3a1;">"%c "</span>, map<span style="color: #a6e3a1;">[</span>i<span style="color: #a6e3a1;">][</span>j<span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span>; -<span class="linenr">29: </span> <span style="color: #fab387;">}</span> -<span class="linenr">30: </span> printf<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"\n"</span><span style="color: #fab387;">)</span>; -<span class="linenr">31: </span> <span style="color: #f38ba8;">}</span> -<span class="linenr">32: </span> +<pre class="example" id="org968765c"> + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + printf("%c ", map[i][j]); + } + printf("\n"); + } + </pre> -</div> <p> We show the score and the moves too, which at the start of the game are set to 0. and we prompt the user for a direction. Note here the space before the %c, this basically allows for the program to not choke on newlines and also even if the user writes multiple keys at the same time, they will still be done, like <b>ww</b> will make the player move twice up. </p> @@ -234,51 +228,50 @@ We show the score and the moves too, which at the start of the game are set to 0 <p> After that we have some logic which should also be changed to account for the n and m changes yet again </p> -<div class="org-src-container"> -<pre class="src src-c"><span class="linenr">37: </span> <span style="color: #cba6f7;">if</span> <span style="color: #f38ba8;">(</span>input == <span style="color: #a6e3a1;">'w'</span><span style="color: #f38ba8;">)</span> <span style="color: #f38ba8;">{</span> -<span class="linenr">38: </span> printf<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Moving up\n"</span><span style="color: #fab387;">)</span>; -<span class="linenr">39: </span> map<span style="color: #fab387;">[</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">][</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">]</span> = <span style="color: #a6e3a1;">'-'</span>; -<span class="linenr">40: </span> <span style="color: #cba6f7;">if</span> <span style="color: #fab387;">(</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span> == <span style="color: #fab387;">0</span><span style="color: #fab387;">)</span> <span style="color: #fab387;">{</span> -<span class="linenr">41: </span> pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span> = n-<span style="color: #fab387;">1</span>; -<span class="linenr">42: </span> <span style="color: #fab387;">}</span> -<span class="linenr">43: </span> <span style="color: #cba6f7;">else</span> <span style="color: #fab387;">{</span> -<span class="linenr">44: </span> pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span>--; -<span class="linenr">45: </span> <span style="color: #fab387;">}</span> -<span class="linenr">46: </span> <span style="color: #f38ba8;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #cba6f7;">if</span> <span style="color: #f38ba8;">(</span>input == <span style="color: #a6e3a1;">'a'</span><span style="color: #f38ba8;">)</span> <span style="color: #f38ba8;">{</span> -<span class="linenr">47: </span> printf<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Moving left\n"</span><span style="color: #fab387;">)</span>; -<span class="linenr">48: </span> map<span style="color: #fab387;">[</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">][</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">]</span> = <span style="color: #a6e3a1;">'-'</span>; -<span class="linenr">49: </span> <span style="color: #cba6f7;">if</span> <span style="color: #fab387;">(</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span> == <span style="color: #fab387;">0</span><span style="color: #fab387;">)</span> <span style="color: #fab387;">{</span> -<span class="linenr">50: </span> pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span> = m-<span style="color: #fab387;">1</span>; -<span class="linenr">51: </span> <span style="color: #fab387;">}</span> -<span class="linenr">52: </span> <span style="color: #cba6f7;">else</span> <span style="color: #fab387;">{</span> -<span class="linenr">53: </span> pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span>--; -<span class="linenr">54: </span> <span style="color: #fab387;">}</span> -<span class="linenr">55: </span> <span style="color: #f38ba8;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #cba6f7;">if</span> <span style="color: #f38ba8;">(</span>input == <span style="color: #a6e3a1;">'s'</span><span style="color: #f38ba8;">)</span> <span style="color: #f38ba8;">{</span> -<span class="linenr">56: </span> -<span class="linenr">57: </span> printf<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Moving down\n"</span><span style="color: #fab387;">)</span>; -<span class="linenr">58: </span> map<span style="color: #fab387;">[</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">][</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">]</span> = <span style="color: #a6e3a1;">'-'</span>; -<span class="linenr">59: </span> <span style="color: #cba6f7;">if</span> <span style="color: #fab387;">(</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span> == n-<span style="color: #fab387;">1</span><span style="color: #fab387;">)</span> <span style="color: #fab387;">{</span> -<span class="linenr">60: </span> pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span> = <span style="color: #fab387;">0</span>; -<span class="linenr">61: </span> <span style="color: #fab387;">}</span> -<span class="linenr">62: </span> <span style="color: #cba6f7;">else</span> <span style="color: #fab387;">{</span> -<span class="linenr">63: </span> pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span>++; -<span class="linenr">64: </span> <span style="color: #fab387;">}</span> -<span class="linenr">65: </span> <span style="color: #f38ba8;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #cba6f7;">if</span> <span style="color: #f38ba8;">(</span>input == <span style="color: #a6e3a1;">'d'</span><span style="color: #f38ba8;">)</span> <span style="color: #f38ba8;">{</span> -<span class="linenr">66: </span> printf<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Moving right\n"</span><span style="color: #fab387;">)</span>; -<span class="linenr">67: </span> map<span style="color: #fab387;">[</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">0</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">][</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span><span style="color: #fab387;">]</span> = <span style="color: #a6e3a1;">'-'</span>; -<span class="linenr">68: </span> <span style="color: #cba6f7;">if</span> <span style="color: #fab387;">(</span>pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span> == m-<span style="color: #fab387;">1</span><span style="color: #fab387;">)</span> <span style="color: #fab387;">{</span> -<span class="linenr">69: </span> pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span> = <span style="color: #fab387;">0</span>; -<span class="linenr">70: </span> <span style="color: #fab387;">}</span> -<span class="linenr">71: </span> <span style="color: #cba6f7;">else</span> <span style="color: #fab387;">{</span> -<span class="linenr">72: </span> pos<span style="color: #f9e2af;">[</span><span style="color: #fab387;">1</span><span style="color: #f9e2af;">]</span>++; -<span class="linenr">73: </span> <span style="color: #fab387;">}</span> -<span class="linenr">74: </span> <span style="color: #f38ba8;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #cba6f7;">if</span> <span style="color: #f38ba8;">(</span>input == <span style="color: #a6e3a1;">'c'</span><span style="color: #f38ba8;">)</span> <span style="color: #f38ba8;">{</span> -<span class="linenr">75: </span> printf<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Quitting\n"</span><span style="color: #fab387;">)</span>; -<span class="linenr">76: </span> <span style="color: #f38ba8;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #f38ba8;">{</span> -<span class="linenr">77: </span> printf<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Invalid input\n"</span><span style="color: #fab387;">)</span>; -<span class="linenr">78: </span> <span style="color: #f38ba8;">}</span> +<pre class="example" id="org112ebc5"> + if (input == 'w') { + printf("Moving up\n"); + map[pos[0]][pos[1]] = '-'; + if (pos[0] == 0) { + pos[0] = n-1; + } + else { + pos[0]--; + } + } else if (input == 'a') { + printf("Moving left\n"); + map[pos[0]][pos[1]] = '-'; + if (pos[1] == 0) { + pos[1] = m-1; + } + else { + pos[1]--; + } + } else if (input == 's') { + + printf("Moving down\n"); + map[pos[0]][pos[1]] = '-'; + if (pos[0] == n-1) { + pos[0] = 0; + } + else { + pos[0]++; + } + } else if (input == 'd') { + printf("Moving right\n"); + map[pos[0]][pos[1]] = '-'; + if (pos[1] == m-1) { + pos[1] = 0; + } + else { + pos[1]++; + } + } else if (input == 'c') { + printf("Quitting\n"); + } else { + printf("Invalid input\n"); + } </pre> -</div> <p> What this achieves is the “teleportation effect” whenever you are at the border of the screen! @@ -288,7 +281,7 @@ What this achieves is the “teleportation effect” whenever you are at </div> <div id="postamble" class="status"> <p class="author">Author: Crystal</p> -<p class="date">Created: 2024-02-14 Wed 23:43</p> +<p class="date">Created: 2024-02-14 Wed 23:56</p> </div> </body> </html> diff --git a/index.html b/index.html index 56309cd..f015aa2 100755 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> -<!-- 2024-02-14 Wed 23:47 --> +<!-- 2024-02-14 Wed 23:56 --> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Crystal's Website 💜</title> @@ -16,9 +16,9 @@ <body> <div id="content" class="content"> <h1 class="title">Crystal’s Website 💜</h1> -<div id="outline-container-orge660bc6" class="outline-2"> -<h2 id="orge660bc6">Welcome to the wired</h2> -<div class="outline-text-2" id="text-orge660bc6"> +<div id="outline-container-org2d1ff4a" class="outline-2"> +<h2 id="org2d1ff4a">Welcome to the wired</h2> +<div class="outline-text-2" id="text-org2d1ff4a"> <p> Hi there, <a href="./super_secret.html">adorable you!</a> </p> @@ -29,41 +29,41 @@ And welcome to my little corner of the internet, here I will be posting my rando -<div id="org0bb214d" class="figure"> +<div id="orgd5c015a" class="figure"> <p><img src="./src/gifs/Lain_chibi.png" alt="Lain_chibi.png" width="200px" /> </p> </div> </div> </div> -<div id="outline-container-org794e51e" class="outline-2"> -<h2 id="org794e51e">Articles ( NEW !!!! )</h2> -<div class="outline-text-2" id="text-org794e51e"> +<div id="outline-container-org57f13b8" class="outline-2"> +<h2 id="org57f13b8">Articles ( NEW !!!! )</h2> +<div class="outline-text-2" id="text-org57f13b8"> <ul class="org-ul"> <li>*<a href="./articles/feminism1_alex.html">Existing as a woman is a rebellion</a> <i>Thu Nov 2 23:01:23 2023</i></li> <li><b><a href="./articles/discord.html">Discord : an internet cancer</a></b> <i>Sun Sep 10 15:25:22 2023</i></li> </ul> </div> </div> -<div id="outline-container-org7288813" class="outline-2"> -<h2 id="org7288813">Blogs ( NEWER !!!! )</h2> -<div class="outline-text-2" id="text-org7288813"> +<div id="outline-container-orgb8a5c64" class="outline-2"> +<h2 id="orgb8a5c64">Blogs ( NEWER !!!! )</h2> +<div class="outline-text-2" id="text-orgb8a5c64"> </div> -<div id="outline-container-org99193d1" class="outline-3"> -<h3 id="org99193d1">C programming :</h3> -<div class="outline-text-3" id="text-org99193d1"> +<div id="outline-container-org6edf36c" class="outline-3"> +<h3 id="org6edf36c">C programming :</h3> +<div class="outline-text-3" id="text-org6edf36c"> <ul class="org-ul"> -<li><b><a href="https://crystal.tilde.institute/blog/c/game.html">The Lonelyness game</a></b> <i>Wed Feb 14 23:46:35 2024</i></li> +<li><b><a href="https://crystal.tilde.institute/blog/c/game.html">The Loneliness game</a></b> <i>Wed Feb 14 23:46:35 2024</i></li> </ul> </div> </div> </div> -<div id="outline-container-orgd610391" class="outline-2"> -<h2 id="orgd610391">root@localhost $ whoami</h2> -<div class="outline-text-2" id="text-orgd610391"> +<div id="outline-container-org4bc18bb" class="outline-2"> +<h2 id="org4bc18bb">root@localhost $ whoami</h2> +<div class="outline-text-2" id="text-org4bc18bb"> </div> -<div id="outline-container-org9c40587" class="outline-3"> -<h3 id="org9c40587">About me :</h3> -<div class="outline-text-3" id="text-org9c40587"> +<div id="outline-container-orga9e4106" class="outline-3"> +<h3 id="orga9e4106">About me :</h3> +<div class="outline-text-3" id="text-orga9e4106"> <ul class="org-ul"> <li>Name : <b>Crystal</b></li> <li>Age : <b>18 years old</b></li> @@ -82,9 +82,9 @@ If you want to contact me (which would be really surprising) contact me via <a h </p> </div> </div> -<div id="outline-container-org932da6e" class="outline-3"> -<h3 id="org932da6e">About my Navi :</h3> -<div class="outline-text-3" id="text-org932da6e"> +<div id="outline-container-orgf9937a4" class="outline-3"> +<h3 id="orgf9937a4">About my Navi :</h3> +<div class="outline-text-3" id="text-orgf9937a4"> <p> My current setup is : </p> @@ -111,23 +111,23 @@ My GNUPG (GPG) public key <a href="./src/txt/pubkey.asc">./src/txt/pubkey.asc</a </div> </div> </div> -<div id="outline-container-orgbfe6b3c" class="outline-2"> -<h2 id="orgbfe6b3c">Sign my Guestbook (External website warning)</h2> -<div class="outline-text-2" id="text-orgbfe6b3c"> +<div id="outline-container-orgfea63da" class="outline-2"> +<h2 id="orgfea63da">Sign my Guestbook (External website warning)</h2> +<div class="outline-text-2" id="text-orgfea63da"> <p> Want to leave a message, opinion, review or a salty insult ? Be sure to Sign my Guestbook then, it takes two seconds but it will mean the world to me !!! </p> -<div id="org84d39f6" class="figure"> +<div id="org6ed9b6d" class="figure"> <p><a href="https://crystaltilde.123guestbook.com/"><img src="./src/gifs/links/sign_my_guestbook-anim.gif" alt="sign_my_guestbook-anim.gif" /></a> </p> </div> </div> </div> -<div id="outline-container-orgb00ebc5" class="outline-2"> -<h2 id="orgb00ebc5">Blinkies</h2> -<div class="outline-text-2" id="text-orgb00ebc5"> +<div id="outline-container-orgca88b51" class="outline-2"> +<h2 id="orgca88b51">Blinkies</h2> +<div class="outline-text-2" id="text-orgca88b51"> <a href="http://validator.w3.org/check?uri=referer"><img src="./src/gifs/blinkies/valid-xhtml10.png" alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a> <a href="https://jigsaw.w3.org/css-validator/check/referer"> @@ -157,20 +157,20 @@ Want to leave a message, opinion, review or a salty insult ? Be sure to Sign my <a href="https://partysepe13.neocities.org/"><img src="./src/gifs/blinkies/partysepe.png" alt="partysepe.png" /></a> </p> </div> -<div id="outline-container-orgd62e9af" class="outline-3"> -<h3 id="orgd62e9af">My banner</h3> -<div class="outline-text-3" id="text-orgd62e9af"> +<div id="outline-container-org913f2cf" class="outline-3"> +<h3 id="org913f2cf">My banner</h3> +<div class="outline-text-3" id="text-org913f2cf"> <p> If you enjoyed my website, you could link me on your personal website using this banner. If you don’t want to, then no pressure 💜 I still love you and I hope that this small shrine of mine will impress you in the future!!! </p> -<div id="org8640b83" class="figure"> +<div id="orgb3966a1" class="figure"> <p><img src="./src/gifs/crystal-tilde.gif" alt="crystal-tilde.gif" /> </p> </div> -<div id="orgb259f28" class="figure"> +<div id="orgd147e57" class="figure"> <p><img src="./src/gifs/my_buttons/lain_crystal_glitch.gif" alt="lain_crystal_glitch.gif" width="240px" /> </p> </div> @@ -181,12 +181,12 @@ If you enjoyed my website, you could link me on your personal website using this </div> </div> </div> -<div id="outline-container-org533130e" class="outline-2"> -<h2 id="org533130e"><a href="https://crystal.tilde.institute/links.html">Close this website, txEn eht nepO.( Webrings , so expect JavaScript on this page)!!</a></h2> +<div id="outline-container-org6f434af" class="outline-2"> +<h2 id="org6f434af"><a href="https://crystal.tilde.institute/links.html">Close this website, txEn eht nepO.( Webrings , so expect JavaScript on this page)!!</a></h2> </div> -<div id="outline-container-org8c456d5" class="outline-2"> -<h2 id="org8c456d5">Misc :</h2> -<div class="outline-text-2" id="text-org8c456d5"> +<div id="outline-container-orga0d929f" class="outline-2"> +<h2 id="orga0d929f">Misc :</h2> +<div class="outline-text-2" id="text-orga0d929f"> <ol class="org-ol"> <li><b><a href="./uni_notes/">My University notes</a></b></li> </ol> @@ -195,7 +195,7 @@ If you enjoyed my website, you could link me on your personal website using this </div> <div id="postamble" class="status"> <p class="author">Author: Crystal</p> -<p class="date">Created: 2024-02-14 Wed 23:47</p> +<p class="date">Created: 2024-02-14 Wed 23:56</p> </div> </body> </html> diff --git a/src/org/blog/c/game.org b/src/org/blog/c/game.org index 3ed154e..7e9c49a 100644 --- a/src/org/blog/c/game.org +++ b/src/org/blog/c/game.org @@ -19,7 +19,7 @@ Hello !!, I hope you are doing great you amazing person whoever you are, and I r Basically the player is faced with a NxM field made up with the sign *"-"* and the player is denoted by the symbol *"+"*, there are also Bonuses *"B"* which add 1 to your score, Traps *"T"*, that remove one from your score, and Dead *"D"* which resets the score to 0. I will go into more of the specifics later but for now this is how it works, and the controls are Basic WASD bindings, though i may go for a HJKL style later. ** The code : - #+BEGIN_SRC c -n + #+BEGIN_EXAMPLE #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { @@ -147,41 +147,41 @@ int main(int argc, char *argv[]) { return 0; } - #+END_SRC + #+END_EXAMPLE Let's go step by step and see what we can fix or improve, to start off, line 4 to 10 can be reduced to a single line (which will be beneficial later too) - #+BEGIN_SRC c -n 4 + #+BEGIN_EXAMPLE char input,map[5][5] = {'-'}; - #+END_SRC + #+END_EXAMPLE Much better...but can be even more better, why stop at 5 when we can give the choice to the user !! - #+BEGIN_SRC c -n 4 + #+BEGIN_EXAMPLE int n=5,m=5; char input,map[n][m]={'-'}; - #+END_SRC + #+END_EXAMPLE For now at least, n and m are hardcoded to 5, but this will change later. Of course we have the usual inits on line 11, though since we are using variables instead of hardcoding 5, we will have to find the center by ourselves - #+BEGIN_SRC c -n 11 + #+BEGIN_EXAMPLE int stop=0,i=0,moves=0,score=0,pos[2] = {n/2,m/2}; - #+END_SRC + #+END_EXAMPLE This is getting better, of course we then initialize the coordinates of bonus, trap, and death, and set the player as a *'+'* in the field. Here comes the line 17-21, where it generates a random coordinate for the aforementioned pickups, and do that until there is no conflict between eachother and the player) here we will need to change it a tiny bit. - #+BEGIN_SRC c -n 17 + #+BEGIN_EXAMPLE bonus[0] = arc4random_uniform(n); bonus[1] = arc4random_uniform(m); trap[0] = arc4random_uniform(n); trap[1] = arc4random_uniform(m); death[0] = arc4random_uniform(n); death[1] = arc4random_uniform(m); - #+END_SRC + #+END_EXAMPLE Looking good so far!!, We then have line 21-23 which also shows the pickups as their respective symbols in the map. The main interactive program starts here, which will learn at least one time and stop if the received input is a *'c'*, it starts with a nested for loop on line 26 up to 31 to show the content of the map, nothing fancy, just some matrix stuff. we need to change the 5 though! - #+BEGIN_SRC c -n 26 + #+BEGIN_EXAMPLE for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { printf("%c ", map[i][j]); @@ -189,11 +189,11 @@ The main interactive program starts here, which will learn at least one time and printf("\n"); } - #+END_SRC + #+END_EXAMPLE We show the score and the moves too, which at the start of the game are set to 0. and we prompt the user for a direction. Note here the space before the %c, this basically allows for the program to not choke on newlines and also even if the user writes multiple keys at the same time, they will still be done, like *ww* will make the player move twice up. After that we have some logic which should also be changed to account for the n and m changes yet again -#+BEGIN_SRC c -n 37 +#+BEGIN_EXAMPLE if (input == 'w') { printf("Moving up\n"); map[pos[0]][pos[1]] = '-'; @@ -236,6 +236,6 @@ After that we have some logic which should also be changed to account for the n } else { printf("Invalid input\n"); } -#+END_SRC +#+END_EXAMPLE What this achieves is the "teleportation effect" whenever you are at the border of the screen! diff --git a/src/org/index.org b/src/org/index.org index 8d13bf0..61c9236 100755 --- a/src/org/index.org +++ b/src/org/index.org @@ -22,7 +22,7 @@ And welcome to my little corner of the internet, here I will be posting my rando - *[[./articles/discord.html][Discord : an internet cancer]]* /Sun Sep 10 15:25:22 2023/ * Blogs ( NEWER !!!! ) ** C programming : -- *[[https://crystal.tilde.institute/blog/c/game.html][The Lonelyness game]]* /Wed Feb 14 23:46:35 2024/ +- *[[https://crystal.tilde.institute/blog/c/game.html][The Loneliness game]]* /Wed Feb 14 23:46:35 2024/ * root@localhost $ whoami ** About me : - Name : *Crystal* |