测试
你是用Win8.1的,试试下面的程序能不能运行:
下载解压后运行即可,把结果告诉我。
该程序代码如下:
程序代码:
#include "stdafx.h"
using namespace System;
// 矩形範圍結構
struct Region
{
Int32 Left;
Int32 Top;
Int32 Right;
Int32 Bottom;
};
// 座標結構
struct Coord
{
Int32 x;
Int32 y;
};
const Int32 Rows = 50; // 屏幕行數
const Int32 Columns = 160; // 屏幕列數
const Char Face = L'◆'; // 顯示的圖符
const Char ClearFace = L' '; //
// 產生隨機座標
Coord RandomCoord(Region region)
{
Random r;
Coord pos = { r.Next(0, region.Right - region.Left), r.Next(0, region.Bottom - region.Top) };
return pos;
}
int main(array<String^>^ args)
{
const Region boxRegion = { 1, 1, Columns - 2, Rows - 2 }; // 圖案輸出範圍
Console::SetWindowSize(Columns, Rows);
Console::BackgroundColor = ConsoleColor::DarkBlue;
Console::ForegroundColor = ConsoleColor::Yellow;
Console::Clear();
ConsoleKeyInfo key;
do
{
static Coord pos = RandomCoord(boxRegion);
Console::SetCursorPosition(boxRegion.Left + pos.x, boxRegion.Top + pos.y);
Console::Write(Face);
key = Console::ReadKey(true);
Console::SetCursorPosition(boxRegion.Left + pos.x, boxRegion.Top + pos.y);
Console::Write(ClearFace);
switch (key.Key)
{
case ConsoleKey::LeftArrow:
--pos.x;
if (pos.x < 0)
{
pos.x = boxRegion.Right - 2;
}
break;
case ConsoleKey::RightArrow:
++pos.x;
if (pos.x > boxRegion.Right - 2)
{
pos.x = 0;
}
break;
case ConsoleKey::UpArrow:
--pos.y;
if (pos.y < 0)
{
pos.y = boxRegion.Bottom - 1;
}
break;
case ConsoleKey::DownArrow:
++pos.y;
if (pos.y > boxRegion.Bottom - 1)
{
pos.y = 0;
}
break;
default:
break;
}
} while (key.Key != ConsoleKey::Escape);
return 0;
}
[
本帖最后由 TonyDeng 于 2015-9-10 14:52 编辑 ]