|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
先用一个矩阵做一个地图,然后再用一个函数设置地图上的石头,石头在地图里返回1 石头不能再地图外否则返回0; 但我不知道石头的函数应该怎样修改
#include<stdio.h>
#include<stdlib.h>
#include "tt.h"
#define M 6
int map(){
int i,j;
int tab[M][M]={};
for (i=0;i<M;i++){
for(j=0;j<M;j++){
printf("%d ",tab[i][j]);
}
printf("\n");
}
return 0;
}
int shitou(int lig, int col){
int i,j,tab[M][M]={};
if(tab[i][j]!=map())
return 0;
else
return 1;
}
int main(){
int c;
c=shitou(3,2);
return 0;
}
- #include <stdio.h>
- #include <windows.h>
- #define MAP_WIDTH 6
- #define MAP_SPACE 0
- #define MAP_STONE 1
- static void GotoXY(unsigned int x, unsigned int y)
- {
- COORD coord = {x * 2, y}; // unicode
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- static void HideCursor()
- {
- CONSOLE_CURSOR_INFO cci;
- cci.bVisible = FALSE;
- cci.dwSize = sizeof(cci);
- HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleCursorInfo(handle, &cci);
- }
- void MapInit(unsigned char map[MAP_WIDTH][MAP_WIDTH])
- {
- for(int h = 0; h < MAP_WIDTH; ++h)
- {
- for(int w = 0; w < MAP_WIDTH; ++w)
- {
- map[h][w] = MAP_SPACE;
- }
- }
- }
- void MapSetStone(unsigned char map[MAP_WIDTH][MAP_WIDTH], unsigned int x, unsigned int y)
- {
- if((x >= MAP_WIDTH) || (y >= MAP_WIDTH))
- return;
- map[y][x] = MAP_STONE;
- }
- void MapPrint(unsigned char map[MAP_WIDTH][MAP_WIDTH])
- {
- for(int h = 0; h < MAP_WIDTH; ++h)
- {
- for(int w = 0; w < MAP_WIDTH; ++w)
- {
- GotoXY(w, h);
- switch(map[h][w])
- {
- case MAP_SPACE:
- puts("※");
- break;
- case MAP_STONE:
- puts("●");
- break;
- }
- }
- }
- }
- int main(void)
- {
- HideCursor();
- unsigned char map[MAP_WIDTH][MAP_WIDTH];
- MapInit(map);
- MapSetStone(map, 1, 1);
- MapSetStone(map, 2, 1);
- MapSetStone(map, 3, 5);
- MapSetStone(map, 3, 4);
- MapPrint(map);
- return 0;
- }
复制代码
|
|