Iman Anwarzai 1 year ago
parent
commit
d20b602e02
10 changed files with 35 additions and 8 deletions
  1. 13 4
      board.c
  2. BIN
      board.o
  3. BIN
      boggle
  4. 4 2
      boggle.h
  5. BIN
      dictionaryChecker.o
  6. BIN
      scoreboard.o
  7. 17 1
      signals.c
  8. BIN
      signals.o
  9. BIN
      user.o
  10. 1 1
      users.txt

+ 13 - 4
board.c

@@ -5,14 +5,14 @@
 #include <ctype.h>
 #include <unistd.h>
 #include "boggle.h"
-//not working
 
 extern int signaled;
 extern int rounds;
-
+extern int end;
 char dice[16][6]; 
 int rounds = 1;
 int signaled = 0;
+int end = 0;
 
 void freeall(int ** arr){
         for(int i = 0; i < 4; i++)
@@ -133,7 +133,8 @@ int main () {
         arr[1] = malloc(sizeof(char) * 4);
         arr[2] = malloc(sizeof(char) * 4);
         arr[3] = malloc(sizeof(char) * 4);
-	create_sigaction();
+	create_sigaction_rounds();
+	create_sigaction_endgame();
         createboard(arr);
 
         int score = 0;
@@ -197,8 +198,16 @@ int main () {
 			displayScoreboard(head_s);
 			createboard(arr);
 			signaled = 0;
+			userUpdate(head, user, score);
 			alarm(TIME_INTERVAL);
 		}
+		else if(end == 1) {
+			system("clear");
+			printf("A signal has been recived to end the game :,(\n");
+			displayScoreboard(head_s);
+			printf("Goodbye!\n");
+			break;
+		}
 		else if(strcmp(word, "u") == 0){
 			char * entered = malloc(2);
 			printf("are you sure you want to logout? press y or n\n");
@@ -206,7 +215,7 @@ int main () {
 			if(strcmp(entered, "y") == 0){
 				rounds = 1;
 				system("clear");
-				userUpdate(head, user, score);
+//				userUpdate(head, user, score);
 			//User * p = head;
 			//while(p->next)
 			//	p = p->next;

BIN
board.o


BIN
boggle


+ 4 - 2
boggle.h

@@ -4,9 +4,10 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#define TIME_INTERVAL 10
+#define TIME_INTERVAL 60
 extern int rounds;
 extern int signaled;
+extern int end;
 
 typedef struct user {
         char * name;
@@ -36,6 +37,7 @@ void freeLL_s(User_s * head);
 void displayScoreboard(User_s * head);
 int isInDictionary(char * word);
 int hasBeenUsed(char ** words, char * word);
-int create_sigaction();
+int create_sigaction_rounds();
+int create_sigaction_endgame();
 void createboard(char ** arr);
 #endif

BIN
dictionaryChecker.o


BIN
scoreboard.o


+ 17 - 1
signals.c

@@ -9,6 +9,7 @@
 
 extern int rounds;
 extern int signaled;
+extern int end;
 
 void new_round (int sig) {
         //system("clear");
@@ -21,7 +22,7 @@ void new_round (int sig) {
 }
 
 
-int create_sigaction() {
+int create_sigaction_rounds() {
         //create sigaction variable
 	struct sigaction action;
         action.sa_handler = new_round;
@@ -33,6 +34,21 @@ int create_sigaction() {
         return 0;
 } 
 
+void end_game (int sig) {
+	end = 1;
+}
+
+int create_sigaction_endgame() {
+        //create sigaction variable
+	struct sigaction action;
+        action.sa_handler = end_game;
+        sigemptyset(&action.sa_mask);
+        action.sa_flags = 0;
+        //register new handling behaviour
+        sigaction(SIGINT, &action, NULL);
+        //int i = 0;
+        return 0;
+}
 /*char *name;
 
 void sing(int code) {

BIN
signals.o


BIN
user.o


+ 1 - 1
users.txt

@@ -1,4 +1,4 @@
-iman 9 169 101
+iman 9 171 101
 alena 4 8 7
 ella 7 15 10
 ale 2 12 5