Beispiel #1
0
        private void HellCanvas_KeyDown(object sender, KeyEventArgs e)
        {
            GenObstacle.CollisionCheck();
            GenObstacle obs = GenObstacle.ClosestElement();

            if (GoodStory.OccuredOnce != true)
            {
                GoodStory.PrintLevelIntro(StoryBox);
            }

            if (e.Key == Key.Escape)
            {
                PauseScreen pause = new PauseScreen(this);
                pause.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                pause.ShowDialog();
            }
            else if (obs.CollisionStatus)
            {
                if (obs.collideable)
                {
                    if (Canvas.GetRight(MainCharacter) == Canvas.GetLeft(GenObstacle.ClosestObstacle))//going right
                    {
                        press.RestrictRight(e);
                    }

                    else if (Canvas.GetBottom(MainCharacter) == Canvas.GetTop(GenObstacle.ClosestObstacle))//going down
                    {
                        press.RestrictDown(e);
                    }

                    else if (Canvas.GetTop(MainCharacter) == Canvas.GetBottom(GenObstacle.ClosestObstacle))//going up
                    {
                        press.RestrictUp(e);
                    }

                    else if (Canvas.GetLeft(MainCharacter) == Canvas.GetRight(GenObstacle.ClosestObstacle))//going left
                    {
                        press.RestrictLeft(e);
                    }

                    else
                    {
                        press.MoveFreely(e);
                    }
                }
                else if (obs is Item)
                {
                    HellCanvas.Children.Remove(GenObstacle.ClosestObstacle);
                    CollectItm.Collect(GenObstacle.ClosestObstacle);
                    obs.Remove(obs);
                    LevelFinished = true;

                    GoodStory.PrintConversation(StoryBox);
                    GoodStory.ShouldContinue = true;
                }
                else if (obs is Door)
                {
                    if (LevelFinished)
                    {
                        obs.Clear();
                        this.Close();
                    }
                    else if (Canvas.GetLeft(MainCharacter) == Canvas.GetRight(GenObstacle.ClosestObstacle))
                    {
                        press.RestrictLeft(e);
                    }

                    else if (Canvas.GetBottom(MainCharacter) == Canvas.GetTop(GenObstacle.ClosestObstacle))
                    {
                        press.RestrictDown(e);
                    }
                    else
                    {
                        press.MoveFreely(e);
                    }
                }
            }
            else
            {
                press.MoveFreely(e);
            }
            Canvas.SetRight(MainCharacter, Canvas.GetLeft(MainCharacter) + MainCharacter.Width);//setting right and bottom of character
            Canvas.SetBottom(MainCharacter, Canvas.GetTop(MainCharacter) + MainCharacter.Height);
        }
        private void HellCanvas_KeyDown(object sender, KeyEventArgs e)
        {
            GenObstacle.CollisionCheck();
            GenObstacle obs = GenObstacle.ClosestElement();

            if (GoodStory.OccuredOnce != true)
            {
                GoodStory.PrintLevelIntro(StoryText);
            }

            if (e.Key == Key.Escape)
            {
                PauseScreen pause = new PauseScreen(this);
                pause.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                pause.ShowDialog();
            }
            else if (obs.CollisionStatus)
            {
                if (obs.collideable)
                {
                    if (Canvas.GetRight(MainCharacter) == Canvas.GetLeft(GenObstacle.ClosestObstacle))//going right
                    {
                        press.RestrictRight(e);
                    }

                    else if (Canvas.GetBottom(MainCharacter) == Canvas.GetTop(GenObstacle.ClosestObstacle))//going down
                    {
                        press.RestrictDown(e);
                    }

                    else if (Canvas.GetTop(MainCharacter) == Canvas.GetBottom(GenObstacle.ClosestObstacle))//going up
                    {
                        press.RestrictUp(e);
                    }

                    else if (Canvas.GetLeft(MainCharacter) == Canvas.GetRight(GenObstacle.ClosestObstacle))//going left
                    {
                        press.RestrictLeft(e);
                    }

                    else
                    {
                        press.MoveFreely(e);
                    }
                }
                else if (obs is NPC)
                {
                    if (inv.Count == 1)
                    {
                        if (GoodStory.ShouldContinue)
                        {
                            if (GoodStory.IsComplete != true)
                            {
                                GoodStory.PrintConversation(StoryText);
                                LevelFinished = true;
                                GameBeaten    = true;
                            }
                        }
                    }
                    press.MoveFreely(e);
                }
                else if (obs is Item)
                {
                    HellCanvas.Children.Remove(GenObstacle.ClosestObstacle);
                    CollectItm.Collect(GenObstacle.ClosestObstacle);
                    obs.Remove(obs);

                    if (inv.Count == 3)
                    {
                        inv.Clear();

                        Image       img = new Image();
                        BitmapImage bit = new BitmapImage();

                        bit.BeginInit();
                        bit.UriSource = new Uri("../../Object Model/Trident.png", UriKind.Relative);
                        bit.EndInit();

                        img.Source = bit;
                        CollectItm.Collect(img);
                        GoodStory.ShouldContinue = true;
                    }
                }
                else if (obs is Door)
                {
                    if (GoodStory.IsComplete)
                    {
                        this.Close();
                    }

                    else if (Canvas.GetTop(MainCharacter) == Canvas.GetBottom(GenObstacle.ClosestObstacle))//going up
                    {
                        press.RestrictUp(e);
                    }

                    else if (Canvas.GetLeft(MainCharacter) == Canvas.GetRight(GenObstacle.ClosestObstacle))//going left
                    {
                        press.RestrictLeft(e);
                    }

                    else
                    {
                        press.MoveFreely(e);
                    }
                }
            }
            else
            {
                press.MoveFreely(e);
            }
            Canvas.SetRight(MainCharacter, Canvas.GetLeft(MainCharacter) + MainCharacter.Width);//setting right and bottom of character
            Canvas.SetBottom(MainCharacter, Canvas.GetTop(MainCharacter) + MainCharacter.Height);
        }
Beispiel #3
0
        private void TraverseCanvas_KeyDown(object sender, KeyEventArgs e)
        {
            /*<Summary> Controls player movement, collision checking and the story within the level. />*/

            GenObstacle.CollisionCheck();
            GenObstacle obs = GenObstacle.ClosestElement();

            if (GoodStory.OccuredOnce != true)
            {
                GoodStory.PrintLevelIntro(StoryBox);
            }

            if (e.Key == Key.Escape)
            {
                PauseScreen pause = new PauseScreen(this);
                pause.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                pause.ShowDialog();
            }
            else if (obs.CollisionStatus)
            {
                if (obs.collideable)
                {
                    if (Canvas.GetRight(character) == Canvas.GetLeft(GenObstacle.ClosestObstacle))//going right
                    {
                        move.RestrictRight(e);
                    }

                    else if (Canvas.GetBottom(character) == Canvas.GetTop(GenObstacle.ClosestObstacle))//going down
                    {
                        move.RestrictDown(e);
                    }

                    else if (Canvas.GetTop(character) == Canvas.GetBottom(GenObstacle.ClosestObstacle))//going up
                    {
                        move.RestrictUp(e);
                    }

                    else if (Canvas.GetLeft(character) == Canvas.GetRight(GenObstacle.ClosestObstacle))//going left
                    {
                        move.RestrictLeft(e);
                    }

                    else
                    {
                        move.MoveFreely(e);
                    }
                }
                else if (obs is NPC)
                {
                    if (GoodStory.ShouldContinue == false && observe.Count == 0)
                    {
                        /*<Summary> The player chooses the good path. />*/

                        GoodStory.PrintConversation(StoryBox);
                        make.MakeItem(character, canvas, @"../../Object Model/Band.png", bandage1);
                        make.MakeItem(character, canvas, @"../../Object Model/Band.png", bandage2);
                        make.MakeItem(character, canvas, @"../../Object Model/Band.png", bandage3);
                        GoodStory.ShouldContinue = true;

                        canvas.Children.Remove(money);
                    }

                    else if (GoodStory.ShouldContinue == true && observe.Count == 3 && GoodStory.IsComplete == false)
                    {
                        BitmapImage bit = new BitmapImage();

                        bit.BeginInit();
                        bit.UriSource = new Uri("../../Object Model/Amb.png", UriKind.Relative);
                        bit.EndInit();

                        ambulance.Source = bit;

                        GoodStory.PrintConversation(StoryBox);
                        canvas.Children.Remove(NPC1);
                        observe.Clear();
                        GameBeaten = true;
                    }

                    move.MoveFreely(e);
                }

                else if (obs is Item)
                {
                    if (GoodStory.ShouldContinue == false && BadStory.IsComplete == false)
                    {
                        BadStory.PrintConversation(StoryBox);
                    }

                    canvas.Children.Remove(GenObstacle.ClosestObstacle);

                    ItmCollect.Collect(GenObstacle.ClosestObstacle);
                    obs.Remove(obs);
                }

                else if (obs is Door)
                {
                    if (BadStory.IsComplete)
                    {
                        obs.Clear();
                        LevelFinished = true;
                        this.Close();
                    }
                    else if (GoodStory.IsComplete)
                    {
                        obs.Clear();
                        GameBeaten = true;
                        this.Close();
                    }
                    move.RestrictUp(e);
                }
            }

            else
            {
                move.MoveFreely(e);
            }

            Canvas.SetRight(character, Canvas.GetLeft(character) + character.Width);
            Canvas.SetBottom(character, Canvas.GetTop(character) + character.Height);
        }
 public void Remove(GenObstacle obs)
 {
     GenObs.Remove(obs);
 }
Beispiel #5
0
        private void HellCanvas_keyDown(object sender, KeyEventArgs e)
        {
            GenObstacle.CollisionCheck();
            GenObstacle obs = GenObstacle.ClosestElement();

            if (GoodStory.OccuredOnce != true)
            {
                GoodStory.PrintLevelIntro(StoryBox);
            }

            if (e.Key == Key.Escape)
            {
                PauseScreen pause = new PauseScreen(this);
                pause.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                pause.ShowDialog();
            }
            else if (obs.CollisionStatus)
            {
                if (obs is NPC)
                {
                    if (GoodStory.ShouldContinue == false)
                    {
                        GoodStory.PrintConversation(StoryBox);
                        GoodStory.ShouldContinue = true;
                        LevelFinished            = true;
                        GoodEnding = true;
                        make.MakeItem(MainCharacter, HellCanvas, "../../Object Model/Fan.png", Fan);
                    }
                    move.MoveFreely(e);
                }

                else if (obs is Item)
                {
                    HellCanvas.Children.Remove(GenObstacle.ClosestObstacle);

                    CollectItm.Collect(GenObstacle.ClosestObstacle);
                    obs.Remove(obs);

                    BadStory.ShouldContinue = true;
                    GoodEnding = false;
                }

                else if (obs is Door)
                {
                    if (BadStory.ShouldContinue == true || GoodStory.ShouldContinue == true)
                    {
                        obs.Clear();
                        this.Close();
                    }

                    else if (Canvas.GetRight(MainCharacter) == Canvas.GetLeft(GenObstacle.ClosestObstacle))//going right
                    {
                        move.RestrictRight(e);
                    }

                    else if (Canvas.GetBottom(MainCharacter) == Canvas.GetTop(GenObstacle.ClosestObstacle))//going down
                    {
                        move.RestrictDown(e);
                    }

                    else if (Canvas.GetTop(MainCharacter) == Canvas.GetBottom(GenObstacle.ClosestObstacle))//going up
                    {
                        move.RestrictUp(e);
                    }

                    else if (Canvas.GetLeft(MainCharacter) == Canvas.GetRight(GenObstacle.ClosestObstacle))//going left
                    {
                        move.RestrictLeft(e);
                    }

                    else
                    {
                        move.MoveFreely(e);
                    }
                }
            }

            else
            {
                move.MoveFreely(e);
            }

            Canvas.SetRight(MainCharacter, Canvas.GetLeft(MainCharacter) + MainCharacter.Width);
            Canvas.SetBottom(MainCharacter, Canvas.GetTop(MainCharacter) + MainCharacter.Height);
        }
        private void TraverseCanvas_KeyDown(object sender, KeyEventArgs e)//controls the movement of the character
        {
            /*<Note> Switch statements are a thing to look into />*/
            /*<Note> strategy pattern is a thing to look into for collision behavior. Might be a problem book talks of revealing the strategies to the client. />*/
            /*<Note> observer pattern might do well for collision tracking />*/

            /*<Strategy> have a timer inside to determine when to create a thread that runs only when the keys are pressed. The timer will make the thread wait a certain amount of time before activating player
             * run />*/
            /*<Problem> I think the problem now is when the player reaches the corner then it is equidistant from two elements />*/
            /*<Question> What if i detect a collision fixing to happen and stop it from happening by not allowing movement but then you have to predict the next move />*/

            BitmapImage    bit  = new BitmapImage();
            PlayerMovement move = new PlayerMovement(character, canvas);

            GenObstacle.CollisionCheck();//might look into being able to remove GenObstacle in favor of MakeObstacle or remove it all together
            GenObstacle obs = GenObstacle.ClosestElement();

            if (obs.CollisionStatus)
            {
                if (obs is NPC)
                {
                    story.PrintConversation();
                    move.MoveFreely(e);
                }

                //MessageBox.Show("X " + Convert.ToString(Canvas.GetRight(GenObstacle.ClosestObstacle)) + " Y " + Convert.ToString(Canvas.GetTop(GenObstacle.ClosestObstacle)));
                if (obs.collideable)
                {
                    if (Canvas.GetRight(character) == Canvas.GetLeft(GenObstacle.ClosestObstacle)) //going right
                    {                                                                              //MessageBox.Show("Character " + Convert.ToString(Canvas.GetRight(character) + " obs " + Convert.ToString(Canvas.GetLeft(GenObstacle.ClosestObstacle))));
                        move.RestrictRight(e);
                    }

                    else if (Canvas.GetBottom(character) == Canvas.GetTop(GenObstacle.ClosestObstacle))//going down
                    {
                        move.RestrictDown(e);
                    }

                    else if (Canvas.GetTop(character) == Canvas.GetBottom(GenObstacle.ClosestObstacle))//going up
                    {
                        move.RestrictUp(e);
                        //MessageBox.Show("Character " + Convert.ToString(Canvas.GetTop(character) + " obs " + Convert.ToString(Canvas.GetBottom(GenObstacle.ClosestObstacle))));
                    }

                    else if (Canvas.GetLeft(character) == Canvas.GetRight(GenObstacle.ClosestObstacle))//going left
                    {
                        move.RestrictLeft(e);
                        //MessageBox.Show("Character " + Convert.ToString(Canvas.GetLeft(character) + " obs " + Convert.ToString(Canvas.GetRight(GenObstacle.ClosestObstacle))));
                    }

                    else
                    {
                        move.MoveFreely(e);
                    }
                }

                else if (obs is Item)//type checking
                {
                    canvas.Children.Remove(GenObstacle.ClosestObstacle);

                    obs.Remove(obs);//quick and dirty. Needs improvement.
                }
                else if (obs is Door)
                {
                    MessageBox.Show("door");

                    /*MakeObstacle make = new MakeObstacle();
                     * Publisher pub = new Publisher();
                     * //make.MakeDoor(character, canvas, null, Door1, pub);
                     * pub.DoSomething();*/
                    //raise an event here that will change the level
                }
            }

            else
            {
                if (e.Key == Key.W)
                {
                    bit.BeginInit();
                    bit.UriSource = new Uri(@"..\..\Object Model\MOVEMENTLEFT.png", UriKind.Relative);
                    bit.EndInit();

                    character.Source = bit;
                    Canvas.SetTop(character, Canvas.GetTop(character) - 10);
                }
                else if (e.Key == Key.S)
                {
                    bit.BeginInit();
                    bit.UriSource = new Uri(@"..\..\Object Model\MOVEMENTLEFT.png", UriKind.Relative);
                    bit.EndInit();

                    character.Source = bit;
                    Canvas.SetTop(character, Canvas.GetTop(character) + 10);
                }
                else if (e.Key == Key.A)
                {
                    bit.BeginInit();
                    bit.UriSource = new Uri(@"..\..\Object Model\MOVEMENTLEFT.png", UriKind.Relative);
                    bit.EndInit();

                    character.Source = bit;
                    Canvas.SetLeft(character, Canvas.GetLeft(character) - 10);
                }
                else if (e.Key == Key.D)
                {
                    bit.BeginInit();
                    bit.UriSource = new Uri(@"..\..\Object Model\MOVEMENTRIGHT.png", UriKind.Relative);
                    bit.EndInit();

                    character.Source = bit;
                    Canvas.SetLeft(character, Canvas.GetLeft(character) + 10);
                }
            }
            Canvas.SetRight(character, Canvas.GetLeft(character) + character.Width);//setting right and bottom of character
            Canvas.SetBottom(character, Canvas.GetTop(character) + character.Height);
        }