From d76770c2a56bcc5cb795661d76e24f6116f26154 Mon Sep 17 00:00:00 2001 From: Crystal Date: Thu, 22 Feb 2024 19:09:31 +0100 Subject: Add stuff --- blog/c/game.html | 90 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 19 deletions(-) (limited to 'blog') diff --git a/blog/c/game.html b/blog/c/game.html index 6543e5a..90c1965 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"> - + The loneliness Game @@ -23,17 +23,17 @@

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!

-
-

The concept :

-
+
+

The concept :

+

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 :

-
+
+

The code :

+
  1: #include <stdio.h>
   2: #include <stdlib.h>
@@ -167,23 +167,22 @@ Basically the player is faced with a NxM field made up with the sign “-
 
 
 

-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) +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 7 or 8 lines (which will be beneficial later too)

-
4: char input,map[5][5] = {'-'};
-
-
-

-Much better…but can be even more better, why stop at 5 when we can give the choice to the user !! -

-
-
4: int n=5,m=5;
-5: char input,map[n][m]={'-'};
+
 4: int n=5,m=5;
+ 5: char input,map[50][50];
+ 6:     for (int i = 0; i < n; i++) {
+ 7:         for (int j = 0; j < m; j++) {
+ 8:             map[i][j] = '-';
+ 9:         }
+10:     }
+11: 
 

-For now at least, n and m are hardcoded to 5, but this will change later. +For now at least, n and m are hardcoded to 5, but this will change later. And I picked 50x50 as a max size because why not

@@ -283,12 +282,65 @@ After that we have some logic which should also be changed to account for the n

What this achieves is the “teleportation effect” whenever you are at the border of the screen!

+ + +

+Now we fix things from line 80 to the end of the program, aka replacing ever occurrence of 5 with n or m +

+
+
 80:     if (pos[0] == bonus[0] && pos[1] == bonus[1]) {
+ 81:         score++;
+ 82:         do{
+ 83:         bonus[0]= arc4random_uniform(n);
+ 84:         bonus[1]= arc4random_uniform(m);
+ 85:         }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]));
+ 86:     }
+ 87:     if (pos[0] == trap[0] && pos[1] == trap[1]) {
+ 88:         score--;
+ 89:         do{
+ 90:         trap[0]= arc4random_uniform(n);
+ 91:         trap[1]= arc4random_uniform(m);
+ 92:         }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]));
+ 93:         }
+ 94:     if (pos[0] == death[0] && pos[1] == death[1]) {
+ 95:         score = 0;
+ 96:         do{
+ 97:         death[0]= arc4random_uniform(n);
+ 98:         death[1]= arc4random_uniform(m);
+ 99:         }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]));
+100:     }
+101:     if (score % 3 == 0 && score != 0 && stop == 0) {
+102:         map[death[0]][death[1]] = '-';
+103:         do{
+104:         death[0]= arc4random_uniform(n);
+105:         death[1]= arc4random_uniform(m);
+106:         }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]));
+107:         stop = 1;
+108:     }
+109:     else if (score % 3 != 0) {
+110:     stop = 0;
+111:     }
+112:     if (moves % 5 == 0 && moves != 0) {
+113:         do{
+114:             map[trap[0]][trap[1]] = '-';
+115:         trap[0]= arc4random_uniform(n);
+116:         trap[1]= arc4random_uniform(m);
+117:         }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]));
+118: 
+119:     }
+
+
+ + +

+Aaaaand this should be it +

Author: Crystal

-

Created: 2024-02-15 Thu 00:09

+

Created: 2024-02-22 Thu 19:09

-- cgit 1.4.1-2-gfad0