garten
annotate clock.c @ 18:5937504619f2
rename game.h -> modules.h; added some error handling; and more
author | meillo@marmaro.de |
---|---|
date | Wed, 23 Jul 2008 17:40:55 +0200 |
parents | 5e6c9260913a |
children |
rev | line source |
---|---|
meillo@0 | 1 #include <stdio.h> |
meillo@0 | 2 #include <stdlib.h> |
meillo@0 | 3 #include "db.h" |
meillo@0 | 4 |
meillo@0 | 5 |
meillo@18 | 6 int inc_time() { |
meillo@0 | 7 /* get current time */ |
meillo@11 | 8 sprintf(query, "select time from game;"); |
meillo@17 | 9 stmt = db_query(query); |
meillo@11 | 10 if (sqlite3_step(stmt) == SQLITE_ROW) { |
meillo@11 | 11 gametime = sqlite3_column_int(stmt, 0); |
meillo@11 | 12 } else { |
meillo@17 | 13 db_error("get current time"); |
meillo@18 | 14 return 0; |
meillo@0 | 15 } |
meillo@11 | 16 sqlite3_finalize(stmt); |
meillo@0 | 17 |
meillo@0 | 18 /* increment time */ |
meillo@17 | 19 sprintf(query, |
meillo@18 | 20 "update game " |
meillo@17 | 21 "set time = '%d';" |
meillo@17 | 22 , ++gametime |
meillo@17 | 23 ); |
meillo@12 | 24 if (!db_update(query)) { |
meillo@17 | 25 db_error("time update"); |
meillo@18 | 26 return 0; |
meillo@0 | 27 } |
meillo@18 | 28 return 1; |
meillo@0 | 29 } |
meillo@0 | 30 |
meillo@0 | 31 |
meillo@18 | 32 int worldclock(void) { |
meillo@18 | 33 int ret; |
meillo@18 | 34 |
meillo@18 | 35 ret = inc_time(); |
meillo@12 | 36 printf("gametime: %d\n", gametime); |
meillo@18 | 37 |
meillo@18 | 38 return ret; |
meillo@0 | 39 } |