Home > other >  How do I get the user to only press 1 button per turn?
How do I get the user to only press 1 button per turn?

Time:11-13

I am creating a windows forms app (C#) and I want to make a little rpg style battle game where you can perform 1 action per turn: Attack, block, use item, or run. I am new to these kinds of apps however, so can someone explain how I can only let the user hit 1 of the 4 buttons per turn?

I attempted to use .Click, but didn't understand it well enough.

CodePudding user response:

Bool would be the best go to for an action that can happen only once as there’s only 2 outcomes (true or false) you’re able to set to True to start with and then check if an action has been completed and if so, set to false then, the next turn, would go back to true.

CodePudding user response:

Big deal to start right away with the game.

If you want to prohibit clicking on buttons, make them non-clickable.

e.g. on a click action

private void button2_Click(object sender, EventArgs e)
{
    // action is being performed here
    // ...
    // then all buttons become inactive:
    button1.Enabled = false;
    button2.Enabled = false;
    button3.Enabled = false;
    button4.Enabled = false;

    // then you wait for another action where the button's accessibility becomes true
}
  • Related