summary refs log tree commit diff stats
path: root/src/org/blog/c/game.org
diff options
context:
space:
mode:
authorCrystal <crystal@wizard.tower>2024-02-22 19:09:31 +0100
committerCrystal <crystal@wizard.tower>2024-02-22 19:09:31 +0100
commitd76770c2a56bcc5cb795661d76e24f6116f26154 (patch)
tree2b143354dd465d941d6d53573bc0cfcfb464faab /src/org/blog/c/game.org
parent0e5f79d7bcf76abb6712ad3ecf69f28f27019fc2 (diff)
downloadwww-d76770c2a56bcc5cb795661d76e24f6116f26154.tar.gz
Add stuff
Diffstat (limited to 'src/org/blog/c/game.org')
-rw-r--r--src/org/blog/c/game.org64
1 files changed, 57 insertions, 7 deletions
diff --git a/src/org/blog/c/game.org b/src/org/blog/c/game.org
index 3ed154e..1f618e4 100644
--- a/src/org/blog/c/game.org
+++ b/src/org/blog/c/game.org
@@ -150,17 +150,19 @@ int main(int argc, char *argv[]) {
     #+END_SRC
 
 
-    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
-char input,map[5][5] = {'-'};
-    #+END_SRC
-    Much better...but can be even more better, why stop at 5 when we can give the choice to the user !!
+    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)
     #+BEGIN_SRC c -n 4
 int n=5,m=5;
-char input,map[n][m]={'-'};
+char input,map[50][50];
+    for (int i = 0; i < n; i++) {
+        for (int j = 0; j < m; j++) {
+            map[i][j] = '-';
+        }
+    }
+
     #+END_SRC
 
-    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
 
     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
@@ -239,3 +241,51 @@ After that we have some logic which should also be changed to account for the n
 #+END_SRC
 
 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
+#+BEGIN_SRC c -n 80
+    if (pos[0] == bonus[0] && pos[1] == bonus[1]) {
+        score++;
+        do{
+        bonus[0]= arc4random_uniform(n);
+        bonus[1]= arc4random_uniform(m);
+        }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(n);
+        trap[1]= arc4random_uniform(m);
+        }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(n);
+        death[1]= arc4random_uniform(m);
+        }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(n);
+        death[1]= arc4random_uniform(m);
+        }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(n);
+        trap[1]= arc4random_uniform(m);
+        }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]));
+
+    }
+#+END_SRC
+
+
+Aaaaand this should be it