简体   繁体   English

C#-我需要弄清楚如何使GUI监听IF语句中被按下的按钮

[英]C# - I need to figure out how to make GUI that listens for buttons being pressed in a IF statement

So currently, I am writing a small text adventure game in C# and I am using Visual Studio Express 2013. In the forms method, I have a button "buttonContinue" method that is called when I press the button; 因此,当前,我正在用C#编写一个小型的文字冒险游戏,并且正在使用Visual Studio Express2013。在Forms方法中,我有一个按钮“ buttonContinue”方法,当我按下该按钮时会调用它; pretty simple. 很简单 I also have a button "buttonA", "buttonB", "buttonC" which are the controls for the game. 我还有一个按钮“ buttonA”,“ buttonB”,“ buttonC”,它们是游戏的控件。

Now. 现在。 How the game is working currently is that you press the buttonContinue to progress through the game and when you press the continue button, you have a random chance of coming across an event such as coming across a monster, finding an NPC, or coming across an "event" (event is not important at the moment). 当前游戏的运行方式是您按下按钮继续游戏的进行,当您按下继续按钮时,您会随机遇到一个事件,例如遇到怪物,找到NPC或遇到“事件”(当前事件不重要)。 As of now, buttonA and buttonB is being used to eat an apple that you might pick up during the game or to drink water that you might be carrying. 截至目前,buttonA和buttonB已用于吃游戏中可能会捡起的苹果或喝水。

Here is the problem: I want to make buttonA and buttonB to function differently when in a battle or an event. 这是问题所在:我想让buttonA和buttonB在战斗或事件中发挥不同的作用。 I want buttonA to be a button to fight the monster, buttonB is to try to hide from the monster, buttonC is to make an attempt to run. 我希望buttonA是与怪物战斗的按钮,buttonB是试图躲避怪物的按钮,buttonC是尝试运行的按钮。 As of now the only solution I'v come up with is to make a while LOOP that checks if buttonA, B, or C has been pressed when encountered a monster -BUT- the GUI does not PAUSE or LISTEN for buttonA, B, or C is being pressed as an IF statement. 到目前为止,我想出的唯一解决方案是创建一个LOOP,以检查遇到怪兽时是否按下了buttonA,B或C-但是,GUI不会暂停或监听按钮A,B或C C作为IF语句被按下。

Here is the small part of the code from my game: 这是我的游戏代码的一小部分:

Attributes.monsterDead = false;
    while (Attributes.monsterDead == false)
    {
        if (buttonAClicked == true)
        {
            Goblin.GoblinAttack();
            buttonAClicked = false;
        }
        if (buttonBClicked == true)
        {

        }
        if (buttonCClicked == true)
        {

        }
   }

Now where the WHILE statement is called, since there is nothing that waits and listens for these if statements are true, it just goes on a infinite loop with no time limit causing the program to completely freeze. 现在调用WHILE语句的地方,由于没有任何等待和监听这些if语句为true的情况,因此它会无限循环,没有时间限制,导致程序完全冻结。

I am not very skilled in C# yet as I am still learning and taking class for it. 我还不太熟练C#,因为我仍在学习和上C#。 Furthermore, this is my first post in this website. 此外,这是我在本网站上的第一篇文章。 Please help me fix this problem, I can give you any more information if needed! 请帮助我解决此问题,如果需要,我可以为您提供更多信息! Thank you! 谢谢!

EDIT: I decided to include the source-code so I can get this problem fixed faster. 编辑:我决定包括源代码,以便可以更快地解决此问题。
Form1.cs - pastebin(DOT)com/idJaR20V Form1.cs-pastebin(DOT)com / idJaR20V
Goblin.cs - pastebin(DOT)com/Ti1L4XzN Goblin.cs-pastebin(DOT)com / Ti1L4XzN
Attrivutes.cs - pastebin(DOT)com/GfJAJ1u5 Attrivutes.cs-pastebin(DOT)com / GfJAJ1u5

I'm still inexperienced with C# programming and it's functions but would it be possible to run both buttonContinue and buttonA method at the same time? 我对C#编程及其功能仍然缺乏经验,但是可以同时运行buttonContinue和buttonA方法吗? Make it so buttonContinue is disabled when encountered a monster and have only buttonA, B, C have functions while the buttonContinue is still running? 使其在遇到怪物时被禁用buttonContinue,并且在buttonContinue仍在运行时只有按钮A,B,C具有功能吗? :/ :/

If i were to initiate another method while a different method is running, wouldn't one of the method stop working and pop out all the data/progress it was in? 如果我要在运行其他方法时启动另一个方法,该方法中的一个不会停止工作并弹出其中的所有数据/进程吗? I'm not too sure. 我不太确定

Create 3 different buttons X, Y, Z . 创建3个不同的按钮X, Y, Z Put wanted functionality for battle in this 3 buttons in OnClick functionality. OnClick功能的这3个按钮中放置所需的战斗功能。

When you are in event A, B, C visible. 当您处于事件A, B, C可见。 In this case X, Y, Z are not visible. 在这种情况下, X, Y, Z不可见。

When you are in battle X, Y, Z visibile. 当您在战斗中时, X, Y, Z可见。 In this case A, B, C are not. 在这种情况下, A, B, C不是。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XNA C#-如何在不被按下的情况下按下按钮 - XNA C# - How to make a button pressed without being pressed 如何在C#中的单击事件中找出正在按下的键? - How can i find out what key is being pressed in a click event in C#? 如何确保在 C# 中没有按下按钮? - How do I make sure that a button is not pressed down in C#? 如何在C#中制作GUI - How to make gui in c# C#需要如果语句来检查空间和箭头键按下 - c# need if statement to check for space and arrow keys pressed 在使用C#Code生成Midi Track时,如何才能播放音调,而不是淡出? - In generating Midi Track using C# Code, how Can I make the tone being played, not fading out? 需要帮助弄清楚如何在 C# WinForms GUI 中捕获和显示 C 类型的结构值 - Need help figuring out how to capture and display a C type struct value in a C# WinForms GUI 如何为C#XNA游戏制作GUI? - How can I make a GUI for my C# XNA game? 我只需要减少每行的输入。 然后在C#中每个单词空间剪切每一行,但我似乎无法弄清楚2D数组是如何工作的 - I just need to cut an input per line. and then cut each line per word space in C# but I cant seem to figure out how 2d arrays work 我正在尝试在 c# 控制台应用程序中制作一个简单的流氓进行练习,但不知道如何为项目添加各种效果 - I am trying to make a simple rogue like in c# console app for practice and can't figure out how to add various Effects to items
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM