开头
大家好,我叫这是我58。
程序
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <Windows.h>
void printmap(const char strmap[10][10]) {
int ia = 0;
int ib = 0;
for (ia = 0; ia < 10; ia++) {
for (ib = 0; ib < 10; ib++) {
printf("\033[3%sm%c\033[0m", '*' == strmap[ia][ib] ? "2;1" : '-' == strmap[ia][ib] ? "1;1" : "6", strmap[ia][ib]);
}
printf("\n");
}
}
void change(char* cp, char* cpa) {
char chan[10] = { 0 };
const int arr[9] = { -11, -10, -9, -1, 0, 1, 9, 10, 11 };
const char chana[3] = "-|";
int i = 0;
int ia = 0;
int ib = 0;
int ic = 0;
char* ccp = chan;
for (; i < 9; i++) {
('*' != *(cp + arr[i]) && (*ccp++ = *(cp + arr[i]), ('-' == *(cp + arr[i]) && ia++, '|' == *(cp + arr[i]) && ib++))), ('*' == *(cp + arr[i]) && ic++);
}
if (ia == ib) {
*ccp = chana[rand() % 2];
}
else if (ia < ib) {
*ccp = '|';
}
else {
*ccp = '-';
}
*cpa = chan[(i = rand() % (10 - ic))];
}
int main() {
float fspd = 1.0f;
char stw[9] = "color 0";
srand((unsigned int)time(NULL));
char strmap[10][10] = {
'*','*','*','*','*','*','*','*','*','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','*','*','*','*','*','*','*','*','*'
};
char strmapa[10][10] = {
'*','*','*','*','*','*','*','*','*','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','-','-','-','-','|','|','|','|','*',
'*','*','*','*','*','*','*','*','*','*'
};
int i = 1;
int ia = 1;
int iw = 0;
printf("这次游戏的倍速为多少?(0倍速自动转为1倍速) -> ");
scanf("%f", &fspd);
0 == fspd && (fspd = 1.0f);
system("cls");
while (!iw) {
for (i = 1; i < 9; i++) {
for (ia = 1; ia < 9; ia++) {
change(&strmap[i][ia], &strmapa[i][ia]);
}
}
for (i = 1; i < 9; i++) {
for (ia = 1; ia < 9; ia++) {
strmap[i][ia] = strmapa[i][ia];
}
}
printmap(strmap);
'-' == strmap[1][1] && (iw = 1), '|' == strmap[1][1] && (iw = -1);
for (i = 1; i < 9; i++) {
for (ia = 1; ia < 9; ia++) {
if (iw > 0) {
if ('|' == strmap[i][ia]) {
iw = 0;
goto g;
}
}
else {
if ('-' == strmap[i][ia]) {
iw = 0;
goto g;
}
}
}
}//判断
g:
Sleep(1000 / fspd);
system("cls");
}
strcat(stw, iw > 0 ? "C" : "9");
system(stw);
printf("“%c”赢了", iw > 0 ? '-' : '|');
return 0;
}//占领游戏(我随便取的):改变 打印 判断-->改变(概率:(←↑→↓↖↗↘↙)?本+多数)
程序的流程图
程序的效果
「占领游戏」
结尾
你觉得我这次做的游戏好吗?如果你觉得我这次做的游戏不好的话,就可以评论一下我这次做的游戏不好的原因吧。