feat: l geminada working
This commit is contained in:
parent
1869a92580
commit
30ca50fb35
15 changed files with 189 additions and 29 deletions
|
@ -1,27 +1,42 @@
|
|||
using System.Collections.Generic;
|
||||
using Extensions;
|
||||
|
||||
namespace Domain {
|
||||
public class KeyHistory {
|
||||
private readonly List<int> _lastPresses = new();
|
||||
private readonly List<int> _desiredSequence;
|
||||
private readonly LimitedSizeList<int> _lastPresses = new(10);
|
||||
|
||||
public KeyHistory(List<int> desiredSequence) {
|
||||
_desiredSequence = desiredSequence;
|
||||
}
|
||||
private readonly bool[] _isPressed = new bool[26];
|
||||
private readonly bool[] _wasPressed = new bool[26];
|
||||
|
||||
public void KeyPressed(int key) => _lastPresses.Add(key);
|
||||
public void ClearPressed() => _lastPresses.Clear();
|
||||
|
||||
public bool ContainsSequence() {
|
||||
if (_lastPresses.Count < _desiredSequence.Count)
|
||||
public void CheckPresses() {
|
||||
const int aIndex = 0x41;
|
||||
const int zIndex = 0x5A;
|
||||
|
||||
for (int i = aIndex, j = 0; i <= zIndex; i++, j++) {
|
||||
_wasPressed[j] = _isPressed[j];
|
||||
short state = Win32API.GetAsyncKeyState(i);
|
||||
|
||||
if (!_wasPressed[j] && state != 0) {
|
||||
_isPressed[j] = true;
|
||||
KeyPressed(i);
|
||||
}else if (_isPressed[j] && state == 0) {
|
||||
_isPressed[j] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsSequence(List<int> sequence) {
|
||||
if (_lastPresses.List.Count < sequence.Count)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < _lastPresses.Count; i++) {
|
||||
if (i >= _desiredSequence.Count)
|
||||
for (int i = 0; i < _lastPresses.List.Count; i++) {
|
||||
if (i >= sequence.Count)
|
||||
break;
|
||||
|
||||
int keyPressed = _lastPresses[_lastPresses.Count - 1 - i];
|
||||
int sequenceKey = _desiredSequence[_desiredSequence.Count - 1 - i];
|
||||
int keyPressed = _lastPresses.List[_lastPresses.List.Count - 1 - i];
|
||||
int sequenceKey = sequence[sequence.Count - 1 - i];
|
||||
|
||||
if (keyPressed != sequenceKey) {
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue