我正在做一个记忆匹配游戏,这些是图像和它们的标签。
private void Fruits_Load(object sender, EventArgs e)
{
countDown1.Start();
countDown5.Start();
picApple.Image = Properties.Resources.apple;
wrdApple.Image = Properties.Resources.wrdApple;
picBanana.Image = Properties.Resources.banana;
wrdbanana.Image = Properties.Resources.wrdBanana;
picKiwi.Image = Properties.Resources.kiwi;
wrdKiwi.Image = Properties.Resources.wrdKiwi;
picOrange.Image = Properties.Resources.orange;
wrdOrange.Image = Properties.Resources.wrdOrange;
picPineapple.Image = Properties.Resources.pineapple;
wrdPineapple.Image = Properties.Resources.wrdPineapple;
picStrawberry.Image = Properties.Resources.strawberry;
wrdStrawberry.Image = Properties.Resources.wrdStrawberry;
picBlackberry.Image = Properties.Resources.blackberry;
wrdblackberry.Image = Properties.Resources.wrdBlackberry;
picMango.Image = Properties.Resources.mango;
wrdMango.Image = Properties.Resources.wrdMango;
picApple.Tag = "apple";
wrdApple.Tag = "apple";
picBanana.Tag = "banana";
wrdbanana.Tag = "banana";
picKiwi.Tag = "kiwi";
wrdKiwi.Tag = "kiwi";
picOrange.Tag = "orange";
wrdOrange.Tag = "orange";
picPineapple.Tag = "pineapple";
wrdPineapple.Tag = "pineapple";
picStrawberry.Tag = "strawberry";
wrdStrawberry.Tag = "strawberry";
picBlackberry.Tag = "blackberry";
wrdblackberry.Tag = "blackberry";
picMango.Tag = "mango";
wrdMango.Tag = "mango";
}
我有2个图像,第一个是picApple,另一个是wrdApple,如下面的代码所示,我使用了if语句,但是当我运行该应用程序时,当我单击picApple时,它与wrdApple一起立即变得不可见。 我想要的是让用户首先看到第一张图像,然后再看到另一张图像(如果它们匹配),如果不匹配,它们将变为不可见,然后应再次遮盖它们。 关于如何做到这一点的任何想法吗? 这是图片框的代码
private void picApple_Click(object sender, EventArgs e)
{
picApple.Image = Properties.Resources.apple;
if ((string)picApple.Tag == (string)wrdApple.Tag)
{
picApple.Visible = false;
wrdApple.Visible = false;
}
else if ((string)picApple.Tag != (string)wrdApple.Tag)
{
picApple.Image = Properties.Resources.apple;
wrdApple.Image = Properties.Resources.wrdApple;
}
}
private void wrdApple_Click(object sender, EventArgs e)
{
wrdApple.Image = Properties.Resources.wrdApple;
if ((string)wrdApple.Tag == (string)picApple.Tag)
{
picApple.Visible = false;
wrdApple.Visible = false;
}
答案 0 :(得分:0)
我不知道Winform,但是逻辑将是:
public class GameWindows
{
private Image _firstSelected = null;
private void Image_Click(object sender, EventArgs e)
{
var selectedImage = (Image)sender;
if(_firstSelected == null)
{
//First selection
_firstSelected = selectedImage;
ApplySeletedEffect(selectedImage);
}
else
{
//Second selection
if ((string)selectedImage.Tag == (string)_firstSelected.Tag)
{
selectedImage.Visible = false;
_firstSelected.Visible = false;
}
RemoveSeletedEffect(_firstSelected);
_firstSelected = null;
}
}
}
当播放器单击图像时,调用Image_Click
方法。 ApplySeletedEffect
将是Winform效果以显示已选择图像,而RemoveSeletedEffect
将是删除该效果。
首先,您可以尝试不使用选定的效果。
答案 1 :(得分:0)
我的回答假设您要在一段时间内显示第二张图像,并且相似的卡片使用相同的图像,但是这里是:
2018/12/04 16:35:54 [error] 17338: *1 openat() "/usr/share/nginx/html/api/public/upload/201812/20181204133821.jpg" failed (20: Not a directory), request: "GET /upload/201812/20181204133821.jpg HTTP/1.1"
这一切都在主窗体内部完成,但是您可以根据需要拆分逻辑。我也为此使用了PictureBox控件,不确定您使用的是什么。