作者ofz (╴△╴)
看板C_Sharp
标题[问题] 请问console速度
时间Mon Mar 21 14:34:26 2011
刚学C#
想在console里作一行行扫描下来的纯文字图像游戏
可是速度很慢不知有甚麽改善方法??
感谢@@
======================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("please input the key control for 上:");
System.ConsoleKeyInfo a = Console.ReadKey();
Console.WriteLine("key for 下:");
System.ConsoleKeyInfo b = Console.ReadKey();
Console.WriteLine("key for 左:");
System.ConsoleKeyInfo c = Console.ReadKey();
Console.Write("key for 右:");
System.ConsoleKeyInfo d = Console.ReadKey();
int t = 1;
int j = 10;
int i = 10;
int h = 22;
int w = 77;
string[,] map = new string[w, h];
for (int y = 0; y <= h - 1; y++)
{
for (int x = 0; x <= w - 1; x++)
{
map[x, y] = " ";
}
}
string[,] screen= map;
screen[i, j] = "囧";
for (int y = 0; y <= j; y++)
{
Console.WriteLine();
for (int x = 0; x <= i; x++)
{
Console.Write(screen[x, y]);
}
}
screen= map;
while (t >= 0)
{screen= map;
ConsoleKeyInfo z = Console.ReadKey();
if (z == a)
{
j = j - 1;
if (j >= 24)
{ j = 0; }
screen[i, j] = "囧";
screen[i, j-1] = "大";
for (int y = 0; y <= j; y++)
{
Console.WriteLine();
for (int x = 0; x <= i; x++)
{
Console.Write(screen[x, y]);
}
}
}
else if (z == b)
{
j++;
if (j == -2) { j = 22; }
screen[i, j] = "囧";
screen[i, j - 1] = "大";
for (int y = 0; y <= j; y++)
{
Console.WriteLine();
for (int x = 0; x <= i; x++)
{
Console.Write(screen[x, y]);
}
}
}
else if (z == c)
{
i = i - 1;
if (i == -1) { i = w; }
screen[i, j] = "囧";
screen[i, j - 1] = "大";
for (int y = 0; y <= j; y++)
{
Console.WriteLine();
for (int x = 0; x <= i; x++)
{
Console.Write(screen[x, y]);
}
}
}
else if (z == d)
{
i++;
if (i == w + 1) { i = 0; }
screen[i, j] = "囧";
screen[i, j - 1] = "大";
for (int y = 0; y <= j; y++)
{
Console.WriteLine();
for (int x = 0; x <= i; x++)
{
Console.Write(screen[x, y]);
}
}
}
else
{ Console.WriteLine("erro"); }
t++;
}
}
}
}
============
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.4.192
※ 编辑: ofz 来自: 140.112.4.192 (03/21 14:48)
1F:推 horngsh:一个文字画面全部画完了(在buffer),再一次贴到console. 03/21 15:48
※ 编辑: ofz 来自: 140.112.4.181 (03/22 19:59)