マップのローマ字のAが赤くするにはどうしたらいいのでしょうか...
ゲームの作成途中で、まったくわからなくなったため投稿させていただきました。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/*構造体定義*/
typedef struct
{
char type;/*種類*/
int omote;/*表フラグ*/
int atari;/*当りフラグ*/
}KEY;
//マップデータ
#define MAXWIDTH 12
#define MAXHEIGHT 9
int g_mapdata[MAXHEIGHT][MAXWIDTH] = {
// 0 1 2 3 4 5 6 7 8 9 10 11
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //0
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, //1
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, //2
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, //3
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, //4
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, //5
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, //6
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, //7
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} //8
};
KEY dt[26];
//プロトタイプ宣言
void shuffle(KEY *);
void init(KEY *);
void mapdeta(void);//マップ作成関数
/****************************/
//メイン関数
/****************************/
void main(void)
{
srand((unsigned int)time(NULL));
system("cls");
mapdeta();
}
void init(KEY *pt){
char c[26]={'A','B','C','D',
'E','F','G','H',
'I','J','K','L',
'M','N','O','P',
'Q','R','S','T',
'U','V','W','X',
'Y','Z'};/*種類*/
int i,j;
for(i=0;i<MAXHEIGHT;++i){
for(j=0;j<MAXWIDTH;j++){
pt->type=c[rand()%26];
pt++;
}
}
}
void shuffle(KEY *pt)
{
KEY wk;/*入れ替え用のワークエリア*/
int i,rnd;/*要素番号用、乱数用*/
i=26;
while(i>1)
{
rnd=rand()%i;/*乱数セット*/
wk=*(pt+rnd);
*(pt+rnd)=*(pt+i-1);
*(pt+i-1)=wk;
i--;
}
}
void mapdeta(void){
int i,j;
for(i=0;i<MAXHEIGHT;i++)
{
for(j=0;j<MAXWIDTH;j++)
{
switch(g_mapdata[i][j])
{
case 0:
printf("■");
break;
case 1:
init(&dt[0]);
shuffle(&dt[0]);
printf("%c ",dt[i].type);
break;
default:
printf("XXX");
break;
}
}
printf("\n");
}
}