Add difficulty levels

This commit is contained in:
Dean Herbert 2022-06-07 18:11:54 +09:00
parent 3bd8bbd297
commit a175defefd
1 changed files with 73 additions and 37 deletions

View File

@ -4,6 +4,7 @@
#nullable enable
using System;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions.Color4Extensions;
@ -45,9 +46,20 @@ public class LatencyComparerScreen : OsuScreen
[Cached]
private readonly OverlayColourProvider overlayColourProvider = new OverlayColourProvider(OverlayColourScheme.Orange);
[Resolved]
private OsuColour colours { get; set; } = null!;
[Resolved]
private FrameworkConfigManager config { get; set; } = null!;
private const int rounds_to_complete = 5;
private int round;
private int correctCount;
private int targetRoundCount = rounds_to_complete;
private int difficulty = 1;
public LatencyComparerScreen()
{
InternalChildren = new Drawable[]
@ -82,12 +94,11 @@ public LatencyComparerScreen()
},
explanatoryText = new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: 20))
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
TextAnchor = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Y = 200,
Text = @"Welcome to the latency comparer!
Use the arrow keys or Z/X to move the square.
You can click the targets but you don't have to.
@ -96,9 +107,10 @@ You can click the targets but you don't have to.
},
statusText = new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: 40))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
TextAnchor = Anchor.TopCentre,
Y = 200,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
@ -132,13 +144,6 @@ protected override void LoadComplete()
loadNextRound();
}
private int round;
private const int rounds_to_complete = 10;
private int correctCount;
private int targetRoundCount = rounds_to_complete;
private void recordResult(bool correct)
{
explanatoryText.FadeOut(500, Easing.OutQuint);
@ -157,21 +162,21 @@ private void recordResult(bool correct)
private void loadNextRound()
{
round++;
statusText.Text = $"Round {round} of {targetRoundCount}";
statusText.Text = $"Difficulty {difficulty}\nRound {round} of {targetRoundCount}";
mainArea.Clear();
const int induced_latency = 1;
const int induced_latency = 500;
int betterSide = RNG.Next(0, 2);
mainArea.Add(new LatencyArea(betterSide == 1 ? induced_latency : 0)
mainArea.Add(new LatencyArea(betterSide == 1 ? induced_latency / difficulty : 0)
{
Width = 0.5f,
ReportBetter = () => recordResult(betterSide == 0)
});
mainArea.Add(new LatencyArea(betterSide == 0 ? induced_latency : 0)
mainArea.Add(new LatencyArea(betterSide == 0 ? induced_latency / difficulty : 0)
{
Width = 0.5f,
Anchor = Anchor.TopRight,
@ -186,28 +191,70 @@ private void showResults()
statusText.Text = $"You scored {correctCount} out of {targetRoundCount} ({(float)correctCount / targetRoundCount:P0})!";
resultsArea.Add(new Container
resultsArea.Add(new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Y = 100,
Spacing = new Vector2(20),
Children = new Drawable[]
{
new Button
{
Text = "Increase confidence",
Text = "Increase confidence at current level",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Y = 100,
Action = () =>
{
resultsArea.Clear();
targetRoundCount += rounds_to_complete;
loadNextRound();
}
},
new Button
{
Text = "Increase difficulty",
BackgroundColour = colours.Red2,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Action = () =>
{
changeDifficulty(difficulty + 1);
}
},
new Button
{
Text = "Decrease difficulty",
BackgroundColour = colours.Green,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Enabled = { Value = difficulty > 1 },
Action = () =>
{
resultsArea.Clear();
correctCount = 0;
targetRoundCount = rounds_to_complete;
difficulty--;
loadNextRound();
}
}
}
});
}
private void changeDifficulty(int diff)
{
Debug.Assert(diff > 0);
resultsArea.Clear();
correctCount = 0;
round = 0;
targetRoundCount = rounds_to_complete;
difficulty = diff;
loadNextRound();
}
public class LatencyArea : CompositeDrawable
{
[Resolved]
@ -219,10 +266,6 @@ public class LatencyArea : CompositeDrawable
private readonly int inducedLatency;
private Container interactivePieces = null!;
private Button button = null!;
private long frameCount;
public LatencyArea(int inducedLatency)
@ -244,10 +287,9 @@ protected override void LoadComplete()
Colour = overlayColourProvider.Background6,
RelativeSizeAxes = Axes.Both,
},
interactivePieces = new Container
new Container
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Children = new Drawable[]
{
new LatencyMovableBox
@ -260,10 +302,9 @@ protected override void LoadComplete()
},
}
},
button = new Button
new Button
{
Text = "Feels better",
Alpha = 0,
Y = 20,
Width = 0.8f,
Anchor = Anchor.TopCentre,
@ -271,15 +312,6 @@ protected override void LoadComplete()
Action = () => ReportBetter?.Invoke(),
},
};
base.LoadComplete();
this.FadeInFromZero(500, Easing.OutQuint);
using (BeginDelayedSequence(500))
{
interactivePieces.FadeIn(500, Easing.OutQuint);
button.FadeIn(500, Easing.OutQuint);
}
}
protected override bool OnHover(HoverEvent e)
@ -344,7 +376,11 @@ protected override void Update()
{
float movementAmount = (float)(Clock.CurrentTime - lastFrameTime) / 400;
foreach (var key in inputManager.CurrentState.Keyboard.Keys)
var buttons = inputManager.CurrentState.Keyboard.Keys;
box.Colour = buttons.HasAnyButtonPressed ? overlayColourProvider.Content1 : overlayColourProvider.Colour1;
foreach (var key in buttons)
{
switch (key)
{