Ejemplo n.º 1
0
        //param name="burnDelta">Integer local variable</param>
        public void CalculateNewSpeed(int burnDelta)
        {
            int speed  = current.GetSpeed() + deltaSpeed - burnDelta;
            int height = current.GetHeight() - speed;

            fuel -= burnDelta;
            // create a new current and add it to the history
            mlh.AddRound(height: height, speed: speed);
            current = mlh.Last();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method is called implicitely by the foreach statement.
        /// It iterates through the linked list.
        /// </summary>
        /// <returns>Current round info</returns>
        public IEnumerator GetEnumerator()
        {
            current = null;
            while (current != last)
            {
                if (current == null) current = first;
                else current = current.Next;

                yield return current;
            }
        }
Ejemplo n.º 3
0
 public void AddRound(int h, int s)
 {
     if (numRounds == rounds.Length)
     {
         RoundInfo[] diffRounds = new RoundInfo[numRounds + 10];
         for (int i = 0; i < rounds.Length; i++)
         {
             diffRounds[i] = rounds[i];
         }
         rounds = diffRounds;
     }
     rounds[numRounds] = new RoundInfo(h, s);
     numRounds++;
 }
Ejemplo n.º 4
0
        public void AddRound(int height, int speed)
        {
            if (numRounds > rounds.Length - 1)
            {
                RoundInfo[] extArr = new RoundInfo[rounds.Length + 20];

                for (int i = 0; i < rounds.Length; i++)
                {
                    extArr[i] = rounds[i];
                }
                rounds = extArr;
            }
            rounds[numRounds] = new RoundInfo(height, speed);
            numRounds++;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Create a new RoundInfo and add it to the end of the list
 /// </summary>
 /// <param name="height"></param>
 /// <param name="speed"></param>
 public void AddRound(int height, int speed)
 {
     RoundInfo round = new RoundInfo(t: numRounds++, h: height, s: speed);
     if (first == null)
     {
         first = round;
         last = round;
         current = round;
     }
     else
     {
         last.Next = round;
         last = round;
         current = round;
     }
 }
Ejemplo n.º 6
0
        // Clone is provided to you; it'll create a copy of the current history
        // Look for opportunities to use it elsewhere.
        //RoundInfo[] rounds = new RoundInfo[10];

        // used foreach and INumerable instead of another array
        // list-type I'll keep this code though for later projects.
        //public MarsLanderHistory Clone()
        //{
        //    MarsLanderHistory copy = new MarsLanderHistory();

        //    copy.rounds = new RoundInfo[this.rounds.Length];
        //    copy.numRounds = this.numRounds;
        //    for (int i = 0; i < copy.numRounds; i++)
        //        copy.rounds[i] = this.rounds[i];

        //    return copy;
        //}

        // <param name="height">Integer local variable</param>
        // <param name="speed">Integer local variable</param>
        public void AddRound(int height, int speed)
        {
            RoundInfo round = new RoundInfo(t: numRounds++, h: height, s: speed);

            if (first == null)
            {
                first   = round;
                last    = round;
                current = round;
            }
            else
            {
                last.Next = round;
                last      = round;
                current   = round;
            }
        }
Ejemplo n.º 7
0
        //IEnumerator checks if current is empty and the next space after that if it's not
        //basically this class returns the methods and properties for iteration
        public IEnumerator GetEnumerator()
        {
            current = null;

            while (current != last)
            {
                if (current == null)
                {
                    current = first;
                }
                else
                {
                    current = current.Next;
                }

                yield return(current);
            }
        }
Ejemplo n.º 8
0
        // you'll need to add data fields & methods so that the rest of the program
        // can use the various properties of the lander (such as height, speed, etc)


        public MarsLander()
        {
            mlh.AddRound(height: initialHeight, speed: intitialSpeed);
            current = mlh.Last();
        }
Ejemplo n.º 9
0
 public RoundInfo(int h, int s, int t)
 {
     height = h;
     speed  = s;
     Next   = null;
 }