Reputation: 1
I am creating a Kinect Text Adventure game for a project. I know the code isn't that great, but the project features more on effects of the game than the game itself, so it doesn't have to be complicated. This section of code is used to progress through the game using certain skeletal positions. The problem I am having is that I am trying to use a while loop so that depending on the current value of f, it will go to that specific room. The only problem is when I use a while loop, it always crashes before it's even started. I'm not sure what the problem is
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 = "";
// }
}
}
Upvotes: 0
Views: 880
Reputation: 333
The default value of f is 0. If f is not being set ( >=1 ) before this method is called then it would not enter the while loop.
Since all the code isn't shown, and there is no error shown, could "crash" mean immediate exit?
Upvotes: 0
Reputation: 471
Instead of using a while loop use a switch statement:
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;
}
Upvotes: 4
Reputation: 611
Where do you exit the loop? Looks like you're stuck in an infinite loop. Games usually a check like this every update. I don't think you should stay in this loop all in one frame of game play. You should check what f is and decide what to do each frame.
Edit: also, please post what error you get. It would be easier to tell what happens.
In my opinion, take away the while loop, and just let it check 'f' every frame.
Upvotes: 2