C#游戏中While循环崩溃 - c#

我正在为一个项目创建Kinect Text Adventure游戏。我知道代码不是很好,但是该项目在游戏效果方面的功能远胜于游戏本身,因此不必太复杂。这部分代码用于使用某些骨骼位置来逐步进行游戏。我遇到的问题是我正在尝试使用while循环,以便根据f的当前值,它将进入该特定房间。唯一的问题是,当我使用while循环时,它总是在启动之前就崩溃了。我不确定是什么问题

private void ProcessGesture(Joint head, Joint handleft, Joint handright)
    {

        while (f!=0)
        {


            if (handright.Position.Y > head.Position.Y && handleft.Position.Y > head.Position.Y && f == 1)
            {
                txtBox1.Text = "You find yourself at the foot of a large mountain, with a gaping cave at the front. \nYou have come here to find the Lost Sword of Gaia and you have heard that it lies \nhere in the Cave of Borlak the Red. You can move east";
                f = 2;
                this.btnangle.Visibility = Visibility.Hidden;
                this.slider1.Visibility = Visibility.Hidden;
                this.Degree.Visibility = Visibility.Hidden;
                this.helpbtn.Visibility = Visibility.Hidden;


            } 

            if (handright.Position.X > 0.3 && f == 2)
            {
                txtBox1.Text = "You walk up to the entrance of the cave and spot and \nlittle goblin wearing a suit of armour and holding a spear. \n'I'm so bored' he says. 'What I need is a good high five'\nYou can go west";
                f = 3;
                this.sadGoblin.Visibility = Visibility.Visible;
            }
            if ((f == 3 && handright.Position.Y > head.Position.Y) || (f == 3 && handleft.Position.Y > head.Position.Y))
            {
                Uri uri1 = new Uri("/SkeletalTracking;component/Resources/hgoblin.jpg", UriKind.Relative);

                ImageSource source1 = new BitmapImage(uri1);

                this.sadGoblin.Source = source1;

                txtBox1.Text = "'Ah, thank you kind stranger, for that I shall let you in'.\n The goblin steps to the side ";

                f = 4;
            }
            if (f == 4 && handright.Position.Y > head.Position.Y && handleft.Position.Y > head.Position.Y)
            {
                this.sadGoblin.Visibility = Visibility.Hidden;
                txtBox1.Text = "You are now in the main hall of the mountain. You can hear chanting and singing from the north.\nYou see a statue in the middle of the room and two doors to the left and right of it";
                f = 5;
            }
            if (f == 5 && handleft.Position.X < -0.3)
            {
                txtBox1.Text = "This is Borlak's treasure room. In here are all of the things he has colleted over the years\nSome bought and some not so bought.\nYour eyes are drawn to a necklace in a glass case in the center of the room.\nThere is also a picture of Borlak holding a giant chunk of ham\nYou can go east";
                f = 6;

            }
            if (f == 6 && handright.Position.X > 0.3)
            {
                f = 5;
            }
            //else if (f == 5 && handright.Position.X > 0.3)
            // {
            //     txtBox1.Text = "";
            // }




        }



    }

参考方案

不要使用while循环,而使用switch语句:

int caseSwitch = 1;

switch (caseSwitch)
{

case 1:
    Console.WriteLine("Case 1");
    break;
case 2:
    Console.WriteLine("Case 2");
    break;
default:
    Console.WriteLine("Default case");
    break;

}

当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java

我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…

Mongo汇总 - javascript

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …

如何在Wiremock中为JUNIT匹配精确的json - java

我正在使用Wiremock在Spring启动应用程序中模拟Junit的REST服务。我的问题是,我无法匹配多个匹配模式。 Junit.javaStringValuePattern pattern = WireMock.matching(".*"); givenThat(post(urlEqualTo("/softwares�…

如何在JQuery中操作JSONArray - javascript

我有一个php函数,它以JSON返回此代码{"0":{"title":"Dans l\u2019appartement"},"1":{"title":"A l\u2019a\u00e9roport - D\u00e9part de B\u00e9at…

如何使用C#仅从多层嵌入式MongoDB文档中获取具有相应父元素的确切子元素 - c#

尝试使用C#从嵌入式MongoDB文档中获取确切的子文档及其对应的父文档,但查询返回所有子文档以及对应的父文档和其他文档。如何将参数设置为使用Filter和findOptions获得完全匹配。我的预期结果是频道1->第1集,并且是给定ID的Child Track。这是我的代码:// Class namespace CrudWithMultilvelNe…