Skip to content

Commit

Permalink
Blendet Hinweis automatisch aus (Übung 5-7)
Browse files Browse the repository at this point in the history
  • Loading branch information
suchja committed Apr 18, 2020
1 parent d5de153 commit ee3ef18
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions TicTacToeWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace TicTacToeWPF
{
Expand All @@ -23,9 +24,18 @@ public partial class MainWindow : Window
private bool _istErsterSpielerAmZug = true;
private bool _istSpielBeendet = false;

private readonly DispatcherTimer _blendeHinweisAusTimer = new DispatcherTimer();

public MainWindow()
{
InitializeComponent();
_blendeHinweisAusTimer.Tick += BlendeHinweisAus;
}

private void BlendeHinweisAus(object sender, EventArgs e)
{
_blendeHinweisAusTimer.Stop();
HinweisLabel.Visibility = Visibility.Hidden;
}

private void Window_Loaded(object sender, RoutedEventArgs e)
Expand All @@ -43,16 +53,9 @@ private void Kaestchen_Click(object sender, RoutedEventArgs e)
StarteSpielNeu();
}

if (HinweisLabel.Content != null && HinweisLabel.Content.ToString() != string.Empty)
{
HinweisLabel.Content = string.Empty;
HinweisLabel.Visibility = Visibility.Hidden;
}

if (kaestchen.Content != null && kaestchen.Content.ToString() != "")
{
HinweisLabel.Content = "Kästchen belegt!";
HinweisLabel.Visibility = Visibility.Visible;
ZeigeHinweis("Kästchen belegt!", 1);
return;
}

Expand All @@ -78,27 +81,35 @@ private void Kaestchen_Click(object sender, RoutedEventArgs e)

if (_istErsterSpielerAmZug)
{
HinweisLabel.Content = "O gewinnt!";
HinweisLabel.Visibility = Visibility.Visible;
ZeigeHinweis("O gewinnt!");
}
else
{
HinweisLabel.Content = "X gewinnt!";
HinweisLabel.Visibility = Visibility.Visible;
ZeigeHinweis("X gewinnt!");
}

_istSpielBeendet = true;
return;
}

if (IstSpielfeldVoll())
{
HinweisLabel.Content = "Keiner gewinnt!";
HinweisLabel.Visibility = Visibility.Visible;
ZeigeHinweis("Keiner gewinnt!");
_istSpielBeendet = true;
}
}

private void ZeigeHinweis(string hinweis, int ausblendeZeitInSekunden = 0)
{
HinweisLabel.Content = hinweis;
HinweisLabel.Visibility = Visibility.Visible;

if ((ausblendeZeitInSekunden > 0) && (!_blendeHinweisAusTimer.IsEnabled))
{
_blendeHinweisAusTimer.Interval = TimeSpan.FromSeconds(ausblendeZeitInSekunden);
_blendeHinweisAusTimer.Start();
}
}

private List<Button> SucheGewinnReihe()
{
var resultat = new List<Button>();
Expand Down

0 comments on commit ee3ef18

Please sign in to comment.