Added Function Key based speed settings for conducting user experiments

This commit is contained in:
Dwayne 2019-04-22 16:53:32 -07:00
Родитель fe41a78aff
Коммит 31b92656c8
3 изменённых файлов: 102 добавлений и 29 удалений

Просмотреть файл

@ -155,7 +155,7 @@
<Rectangle Grid.Row="1" Grid.Column="2" Width="180"/> <Rectangle Grid.Row="1" Grid.Column="2" Width="180"/>
<GridView x:Name="GameBoardBackGroundGrid" ItemsSource="{x:Bind Path=Board.Cells, Mode=OneWay}" FontFamily="Segoe UI" Grid.Row="1" Grid.Column="1" Padding="0,0,0,0" FocusVisualPrimaryThickness="0,0,0,0" FocusVisualMargin="0,0,0,-1" FocusVisualSecondaryThickness="0,0,0,0" > <GridView x:Name="GameBoardBackGroundGrid" ItemsSource="{x:Bind Path=Board.Cells, Mode=OneWay}" FontFamily="Segoe UI" Grid.Row="1" Grid.Column="1" Padding="0,0,0,0" FocusVisualPrimaryThickness="0,0,0,0" FocusVisualMargin="0,0,0,-1" FocusVisualSecondaryThickness="0,0,0,0" AllowFocusOnInteraction="False" >
<GridView.ItemsPanel> <GridView.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="4" HorizontalAlignment="Center" VerticalAlignment="Center" /> <ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="4" HorizontalAlignment="Center" VerticalAlignment="Center" />
@ -171,7 +171,7 @@
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</GridView> </GridView>
<GridView x:Name="GameBoardGrid" x:FieldModifier="public" ItemsSource="{x:Bind Path=Board.Cells, Mode=OneWay}" Grid.Row="1" Grid.Column="1" SizeChanged="GameBoardGrid_SizeChanged" FontFamily="Segoe UI" Padding="0,0,0,0" ScrollViewer.VerticalScrollBarVisibility="Disabled" FocusVisualMargin="0,0,0,0" FocusVisualPrimaryThickness="0,0,0,0" FocusVisualSecondaryThickness="0,0,0,0"> <GridView x:Name="GameBoardGrid" x:FieldModifier="public" ItemsSource="{x:Bind Path=Board.Cells, Mode=OneWay}" Grid.Row="1" Grid.Column="1" SizeChanged="GameBoardGrid_SizeChanged" FontFamily="Segoe UI" Padding="0,0,0,0" ScrollViewer.VerticalScrollBarVisibility="Disabled" FocusVisualMargin="0,0,0,0" FocusVisualPrimaryThickness="0,0,0,0" FocusVisualSecondaryThickness="0,0,0,0" AllowFocusOnInteraction="False">
<GridView.ItemsPanel> <GridView.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="10" HorizontalAlignment="Center" VerticalAlignment="Center" /> <ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="10" HorizontalAlignment="Center" VerticalAlignment="Center" />
@ -216,22 +216,22 @@
<Rectangle Width="{x:Bind GameBoardGrid.ActualWidth}" Height="{x:Bind GameBoardGrid.ActualHeight}" Grid.Row="1" Grid.Column="1"></Rectangle> <Rectangle Width="{x:Bind GameBoardGrid.ActualWidth}" Height="{x:Bind GameBoardGrid.ActualHeight}" Grid.Row="1" Grid.Column="1"></Rectangle>
<Button x:Name="UpButton" Grid.Row="0" Grid.Column="1" Style="{StaticResource ButtonStyle}" Click="OnUpClick" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Foreground="{StaticResource TileForeground}" Width="{x:Bind Board.CellSpace, Mode=OneWay}" Background="{x:Null}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" > <Button x:Name="UpButton" Grid.Row="0" Grid.Column="1" Style="{StaticResource ButtonStyle}" Click="OnUpClick" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Foreground="{StaticResource TileForeground}" Width="{x:Bind Board.CellSpace, Mode=OneWay}" Background="{x:Null}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" gaze:GazeInput.DwellDuration="{x:Bind Board.SlideDwellSpeed, Mode=OneWay}">
<Border Background="{StaticResource TileBackground}" CornerRadius="5" HorizontalAlignment="Stretch"> <Border Background="{StaticResource TileBackground}" CornerRadius="5" HorizontalAlignment="Stretch">
<TextBlock Text="&#xe70e;" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold"></TextBlock> <TextBlock Text="&#xe70e;" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold"></TextBlock>
</Border> </Border>
</Button> </Button>
<Button x:Name="DownButton" Grid.Row="2" Grid.Column="1" Style="{StaticResource ButtonStyle}" Click="OnDownClick" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="{StaticResource TileForeground}" Width="{x:Bind Board.CellSpace, Mode=OneWay}" Background="{x:Null}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> <Button x:Name="DownButton" Grid.Row="2" Grid.Column="1" Style="{StaticResource ButtonStyle}" Click="OnDownClick" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="{StaticResource TileForeground}" Width="{x:Bind Board.CellSpace, Mode=OneWay}" Background="{x:Null}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" gaze:GazeInput.DwellDuration="{x:Bind Board.SlideDwellSpeed, Mode=OneWay}">
<Border Background="{StaticResource TileBackground}" CornerRadius="5" HorizontalAlignment="Stretch"> <Border Background="{StaticResource TileBackground}" CornerRadius="5" HorizontalAlignment="Stretch">
<TextBlock Text="&#xe70d;" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold"></TextBlock> <TextBlock Text="&#xe70d;" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold"></TextBlock>
</Border> </Border>
</Button> </Button>
<Button x:Name="LeftButton" Grid.Row="1" Grid.Column="0" Style="{StaticResource ButtonStyle}" Click="OnLeftClick" HorizontalAlignment="Right" VerticalAlignment="Stretch" Background="{x:Null}" Foreground="{StaticResource TileForeground}" Height="{x:Bind Board.CellSpace, Mode=OneWay}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> <Button x:Name="LeftButton" Grid.Row="1" Grid.Column="0" Style="{StaticResource ButtonStyle}" Click="OnLeftClick" HorizontalAlignment="Right" VerticalAlignment="Stretch" Background="{x:Null}" Foreground="{StaticResource TileForeground}" Height="{x:Bind Board.CellSpace, Mode=OneWay}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" gaze:GazeInput.DwellDuration="{x:Bind Board.SlideDwellSpeed, Mode=OneWay}">
<Border Background="{StaticResource TileBackground}" CornerRadius="5" HorizontalAlignment="Stretch"> <Border Background="{StaticResource TileBackground}" CornerRadius="5" HorizontalAlignment="Stretch">
<TextBlock Text="&#xe76b;" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold"></TextBlock> <TextBlock Text="&#xe76b;" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold"></TextBlock>
</Border> </Border>
</Button> </Button>
<Button x:Name="RightButton" Grid.Row="1" Grid.Column="2" Style="{StaticResource ButtonStyle}" Click="OnRightClick" HorizontalAlignment="Left" VerticalAlignment="Stretch" Background="{x:Null}" Foreground="{StaticResource TileForeground}" Height="{x:Bind Board.CellSpace, Mode=OneWay}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> <Button x:Name="RightButton" Grid.Row="1" Grid.Column="2" Style="{StaticResource ButtonStyle}" Click="OnRightClick" HorizontalAlignment="Left" VerticalAlignment="Stretch" Background="{x:Null}" Foreground="{StaticResource TileForeground}" Height="{x:Bind Board.CellSpace, Mode=OneWay}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" gaze:GazeInput.DwellDuration="{x:Bind Board.SlideDwellSpeed, Mode=OneWay}">
<Border Background="{StaticResource TileBackground}" CornerRadius="5" HorizontalAlignment="Stretch"> <Border Background="{StaticResource TileBackground}" CornerRadius="5" HorizontalAlignment="Stretch">
<TextBlock Text="&#xe76c;" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold"></TextBlock> <TextBlock Text="&#xe76c;" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold"></TextBlock>
</Border> </Border>

Просмотреть файл

@ -191,8 +191,9 @@ namespace TwoZeroFourEight
public class Board : NotificationBase public class Board : NotificationBase
{ {
private int _SlideSpeed = 200; private BoardSpeed _boardSpeed = BoardSpeed.Slow;
private int _AddSpeed = 500; private int _SlideSpeed = 200;
private int _AddSpeed = 500;
private int _SpawnSpeed = 25; private int _SpawnSpeed = 25;
private int _maxCells; private int _maxCells;
private Random _random = new Random(); private Random _random = new Random();
@ -265,6 +266,49 @@ namespace TwoZeroFourEight
} }
} }
private TimeSpan _slideDwellSpeed = TimeSpan.FromMilliseconds(100);
public TimeSpan SlideDwellSpeed
{
get { return _slideDwellSpeed; }
set
{
SetField<TimeSpan>(ref _slideDwellSpeed, value, "SlideDwellSpeed");
}
}
public enum BoardSpeed
{
Slow,
Fast
}
public void SetBoardSpeed(BoardSpeed speed)
{
_boardSpeed = speed;
switch (_boardSpeed)
{
case BoardSpeed.Slow:
_SlideSpeed = 200;
_AddSpeed = 500;
_SpawnSpeed = 25;
break;
case BoardSpeed.Fast:
_SlideSpeed = 100;
_AddSpeed = 100;
_SpawnSpeed = 25;
break;
default:
_SlideSpeed = 200;
_AddSpeed = 500;
_SpawnSpeed = 25;
break;
}
}
private void UpdateCellSizes() private void UpdateCellSizes()
{ {
double borderSpace = _boardSize * 4; // cells get default margin of 4 double borderSpace = _boardSize * 4; // cells get default margin of 4
@ -412,8 +456,8 @@ namespace TwoZeroFourEight
var scaleAnimation = compositor.CreateSpringVector3Animation(); var scaleAnimation = compositor.CreateSpringVector3Animation();
scaleAnimation.InitialValue = new System.Numerics.Vector3(0.5f, 0.5f, 0f); scaleAnimation.InitialValue = new System.Numerics.Vector3(0.5f, 0.5f, 0f);
scaleAnimation.FinalValue = new System.Numerics.Vector3(1.0f, 1.0f, 0f); scaleAnimation.FinalValue = new System.Numerics.Vector3(1.0f, 1.0f, 0f);
scaleAnimation.DampingRatio = 0.09f; scaleAnimation.DampingRatio = 0.6f;
scaleAnimation.Period = TimeSpan.FromMilliseconds(_SpawnSpeed); scaleAnimation.Period = TimeSpan.FromMilliseconds(_SpawnSpeed);
newCellVisual.StartAnimation(nameof(newCellVisual.Scale), scaleAnimation); newCellVisual.StartAnimation(nameof(newCellVisual.Scale), scaleAnimation);
@ -457,8 +501,8 @@ namespace TwoZeroFourEight
var slideToCellVisual = ElementCompositionPreview.GetElementVisual(Buttons[cur]); var slideToCellVisual = ElementCompositionPreview.GetElementVisual(Buttons[cur]);
var compositor = slideToCellVisual.Compositor; var compositor = slideToCellVisual.Compositor;
var slideFromCellVisual = ElementCompositionPreview.GetElementVisual(Buttons[j]); var slideFromCellVisual = ElementCompositionPreview.GetElementVisual(Buttons[j]);
var easing = compositor.CreateLinearEasingFunction(); CubicBezierEasingFunction easing = compositor.CreateCubicBezierEasingFunction(new Vector2(.86f, 0.0f), new Vector2(.07f, 1.00f));
///slideAnimation ///slideAnimation
/// ///
@ -523,15 +567,15 @@ namespace TwoZeroFourEight
var answerTextVisual = ElementCompositionPreview.GetElementVisual(answerText as FrameworkElement); var answerTextVisual = ElementCompositionPreview.GetElementVisual(answerText as FrameworkElement);
var cellTextVisual = ElementCompositionPreview.GetElementVisual(cellText as FrameworkElement); var cellTextVisual = ElementCompositionPreview.GetElementVisual(cellText as FrameworkElement);
var easing = compositor.CreateLinearEasingFunction(); CubicBezierEasingFunction easing = compositor.CreateCubicBezierEasingFunction(new Vector2(.86f, 0.0f), new Vector2(.07f, 1.00f));
///Scale the ToCell to breifly be twice the size and then back down to regular size ///Scale the ToCell to breifly be twice the size and then back down to regular size
/// ///
slideToCellVisual.CenterPoint = new System.Numerics.Vector3(slideToCellVisual.Size.X / 2, slideToCellVisual.Size.Y / 2, 0f); slideToCellVisual.CenterPoint = new System.Numerics.Vector3(slideToCellVisual.Size.X / 2, slideToCellVisual.Size.Y / 2, 0f);
var scaleUpAnimation = compositor.CreateVector3KeyFrameAnimation(); var scaleUpAnimation = compositor.CreateVector3KeyFrameAnimation();
scaleUpAnimation.InsertKeyFrame(0f, new System.Numerics.Vector3(1.0f, 1.0f, 0f), easing); scaleUpAnimation.InsertKeyFrame(0f, new System.Numerics.Vector3(1.0f, 1.0f, 0f), easing);
scaleUpAnimation.InsertKeyFrame(0.5f, new System.Numerics.Vector3(1.5f, 1.5f, 0f), easing); scaleUpAnimation.InsertKeyFrame(0.5f, new System.Numerics.Vector3(1.2f, 1.2f, 0f), easing);
scaleUpAnimation.InsertKeyFrame(1f, new System.Numerics.Vector3(1.0f, 1.0f, 0f), easing); scaleUpAnimation.InsertKeyFrame(1f, new System.Numerics.Vector3(1.0f, 1.0f, 0f), easing);
scaleUpAnimation.Duration = TimeSpan.FromMilliseconds(_AddSpeed); scaleUpAnimation.Duration = TimeSpan.FromMilliseconds(_AddSpeed);
@ -567,17 +611,23 @@ namespace TwoZeroFourEight
_slideBatchAnimation.Suspend(); _slideBatchAnimation.Suspend();
_addAdjacentBatchAnimation.Suspend(); _addAdjacentBatchAnimation.Suspend();
slideToCellVisual.StartAnimation(nameof(slideToCellVisual.Scale), scaleUpAnimation); slideToCellVisual.StartAnimation(nameof(slideToCellVisual.Scale), scaleUpAnimation);
answerTextVisual.StartAnimation(nameof(answerTextVisual.Opacity), showAnswerAnimation); if (_boardSpeed == BoardSpeed.Slow)
answerTextVisual.StartAnimation(nameof(answerTextVisual.Scale), scaleAnswerAnimation); {
cellTextVisual.StartAnimation(nameof(cellTextVisual.Opacity), showCellTextAnimation); answerTextVisual.StartAnimation(nameof(answerTextVisual.Opacity), showAnswerAnimation);
answerTextVisual.StartAnimation(nameof(answerTextVisual.Scale), scaleAnswerAnimation);
cellTextVisual.StartAnimation(nameof(cellTextVisual.Opacity), showCellTextAnimation);
}
_addAdjacentBatchAnimation.Resume(); _addAdjacentBatchAnimation.Resume();
_slideBatchAnimation.Resume(); _slideBatchAnimation.Resume();
Canvas.SetZIndex(Buttons[cur], GetHighestButtonIndex() + 1); Canvas.SetZIndex(Buttons[cur], GetHighestButtonIndex() + 1);
Cells[cur].AnswerString = Cells[cur].IntVal.ToString() + " + " + Cells[cur + delta].IntVal.ToString(); if (_boardSpeed == BoardSpeed.Slow)
{
Cells[cur].AnswerString = Cells[cur].IntVal.ToString() + " + " + Cells[cur + delta].IntVal.ToString();
}
Cells[cur].IntVal += Cells[cur + delta].IntVal; Cells[cur].IntVal += Cells[cur + delta].IntVal;
doubledVal = Cells[cur].IntVal; doubledVal = Cells[cur].IntVal;
if (totalBonus > -1) if (totalBonus > -1)
@ -793,7 +843,7 @@ namespace TwoZeroFourEight
public Board Board; public Board Board;
private SolidColorBrush _solidTileForegroundBrush; private SolidColorBrush _solidTileForegroundBrush;
private SolidColorBrush _solidTileBrush; private SolidColorBrush _solidTileBrush;
public MainPage() public MainPage()
{ {
@ -814,8 +864,8 @@ namespace TwoZeroFourEight
GazeSettingsHelper.RetrieveSharedSettings(sharedSettings).Completed = new AsyncActionCompletedHandler((asyncInfo, asyncStatus) => GazeSettingsHelper.RetrieveSharedSettings(sharedSettings).Completed = new AsyncActionCompletedHandler((asyncInfo, asyncStatus) =>
{ {
GazeInput.LoadSettings(sharedSettings); GazeInput.LoadSettings(sharedSettings);
}); });
} }
private void OnNewGame(object sender, RoutedEventArgs e) private void OnNewGame(object sender, RoutedEventArgs e)
{ {
@ -848,17 +898,40 @@ namespace TwoZeroFourEight
switch (e.Key) switch (e.Key)
{ {
case VirtualKey.Up: case VirtualKey.Up:
Board.SlideUp(); Board.SlideUp();
break; break;
case VirtualKey.Down: case VirtualKey.Down:
Board.SlideDown(); Board.SlideDown();
break; break;
case VirtualKey.Left: case VirtualKey.Left:
Board.SlideLeft(); Board.SlideLeft();
break; break;
case VirtualKey.Right: case VirtualKey.Right:
Board.SlideRight(); Board.SlideRight();
break; break;
case VirtualKey.F1:
Board.SetBoardSpeed(Board.BoardSpeed.Slow);
break;
case VirtualKey.F2:
Board.SetBoardSpeed(Board.BoardSpeed.Fast);
break;
case VirtualKey.F3:
int newSpeed = Board.SlideDwellSpeed.Milliseconds - 100;
if (newSpeed < 100) newSpeed = 100;
Board.SlideDwellSpeed = TimeSpan.FromMilliseconds(newSpeed);
break;
case VirtualKey.F4:
Board.SlideDwellSpeed = TimeSpan.FromMilliseconds(800);
break;
case VirtualKey.F5:
Board.SlideDwellSpeed = TimeSpan.FromMilliseconds(Board.SlideDwellSpeed.Milliseconds + 100);
break;
} }
} }

Просмотреть файл

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp"> <Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Identity Name="4e21ae5c-147f-4626-b664-0dddb7bcfbab" Publisher="CN=harishsk" Version="1.0.19.0" /> <Identity Name="4e21ae5c-147f-4626-b664-0dddb7bcfbab" Publisher="CN=harishsk" Version="1.0.21.0" />
<mp:PhoneIdentity PhoneProductId="4e21ae5c-147f-4626-b664-0dddb7bcfbab" PhonePublisherId="00000000-0000-0000-0000-000000000000" /> <mp:PhoneIdentity PhoneProductId="4e21ae5c-147f-4626-b664-0dddb7bcfbab" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties> <Properties>
<DisplayName>2048</DisplayName> <DisplayName>2048</DisplayName>