I have a method to assign six images to each player as follows:
public void AddCards(Player one, Player two) { one.Images.Add(Card1Player); one.Images.Add(Card2Player); one.Images.Add(Card3Player); one.Images.Add(Card4Player); one.Images.Add(Card5Player); one.Images.Add(Card6Player); two.Images.Add(Card1Computer); two.Images.Add(Card2Computer); two.Images.Add(Card3Computer); two.Images.Add(Card4Computer); two.Images.Add(Card5Computer); two.Images.Add(Card6Computer); } My xaml file contains these images:
<Image Name="Card1Player" HorizontalAlignment="Left" Height="97" Margin="259,249,0,0" VerticalAlignment="Top" Width="71" /> <Image Name="Card2Player" HorizontalAlignment="Left" Height="97" Margin="369,249,0,0" VerticalAlignment="Top" Width="71" /> <Image Name="Card3Player" HorizontalAlignment="Left" Height="97" Margin="158,249,0,0" VerticalAlignment="Top" Width="71" /> <Image Name="Card4Player" HorizontalAlignment="Left" Height="97" Margin="478,249,0,0" VerticalAlignment="Top" Width="71" /> <Image Name="Card5Player" HorizontalAlignment="Left" Height="97" Margin="59,249,0,0" VerticalAlignment="Top" Width="71" /> <Image Name="Card6Player" HorizontalAlignment="Left" Height="97" Margin="581,249,0,0" VerticalAlignment="Top" Width="71" /> Same for the other six cards.
Is it possible to do this in a better way? I was thinking about something like creating a parent for each six Images and then getting the images from that. I don't know if this is possible.
I could also change the AddCards method to something like this:
public void AddCards(Player one, Player two) { one.Images.AddRange(new List<Image>() { Card1Player, Card2Player}); two.Images.AddRange(new List<Image>() { Card1Computer, Card2Computer}); } It would be neat to get all images from the xaml without specifying all those names. Thats why I was thinking about a container / parent for those images.