剛學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)
推
03/21 15:48, , 1F
03/21 15:48, 1F
※ 編輯: ofz 來自: 140.112.4.181 (03/22 19:59)