changeset 1102:dbea3e42bf93

Initial random number generator for tank
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 05 Dec 2010 13:47:07 +0800
parents e1a76d10953e
children 2b8b6deb35c8
files examples/tank/enemy.c examples/tank/tank_main.c
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/examples/tank/enemy.c	Sun Dec 05 13:37:13 2010 +0800
+++ b/examples/tank/enemy.c	Sun Dec 05 13:47:07 2010 +0800
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <time.h>
 #include <stdlib.h>
 #include <string.h>
 #include "tank.h"
@@ -219,13 +220,16 @@
 enemy_tank_driver(int hdl, const mb_timeval_t *tmo,
 		  const mb_timeval_t *now, void *data) {
     tank_rt_t *tank_rt = (tank_rt_t *)data;
+    enemy_t *enemy;
     int n_enemy;
     mb_timeval_t timeout, addend;
     int i;
     
     n_enemy = tank_rt->n_enemy;
     for(i = 0; i < n_enemy; i++) {
-	_drive_enemy_tank(enemies + i);
+	enemy = enemies + i;
+	if(enemy->tank->progm == NULL)
+	    _drive_enemy_tank(enemy);
     }
     
     get_now(&timeout);
@@ -268,5 +272,6 @@
 	    enemies[i].memory[j] = SOMETHING;
     }
 
+    srand(time(NULL));
     start_enemy_tank_timer(tank_rt);
 }
--- a/examples/tank/tank_main.c	Sun Dec 05 13:37:13 2010 +0800
+++ b/examples/tank/tank_main.c	Sun Dec 05 13:47:07 2010 +0800
@@ -666,7 +666,7 @@
 
     initial_tank(&tank_rt, rt);
     
-    /* init_enemies(&tank_rt); */
+    init_enemies(&tank_rt);
     
     mb_runtime_event_loop(rt);