c# - Interactive game, card won't reveal other card when flipped for UWP application
问题描述
I click on an image, and then the other card that I'm trying to display by giving the clicked image the source patch of the image I want to reveal won't show the new image. It just displays a blank space on my grid. Here is my code so far
Image _imgMatch1 = new Image();
Image _imgMatch2 = new Image();
Image _imgMatch3 = new Image();
Image _imgMatch4 = new Image();
Image imagedClickedOne;
Image imagedClickedTwo;
Dictionary<string, Image> minionsDict = new Dictionary<string, Image>();
int count = 0;
public MainPage()
{
this.InitializeComponent();
_imgMatch1.Source = new BitmapImage(new Uri("ms-appx://Assets/Tile1.jpg", UriKind.Absolute));
_imgMatch2.Source = new BitmapImage(new Uri("ms-appx://Assets/Tile2.jpg", UriKind.Absolute));
_imgMatch3.Source = new BitmapImage(new Uri("ms-appx://Assets/Tile3.jpg", UriKind.Absolute));
_imgMatch4.Source = new BitmapImage(new Uri("ms-appx://Assets/Tile4.gif", UriKind.Absolute));
//var imgSource = _imgMatch1;
minionsDict.Add("_imgTile1", _imgMatch1);
minionsDict.Add("_imgTile2", _imgMatch2);
minionsDict.Add("_imgTile3", _imgMatch3);
minionsDict.Add("_imgTile4", _imgMatch4);
minionsDict.Add("_imgTile5", _imgMatch1);
minionsDict.Add("_imgTile6", _imgMatch2);
minionsDict.Add("_imgTile7", _imgMatch3);
minionsDict.Add("_imgTile8", _imgMatch4);
}
private void OnClickTap(object sender, TappedRoutedEventArgs e)
{
count++;
Image imagedClicked = sender as Image;
var imageName = imagedClicked.Name;
Image image = minionsDict[imageName];
if (imagedClicked != null)
{
if (imagedClickedOne == null)
{
imagedClickedOne = image;
BitmapImage myBitmapImage = new BitmapImage
{
UriSource = new Uri("ms-appx://Assets/Tile2.jpg")
};
imagedClicked.Source = myBitmapImage;
return;
}
imagedClickedTwo = image;
if (imagedClickedOne.Name == imagedClickedTwo.Name)
{
imagedClickedOne = null;
imagedClickedTwo = null;
}
}
Note I am using a Grid to set my 8 squares. My XAML code is simply
<Image "attributes">
<Image.Source>
<BitmapImage uriSource = "source" />
<Image.Source>
<Image>
Times 8 for all 8 initial images
解决方案
推荐阅读
- javascript - 比较数组和对象以查看项目是否存在
- javascript - 我在节点上没有得到正确的响应
- java - 使用 --enable-preview 选项运行 .jar
- r - 根据R中的条件将值替换为前一行值
- php - 显示三元运算符的颜色
- java - 如何以编程方式使用 Spring Boot 和 Tomcat 提供密钥库文件?
- python - 来自numpy数组索引的PIL图像
- vb.net - Vb.net - 正则表达式创建 url
- javascript - 错误:尝试使网页正常工作时找不到模块“./suns.png”
- python - 为什么我的 Tkinter 滚动条不滚动我的画布?