Initial
parent
ed67eea321
commit
2e4a377bfe
|
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.11.35431.28
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "TestProject\TestProject.csproj", "{819BC87A-230C-488C-B5A2-050401FBF03D}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{819BC87A-230C-488C-B5A2-050401FBF03D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{819BC87A-230C-488C-B5A2-050401FBF03D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{819BC87A-230C-488C-B5A2-050401FBF03D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{819BC87A-230C-488C-B5A2-050401FBF03D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {95160B41-7027-401C-9FBC-8475F077EE81}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
<Application x:Class="TestProject.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:TestProject"
|
||||||
|
StartupUri="MainWindow.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Data;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace TestProject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for App.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
[assembly: ThemeInfo(
|
||||||
|
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// or application resource dictionaries)
|
||||||
|
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// app, or any theme specific resource dictionaries)
|
||||||
|
)]
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace TestProject
|
||||||
|
{
|
||||||
|
class MainController
|
||||||
|
{
|
||||||
|
//Liste der Karten
|
||||||
|
List<Karte> KartenListe = new();
|
||||||
|
//"View"
|
||||||
|
MainWindow mainWindow;
|
||||||
|
|
||||||
|
//Hierbei handelt es sich um einen Konstruktor. Dieser wird immer beim Erstellen der Klasse mit new aufgerufen. Dieser Konstruktor will zusätzlich als Übergabewert das MainWindow haben.
|
||||||
|
public MainController(MainWindow mw)
|
||||||
|
{
|
||||||
|
//Setzen der "View", also des Hauptfensters
|
||||||
|
mainWindow = mw;
|
||||||
|
//Erstellen der Karten
|
||||||
|
KartenListe = Karte.GenerateCardPairs(5);
|
||||||
|
|
||||||
|
//Einfügen der Karten in die GUI
|
||||||
|
mainWindow.InsertCardsIntoGui(KartenListe);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Diese Methode behandelt die Aktion, wenn ein User auf ein gewisses Element klickt. Dabei benötigt die Methode die individuelle ID der Karte.
|
||||||
|
public void ClickOnCard(int individualID)
|
||||||
|
{
|
||||||
|
//Zuerst suchen wir die Karte, zu der die ID gehört
|
||||||
|
Karte k = KartenListe.Where(k => k.IndividualID == individualID).ToList().First();
|
||||||
|
//Dann ändern wir den Status ab
|
||||||
|
k.IsChecked = !k.IsChecked;
|
||||||
|
//Danach prüfen wir, ob Elemente rausgenommen werden müssen.
|
||||||
|
testCards();
|
||||||
|
//Zum Schluss geben wir die neue Liste zur GUI, die diese dann aktualisiert
|
||||||
|
mainWindow.InsertCardsIntoGui(KartenListe);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Diese Methode überprüft, ob zwei gleiche Elemente ausgewählt sind und löscht diese dann aus der Liste.
|
||||||
|
void testCards()
|
||||||
|
{
|
||||||
|
//Zuerst holen wir uns alle Elemente, die gecheckt (ausgewählt) sind.
|
||||||
|
var checkedList = KartenListe.Where(k => k.IsChecked).ToList();
|
||||||
|
//In dieser Liste sollen dann alle PairIDs stehen, die rausgelöscht werden sollen
|
||||||
|
List<int> ints = new();
|
||||||
|
//Mit der geschachtelten foreach-Schleife vergleichen wir alle Elemente miteinander und merken uns, wo beide Pairs gleich gleich waren
|
||||||
|
foreach (var element in checkedList)
|
||||||
|
foreach(var item in checkedList)
|
||||||
|
if(element.IndividualID != item.IndividualID && element.PairID == item.PairID)
|
||||||
|
ints.Add(item.PairID);
|
||||||
|
//Zum Schluss laufen wir durch alle Karten durch und löschen die jewiligen Pairs aus der Liste.
|
||||||
|
for (int i = 0; i < KartenListe.Count; i++)
|
||||||
|
if (ints.Contains(KartenListe[i].PairID))
|
||||||
|
{
|
||||||
|
KartenListe.RemoveAt(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace TestProject
|
||||||
|
{
|
||||||
|
public class Karte
|
||||||
|
{
|
||||||
|
//Hier ist eine Liste der Bilder, die geladen werden können
|
||||||
|
private static List<string> _sourceList = new() { @"C:\Users\s.schueler.doz\Pictures\image1.png", @"C:\Users\s.schueler.doz\Pictures\image2.jpg", @"C:\Users\s.schueler.doz\Pictures\image3.jpg", @"C:\Users\s.schueler.doz\Pictures\image4.jpg", @"C:\Users\s.schueler.doz\Pictures\image5.jpg" };
|
||||||
|
|
||||||
|
//Das ist das Bild des aktuellen Objekts
|
||||||
|
public string Bild { get; set; }
|
||||||
|
//Dies ist die individuelle ID jedes Objekts
|
||||||
|
public int IndividualID { get; set; }
|
||||||
|
//Zwei Paare besitzen die selbe PairID.
|
||||||
|
public int PairID { get; set; }
|
||||||
|
//Hier wird gesetzt, ob der User das Element ausgewählt hat, oder nicht
|
||||||
|
public bool IsChecked { get; set; }
|
||||||
|
|
||||||
|
//Dieser Methode übergibt man eine Menge an Kartenpaaren, die man haben will. Dann bekommt man die Karten in einer Liste zurück.
|
||||||
|
public static List<Karte> GenerateCardPairs(int amount)
|
||||||
|
{
|
||||||
|
//Wir erstellen zuerst eine neue Liste aus Karten
|
||||||
|
List<Karte> CardList = new();
|
||||||
|
//Das k brauchen wir für die einzigartige ID
|
||||||
|
int k = 0;
|
||||||
|
//Wir laufen dann so oft durch die Schleife und erstellen Elemente, je nachdem wie viele Paare der Aufrufer haben will
|
||||||
|
for (int i = 0; i < amount; i++)
|
||||||
|
{
|
||||||
|
//In jedem Durchlauf erstellen wir zwei neue Karten, mit derselben PairID und jeweils einer anderen individuellen ID. Mit dem Add fügen wir diese der Liste hinzu.
|
||||||
|
CardList.Add(new Karte { Bild = _sourceList[i], PairID = i, IndividualID = k });
|
||||||
|
k++;
|
||||||
|
CardList.Add(new Karte { Bild = _sourceList[i], PairID = i, IndividualID = k });
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
//Zum Schluss geben wir die Liste zurück.
|
||||||
|
return CardList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<Window x:Class="TestProject.MainWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:TestProject"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="MainWindow" Height="450" Width="800">
|
||||||
|
<Grid>
|
||||||
|
<TextBlock Text="Memory" FontSize="35" TextAlignment="Center" Height="66" VerticalAlignment="Top" />
|
||||||
|
<WrapPanel Name="mainWrapPanel" Margin="0,66,0,0">
|
||||||
|
|
||||||
|
</WrapPanel>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace TestProject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for MainWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class MainWindow : Window
|
||||||
|
{
|
||||||
|
MainController controller;
|
||||||
|
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
//this ist immer das Objekt, indem man sich gerade befindet
|
||||||
|
controller = new(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Diese Methode fügt eine übergebene Liste von Karten in die GUI ein.
|
||||||
|
public void InsertCardsIntoGui(List<Karte> cardList)
|
||||||
|
{
|
||||||
|
//Zuerst wird das Feld geleert
|
||||||
|
mainWrapPanel.Children.Clear();
|
||||||
|
//Danach wird jedes übergebene Kartenobjekt in die GUI eingefügt
|
||||||
|
foreach (var element in cardList)
|
||||||
|
InsertKarteInGui(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fügt die Karte in die GUI ein
|
||||||
|
void InsertKarteInGui(Karte k)
|
||||||
|
{
|
||||||
|
//Das ist der Rand außen rum, der für das Markieren zuständig ist
|
||||||
|
Border border = new();
|
||||||
|
//Dies ist das Bild, das angezeigt wird
|
||||||
|
Image image = new();
|
||||||
|
//Sollte das Objekt schon ausgewählt sein, muss man den Rahmen setzen
|
||||||
|
if (k.IsChecked)
|
||||||
|
{
|
||||||
|
border.BorderThickness = new(3);
|
||||||
|
border.BorderBrush = Brushes.Crimson;
|
||||||
|
//Hier wird das Bild gesetzt
|
||||||
|
var converter = new ImageSourceConverter();
|
||||||
|
image.Source = (ImageSource)(converter.ConvertFromString(k.Bild) ?? new());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Hier wird die Rückseite gesetzt
|
||||||
|
var converter = new ImageSourceConverter();
|
||||||
|
image.Source = (ImageSource)(converter.ConvertFromString(@"C:\Users\s.schueler.doz\Pictures\back.jpg") ?? new());
|
||||||
|
}
|
||||||
|
//Hier wird das Event gesetzt, wenn wer auf das Bild klickt
|
||||||
|
image.MouseLeftButtonUp += Image_MouseLeftButtonUp;
|
||||||
|
//Hier werden die Höhe und die Seitenabstände definiert
|
||||||
|
image.Height = 100;
|
||||||
|
image.Margin = new(5);
|
||||||
|
//Hier wird die individuelle ID gesetzt
|
||||||
|
image.Tag = k.IndividualID;
|
||||||
|
//Der Border wird dann das Bild hinzugefügt
|
||||||
|
border.Child = image;
|
||||||
|
//Dem WrapPanel wird dann die Border hinzugefügt und somit in der GUI sichtbar
|
||||||
|
mainWrapPanel.Children.Add(border);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Behandelt den Klick auf eine Karte
|
||||||
|
private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
//Wir holen und zuerst das Image
|
||||||
|
Image i = (Image)sender;
|
||||||
|
//Dann teilen wir dem Controller mit, dass auf dieses Objekt geklickt wurde. Dabei verwenden wir die individuelle ID aus dem Tag.
|
||||||
|
controller.ClickOnCard((int)i.Tag);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Loading…
Reference in New Issue