0

我正在尝试制作自己的俄罗斯方块游戏版本。到目前为止,我能够展示、旋转它们。但我被困在一个点上,不知道如何继续。

在此处输入图像描述

我有一个

  • BoardClass网格的静态整数数组board。使用不同的整数,我显示不同的颜色。
  • Block具有生成随机块并旋转它们的方法的类。
  • 一个Graphic基于board数组显示颜色的类,以及
  • GameLogic用于开始、暂停游戏的类。

对于当前作品,我采用了一个 4x4 阵列并放置在板上的前四行board

一切正常。但是我如何开始移动东西。如何建立块之间的关系是我卡住的地方。

我的问题

  • 我在正确的轨道上工作吗?
  • 如何使事情自动化,我的意思是,块将如何一个接一个地自动出现。我知道我可以有一个 DispatcherTimer 并在滴答事件中移动块,但绘制和重绘整个网格很慢。我只想重绘游戏网格的一部分。
  • 如果我向左/向右/向下移动我的棋子,整个棋子阵列就会移动,这意味着一个 4x4 棋子在移动,而不仅仅是可能是 1x3 或 2x2 的棋子。
  • 如何知道这件作品是新的还是旧的定居作品。我知道我可以取一个布尔值,但我认为 10x20 的布尔数组会很大。

我知道这些可能不是关于 SO 的好问题,但我被卡住了,任何帮助都将不胜感激。并问我是否想查看任何代码。

4

4 回答 4

2

Am I working on right track?

I think you are.

How to automate things, I mean, how will the blocks appear automatically one after another. I know I can have a DispatcherTimer and move block at tick event but drawing and redrawing the complete grid is slow. I want only the portion of the game grid to be redrawn.

Have you measured it? Most of the games redraw the whole scene at a 30 frames per second rate. Make it first work, optimise later on.

If I move my piece left/right/down the complete piece array would move and this would mean a 4x4 piece moving and not just the piece which may be in 1x3 or 2x2.

You need to check the bounds before every move. You can do it for each square, you only have 16 comparisons. It is not very difficult and it won't be slow.

How to know if the piece is new or an old settled piece. I know I can take a boolean value but I think a boolean array of 10x20 would be large.

It is not large.

于 2013-05-13T12:07:53.990 回答
1

如何自动化事物/绘制和重绘完整的网格很慢。我只想重绘游戏网格的一部分。

当用户对一条线进行评分时-无论如何,您都必须重新绘制整个网格。(降低线顶部的数字);

如果我向左/向右/向下移动我的棋子,整个棋子阵列就会移动,这意味着一个 4x4 棋子在移动,而不仅仅是可能是 1x3 或 2x2 的棋子。

我认为错误在于当您实际需要 1x4 块列表(对于每个俄罗斯方块图)时,为每个图制作一个 4x4 数组;您使用了 4 倍的内存和空间!

如何知道这件作品是新的还是旧的定居作品。我知道我可以取一个布尔值,但我认为 10x20 的布尔数组会很大。

数组永远不会太大(如果我们不是在谈论数百万);你可以按照我的方式来做:制作一个列表,在其中存储游戏的所有“旧”部分。并制作一个指向板上“新”图形的变量(图形对象)。在“新”人物降落后 - 您只需将其放入您拥有“旧”作品的列表中。并使 VARIABLE 指向网格上“新”添加的图形。

希望有帮助。

你可以在这里查看我的俄罗斯方块实现示例(Java 中)

于 2014-10-20T21:34:08.017 回答
0

我在正确的轨道上工作吗?

如果你的愿望是学习游戏编程而不是在每个小细节上费尽心思,我建议使用像 Box2D 这样的库来处理世界空间和对象的碰撞。

除了 Box2D,我还建议使用游戏框架来处理游戏编程、频率、输入、声音等的许多基础知识。PlayN 和 LibGDX 是很棒的免费框架,可以让您快速入门。

使用这些工具,您将更多地关注您的游戏,而不是基础知识。

https://code.google.com/p/playn/

https://code.google.com/p/libgdx/

于 2013-05-13T12:33:25.410 回答
0

What your've done so far sounds okay to me. As far as your other questions go:

How to automate things, I mean, how will the blocks appear automatically one after another. I know I can have a DispatcherTimer and move block at tick event but drawing and redrawing the complete grid is slow. I want only the portion of the game grid to be redrawn.

  • You could use a dirty recatangle to figure out where to redraw. But if you really have performance troubles with an application as simple as a tetris game I's rather try to figure out why exactly your drawingcode is so slow. On any hardware that has been produced in the last 10 years you should easily archive 100+ fps, even if you redraw your complete board each frame.

How to know if the piece is new or an old settled piece. I know I can take a boolean value but I think a boolean array of 10x20 would be large.

Quite frankly no. Just use an array. 10x20 = 200 entries in your array. AFAIK bools will take 1 Byte each in an arra, that would mean 200 Bytes, so that should not be a problem for a machine built in the last 30 years. Even if you use integers you'd still use less than 1 kb of memory for the board.

于 2013-05-13T12:09:05.667 回答