-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrainingPage.xaml.cs
77 lines (66 loc) · 2.04 KB
/
TrainingPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ShakeGestures;
namespace PhoneApp1
{
public partial class TrainingPage : PhoneApplicationPage
{
Abacus abacus;
public static EventHandler Started;
public static EventHandler Ended;
public TrainingPage()
{
InitializeComponent();
abacus = new Abacus(9);
Container.Children.Add(abacus.GetContainer());
ShakeGesturesHelper.Instance.MinimumRequiredMovesForShake = 3;
ShakeGesturesHelper.Instance.Active = true;
ShakeGesturesHelper.Instance.ShakeGesture += new EventHandler<ShakeGestureEventArgs>(ResetOnShake);
EventBinder.Bind(ref Bead.BeadMoved, UpdateValue);
}
public void OnStarted(EventArgs e)
{
if (Started != null)
{
Started(this, e);
}
}
public void OnEnded(EventArgs e)
{
if (Ended != null)
{
Ended(this, e);
}
}
private void GoToGame(object sender, GestureEventArgs e)
{
OnEnded(EventArgs.Empty);
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
OnStarted(EventArgs.Empty);
}
private void ResetOnShake(object sender, ShakeGestureEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
abacus.Reset();
});
}
private void UpdateValue(object sender, EventArgs e)
{
Number.Text = abacus.GetValue().ToString();
}
}
}