1.3. マップの配列を宣言しよう

まずはマップの配列を作ります。gboolean map[MAP_W][MAP_H];。FALSEが壁、TRUEが通れるところ。配列を初期化します。


#include <glib.h>

enum {
  MAP_W = 50,
  MAP_H = 40
};

gboolean map[MAP_W][MAP_H];

int main(int argc, char *argv[])
{
  int i, j;
  for (j = 0; j < MAP_H; j++) {
    for (i = 0; i < MAP_W; i++) {
      map[i][j] = FALSE;
    };
  };
  for (j = 0; j < MAP_H; j++) { 
    for (i = 0; i < MAP_W; i++) {
      if (map[i][j]) g_print("#") else g_print(".");
    }; 
    g_print("\n"); 
  }; 
  return 0;
} 

出力してみます。

[user@machine ~/dir]$ ./test
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................