用for循环写了一个 黑白相间的棋盘
本帖最后由 江沪椿明 于 2015-9-14 14:49 编辑想要他们他们时隔1秒进行一次位置替换,看看广大鱼又们有什么思路嘛?
随便写的O__O"!!
#include<stdio.h>
#include<windows.h>
void sleep_peony();//可以直接用Sleep()代替
int main()
{
int f;
int s;
int i, j, t = 0;
for (i = 0; i < 9; i++)
{
for (j = 0; j < 9; j++)
{
f = 1;
}
}
for (i = 1; i<9; i = i + 2)
{
f = 0;
}
for (i = 0; i<9; i++)
{
if (f)
{
for (j = 1; j<9; j += 2)
{
f = 0;
}
}
else
{
for (j = 2; j<9; j += 2)
{
f = 0;
}
}
}
for (i = 0; i < 9; i++)
{
for (j = 0; j < 9; j++)
{
if (f)
{
s = 0;
}
else
{
s = 1;
}
}
}
while (1)
{
system("cls");
if (t)
{
for (i = 0; i<9; i++)
{
for (j = 0; j<9; j++)
{
printf("%-2d", f);
}
printf("\n");
}
t = 0;
}
else
{
for (i = 0; i<9; i++)
{
for (j = 0; j<9; j++)
{
printf("%-2d", s);
}
printf("\n");
}
t = 1;
}
sleep_peony(1000);
}
return 0;
}
void sleep_peony(long time)
{
HANDLE timehandle;
LARGE_INTEGER sleeptime;
MSG Msg;
LPHANDLE handle;
handle = &timehandle;
timehandle = CreateWaitableTimer(NULL, 0, NULL);
sleeptime.QuadPart = time * -10000;
SetWaitableTimer(timehandle, &sleeptime, 0, NULL, NULL, 0);
while (MsgWaitForMultipleObjects(1, handle, 0, -1, 255) != 0)
{
if (GetInputState() != 0)
{
while (PeekMessageA(&Msg, 0, 0, 0, 1))
{
TranslateMessage(&Msg);
DispatchMessageA(&Msg);
}
}
}
CloseHandle(timehandle);
} 牡丹花下死做鬼 发表于 2015-9-14 16:42
随便写的O__O"!!
感谢大版主开导 不过数组和独立函数还没学,有的慢慢研究了谢谢!
页:
[1]