博客搬家:最爱午后红茶
写完基于Linux中curses库的贪吃蛇,发现只需要用到一个WIN的API(移动光标那个)改写move(int y, int x)函数,然后加上conio.h(一般编译器都会包含这个头文件)的getch(),就可以在Windows系统运行!
Linux版链接:http://blog.youkuaiyun.com/u013351484/article/details/43940803
游戏规则:
初始时两条蛇会在中间,一条蛇头是'@',食物是‘$’;另一条蛇头是'+',食物是'*',蛇身都是'#'。WASD控制'+'蛇方向,方向键控制'@'蛇方向,空格键暂停游戏,再按一次继续游戏。每条蛇只能吃自己的食物。撞墙,碰到自己或另一条蛇的身体,吃到另一条蛇的食物都会结束游戏。
运行环境:windows系统
编译器:VC++, g++,gcc, VS
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
#define LINES 23
#define COLS 70
int dir_y[] = {-1, 1, 0, 0};
int dir_x[] = {0, 0, -1, 1};
int vis[100][100];
int scord;
typedef struct body
{
int y, x;
struct bod