this is my first time working with UWP and Xaml, and I am trying to create a memory matching game.
Here is what I have so far:
private void Start_Click(object sender, RoutedEventArgs e)
{
btnStart.Opacity = 0;
btnStart.IsEnabled = false;
CardAssign();
}
public void CardAssign()
{
List<string> cards = new List<string>
{
"ms-appx:///Assets/CardA.png", "ms-appx:///Assets/CardA.png",
"ms-appx:///Assets/CardB.png", "ms-appx:///Assets/CardB.png",
"ms-appx:///Assets/CardC.png", "ms-appx:///Assets/CardC.png",
"ms-appx:///Assets/CardD.png", "ms-appx:///Assets/CardD.png",
"ms-appx:///Assets/CardE.png", "ms-appx:///Assets/CardE.png",
"ms-appx:///Assets/CardF.png", "ms-appx:///Assets/CardF.png",
"ms-appx:///Assets/CardG.png", "ms-appx:///Assets/CardG.png",
"ms-appx:///Assets/CardH.png", "ms-appx:///Assets/CardH.png"
};
var shuffledcards = cards.OrderBy(a => Guid.NewGuid()).ToList();
Card1Img.Source = new BitmapImage(new Uri(shuffledcards[0]));
Card2Img.Source = new BitmapImage(new Uri(shuffledcards[1]));
Card3Img.Source = new BitmapImage(new Uri(shuffledcards[2]));
Card4Img.Source = new BitmapImage(new Uri(shuffledcards[3]));
Card5Img.Source = new BitmapImage(new Uri(shuffledcards[4]));
Card6Img.Source = new BitmapImage(new Uri(shuffledcards[5]));
Card7Img.Source = new BitmapImage(new Uri(shuffledcards[6]));
Card8Img.Source = new BitmapImage(new Uri(shuffledcards[7]));
Card9Img.Source = new BitmapImage(new Uri(shuffledcards[8]));
Card10Img.Source = new BitmapImage(new Uri(shuffledcards[9]));
Card11Img.Source = new BitmapImage(new Uri(shuffledcards[10]));
Card12Img.Source = new BitmapImage(new Uri(shuffledcards[11]));
Card13Img.Source = new BitmapImage(new Uri(shuffledcards[12]));
Card14Img.Source = new BitmapImage(new Uri(shuffledcards[13]));
Card15Img.Source = new BitmapImage(new Uri(shuffledcards[14]));
Card16Img.Source = new BitmapImage(new Uri(shuffledcards[15]));
Countdown();
}
private async void Countdown()
{
await Task.Delay(7000);
Hide();
}
private void Hide()
{
Card1.IsEnabled = true;
Card2.IsEnabled = true;
Card3.IsEnabled = true;
Card4.IsEnabled = true;
Card5.IsEnabled = true;
Card6.IsEnabled = true;
Card7.IsEnabled = true;
Card8.IsEnabled = true;
Card9.IsEnabled = true;
Card10.IsEnabled = true;
Card11.IsEnabled = true;
Card12.IsEnabled = true;
Card13.IsEnabled = true;
Card14.IsEnabled = true;
Card15.IsEnabled = true;
Card16.IsEnabled = true;
Card1Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card2Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card3Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card4Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card5Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card6Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card7Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card8Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card9Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card10Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card11Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card12Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card13Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card14Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card15Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
Card16Img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Card Backs.png"));
}
private void Card1_Click(object sender, RoutedEventArgs e)
{
Card1Img.Source = new BitmapImage(new Uri(shuffledcards[0]));
}
}
The only issue is that whenever I try to display the shuffled card image again, it says that it doesn't exist in the current context. I have not yet been able to figure out how to fix this! Any help would be appreciated.
EDIT: The error I'm getting is as follows: Error CS0103 The name 'shuffledcards' does not exist in the current context