Exemplo n.º 1
0
 internal void AnswerChosen(string mathInfix)
 {
     // as soon as the player first answers a math challenge of this type unlock it
     if (MathChallenge.Locked)
     {
         MathChallenge.Locked = false;
     }
     AnswerChosenEvent?.Invoke(this, MathChallenge.TrySolveWith(mathInfix));
 }
        internal static MathChallenge CreateFromStream(BinaryReader reader, bool keepCurrentMath)
        {
            bool          reading = true;
            MathChallenge dummy   = null;

            while (reading)
            {
                StreamEnum nextEnum = (StreamEnum)reader.ReadByte();
                switch (nextEnum)
                {
                case StreamEnum.NAME:
                {
                    // read the string containing the full name of the challenge class
                    string className = reader.ReadString();
                    dummy = (MathChallenge)TypeHelper.CreateFromTypeName(className);
                }
                break;

                case StreamEnum.LOCKED:
                {
                    var locked = reader.ReadBoolean();
                    if (dummy != null && !keepCurrentMath)
                    {
                        dummy.Locked = locked;
                    }
                }
                break;

                case StreamEnum.COMBO:
                {
                    var combo = reader.ReadInt32();
                    if (dummy != null && !keepCurrentMath)
                    {
                        dummy.Combo = combo;
                    }
                }
                break;

                case StreamEnum.STOP:
                    reading = false;
                    break;
                }
            }
            return(dummy);
        }
Exemplo n.º 3
0
        internal MathChallengeNode(MathChallenge mathChallenge, float multiplVisible = 1, int columns = 2)
        {
            Scale          = 1f;
            MultiplVisible = multiplVisible;
            AnchorPoint    = CCPoint.AnchorLowerLeft;
            MathChallenge  = mathChallenge;
            Columns        = columns;

            QuestionNode = new MathNode(mathChallenge.ChallengeInfix, mathChallenge.ChallengeLaTeX, this);
            AddChild(QuestionNode);
            QuestionNode.Pressable = false; // there is no reason the question node should be allowed to be pressed
            AnswerNodes            = new MathNode[mathChallenge.AnswersLaTeX.Length];
            for (int i = 0; i < AnswerNodes.Length; i++)
            {
                AnswerNodes[i] = new MathNode(mathChallenge.AnswersInfix[i], mathChallenge.AnswersLaTeX[i], this);
                AddChild(AnswerNodes[i]);
            }
            MultiplLabel.AnchorPoint   = CCPoint.AnchorMiddle;
            MultiplLabel.IsAntialiased = false;
            AddChild(DrawNode);
            AddChild(MultiplLabel);
        }
        internal ScrapyardButton(MathChallenge challengeModel, string textureName)
        {
            Scale              = 1f;
            AnchorPoint        = CCPoint.AnchorMiddle;
            Button             = new ScrapyardButtonButton(textureName);
            Button.AnchorPoint = CCPoint.AnchorLowerLeft;
            AddChild(Button);
            ContentSize    = Button.ScaledContentSize;
            ChallengeModel = challengeModel;
            // check if the challenge type is locked
            if (ChallengeModel.Locked)
            {
                var frame = UIElement.spriteSheet.Frames.Find(_ => _.TextureFilename.Equals("scrapyardLockedv2.png"));
                Button.ReplaceTexture(frame.Texture, frame.TextureRectInPixels);
                Button.Pressable = false;
                Button.Color     = CCColor3B.DarkGray;
            }
            else
            {
                // generate and add your drawnode (for drawing the progress bar and other things)
                MyDrawNode           = new CCDrawNode();
                MyDrawNode.BlendFunc = CCBlendFunc.NonPremultiplied;
                MyDrawNode.Position  = (CCPoint)ContentSize / 2;
                AddChild(MyDrawNode, -100000);
            }
            // set the rewards
            switch (ChallengeModel)
            {
            case AddChallenge a:
            {
                PartRewardsTypeNames = new string[] { typeof(BodyPotato).AssemblyQualifiedName, typeof(RotorPotato).AssemblyQualifiedName,
                                                      typeof(RudderPotato).AssemblyQualifiedName, typeof(WeaponPotato).AssemblyQualifiedName,
                                                      typeof(WingPotato).AssemblyQualifiedName };
            }
            break;

            case SubChallenge s:
            {
                PartRewardsTypeNames = new string[] { typeof(BodyBat).AssemblyQualifiedName, typeof(RotorBat).AssemblyQualifiedName,
                                                      typeof(WeaponBat).AssemblyQualifiedName, typeof(WingBat).AssemblyQualifiedName };
            }
            break;

            case MultiplyChallenge m:
            {
                PartRewardsTypeNames = new string[] { typeof(TestRotor).AssemblyQualifiedName, typeof(TestBody).AssemblyQualifiedName,
                                                      typeof(TestDoubleWing).AssemblyQualifiedName, typeof(TestRudder).AssemblyQualifiedName,
                                                      typeof(TestWeapon).AssemblyQualifiedName };
            }
            break;

            case DivideChallenge d:
            {
                PartRewardsTypeNames = new string[] { typeof(BodyBalloon).AssemblyQualifiedName, typeof(RotorBalloon).AssemblyQualifiedName,
                                                      typeof(WeaponBalloon).AssemblyQualifiedName };
            }
            break;

            case SolveChallenge s:
            {
                PartRewardsTypeNames = new string[] { typeof(BodyFighter).AssemblyQualifiedName, typeof(RotorFighter).AssemblyQualifiedName,
                                                      typeof(RudderFighter).AssemblyQualifiedName, typeof(WeaponFighter).AssemblyQualifiedName,
                                                      typeof(WingFighter).AssemblyQualifiedName };
            }
            break;

            default:
                break;
            }
        }