矩阵游戏遇到的问题
先用一个矩阵做一个地图,然后再用一个函数设置地图上的石头,石头在地图里返回1 石头不能再地图外否则返回0; 但我不知道石头的函数应该怎样修改#include<stdio.h>
#include<stdlib.h>
#include "tt.h"
#define M 6
int map(){
int i,j;
int tab={};
for (i=0;i<M;i++){
for(j=0;j<M;j++){
printf("%d ",tab);
}
printf("\n");
}
return 0;
}
int shitou(int lig, int col){
int i,j,tab={};
if(tab!=map())
return 0;
else
return 1;
}
int main(){
int c;
c=shitou(3,2);
return 0;
} 所以你的思路描述的很清晰了,但是你的代码中shitou()函数是要做什么用呢? 怪,你的地图不是共享的,变成全局变量,然后用石头函数在地图上放置石头不就好了吗?
int map;
void rock(int x, int y){
if( x < M && y < M)
map = 1;
}
你要传入地图也可以,这样比较简单。抱歉哈,手机不方便上代码~ newu 发表于 2018-10-6 08:44
所以你的思路描述的很清晰了,但是你的代码中shitou()函数是要做什么用呢?
石头的函数是为了在地图上放置石头啊 claws0n 发表于 2018-10-6 09:10
怪,你的地图不是共享的,变成全局变量,然后用石头函数在地图上放置石头不就好了吗?
int map;
vo ...
就是这里搞不懂 如何让地图共享 怎么去变全局变量 qpwoeiruyt 发表于 2018-10-6 16:28
就是这里搞不懂 如何让地图共享 怎么去变全局变量
不在任何{}内的就是全局变量,照我给你的就行了 claws0n 发表于 2018-10-6 11:05
不在任何{}内的就是全局变量,照我给你的就行了
这样吗?
#include<stdio.h>
#include<stdlib.h>
#include "tt.h"
#define M 6
int map(){
int i,j;
int tab={};
for (i=0;i<M;i++){
for(j=0;j<M;j++){
printf("%d ",tab);
}
printf("\n");
}
return 0;
}
int map;
void shitou(int lig,int col){
if(lig<M&&col<M)
map=1;
else
map=0;
}
int main(){
int c;
c=shitou(3,2);
return 0;
}
qpwoeiruyt 发表于 2018-10-6 19:06
这样吗?
#include
#include <stdio.h>
#define M 6
int map;
void shitou(int x, int y)
{
if(x < M && y < M)
map = 1;
}
void print(int arr[])
{
for(int i = 0; i < M; i++){
for(int j = 0; j < M; j++)
printf("%d ", arr);
printf("\n");}
printf("\n");
}
int main()
{
print(map);
shitou(2,3);
print(map);
return 0;
}c = shitou(3,2); ?什么作用? claws0n 发表于 2018-10-6 12:16
c = shitou(3,2); ?什么作用?
shitou 23 用来设置石头的位置 claws0n 发表于 2018-10-6 12:16
c = shitou(3,2); ?什么作用?
那我想把石头换成X是在 石头的函数里换还是在打印的函数里换?然后x 要变成 char 不能是int吗? qpwoeiruyt 发表于 2018-10-6 20:06
shitou 23 用来设置石头的位置
你把它赋给一个变量是不会有任何作用的
嗯,char map; #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)
{
for(int h = 0; h < MAP_WIDTH; ++h)
{
for(int w = 0; w < MAP_WIDTH; ++w)
{
map = MAP_SPACE;
}
}
}
void MapSetStone(unsigned char map, unsigned int x, unsigned int y)
{
if((x >= MAP_WIDTH) || (y >= MAP_WIDTH))
return;
map = MAP_STONE;
}
void MapPrint(unsigned char map)
{
for(int h = 0; h < MAP_WIDTH; ++h)
{
for(int w = 0; w < MAP_WIDTH; ++w)
{
GotoXY(w, h);
switch(map)
{
case MAP_SPACE:
puts("※");
break;
case MAP_STONE:
puts("●");
break;
}
}
}
}
int main(void)
{
HideCursor();
unsigned char map;
MapInit(map);
MapSetStone(map, 1, 1);
MapSetStone(map, 2, 1);
MapSetStone(map, 3, 5);
MapSetStone(map, 3, 4);
MapPrint(map);
return 0;
}
claws0n 发表于 2018-10-6 13:25
你把它赋给一个变量是不会有任何作用的
嗯,char map;
但是这样子变不了啊?
void print(char arr[])
{
int i,j;
for(i = 0; i < M; i++){
for(j = 0; j < M; j++){
if (arr==8)
arr='X'
printf("%d ", arr);}
printf("\n");}
printf("\n");
} qpwoeiruyt 发表于 2018-10-6 23:35
但是这样子变不了啊?
void print(char arr[])
那个是打印,修改的是另一个函数{:10_250:} claws0n 发表于 2018-10-6 16:54
那个是打印,修改的是另一个函数
不能在打印的函数里面改吗? 但我试着在石头的函数里改也不行啊 qpwoeiruyt 发表于 2018-10-6 23:55
不能在打印的函数里面改吗? 但我试着在石头的函数里改也不行啊
{:10_266:}你有没有看懂我和楼上大佬的代码呀?
修改是修改,打印是打印
你要修改+打印的话,在修改的函数里边套打印的函数 claws0n 发表于 2018-10-6 16:59
你有没有看懂我和楼上大佬的代码呀?
修改是修改,打印是打印
你要修改+打印的话,在修改的 ...
看得不是太懂你的代码里哪个是修改的函数?石头那个? qpwoeiruyt 发表于 2018-10-7 00:58
看得不是太懂你的代码里哪个是修改的函数?石头那个?
是的,按照你的思路写的,不能明白?{:10_250:} claws0n 发表于 2018-10-6 18:02
是的,按照你的思路写的,不能明白?
感谢大佬我在本版发的另一个问题怎么解决呢? 读取文件的字符 判断是不是回文我的编码出现了segmentation fault
页:
[1]