2015/1/22【新提醒】c语言编写小游戏系列教程之推动箱子,C/C++,自学去
22. #include <input.h>23. #include <view.h>24. #include <tool.h>25. #include <update.h>26. #include <obstacle.h>27. #include <target.h>
28. 29. 30. 31. /*extern 表示是一个在其他文件中定义的变量,真正的变量在main.c中定义了32. 如果把全局变量定义在头文件中,会造成多个文件包含这个头文件的时候,33. 都是单独的变量,访问到的并不是同一个全局变量。34. 比如:
35. box.c 包含了 config.h36. main.c 也包含了 config.h
37. 38. 这样 其实就产生了2个 同样的变量, 在main.c 中改变的是属于main.c 的 不会影响到box.c 的。39. 40. 这不是我们想看到的,比如 我们在main.c中改变了箱子位置,但是 box.c中的位置还是没变。
41. 42. 所以,我们要让这个变量全局唯一,就只能在一处声明,别的地方用 extern表明变量已经在其他文件声明了,43. 这样 使用的就是同一个变量。44. */
45. extern dir_t kdir;46. extern game_state_t gs;47. extern char map[H][W];48. extern person_t person; 49. extern box_t box[4]; 50. extern obstacle_t obs[4];51. extern target_t tar[4];52. 53.
#endif