- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试制作我的第一款游戏,一款控制台俄罗斯方 block 。我有一个 Block 类,它包含 x 和 y 整数。然后我有一节课Piece : List<Block>
, 和一个类 Pieces : List<Piece>
.
我已经可以随机生成碎片,并让它们每秒掉落一行。我仍然没有进行碰撞检测,但我想我已经知道以后如何解决它了。问题是我不知道如何控制棋子。我已经阅读了一些关于键盘 Hook 的内容并检查了一些俄罗斯方 block 教程,但其中大部分是针对 Windows 窗体的,这确实简化了事件处理等。
那么...您能否指出在控制台上控制部件的路径的开始?谢谢!
public class Program
{
static void Main(string[] args)
{
const int limite = 60;
Piezas listaDePiezas = new Piezas(); //list of pieces
bool gameOver = false;
Pieza pieza; //piece
Console.CursorVisible = false;
while (gameOver != true)
{
pieza = CrearPieza(); //Cretes a piece
if (HayColision(listaDePiezas, pieza) == true) //if there's a collition
{
gameOver = true;
break;
}
else
listaDePiezas.Add(pieza); //The piece is added to the list of pieces
while (true) //This is where the piece falls. I know that I shouldn't use a sleep. I'll take care of that later
{
Thread.Sleep(1000);
pieza.Bajar(); //Drop the piece one row.
Dibujar(listaDePiezas); //Redraws the gameplay enviroment.
}
}
}
最佳答案
您正在寻找的是非阻塞控制台输入。
这是一个例子:
http://www.dutton.me.uk/2009/02/24/non-blocking-keyboard-input-in-c/
基本上,您会检查 Console.KeyAvailable在你的 while 循环中,然后根据按下的键移动棋子。
if (Console.KeyAvailable)
{
ConsoleKeyInfo cki = Console.ReadKey();
switch (cki.Key)
{
case ConsoleKey.UpArrow:
// not used in tetris game?
break;
case ConsoleKey.DownArrow:
// drop piece
break;
case ConsoleKey.LeftArrow:
// move piece left
break;
case ConsoleKey.RightArrow:
// move piece right
break;
}
}
关于C# 控制台俄罗斯方 block 编程。让棋子动起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2002623/
我正在尝试使用 GUI 的 NetBeans IDE 在 Java 中制作国际象棋游戏,但我无法使棋子停留在棋盘上方,当我尝试时,棋盘就会被推开。我对这两个图像都使用了标签。如何让棋子停留在棋盘上方而
编辑:要查看JS函数的工作版本,see the accepted answer in this followup thread 编辑:我使用的最终正则表达式是这样的: var pattern = /(
我一直在用 C++(使用 MVS2010)开发一个控制台国际象棋游戏,我似乎遇到了一个我自己无法解决的问题。问题是我需要在控制台中显示以下棋子: http://en.wikipedia.org/wik
我正在尝试用 Java 编写自己的国际象棋游戏。我已经开始编写类(class),我的高级想法如下: 我有一个包含这些字段的 Piece 类: private String name; private
我是一名优秀的程序员,十分优秀!