Exemplo n.º 1
0
        internal void Save(string userCommandsFile)
        {
            Logger.Instance.Log4.Info($@"{GetType().Name}: Saving {Program.ConfigPath}MCEControl.commands...");
            var sc = new SerializedCommands();

            var values = Values.Cast <Command>().ToArray();

            // Sort
            sc.commandArray = values.OrderBy(c => c.Cmd).ToArray();

            SerializedCommands.SaveCommands(userCommandsFile, sc, System.Windows.Forms.Application.ProductVersion);
        }
Exemplo n.º 2
0
        internal void Save(string userCommandsFile)
        {
            Logger.Instance.Log4.Info($@"Commands: Saving {Program.ConfigPath}MCEControl.commands...");
            var sc = new SerializedCommands();

            var values = Values.Cast <Command>().ToArray();

            // Sort
            sc.commandArray = values.OrderBy(c => c.Cmd).ToArray();

            SerializedCommands.SaveCommands(userCommandsFile, sc);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the value associated with the specified index.
 /// </summary>
 /// <param name="index"> The index of the value to get.</param>
 /// <returns>The value associated with the specified index.</returns>
 public TValue this[int index]
 {
     get
     {
         // get the item for that index.
         if (index < 0 || index > Count)
         {
             throw new KeyNotFoundException();
         }
         return(Values.Cast <TValue>().ToArray()[index]);
     }
 }
Exemplo n.º 4
0
        public void Serialize(BinarySerializer serializer)
        {
            serializer.BeginChunk("VARS");
            int varCount = Count;

            serializer.Serialize(ref varCount);
            var vars = Values.Cast <Variable>().ToList();

            for (int i = 0; i < varCount; i++)
            {
                if (serializer.Mode == SerializerMode.Write)
                {
                    Variable.WriteVariable(serializer, vars[i]);
                }
                else
                {
                    Variable variable = Variable.ReadVariable(serializer);
                    Owner.Add(variable);
                }
            }
            serializer.EndChunk();
        }
Exemplo n.º 5
0
        public bool GameOver()
        {
            bool emptyTileAvailable = Values.Cast <int>().Count(s => s.Equals(0)) > 0; // check if there's at least 1 empty tile
            int  merges             = 0;

            for (int row = 0; row <= MaxRow; row++)
            {
                for (int col = 0; col <= MaxCol; col++)
                {
                    int value = Values[row, col];
                    // 1. column neighbours check (if row index is on the edge, only test neighbouring tiles inside the bounds, else both directions)
                    switch (row)
                    {
                    case 0: merges += Values[row + 1, col] == value ? 1 : 0; break;

                    case 3: merges += Values[row - 1, col] == value ? 1 : 0; break;

                    default:
                        merges += Values[row + 1, col] == value ? 1 : 0;
                        merges += Values[row - 1, col] == value ? 1 : 0;
                        break;
                    }
                    // 2. row neighbours check (if column index is on the edge, only test neighbouring tiles inside the bounds, else both directions)
                    switch (col)
                    {
                    case 0: merges += Values[row, col + 1] == value ? 1 : 0; break;

                    case 3: merges += Values[row, col - 1] == value ? 1 : 0; break;

                    default:
                        merges += Values[row, col + 1] == value ? 1 : 0;
                        merges += Values[row, col - 1] == value ? 1 : 0;
                        break;
                    }
                }
            }
            return(merges == 0 && !emptyTileAvailable); // game over = true IF no possible merges left and no empty tiles available
        }
Exemplo n.º 6
0
        public void Summon(int quantity)
        {
            Random r = new Random();

            for (int a = 0; a < quantity; a++)
            {
                if (Values.Cast <int>().Count(s => s.Equals(0)) > 0)
                {
                    List <int[]> possibleIndexes = new List <int[]>();
                    for (int row = 0; row <= MaxRow; row++)
                    {
                        for (int col = 0; col <= MaxCol; col++)
                        {
                            if (Values[row, col] == 0)
                            {
                                possibleIndexes.Add(new int[] { row, col });
                            }
                        }
                    }
                    int[] newIndex = possibleIndexes[r.Next(0, possibleIndexes.Count())];
                    Values[newIndex[0], newIndex[1]] = 2;
                }
            }
        }
Exemplo n.º 7
0
 public IEnumerator <Element> GetEnumerator()
 {
     return(Branches.Cast <Element>().Concat(Values.Cast <Element>()).GetEnumerator());
 }
Exemplo n.º 8
0
 public string Get(string key)
 {
     EnsureExistence();
     return(Keys.Cast <string>().Corresponding(key, Values.Cast <string>()));
 }
Exemplo n.º 9
0
 public override int GetHashCode()
 {
     return(Values.Cast <object>().Aggregate(0, (current, obj) => current ^ obj.GetHashCode()));
 }
Exemplo n.º 10
0
 public override object[] GetValues()
 {
     return(Values.Cast <object>().ToArray());
 }