private async Task NewQuestion()
        {
            tbComments.Text = "";
            Questions       = await GetQuestions();

            if (Questions == null)
            {
                lbNoResults.Visible = true;
                pnlAll.Visible      = false;
                return;
            }
            QuestionContents = await GetQuestionContents();

            QuestionData = await GetQuestionData();

            if (Bundle != null)
            {
                passageText = Bundle.Get <string>("passageText");
            }
            int idx = 1;

            for (int i = 0; i < Questions.Length; i++)
            {
                QuestionBlock questionBlock = (QuestionBlock)LoadControl("~/UserControls/QuestionBlock.ascx");
                questionBlock.FillContents(Questions[i], QuestionContents[i], QuestionData[i], idx++);
                pnlQuestions.Controls.Add(questionBlock);

                AlreadyVisited.Add(Questions[i].ObjectId);
            }
        }
Exemple #2
0
        private static void CreateItem(IWorld world, string type, float xPosition, float yPosition)
        {
            IBlock block        = new HiddenBlock(new Vector2(0, 0)); // Get size of an arbitrary block to be size of local collision detection scope
            int    blocksWidth  = block.Rectangle.Width;;
            int    blocksHeight = block.Rectangle.Height;
            int    blockIndexX  = (int)Math.Floor(xPosition / blocksWidth);
            int    blockIndexY  = (int)Math.Floor(yPosition / blocksHeight);

            block = world.Blocks[blockIndexX].OneBlockLevel[blockIndexY];
            if (type.Equals("StaticCoin"))
            {
                world.Items.Add(new Coin(new Vector2(xPosition, yPosition), true, new CollectDelegate(ScoreManager.Instance.CollectCoin)));
            }
            else if (block is BrickBlock)
            {
                BrickBlock brickBlock = block as BrickBlock;
                brickBlock.AddItem(type);
            }
            else if (block is QuestionBlock)
            {
                QuestionBlock questionBlock = block as QuestionBlock;
                questionBlock.AddItem(type);
            }
            else if (block is HiddenBlock)
            {
                HiddenBlock hiddenBlock = block as HiddenBlock;
                hiddenBlock.AddItem(type);
            }
        }
        private void buttonAddQuestion_Click(object sender, EventArgs e)
        {
            if (test != null && textBoxQuestion.Text != "" && textBoxTrueAnswer.Text != "" && textBoxQ1.Text != "")
            {
                QuestionBlock questionBlock = new QuestionBlock();

                questionBlock.Question       = textBoxQuestion.Text;
                questionBlock.TrueAnswer     = textBoxTrueAnswer.Text;
                questionBlock.DifficultLevel = int.Parse(comboBoxGrade.Text);
                questionBlock.Q1             = textBoxQ1.Text;

                if (textBoxQ2.Enabled)
                {
                    questionBlock.Q2 = textBoxQ2.Text;
                }

                if (textBoxQ3.Enabled)
                {
                    questionBlock.Q3 = textBoxQ3.Text;
                }

                test.QuestionBlocks.Add(questionBlock);
            }
            else
            {
                MessageBox.Show("Test class is null!", "Warning!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #4
0
    public void PlaceBlock()
    {
        Vector3 mousePos = Input.mousePosition;

        mousePos   = Camera.main.ScreenToWorldPoint(mousePos);
        mousePos   = GameManager.gm.SnapToGrid(mousePos);
        mousePos.z = 0;

        if (currentSelectedBlock == 1 && GameObject.FindGameObjectWithTag("Player") != null)
        {
            return;
        }
        else if (!Physics2D.Raycast(mousePos, Vector2.zero, 0) && currentSelectedBlock != 0)
        {
            GameObject last = Instantiate(blocks[currentSelectedBlock - 1], mousePos, Quaternion.identity).gameObject;

            if (lastBlockPlaced != null)
            {
                lastBlockPlaced.targetDoor = last.GetComponent <DoorBlock>();
            }
            else if (currentSelectedBlock == 3)
            {
                lastBlockPlaced = last.GetComponent <QuestionBlock>();
            }
        }
        else if (currentSelectedBlock == 0)
        {
            if (Physics2D.Raycast(mousePos, Vector2.zero, 0))
            {
                Destroy(Physics2D.Raycast(mousePos, Vector2.zero, 0).collider.gameObject);
            }
        }
    }
Exemple #5
0
    public override void HitBottom(UnityBlock b)
    {
        if (!(this.groundState is FallingState))
        {
            mover.yMoveDir = -1;

            base.HitBottom(b);

            if (b is BrickBlock)
            {
                BrickBlock brick = (BrickBlock)b;
                if (!brick.isHit)
                {
                    SFX.PlayClip(SFX.blockClip);
                }
            }

            else if (b is QuestionBlock)
            {
                QuestionBlock question = (QuestionBlock)b;
                if (!question.struck)
                {
                    SFX.PlayClip(SFX.coinClip);
                }
            }

            b.HitBottom();
        }
    }
Exemple #6
0
        //Probably decide to delete this later. This one for now is just for show.
        public IBlock UsedBlock()
        {
            QuestionBlock q = new QuestionBlock(QuestionBlockSpriteSheet);

            q.StraightToUsed();
            return(q);
        }
        public QuestionBlock GetQuestion()
        {
            QuestionBlock block = new QuestionBlock();

            block.Choice_Question.Text = "Choose products from the given options:-";
            AddChoices(block);
            return(block);
        }
Exemple #8
0
        public IBlock HiddenQuestionBlock()
        {
            QuestionBlock q = new QuestionBlock(QuestionBlockSpriteSheet);

            q.BlockState = new BlockStateHidden(q);
            q.BlockState.Enter();
            return(q);
        }
Exemple #9
0
        static void LevelLoader_Block1()
        {
            // Block loaders
            loaders.Add("indBrick", (game, x, y) =>
            {
                game.Map.SetBlock(x, y, new BrickIndestructable());
            });

            loaders.Add("grBrick", (game, x, y) =>
            {
                game.Map.SetBlock(x, y, new GroundBrick());
            });

            loaders.Add("hidBlock", (game, x, y) =>
            {
                game.Map.SetBlock(x, y, new HiddenBlock(game, new MushroomOneUp(game, x, y - 1)));
            });

            loaders.Add("multiBlock", (game, x, y) =>
            {
                game.Map.SetBlock(x, y, new MultiCoinBlock(game, new Coin(game, new Vector2(x, y - 1))));
            });

            loaders.Add("usedBlock", (game, x, y) =>
            {
                QuestionBlock block = new QuestionBlock(game, null);
                block.Hit(null);
                game.Map.SetBlock(x, y, block);
            });

            loaders.Add("FireBlock", (game, x, y) =>
            {
                IBlock block = new FireBlock(game, x, y);
                game.Map.SetBlock(x, y, block);
            });

            loaders.Add("grayFixBlock", (game, x, y) =>
            {
                IBlock block = new GrayFixBlock();
                game.Map.SetBlock(x, y, block);
            });

            loaders.Add("UGBrick", (game, x, y) =>
            {
                game.Map.SetBlock(x, y, new UGBrick(game));
            });

            loaders.Add("UGgrBrick", (game, x, y) =>
            {
                game.Map.SetBlock(x, y, new UGGroundBrick());
            });

            loaders.Add("GrayBrick", (game, x, y) =>
            {
                game.Map.SetBlock(x, y, new GrayBrick());
            });
        }
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.name == "QuestionBlock")
     {
         Debug.Log("Name : " + other.name);
         QuestionBlock qB = other.GetComponent <QuestionBlock>();
         qB.TriggerBounce();
     }
 }
Exemple #11
0
    // Обновить блок вопроса после прохождения
    void RefreshQuestionBlock()
    {
        QuestionBlock qb = _model.QuestionBlock;

        int  numCorrect  = qb.numberCorrectAnswers;
        int  numQuestion = qb.questionList.Length;
        bool isHeaderOn  = qb.isHeaderOn;

        questionBlockButtons[_model.CurrentQuestionBlockIndex].SetHeaderInfo(numCorrect, numQuestion, isHeaderOn);
    }
        public static void HandleQuestionBlockCollision(IPlayer player, QuestionBlock questionBlock, CollisionSide side)
        {
            PlayerBlockRepel(questionBlock, player, side);

            if (!questionBlock.IsUsed && side == CollisionSide.Bottom) // If block is unused and mario bumps the bottom of the block
            {
                questionBlock.BeBumped();
                questionBlock.SpawnItem();
                questionBlock.BecomeUsed();
            }
        }
 public void AddChoices(string[] layerMembers, QuestionBlock block)
 {
     for (int i = 0; i < layerMembers.Length; i++)
     {
         ToggleButton b1 = new ToggleButton();
         b1.Content    = layerMembers[i];
         b1.Style      = (Style)Application.Current.Resources["ToggleButtonStyle"];
         b1.Checked   += B1_Checked;
         b1.Unchecked += B1_Unchecked;
         block.ChoiceOptions.Children.Add(b1);
     }
 }
Exemple #14
0
        public static GameObject CheckBlocks(Entity entity)
        {
            switch (entity.Type)
            {
            case "BrickBlock":
                return(new BrickBlock(BlockFactory.GetInstance(), new Point(entity.X, entity.Y)));

            case "FloorBlock":
                return(new FloorBlock(BlockFactory.GetInstance(), new Point(entity.X, entity.Y)));

            case "HiddenBlock":
                GameObject block = new QuestionBlock(BlockFactory.GetInstance(), new Point(entity.X, entity.Y));
                return(new HiddenBlock((Block)block));

            case "PyramidBlock":
                return(new PyramidBlock(BlockFactory.GetInstance(), new Point(entity.X, entity.Y)));

            case "QuestionBlock":
                return(new QuestionBlock(BlockFactory.GetInstance(), new Point(entity.X, entity.Y)));

            case "Pipe":
                return(new SmallPipe(BackgroundFactory.GetInstance(), new Point(entity.X, entity.Y), new Vector2()));

            case "CopperPipe":
                GameObject obj = new SmallPipe(BackgroundFactory.GetInstance(), new Point(entity.X, entity.Y), new Vector2());
                obj.Sprite = BackgroundFactory.GetInstance().CreateProduct(BackgroundTypes.CopperPipe);
                return(obj);

            case "MediumPipe":
                return(new MediumPipe(BackgroundFactory.GetInstance(), new Point(entity.X, entity.Y), new Vector2()));

            case "PipeSegment":
                return(new PipeSegment(BackgroundFactory.GetInstance(), new Point(entity.X, entity.Y), new Vector2()));

            case "Win Block":
                return(new WinBlock(BlockFactory.GetInstance(), new Point(entity.X, entity.Y)));

            case "Gate":
                return(new Gate(BlockFactory.GetInstance(), new Point(entity.X, entity.Y)));

            case "Button":
                return(new Button(BlockFactory.GetInstance(), new Point(entity.X, entity.Y)));

            case "InvertedButton":
                return(new Button(true, BlockFactory.GetInstance(), new Point(entity.X, entity.Y)));

            case "CompanionCube":
                return(new CompanionCube(BlockFactory.GetInstance(), new Point(entity.X, entity.Y)));

            default:
                return(null);
            }
        }
Exemple #15
0
        private void nextbtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(questiontextbox.Text))
            {
                MessageBox.Show("Question text must be filled");
            }
            else if (string.IsNullOrEmpty(blockA.Text) && string.IsNullOrWhiteSpace(blockB.Text) && string.IsNullOrWhiteSpace(blockC.Text) && string.IsNullOrWhiteSpace(blockD.Text))
            {
                MessageBox.Show("All options must be filled");
            }
            else if (string.IsNullOrEmpty(correctanswtxtbox.Text))
            {
                MessageBox.Show("Correct answer must be set");
            }
            else
            {
                questionCount++;

                QuestionBlock qb = new QuestionBlock();
                qb.Answers = new List <Answer>();

                qb.id   = questionCount;
                qb.Text = questiontextbox.Text;

                qb.Answers.Add(new Answer {
                    IsCorrect = correctanswtxtbox.Text == "A" || correctanswtxtbox.Text == "a" ? "Yes" : "No", id = 0, Text = blockA.Text
                });
                qb.Answers.Add(new Answer {
                    IsCorrect = correctanswtxtbox.Text == "B" || correctanswtxtbox.Text == "b" ? "Yes" : "No", id = 1, Text = blockB.Text
                });
                qb.Answers.Add(new Answer {
                    IsCorrect = correctanswtxtbox.Text == "C" || correctanswtxtbox.Text == "c" ? "Yes" : "No", id = 2, Text = blockC.Text
                });
                qb.Answers.Add(new Answer {
                    IsCorrect = correctanswtxtbox.Text == "D" || correctanswtxtbox.Text == "d" ? "Yes" : "No", id = 3, Text = blockD.Text
                });

                questionBlock.Add(qb);

                quescount.Text = questionCount.ToString();

                questiontextbox.Text = string.Empty;
                blockA.Text          = string.Empty;
                blockB.Text          = string.Empty;
                blockC.Text          = string.Empty;
                blockD.Text          = string.Empty;


                correctanswtxtbox.Text = string.Empty;
                finishbtn.Visible      = true;
            }
        }
Exemple #16
0
 private static void QuestionBlockMarioCollision(IMario mario, QuestionBlock block, CollisionSide side)
 {
     if (!block.Broken && side == CollisionSide.Bottom)
     {
         (block as QuestionBlock).CreateItem();
         block.BecomeUsed();
         NewLocation(block, mario, side);
     }
     else
     {
         NewLocation(block, mario, side);
     }
 }
Exemple #17
0
        public Sprite BuildSprite(BlockType sprite, Vector2 loc)
        {
            Sprite toReturn = null;

            switch (sprite)
            {
            case BlockType.exploded:
            {
                toReturn = new ExplodingBlock(loc);
                break;
            }

            case BlockType.question:
            {
                toReturn = new QuestionBlock(loc);
                break;
            }

            case BlockType.used:
            {
                toReturn = new UsedBlock(loc);
                break;
            }

            case BlockType.brick:
            {
                toReturn = new BrickBlock(loc);
                break;
            }

            case BlockType.hidden:
            {
                toReturn = new HiddenBlock(loc);
                break;
            }

            case BlockType.pipe:
            {
                toReturn = new PipeBlock(loc);
                break;
            }

            case BlockType.bridge:
            {
                toReturn = new BridgeBlock(loc);
                break;
            }
            }
            return(toReturn);
        }
 public void AddChoices(QuestionBlock block)
 {
     foreach (Products product in productListByChoices)
     {
         ToggleButton b1          = new ToggleButton();
         string       pathToImage = @".\Images\" + product.Name + ".PNG";
         b1.Content = new Image
         {
             Source            = new BitmapImage(new Uri(pathToImage, UriKind.Relative)),
             VerticalAlignment = VerticalAlignment.Center,
         };
         b1.Style  = (Style)Application.Current.Resources["ImageButtonStyle"];
         b1.Click += B1_Click;
         block.ChoiceOptions.Children.Add(b1);
     }
 }
        public QuestionBlock GetQuestion()
        {
            QuestionBlock block = new QuestionBlock();

            if (question.Layer == "lastLayer")
            {
                block.Choice_Question.Text = "Are you sure about the options?? Choose Yes/No..!!";
                AddChoices(new string[] { "Yes", "No" }, block);
            }
            else
            {
                block.Choice_Question.Text = "Choose " + question.Layer + " from ";
                AddChoices(question.LayerMembers, block);
            }
            return(block);
        }
        public async Task <QuestionBlock> Question()
        {
            string[] choices = choicesMade.Split(',');
            await GetNextQuestions(choices);

            if (question.Layer == "Invalid RequestResponse Sent")
            {
                MessageBox.Show("Please choose atleast one option");
                SetPreviousQuestion();
                return(null);
            }
            else
            {
                QuestionBlock block = GetQuestion();
                return(block);
            }
        }
        public Block(Vector2 position, string blockState, string itemType)
        {
            Position                    = position;
            Acceleration                = Vector2.Zero;
            InitialPosition             = position;
            blockStateTransitionMachine = new BlockStateTransitionMachine();
            IsMoving                    = false;

            if (blockState == "Brick")
            {
                BlockState = new BrickBlock(position, this, "Red");
            }
            else if (blockState == "BrickBlue")
            {
                BlockState = new BrickBlock(position, this, "Blue");
            }
            else if (blockState == "Question")
            {
                BlockState = new QuestionBlock(position, this);
            }
            else if (blockState == "Metal")
            {
                this.BlockState = new MetalBlock(position, this);
            }
            else if (blockState == "CoinBrick")
            {
                BlockState = new CoinBrickBlock(position, this);
                CoinCount  = GameValues.BlockCoinBrickCoinAmount;
            }
            else if (blockState == "Used")
            {
                BlockState = new UsedBlock(position, this);
            }

            CollisionRectangle = BlockState.CollisionRectangle;

            if (itemType == "RotatingCoin")
            {
                Item = new Item(new Vector2(Position.X + GameValues.BlockRotatingCoinInitialXPositionOffset, Position.Y), itemType);
            }
            else
            {
                Item = new Item(Position, itemType);
            }
        }
Exemple #22
0
    private void _model_PropertyChanged(object sender, NotifyPropertyChangedEventArgs e)
    {
        currentQuestion = _model.GetNextQuestion;

        if (currentQuestion != null)
        {
            QuestionDisplay(currentQuestion);
        }
        else
        {
            _pagination.GotoPreviousPage();

            QuestionBlock questionBlock = new QuestionBlock();
            questionBlock.numberCorrectAnswers = _numberCorrectAnswers;
            questionBlock.isHeaderOn           = true;

            _controller.Execute(ModelOperation.UpdateQuestionBlockStat, _model, questionBlock);
        }
    }
Exemple #23
0
    // Запоминаем прошлый выбор чтобы не грузить одни и те же данные
    // int prevSectionIndex = -1;
    // int questionBLockIndex = -1;

    public bool Execute(ModelOperation operation, ProjectModel model, QuestionBlock attribute)
    {
        if (model == null)
        {
            Debug.Log("Model is null");
            return(false);
        }

        switch (operation)
        {
        case ModelOperation.UpdateQuestionBlockStat:
            model.QuestionBlockStat = attribute;
            break;

        default:     //Message Box
            break;
        }

        return(true);
    }
        protected void grdQuestions_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "View")
            {
                SelectedQuestionId = e.CommandArgument.ToString();
                Question question = AsyncHelpers.RunSync <Question>(() => Question.GetFullQuestionById(SelectedQuestionId));
                if (question.InBundle)
                {
                    pnlBundle.Visible = true;
                    Image1.ImageUrl   = question.Bundle.Image == null ? "" : question.Bundle.Image.Url.ToString();
                    lbBundleText.Text = question.Bundle.PassageText;
                }
                else
                {
                    pnlBundle.Visible = false;
                }
                QuestionBlock questionBlock = (QuestionBlock)LoadControl("~/UserControls/QuestionBlock.ascx");
                questionBlock.FillContents(question);
                pnlQuestions.Controls.Add(questionBlock);

                popup.Show();
            }
        }
    private void MarioMovementLogic()
    {
        bool rightOrLeftPressed = false;
        bool rightPressed       = false;
        bool leftPressed        = false;

        if (keyEmulated[(int)Key.KEY_LEFT])
        {         //|| Input.GetButton(speedStringName)) {
            running = true;

            if (fire)
            {
                SpawnFireball();
            }

            if (startRunningRecord == 0)
            {
                startRunningRecord = Time.time;
            }
        }
        else if (running && !keyEmulated[(int)Key.KEY_LEFT])
        {
            running = false;

            if (startRunningRecord != 0)
            {
                if (LogHandler.Instance != null)
                {
                    LogHandler.Instance.WriteLine(gameObject.name + " RunState: StTime = " + startRunningRecord + " EdTime = " + Time.time);
                }
                startRunningRecord = 0;
            }
        }

        if (fireTimer > 0)
        {
            fireTimer -= Time.deltaTime;
        }

        //Running (Takes 2 to speed up/slow down)
        if (keyEmulated[(int)Key.KEY_RIGHT])
        {        //||Input.GetAxis(horizontalStringName)>0.5f) {
            rightOrLeftPressed = true;
            RaycastHit?rightHit = HorizontalCollisionCheck(GetPosition(position), GetRightPosition());
            if (rightHit == null)
            {
                rightPressed = true;
                if (rightStart == 0)
                {
                    rightStart = Time.time;
                }
                if (running)
                {
                    velocity.x += changeRunSpeed * Time.deltaTime;
                    if (Mathf.Abs(velocity.x) > maxRunSpeed)
                    {
                        velocity.x = maxRunSpeed;
                    }
                }
                else
                {
                    velocity.x += changeWalkSpeed * Time.deltaTime;
                    if (Mathf.Abs(velocity.x) > maxWalkSpeed)
                    {
                        velocity.x = maxWalkSpeed;
                    }
                }
            }
        }
        else if (keyEmulated[(int)Key.KEY_LEFT])
        {        // ||Input.GetAxis(horizontalStringName)<-0.5f){
            rightOrLeftPressed = true;
            RaycastHit?leftHit = HorizontalCollisionCheck(GetPosition(position), GetLeftPosition());
            if (leftHit == null)
            {
                //Left Start was hit
                if (leftStart == 0)
                {
                    leftStart = Time.time;
                }
                leftPressed = true;
                if (running)
                {
                    velocity.x -= changeRunSpeed * Time.deltaTime;
                    if (Mathf.Abs(velocity.x) > maxRunSpeed)
                    {
                        velocity.x = -1 * maxRunSpeed;
                    }
                }
                else
                {
                    velocity.x -= changeWalkSpeed * Time.deltaTime;
                    if (velocity.x < -1 * maxWalkSpeed)
                    {
                        velocity.x = -1 * maxWalkSpeed;
                    }
                }
            }
        }
        else
        {
            if (Mathf.Abs(velocity.x) > changeWalkSpeed * Time.deltaTime)
            {
                if (velocity.x > 0)
                {
                    velocity.x -= changeWalkSpeed * Time.deltaTime;
                }
                else
                {
                    velocity.x += changeWalkSpeed * Time.deltaTime;
                }
                if (Mathf.Abs(velocity.x) < changeWalkSpeed * Time.deltaTime)
                {
                    velocity.x = 0;
                }
            }
            else
            {
                velocity.x = 0;
            }
        }

        //Logging

        if (!leftPressed && leftStart != 0)
        {
            if (LogHandler.Instance != null)
            {
                LogHandler.Instance.WriteLine(gameObject.name + " LeftMove: StTime = " + leftStart + " EdTime = " + Time.time);
            }
            leftStart = 0;
        }
        if (!rightPressed && rightStart != 0)
        {
            if (LogHandler.Instance != null)
            {
                LogHandler.Instance.WriteLine(gameObject.name + " RightMove: StTime = " + rightStart + " EdTime = " + Time.time);
            }
            rightStart = 0;
        }


        //Determine if in air
        if (velocity.y == 0 && !held)
        {
            RaycastHit?below = VerticalCollisionCheck(GetPosition(position), GetDownPosition());
            if (below == null)
            {
                inAir = true;
            }
            else
            {
                RaycastHit belowHit = (RaycastHit)below;
                if (!Constants.IsSolid(belowHit.collider.tag) && !belowHit.collider.tag.Equals("Plant"))
                {
                    inAir = true;
                }
            }
        }

        //Input -Jumping
        if ((keyEmulated[(int)Key.KEY_JUMP]) && velocity.y == 0 && !inAir)
        {        //|| Input.GetButtonDown(jumpStringName)
            velocity.y = initialChangeSpeed;
            jumping    = true;
            inAir      = true;
            held       = false;
            myAudio.PlayOneShot(jumpSound);
            if (jumpStart == 0)
            {
                jumpStart = Time.time;
            }
        }
        else if (keyEmulated[(int)Key.KEY_JUMP] && jumping && velocity.y > 0)
        {        //||Input.GetButton(jumpStringName)
            velocity.y += changeJumpSpeed * Time.deltaTime;
            if (velocity.y > maxJumpSpeed)
            {
                velocity.y = maxJumpSpeed;
                jumping    = false;
            }
        }
        else if (velocity.y != 0)
        {
            jumping = false;
        }

        //Gravity
        if (inAir)
        {
            velocity.y -= changeGravitySpeed * Time.deltaTime;
        }

        Vector2 possibleNewPos = position + Time.deltaTime * velocity;
        bool    squishedEnemy  = false;

        if (velocity.y > 0)
        {
            RaycastHit?aboveHit = VerticalCollisionCheck(GetUpPosition(), GetUpPosition() + Vector3.up * (possibleNewPos.y - position.y));
            if (aboveHit != null)
            {
                RaycastHit aboveRaycastHit = (RaycastHit)aboveHit;
                if (Constants.IsSolid(aboveRaycastHit.collider.tag))
                {
                    possibleNewPos.y = aboveRaycastHit.point.y - GetHeight() / 2.0f;
                    velocity.y       = 0;

                    if (aboveRaycastHit.collider.tag.Equals("Breakable"))
                    {
                        if (large)
                        {
                            myAudio.PlayOneShot(breakBlock);
                        }
                        else
                        {
                            myAudio.PlayOneShot(bump);
                        }
                        aboveRaycastHit.collider.GetComponent <Block>().HitBelow(gameObject);
                    }
                    else if (aboveRaycastHit.collider.tag.Equals("PowerupBlock"))
                    {
                        myAudio.PlayOneShot(bump);
                        QuestionBlock b = aboveRaycastHit.collider.GetComponent <QuestionBlock>();
                        if (b != null)
                        {
                            //b.HitBelow(this);
                        }
                    }
                    else
                    {
                        myAudio.PlayOneShot(bump);
                    }
                }
                else if (aboveRaycastHit.collider.tag.Equals("Powerup"))
                {
                    HandlePowerup(aboveRaycastHit.collider.GetComponent <BaseSprite>());
                }
                else if (aboveRaycastHit.collider.tag.Equals("Enemy"))
                {
                    Hurt(aboveRaycastHit.collider.GetComponent <BaseSprite>());
                }
                else if (aboveRaycastHit.collider.tag.Equals("Coin"))
                {
                    myAudio.PlayOneShot(coin);
                    //aboveRaycastHit.collider.GetComponent<Coin>().CollectCoin(this);
                }
            }
        }
        else if (velocity.y < 0)
        {
            RaycastHit?belowHit = VerticalCollisionCheck(GetPosition(position), GetDownPosition() + Vector3.down * (position.y - possibleNewPos.y), 0.05f, 0.95f);
            if (belowHit != null)
            {
                RaycastHit belowRaycastHit = (RaycastHit)belowHit;
                if (Constants.IsSolid(belowRaycastHit.collider.tag))
                {
                    possibleNewPos.y = belowRaycastHit.point.y + GetHeight() / 2.0f;
                    inAir            = false;
                    velocity.y       = 0;


                    if (jumpStart != 0)
                    {
                        if (LogHandler.Instance != null)
                        {
                            LogHandler.Instance.WriteLine(gameObject.name + " Jump: StTime = " + jumpStart + " EdTime = " + Time.time);
                        }
                        jumpStart = 0;
                    }
                }
                else if (belowRaycastHit.collider.tag.Equals("Powerup"))
                {
                    HandlePowerup(belowRaycastHit.collider.GetComponent <BaseSprite>());
                }
                else if (belowRaycastHit.collider.tag.Equals("Enemy"))
                {
                    Enemy e = belowRaycastHit.collider.gameObject.GetComponent <Enemy>();
                    if (e != null)
                    {
                        bool squished = e.Squish(gameObject);

                        if (squished)
                        {
                            myAudio.PlayOneShot(squish);
                            //if squished just continue falling as normal
                            squishedEnemy = true;
                        }
                        else if (!IsDead())
                        {
                            myAudio.PlayOneShot(squish);
                            //Wasn't squished so bounce off to get out of the way
                            velocity.y = initialChangeSpeed;
                            jumping    = true;
                            inAir      = true;
                        }
                    }
                }
                else if (belowRaycastHit.collider.tag.Equals("Coin"))
                {
                    myAudio.PlayOneShot(coin);
                    //belowRaycastHit.collider.GetComponent<Coin>().CollectCoin(this);
                }
            }
        }

        if (velocity.x < 0)
        {        //LEFT CHECK
            RaycastHit?leftHit = HorizontalCollisionCheck(GetPosition(position), GetLeftPosition() + Vector3.left * (position.x - possibleNewPos.x));
            if (leftHit != null)
            {
                RaycastHit leftRaycastHit = (RaycastHit)leftHit;
                if (leftRaycastHit.collider.tag.Equals("Enemy") && !squishedEnemy)
                {
                    Shell s = leftRaycastHit.collider.GetComponent <Shell>();
                    if (s == null)
                    {
                        Hurt(leftRaycastHit.collider.GetComponent <BaseSprite>());
                    }
                    else if (s.Moving())
                    {
                        Hurt(leftRaycastHit.collider.GetComponent <BaseSprite>());
                    }
                }
                else if (leftRaycastHit.collider.tag.Equals("Powerup"))
                {
                    HandlePowerup(leftRaycastHit.collider.GetComponent <BaseSprite>());
                }
                else if (leftRaycastHit.collider.tag.Equals("Coin"))
                {
                    myAudio.PlayOneShot(coin);
                    //leftRaycastHit.collider.GetComponent<Coin>().CollectCoin(this);
                }
                else if (Constants.IsSolid(leftRaycastHit.collider.tag))
                {
                    possibleNewPos.x = leftRaycastHit.point.x + GetWidth() / 2.0f;
                    velocity.x       = 0;
                }
            }
            if (!playerTwo)
            {
                //follower.CheckMoveLeft(GetPosition(possibleNewPos), Mathf.Abs(possibleNewPos.x - position.x));
            }
        }
        else if (velocity.x > 0)
        {        //RIGHT CHECK
            RaycastHit?rightHit = HorizontalCollisionCheck(GetPosition(position), GetRightPosition() + Vector3.right * (possibleNewPos.x - position.x));
            if (rightHit != null)
            {
                RaycastHit rightRaycastHit = (RaycastHit)rightHit;
                if (rightRaycastHit.collider.tag.Equals("Enemy") && !squishedEnemy)
                {
                    Shell s = rightRaycastHit.collider.GetComponent <Shell>();
                    if (s == null)
                    {
                        Hurt(rightRaycastHit.collider.GetComponent <BaseSprite>());
                    }
                    else if (s.Moving())
                    {
                        Hurt(rightRaycastHit.collider.GetComponent <BaseSprite>());
                    }
                }
                else if (rightRaycastHit.collider.tag.Equals("Powerup"))
                {
                    HandlePowerup(rightRaycastHit.collider.GetComponent <BaseSprite>());
                }
                else if (rightRaycastHit.collider.tag.Equals("Coin"))
                {
                    myAudio.PlayOneShot(coin);
                    //rightRaycastHit.collider.GetComponent<Coin>().CollectCoin(this);
                }
                else if (Constants.IsSolid(rightRaycastHit.collider.tag))
                {
                    possibleNewPos.x = rightRaycastHit.point.x - GetWidth() / 2.0f;
                    velocity.x       = 0;
                }
            }

            if (!playerTwo)
            {
                //follower.CheckMoveRight(GetPosition(possibleNewPos), Mathf.Abs(possibleNewPos.x - position.x));
            }
        }

        //Set new position
        if (!dying)
        {
            SetPosition(possibleNewPos);

            //Determine animation

            if (velocity.y == 0)
            {
                //Print out dodge log
                //if (duckStart > 0)
                //{
                //	if (LogHandler.Instance != null)
                //	{
                //		LogHandler.Instance.WriteLine(gameObject.name + " Duck: StTime = " + duckStart + " EdTime = " + Time.time);
                //	}
                //	duckStart = 0;
                //}

                if (velocity.x > changeSpeed)
                {
                    currAnimator.SetAnimation("Run", true);
                }
                else if (velocity.x < -1 * changeSpeed)
                {
                    currAnimator.SetAnimation("Run", false);
                }
                else if (velocity.x > 0 && leftPressed)
                {
                    currAnimator.SetAnimation("Turn", false);
                }
                else if (velocity.x < 0 && rightPressed)
                {
                    currAnimator.SetAnimation("Turn", true);
                }
                else if (velocity.x == 0)
                {
                    if (fireTimer <= 0)
                    {
                        currAnimator.SetAnimation("Idle");
                    }
                    else
                    {
                        //currAnimator.SetAnimation ("Fire");
                    }
                }
                else if (velocity.x > 0)
                {
                    currAnimator.SetAnimation("Run", true);
                }
                else if (velocity.x < -1 * 0)
                {
                    currAnimator.SetAnimation("Run", false);
                }
            }
            else if (velocity.y > 0)
            {
                currAnimator.SetAnimation("Jump");
            }
            else if (velocity.y < 0)
            {
                currAnimator.SetAnimation("Fall");
            }


            //Invulnerability flash
            if (invulnerable)
            {
                invulnerabilityTimer -= Time.deltaTime;


                float flashTime    = invulnerabilityTimer * 10f;
                int   flashTimeInt = (int)Mathf.Round(flashTime);

                GetComponent <MeshRenderer>().material.color = new Color32(255, 255, 255, 255);
                if (flashTimeInt % 2 != 0 && invulnerabilityTimer > 0)
                {
                    GetComponent <MeshRenderer>().material.color = new Color32(255, 255, 255, 0);
                }

                if (invulnerabilityTimer < 0)
                {
                    invulnerable = false;
                }
            }
        }
    }
Exemple #26
0
    private void BowserMovementLogic()
    {
        facingRight = mario.transform.position.x > transform.position.x;


        if (fireballTimer < fireballTimerMax)
        {
            fireballTimer += Time.deltaTime;
        }
        else
        {
            SpawnFireball();
        }

        if (!inAir && fireballTimer > 0.1)
        {
            myAnimator.SetAnimation("Walk", !facingRight);
        }

        if (movementTimer < movementTimerMax)
        {
            movementTimer += Time.deltaTime;
        }
        else
        {
            movementTimer = 0;
            rightPressed  = Random.Range(0, 2) == 0;
            leftPressed   = !rightPressed;
        }


        if (transform.position.x - startX > maxX)
        {
            rightPressed = false;
            leftPressed  = true;
        }

        if (startX - transform.position.x > maxX)
        {
            rightPressed = true;
            leftPressed  = false;
        }
        bool rightOrLeftPressed = false;

        //Running (Takes 2 to speed up/slow down)
        if ((rightPressed) && !leftPressed)
        {
            rightOrLeftPressed = true;
            RaycastHit?rightHit = HorizontalCollisionCheck(GetPosition(position), GetRightPosition());
            if (rightHit == null)
            {
                rightPressed = true;

                velocity.x = changeMoveSpeed;
            }
        }
        else if (leftPressed && !rightPressed)
        {
            rightOrLeftPressed = true;
            RaycastHit?leftHit = HorizontalCollisionCheck(GetPosition(position), GetLeftPosition());
            if (leftHit == null)
            {
                //Left Start was hit
                velocity.x = -1 * changeMoveSpeed;
            }
        }

        //Determine if in air
        if (Mathf.Abs(velocity.x) > 0 && velocity.y == 0)
        {
            RaycastHit?below = VerticalCollisionCheck(GetPosition(position), GetDownPosition());
            if (below == null)
            {
                inAir = true;
            }
            else
            {
                RaycastHit belowHit = (RaycastHit)below;
                if (!Constants.IsSolid(belowHit.collider.tag) && !belowHit.collider.tag.Equals("Plant"))
                {
                    inAir = true;
                }
            }
        }

        bool jump = false;

        if (jumpTimer < jumpTimerMax)
        {
            jumpTimer += Time.deltaTime;
        }
        else
        {
            jump      = true;
            jumpTimer = 0;
        }


        //Input -Jumping
        if (jump && velocity.y == 0 && !inAir)
        {
            velocity.y = initialChangeSpeed;
            jumping    = true;
            inAir      = true;
        }
        else if (jump && jumping && velocity.y > 0)
        {
            velocity.y += changeJumpSpeed * Time.deltaTime;
            if (velocity.y > maxJumpSpeed)
            {
                velocity.y = maxJumpSpeed;
                jumping    = false;
            }
        }
        else if (velocity.y != 0)
        {
            jumping = false;
        }

        //Gravity
        if (inAir)
        {
            myAnimator.SetAnimation("Jump", !facingRight);
            velocity.y -= changeGravitySpeed * Time.deltaTime;
        }

        Vector2 possibleNewPos = position + Time.deltaTime * velocity;
        bool    squishedEnemy  = false;

        if (velocity.y > 0)
        {
            RaycastHit?aboveHit = VerticalCollisionCheck(GetUpPosition(), GetUpPosition() + Vector3.up * (possibleNewPos.y - position.y));
            if (aboveHit != null)
            {
                RaycastHit aboveRaycastHit = (RaycastHit)aboveHit;
                if (Constants.IsSolid(aboveRaycastHit.collider.tag))
                {
                    possibleNewPos.y = aboveRaycastHit.point.y - GetHeight() / 2.0f;
                    velocity.y       = 0;

                    if (aboveRaycastHit.collider.tag.Equals("Breakable"))
                    {
                        aboveRaycastHit.collider.GetComponent <Block> ().HitBelow(gameObject);
                    }
                    else if (aboveRaycastHit.collider.tag.Equals("PowerupBlock"))
                    {
                        QuestionBlock b = aboveRaycastHit.collider.GetComponent <QuestionBlock> ();
                        if (b != null)
                        {
                            b.HitBelow(null);
                        }
                    }
                }
            }
        }
        else if (velocity.y < 0)
        {
            RaycastHit?belowHit = VerticalCollisionCheck(GetPosition(position), GetDownPosition() + Vector3.down * (position.y - possibleNewPos.y), 0.05f, 0.95f);
            if (belowHit != null)
            {
                RaycastHit belowRaycastHit = (RaycastHit)belowHit;
                if (Constants.IsSolid(belowRaycastHit.collider.tag))
                {
                    possibleNewPos.y = belowRaycastHit.point.y + GetHeight() / 2.0f;
                    inAir            = false;
                    velocity.y       = 0;
                }
                else if (belowRaycastHit.collider.tag.Equals("Player"))
                {
                    Mario m = belowRaycastHit.collider.GetComponent <Mario> ();
                    m.Hurt(this);
                }
            }
        }

        if (velocity.x < 0)          //LEFT CHECK
        {
            RaycastHit?leftHit = HorizontalCollisionCheck(GetPosition(position), GetLeftPosition() + Vector3.left * (position.x - possibleNewPos.x));
            if (leftHit != null)
            {
                RaycastHit leftRaycastHit = (RaycastHit)leftHit;
                if (Constants.IsSolid(leftRaycastHit.collider.tag))
                {
                    possibleNewPos.x = leftRaycastHit.point.x + GetWidth() / 2.0f;
                    velocity.x       = 0;
                }
                else if (leftRaycastHit.collider.tag.Equals("Player"))
                {
                    Mario m = leftRaycastHit.collider.GetComponent <Mario> ();
                    m.Hurt(this);
                }
            }
        }
        else if (velocity.x > 0)          //RIGHT CHECK
        {
            RaycastHit?rightHit = HorizontalCollisionCheck(GetPosition(position), GetRightPosition() + Vector3.right * (possibleNewPos.x - position.x));
            if (rightHit != null)
            {
                RaycastHit rightRaycastHit = (RaycastHit)rightHit;
                if (Constants.IsSolid(rightRaycastHit.collider.tag))
                {
                    possibleNewPos.x = rightRaycastHit.point.x - GetWidth() / 2.0f;
                    velocity.x       = 0;
                }
                else if (rightRaycastHit.collider.tag.Equals("Player"))
                {
                    Mario m = rightRaycastHit.collider.GetComponent <Mario> ();
                    m.Hurt(this);
                }
            }
        }

        SetPosition(possibleNewPos);
    }
        private static void LoadLevel(XmlReader reader)
        {
            Random         random       = new Random();
            string         objectType   = "";
            string         objectName   = "";
            string         location     = "";
            bool           typeFlag     = false;
            bool           nameFlag     = false;
            bool           locationFlag = false;
            IList <IBlock> blockList    = new List <IBlock>();
            IList <IEnemy> enemyList    = new List <IEnemy>();
            IList <IItem>  itemList     = new List <IItem>();

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name.ToString())
                    {
                    case "ObjectType":
                        objectType = reader.ReadString();
                        typeFlag   = true;
                        break;

                    case "ObjectName":
                        objectName = reader.ReadString();
                        nameFlag   = true;
                        break;

                    case "Location":
                        location     = reader.ReadString();
                        locationFlag = true;
                        break;
                    }

                    if (typeFlag && nameFlag && locationFlag)
                    {
                        switch (objectType)
                        {
                        case "Player":
                            string[] coordinates = location.Split(' ');
                            Mario.Instance.ConditionState = new SmallMarioState(Mario.Instance);
                            Mario.Instance.Location       = new Vector2(Int32.Parse(coordinates[0]), Int32.Parse(coordinates[1]));
                            break;

                        case "Block":
                            switch (objectName)
                            {
                            case "HiddenBlock":
                                string[] blockCoordinates = location.Split(' ');
                                IBlock   block            = new HiddenBlock();
                                block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "HiddenBlockEmpty":
                                blockCoordinates = location.Split(' ');
                                block            = new HiddenBlockEmpty();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "HiddenBlockCoin":
                                blockCoordinates = location.Split(' ');
                                block            = new HiddenBlockCoin();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "HiddenBlockStar":
                                blockCoordinates = location.Split(' ');
                                block            = new HiddenBlockStar();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "BrickBlock":
                                blockCoordinates = location.Split(' ');
                                block            = new BrickBlock();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "BrickBlockEmpty":
                                blockCoordinates = location.Split(' ');
                                block            = new BrickBlockEmpty();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "ItemBrick":
                                blockCoordinates = location.Split(' ');
                                block            = new BrickBlockWithItem();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "ItemBrickCoin":
                                blockCoordinates = location.Split(' ');
                                block            = new BrickBlockWithCoin();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "ItemBrickStar":
                                blockCoordinates = location.Split(' ');
                                block            = new BrickBlockWithStar();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "QuestionBlock":
                                blockCoordinates = location.Split(' ');
                                block            = new QuestionBlock();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "QuestionBlockEmpty":
                                blockCoordinates = location.Split(' ');
                                block            = new QuestionBlockEmpty();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "QuestionBlockStar":
                                blockCoordinates = location.Split(' ');
                                block            = new QuestionBlockStar();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "QuestionBlockCoin":
                                blockCoordinates = location.Split(' ');
                                block            = new QuestionBlockCoin();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "UnbreakableBlock":
                                blockCoordinates = location.Split(' ');
                                block            = new UnbreakableBlock();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "UsedBlock":
                                blockCoordinates = location.Split(' ');
                                block            = new UsedBlock();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "GroundBlock":
                                blockCoordinates = location.Split(' ');
                                block            = new GroundBlock();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "Pipe":
                                blockCoordinates = location.Split(' ');
                                block            = new Pipe();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "PipeBottom":
                                blockCoordinates = location.Split(' ');
                                block            = new PipeBottom();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;

                            case "WarpPipe":
                                blockCoordinates = location.Split(' ');
                                WarpPipe pipe = new WarpPipe();
                                pipe.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                switch (pipe.Location.X)
                                {
                                case 1760:
                                    pipe.WarpDestination = new Vector2(8000, 384);
                                    break;

                                case 8736:
                                    pipe.WarpDestination = new Vector2(2080, 352);
                                    break;
                                }
                                blockList.Add((IBlock)pipe);
                                break;

                            case "FlagPole":
                                blockCoordinates = location.Split(' ');
                                block            = new FlagPole();
                                block.Location   = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1]));
                                blockList.Add(block);
                                break;
                            }
                            break;

                        case "Enemy":
                            switch (objectName)
                            {
                            case "Goomba":
                                string[] enemyCoordinates = location.Split(' ');
                                IEnemy   enemy            = new Goomba();
                                enemy.RowId    = random.Next(0, 160);
                                enemy.Location = new Vector2(Int32.Parse(enemyCoordinates[0]), Int32.Parse(enemyCoordinates[1]));
                                enemyList.Add(enemy);
                                break;

                            case "Koopa":
                                enemyCoordinates = location.Split(' ');
                                enemy            = new Koopa();
                                enemy.RowId      = random.Next(0, 160);
                                enemy.Location   = new Vector2(Int32.Parse(enemyCoordinates[0]), Int32.Parse(enemyCoordinates[1]));
                                enemyList.Add(enemy);
                                break;
                            }
                            break;

                        case "Item":
                            switch (objectName)
                            {
                            case "Coin":
                                string[] itemCoordinates = location.Split(' ');
                                IItem    item            = new Coin();
                                item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1]));
                                itemList.Add(item);
                                break;

                            case "FireFlower":
                                itemCoordinates = location.Split(' ');
                                item            = new FireFlower();
                                item.Location   = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1]));
                                itemList.Add(item);
                                break;

                            case "OneUpMush":
                                itemCoordinates = location.Split(' ');
                                item            = new OneUpMushroom();
                                item.Location   = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1]));
                                itemList.Add(item);
                                break;

                            case "SuperMush":
                                itemCoordinates = location.Split(' ');
                                item            = new SuperMushroom();
                                item.Location   = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1]));
                                itemList.Add(item);
                                break;

                            case "Star":
                                itemCoordinates = location.Split(' ');
                                item            = new Star();
                                item.Location   = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1]));
                                itemList.Add(item);
                                break;
                            }
                            break;
                        }
                        typeFlag     = false;
                        nameFlag     = false;
                        locationFlag = false;
                    }
                }
            }
            PlayerLevel.Instance.BlockArray = blockList;
            PlayerLevel.Instance.EnemyArray = enemyList;
            PlayerLevel.Instance.ItemArray  = itemList;
        }
 public void SetValues(QuestionBlock q)
 {
     q.question       = question;
     q.answers        = answers;
     q.correctAnswers = correctAnswers.ToArray();
 }
        private void button_Save_Click(object sender, EventArgs e)
        {
            List <QuestionBlock> Questions = new List <QuestionBlock>();
            QuestionBlock        questionsXML;



            foreach (var panel in Panel_Main.Controls)
            {
                int tempAnswerID = 0;


                questionsXML = new QuestionBlock
                {
                    Answers = new List <Answer>()
                };



                if (panel is Panel p)
                {
                    foreach (var any in p.Controls)
                    {
                        if (any is TextBox t)
                        {
                            if (t.Tag?.ToString() == "Question")
                            {
                                questionsXML.Text = t.Text;
                            }
                        }


                        if (any is Label l)
                        {
                            if (l.Tag?.ToString() == "ID")
                            {
                                questionsXML.id = (int)(double.Parse(l.Text)) - 1;
                            }
                        }



                        if (any is Panel panelAnswers)
                        {
                            foreach (var answers in panelAnswers.Controls)
                            {
                                if (answers is TextBox tbAnswer)
                                {
                                    if (tbAnswer.Tag?.ToString() == "No" || tbAnswer.Tag?.ToString() == "Yes")
                                    {
                                        questionsXML.Answers.Add(new Answer {
                                            Text = tbAnswer.Text, id = tempAnswerID++, IsCorrect = tbAnswer.Tag?.ToString()
                                        });
                                    }
                                }
                            }
                        }
                    }
                    Questions.Add(questionsXML);
                }
            }

            if (textBox_QuizName.Text == "")
            {
                textBox_QuizName.Text = DateTime.Now.ToShortDateString();
            }

            var xml = new XmlSerializer(typeof(List <QuestionBlock>));

            using (var fs = new FileStream($@"C:\Users\{Environment.UserName}\Documents\Quiz App\{textBox_QuizName.Text}.xml", FileMode.Create))
            {
                xml.Serialize(fs, Questions);
                textBox_QuizName.Text = "";
                this.Select();
                MessageBox.Show("Ready!");
            }
        }
Exemple #30
0
    private void MoveMario()
    {
        controller2D.Move(velocity * Time.fixedDeltaTime);

        // After move check to see if we hit a ceiling or the ground.
        // If so we want to reset velocity.y to 0 as it means we're ending
        // a jump potentially.
        if (controller2D.collisions.above || controller2D.collisions.below)
        {
            velocity.y     = 0;
            jumping        = false;
            hitBlockOnJump = false;
        }

        if (controller2D.collisions.left || controller2D.collisions.right)
        {
            velocity.x = 0;
        }

        UpdateAnimations();

        if (!hitBlockOnJump)
        {
            GameObject ceilingObject = controller2D.HitCeilingObject();
            GameObject groundObject  = controller2D.HitGroundObject();

            if (ceilingObject)
            {
                if (ceilingObject.tag == "BrickBlock")
                {
                    BrickBlock brickBlock = ceilingObject.GetComponent <BrickBlock>();
                    brickBlock.HitBlock();
                    hitBlockOnJump = true;
                }

                if (ceilingObject.tag == "QuestionBlock")
                {
                    QuestionBlock questionBlock = ceilingObject.GetComponent <QuestionBlock>();
                    questionBlock.HitBlock();
                    hitBlockOnJump = true;
                }
            }

            if (groundObject)
            {
                if (groundObject.tag == "Enemy")
                {
                    Enemy enemy = groundObject.GetComponent <Enemy>();
                    enemy.Damage();
                    hitBlockOnJump = true;
                    velocity.y     = enemyJumpVelocity;
                    jumping        = true;
                }
            }
        }

        GameObject itemObject = controller2D.HitItem();

        if (itemObject)
        {
            if (itemObject.tag == "Mushroom")
            {
                MakeMarioBig();
                Destroy(itemObject);
            }
        }
    }