我的拼图的一点更新(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/a-little-update-to-my-jigsaw-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 4 分钟阅读 - 1543 个词 阅读量 0我的拼图的一点更新(译文)
原文地址:https://www.codeproject.com/Articles/30544/A-Little-Update-to-My-Jigsaw
原文作者:spidergeuse
译文由本站 robot-v1.0 翻译
前言
This is an update to my jigsaw, which allows the user to customize the jigsaw (size and picture).
这是对我的拼图的更新,它允许用户自定义拼图(大小和图片).
设置表格(Setup Form)
主板(Main Board)## 介绍(Introduction) 这是对我先前的Jigsaw应用程序的一点更新.您可以从以下链接中找到:(This is a little update to my previous Jigsaw application. You can find that from the link here:) http://www.codeproject.com/KB/graphics/Jigsaw.aspx(http://www.codeproject.com/KB/graphics/Jigsaw.aspx) .(.) 原始应用程序只有一张图片(内置)和一张大小(300 x 300)px.电路板尺寸和(60 x 60)像素.令牌大小.就像我之前说过的那样,我认为我已经实施了与该新版本相似的内容,直到我将一切都输给了SHFT + DEL.(The original application had only one picture (in-built) and one size (300 x 300) px. board size, and (60 x 60) px. token size. Like I said before, I had implemented something close to this new one until I lost everything to SHFT + DEL, I think.)
背景(Background)
因此,现在受一位好朋友(缩写J P)的启发,我添加了另一种形式,允许游戏玩家/玩家自定义棋盘的大小以及棋盘上显示的图片.(So now by the inspiration of a good buddy (acronym J P), I have added another form which allows the gamer/player to customize the size of the board as well as the picture that shows on the board.)
但是请注意,我对拼图的主要功能所做的更改很少.(Note however, that I made very little changes to the main functionality of the jigsaw.)
我添加了一个表单,用户可以在其中输入一些内容,然后使用用户提供的参数加载拼图板.因此,竖锯形式的静态值(板子尺寸,令牌尺寸和图片)已更改.(I have added a form where the user can make some input which then loads the jigsaw board with the parameters provided by the user. So the static values in the jigsaw form (board size, token size, and picture) are what have been changed.)
另外,我在拼图形式中添加了一个新的构造函数,其中一个参数的类型为"(Also I have added a new constructor into the jigsaw form, and of which one parameter is of type “) Setup
“,这是一个消耗用户在SetupForm上设置的值的对象(仅使用OOP).(”, which is an object to consume the values set by the user on the SetupForm (just enjoying OOP).)
使用代码(Using the code)
该代码看起来类似于上一个.以新形式((The code looks similar to the previous one. In the new form () SetupForm
),"(), an instance of the “) Jigsaw
“表格已创建;(” form is created;)
new Jigsaw(new Setup((int)numericUpDown2.Value,(int)numericUpDown1.Value, filename)).Show(this);
在拼图中,使用以下命令分别调整板的图像和令牌的图像的大小,以适应板和令牌的新尺寸:(In the jigsaw form, the board’s image and the image of the tokens are resized to fit the new dimensiond of the board and the token, respectively, using:)
mainpic.Image = new Bitmap(_Setup.Image,new Size(_Setup.BoardSize,_Setup.BoardSize));
对于空白令牌:(For blank token:)
tokenpic.Image =new Bitmap( JigsawCSII.Properties.Resources.blank,
new Size(_Setup.TokenHW,_Setup.TokenHW));// Image.FromFile("blank.jpg");
对于主要代币:(For main tokens:)
tokenpic.Image = bmp.Clone(new Rectangle(left, top, _Setup.TokenHW,
_Setup.TokenHW), System.Drawing.Imaging.PixelFormat.DontCare);
在上面的代码中,使用令牌的维度克隆了主图像的一部分.(In the above code, a portion of the main image is cloned, using the dimension of the token.) 为了获得赢家,令牌在每次移动后都会将当前(未改组的)板状态与当前板状态进行比较-这是一种缓慢的过程,但在普通计算机上可能看不到.如果1 ==1,2 ==2,3 ==3,…(使用最初放置的标记索引)直到最后一个标记,那将是非常简单的.(To get a winner, the token checks the actual (unshuffled) board state against the current board state after every move - a kind of slow process but might not be visible to you on an average machine. And that is a very simple if 1==1,2==2,3==3,… (using the index of the tokens as they are originally placed) up to the last token.)
/// <summary>
/// Find out if solved
/// </summary>
private void checksolve()
{
bool lose=false;
for (int i = 0; i < _Setup.Tokens * _Setup.Tokens; i++)
{
PictureBox tokenpic = (PictureBox)tokens[i];
if (Convert.ToInt32(tokenstate[i]) != i)
lose = true;
}
if (lose == false)
MessageBox.Show("Congratulations, You Win !");
}
对此的一种改进是,一旦”(An improvement to this is to exit from the loop as soon as the “) if
“条件进行评估,因此,如果第一个令牌不匹配,它将不浪费时间进行其余的令牌.(” condition evaluates, so that if the first token does not match, it would waste no time to go through the rest.)
还有更多改进的余地,这就是为什么我与其他开发人员(尤其是初学者)共享此内容,以进行改进.(There is more room for more improvements and this is why I’m sharing this with fellow developers (beginners especially) to play around with it.)
如有任何解释或帮助,请随时与我联系.(Feel easy to contact me for any explanations or help.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# .NET3.0 .NET3.5 .NET .NET2.0 Dev 新闻 翻译