garten
annotate clock.c @ 17:5e6c9260913a
lots of cleanups and small fixes
author | meillo@marmaro.de |
---|---|
date | Wed, 23 Jul 2008 17:14:38 +0200 |
parents | 8db6497d6065 |
children | 5937504619f2 |
rev | line source |
---|---|
meillo@0 | 1 #include <stdio.h> |
meillo@0 | 2 #include <stdlib.h> |
meillo@0 | 3 #include "db.h" |
meillo@2 | 4 #include "game.h" |
meillo@0 | 5 |
meillo@0 | 6 |
meillo@2 | 7 void inc_time() { |
meillo@0 | 8 /* get current time */ |
meillo@11 | 9 sprintf(query, "select time from game;"); |
meillo@17 | 10 stmt = db_query(query); |
meillo@11 | 11 if (sqlite3_step(stmt) == SQLITE_ROW) { |
meillo@11 | 12 gametime = sqlite3_column_int(stmt, 0); |
meillo@11 | 13 } else { |
meillo@17 | 14 db_error("get current time"); |
meillo@0 | 15 } |
meillo@11 | 16 sqlite3_finalize(stmt); |
meillo@0 | 17 |
meillo@0 | 18 /* increment time */ |
meillo@17 | 19 sprintf(query, |
meillo@17 | 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@0 | 26 } |
meillo@0 | 27 } |
meillo@0 | 28 |
meillo@0 | 29 |
meillo@12 | 30 void worldclock(void) { |
meillo@2 | 31 inc_time(); |
meillo@12 | 32 printf("gametime: %d\n", gametime); |
meillo@0 | 33 } |