-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainPage.BE.cs
193 lines (179 loc) · 5.98 KB
/
MainPage.BE.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
namespace Game2048Maui;
public partial class MainPage : FmgLibContentPage<MainPageViewModel>
{
private bool canHitMauiRobot = true;
private DateTime tappedDateTime = DateTime.MaxValue;
double eTotalXStart = 0;
double eTotalYStart = 0;
private MainPageViewModel CurrentViewModel;
private Grid MainGrid;
private Grid MyToolsPhotosItem;
private Frame tttt;
private Label AddedScoreLabel;
private HorizontalStackLayout phraseLayout;
private SKLottieView GameOverAnimation;
private SKConfettiView skConfetti;
string[] phrases = new string[]
{
"I am thankful to the community",
"You can stop poking me and play some game",
"I am feeling sleepy now"
};
public MainPage(MainPageViewModel viewModel) : base(viewModel)
{
CurrentViewModel = BindingContext;
skConfetti.Systems.Clear();
}
private void DisplayConfettiAnimation()
{
var sus = new SKConfettiSystem()
{
Lifetime = 2,
Colors = new SKConfettiColorCollection(ConfettiConfig.Colors),
Shapes = new SKConfettiShapeCollection(ConfettiConfig.GetShapes(ConfettiConfig.Shapes).SelectMany(s => s)),
MinimumInitialVelocity = 30,
MaximumInitialVelocity = 150,
Emitter = SKConfettiEmitter.Burst(100),
EmitterBounds = SKConfettiEmitterBounds.Top,
};
skConfetti.Systems.Add(sus);
}
void MainPageViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
var bindingContext = (MainPageViewModel)BindingContext;
if (e.PropertyName == nameof(MainPageViewModel.State))
{
if ((bindingContext.State == LevelState.GameOver))
{
GameOverAnimation.IsAnimationEnabled = true;
}
else if ((bindingContext.State == LevelState.Playing))
{
GameOverAnimation.IsAnimationEnabled = false;
}
}
else if (e.PropertyName == nameof(MainPageViewModel.AddedScore))
{
Device.BeginInvokeOnMainThread(async () =>
{
AddedScoreLabel.IsVisible = true;
await AddedScoreLabel.TranslateTo(0, -40, 500, Easing.Linear);
AddedScoreLabel.TranslateTo(0, 0, 0, Easing.Linear);
AddedScoreLabel.IsVisible = false;
});
}
}
void OnSwiped(object sender, SwipedEventArgs e)
{
switch (e.Direction)
{
case SwipeDirection.Left:
// Handle the swipe
break;
case SwipeDirection.Right:
// Handle the swipe
break;
case SwipeDirection.Up:
// Handle the swipe
break;
case SwipeDirection.Down:
// Handle the swipe
break;
}
}
private SwipeDirection? swipedDirection;
private void PanGestureRecognizer_PanUpdated(object sender, PanUpdatedEventArgs e)
{
switch (e.StatusType)
{
//case GestureStatus.Started:
// HandleTouchStart(e.TotalX, e.TotalY);
// break;
case GestureStatus.Running:
HandleTouch(e.TotalX, e.TotalY);
break;
case GestureStatus.Completed:
HandleTouchEnd(swipedDirection);
break;
}
}
private void HandleTouchStart(double eTotalX, double eTotalY)
{
eTotalXStart = eTotalX;
eTotalYStart = eTotalY;
}
private void HandleTouch(double eTotalX, double eTotalY)
{
swipedDirection = null;
const int delta = 10;
if (eTotalX > delta)
{
swipedDirection = SwipeDirection.Right;
}
else if (eTotalX < -delta)
{
swipedDirection = SwipeDirection.Left;
}
else if (eTotalY > delta)
{
swipedDirection = SwipeDirection.Down;
}
else if (eTotalY < -delta)
{
swipedDirection = SwipeDirection.Up;
}
}
private void HandleTouchEnd(SwipeDirection? swiped)
{
if (swiped == null)
{
return;
}
var currentViewModel = (MainPageViewModel)BindingContext;
switch (swiped)
{
case SwipeDirection.Right:
currentViewModel.RightSwipeCommand.Execute(null);
break;
case SwipeDirection.Left:
currentViewModel.LeftSwipeCommand.Execute(null);
break;
case SwipeDirection.Up:
currentViewModel.UpSwipeCommand.Execute(null);
break;
case SwipeDirection.Down:
currentViewModel.DownSwipeCommand.Execute(null);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
async void UndoButton_Clicked(System.Object sender, System.EventArgs e)
{
await Speak("Feature is not supported yet!!");
}
async void MauiRobotTapGestureRecognizer_Tapped(System.Object sender, System.EventArgs e)
{
await Speak("Hey I am MauiMarkup Robot!");
}
private async Task Speak(string phrase)
{
//Prevent multiple Taps before the animation gets completed.
if (canHitMauiRobot)
{
canHitMauiRobot = false;
HapticFeedback.Default.Perform(HapticFeedbackType.Click);
CurrentViewModel.MauiRobotPhrase = phrase;
phraseLayout.IsVisible = true;
await phraseLayout.TranslateTo(10, 30, 1000, Easing.CubicOut);
await phraseLayout.TranslateTo(0, 0, 1000, Easing.CubicIn);
phraseLayout.IsVisible = false;
canHitMauiRobot = true;
tappedDateTime = DateTime.Now;
}
}
void GameLabelTapGestureRecognizer_Tapped(System.Object sender, System.EventArgs e)
{
DisplayConfettiAnimation();
}
}