Ninja Kirby
Ninja Kirby
CC#
Created by Ninja Kirby on 7/5/2024 in #help
should state machine have ability to add/remove
are state machines meant to be dynamic? lets say i got deez:
c#
public class State<TArgs>
{
public event EventHandler<TArgs> OnEnter;

public void Enter(object sender, TArgs e)
{
OnEnter?.Invoke(sender, e);
}

public event EventHandler<TArgs> OnExit;

public void Exit(object sender, TArgs e)
{
OnExit?.Invoke(sender, e);
}
}

public class StateMachine<TArgs>
{
private State<TArgs> _currentState;

public State<TArgs> CurrentState
{
get
{
return _currentState;
}
set
{

if (_currentState != value)
{
if (_currentState is not null)
{
_currentState.Exit(this, StateArguments);
}

value.Enter(this, StateArguments);

_currentState = value;
}

}
}

//adding/removing omitted for brevity :trolol:
}
c#
public class State<TArgs>
{
public event EventHandler<TArgs> OnEnter;

public void Enter(object sender, TArgs e)
{
OnEnter?.Invoke(sender, e);
}

public event EventHandler<TArgs> OnExit;

public void Exit(object sender, TArgs e)
{
OnExit?.Invoke(sender, e);
}
}

public class StateMachine<TArgs>
{
private State<TArgs> _currentState;

public State<TArgs> CurrentState
{
get
{
return _currentState;
}
set
{

if (_currentState != value)
{
if (_currentState is not null)
{
_currentState.Exit(this, StateArguments);
}

value.Enter(this, StateArguments);

_currentState = value;
}

}
}

//adding/removing omitted for brevity :trolol:
}
3 replies
CC#
Created by Ninja Kirby on 3/13/2024 in #help
✅ having stupidity. why can THE ROOOOOOOOOOOOOOOOK!!! move through the first pawn?
No description
63 replies
CC#
Created by Ninja Kirby on 2/17/2024 in #help
✅ what is this? i dont know what to call this.
I'm making the game "simon" in winforms, and i ran into a 'problem'. In my game class, there's 2 lists of integers, the event sequence (the one the player should input) and the player input (the one the player actually inputs.) Whenever the player clicks a corresponding button, I add that button's index to the player inputs list. However, I do this via a lambda expression within a for loop as shown here:
for (int i = 0; i < 4; i++)
{
int idx = i;

SimonButton btn = SimonButtons[idx];

btn.MouseClick += (sender, e) =>
{
if (btn.IsLocked)
return;

_playerInputs.Add(i); // always results in adding 4 if I use i but not idx?? ????????
Console.WriteLine(i);
Console.WriteLine(idx);

_gameOver = IsGameOver();
};
}
for (int i = 0; i < 4; i++)
{
int idx = i;

SimonButton btn = SimonButtons[idx];

btn.MouseClick += (sender, e) =>
{
if (btn.IsLocked)
return;

_playerInputs.Add(i); // always results in adding 4 if I use i but not idx?? ????????
Console.WriteLine(i);
Console.WriteLine(idx);

_gameOver = IsGameOver();
};
}
why is it that if I put i as the .Add() parameter, it's always 4, but not idx, which is always i anyway?
7 replies
CC#
Created by Ninja Kirby on 2/16/2024 in #help
✅ WinForms - Parameter is not valid?
No description
27 replies
CC#
Created by Ninja Kirby on 12/16/2023 in #help
is there a way to do Console.ReadLine() asynchronously?
what the title says. it's always a blocking method, no matter which way you spin it, so im not sure if there's like a workaround or something
28 replies