Example #1
0
        /// <summary>
        /// Validate a password by checking the checksum.
        /// </summary>
        /// <param name="password">Password to validate.</param>
        /// <returns><c>true</c> if the password is valid, <c>false</c> otherwise.</returns>
        public static bool ValidatePassword(string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException(nameof(password));
            }

            // Sanitaze and check password
            password = password.Replace(" ", "");
            password = password.Replace(Environment.NewLine, "");
            password = password.ToUpper();
            if (password.Length != PasswordLength)
            {
                throw new ArgumentException("Invalid password length");
            }

            // Do decryption rounds
            byte[] binary;
            try {
                password = Permutation.Decrypt(password, false);
                binary   = Substitution.Decrypt(password);
                Scramble.Decrypt(binary[0], binary, 4, binary.Length - 5);
            } catch {
                return(false);
            }

            // Validate checksum
            uint crc32    = BitConverter.ToUInt32(binary, 0);
            uint newCrc32 = Crc32.Calculate(binary, 4, binary.Length - 5);

            return(crc32 == newCrc32);
        }
        /// <summary>
        /// Validate a password by checking the checksum.
        /// </summary>
        /// <param name="password">Password to validate.</param>
        /// <returns><c>true</c> if the password is valid, <c>false</c> otherwise.</returns>
        public static bool ValidatePassword(string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException(nameof(password));
            }

            // Sanitaze and check password
            password = password.Replace(" ", "");
            password = password.Replace(Environment.NewLine, "");
            password = password.ToUpper();
            if (password.Length != PasswordLength)
            {
                throw new ArgumentException("Invalid password length");
            }

            // Do decryption rounds
            byte[] binary;
            try {
                password = Permutation.Decrypt(password, true);
                binary   = Substitution.Decrypt(password);
                Scramble.Decrypt(binary[0], binary, 1, binary.Length - 2);
            } catch {
                return(false);
            }

            // Validate checksum
            byte checksum    = binary[0];
            byte newChecksum = Checksum.Calculate(binary, 1, binary.Length - 1);

            return(checksum == newChecksum);
        }
Example #3
0
        /// <summary>
        /// Converts a password into mail information.
        /// </summary>
        /// <param name="password">The password to convert.</param>
        /// <returns>Mail information from the password.</returns>
        public static WonderSMail Convert(string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException(nameof(password));
            }

            // Sanitaze and check password
            password = password.Replace(" ", "");
            password = password.Replace("\t", "");
            password = password.Replace(Environment.NewLine, "");
            password = password.ToUpper();
            if (password.Length != PasswordLength)
            {
                throw new ArgumentException("Invalid password length");
            }

            // Do decryption rounds
            // The last byte for "scramble" is ignored. It should be the null
            // terminator 0x00.
            password = Permutation.Decrypt(password, false);
            byte[] binary = Substitution.Decrypt(password);
            Scramble.Decrypt(binary[0], binary, 4, binary.Length - 5);

            // Validate checksum
            uint crc32    = BitConverter.ToUInt32(binary, 0);
            uint newCrc32 = Crc32.Calculate(binary, 4, binary.Length - 5);

            if (crc32 != newCrc32)
            {
                throw new FormatException("Invalid crc32");
            }

            // Convert the binary password into the structure.
            // Write the array into a stream to use the BitReader.
            DataStream stream = new DataStream();

            stream.Write(binary, 4, binary.Length - 4);
            BitReader reader = new BitReader(stream);

            WonderSMail info = new WonderSMail();

            info.MailType           = reader.ReadByte(4);
            info.MissionType        = reader.ReadByte(4);
            info.MissionSubType     = reader.ReadByte(4);
            info.SourceClientId     = reader.ReadUInt16(11);
            info.TargetClientId     = reader.ReadUInt16(11);
            info.TargetClientFemale = reader.ReadUInt16(11);
            info.RewardObjectId     = reader.ReadUInt16(10);
            info.RewardType         = reader.ReadByte(4);
            info.RewardId           = reader.ReadUInt16(11);
            info.RestrictionType    = reader.ReadByte(1);
            info.RestrictionParam   = reader.ReadUInt16(11);
            info.Random             = reader.ReadUInt32(24);
            info.LocationId         = reader.ReadByte(8);
            info.FloorNumber        = reader.ReadByte(8);
            info.Requirement        = reader.ReadByte(8);

            return(info);
        }
Example #4
0
        public static Time ToTime(this String str, Scramble scramble, User user)
        {
            StateOfTime sot          = StateOfTime.Default;
            int         milliseconds = 0;
            short       seconds      = 0;
            short       minutes      = 0;
            short       hours        = 0;

            if (str.Contains("DNF"))
            {
                sot = StateOfTime.DNF;
                var inthebrackets = str.Split('(');
                inthebrackets = str.Split(new[] { ')' }, StringSplitOptions.RemoveEmptyEntries);
                str           = inthebrackets[0];
            }
            if (str.Contains("+"))
            {
                sot = StateOfTime.SEC2;
            }
            var split = str.Split(':');

            if (split.Count() == 1)                       // "2.2" - there are no ':'
            {
                String secs = split[0];                   // getting seconds
                split        = secs.Split('.');
                milliseconds = Convert.ToInt32(split[1]); // getting seconds - "2.2" - seconds 2 means milliseconds
                seconds      = Convert.ToInt16(split[0]);
            }
            else if (split.Count() == 2)
            {
                String secs      = split[1]; // getting seconds
                String s_minutes = split[0];
                minutes = Int16.Parse(s_minutes);

                split        = secs.Split('.');
                milliseconds = Convert.ToInt32(split[1]); // getting seconds - "2.2" - seconds 2 means milliseconds
                seconds      = Convert.ToInt16(split[0]);
            }
            else if (split.Count() == 3)
            {
                String secs      = split[2]; // getting seconds
                String s_minutes = split[1];
                minutes = Int16.Parse(s_minutes);

                String s_hours = split[0];
                hours = Int16.Parse(s_hours);

                split        = secs.Split('.');
                milliseconds = Convert.ToInt32(split[1]); // getting seconds - "2.2" - seconds 2 means milliseconds
                seconds      = Convert.ToInt16(split[0]);
            }
            Time time = new Time(hours, minutes, seconds, milliseconds, scramble); //, user

            time.SOT = sot;
            return(time);
        }
        /// <summary>
        /// Converts a password into mail information.
        /// </summary>
        /// <param name="password">The password to convert.</param>
        /// <returns>Mail information from the password.</returns>
        public static MissionMail Convert(string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException(nameof(password));
            }

            // Sanitaze and check password
            password = password.Replace(" ", "");
            password = password.Replace(Environment.NewLine, "");
            password = password.ToUpper();
            if (password.Length != PasswordLength)
            {
                throw new ArgumentException("Invalid password length");
            }

            // Do decryption rounds
            // The last byte for "scramble" is ignored. It should be the null
            // terminator 0x00.
            password = Permutation.Decrypt(password, true);
            byte[] binary = Substitution.Decrypt(password);
            Scramble.Decrypt(binary[0], binary, 1, binary.Length - 2);

            // Validate checksum
            byte checksum    = binary[0]; // The scramble key is the checksum too.
            byte newChecksum = Checksum.Calculate(binary, 1, binary.Length - 1);

            if (checksum != newChecksum)
            {
                throw new FormatException("Invalid checksum");
            }

            // Convert the binary password into the structure.
            // Write the array into a stream to use the BitReader.
            DataStream stream = new DataStream();

            stream.Write(binary, 1, binary.Length - 1);
            BitReader reader = new BitReader(stream);

            MissionMail info = new MissionMail();

            info.Type           = (MissionState)reader.ReadByte(4);
            info.LocationId     = reader.ReadByte(7);
            info.FloorNumber    = reader.ReadByte(7);
            info.Random         = (info.Type == MissionState.Sos) ? reader.ReadUInt32(24) : 0x00;
            info.UID            = reader.ReadUInt64(64);
            info.ClientLanguage = (GameLanguage)reader.ReadByte(4);
            info.ClientName     = reader.ReadString(80, EncodingName);
            info.ObjectID1      = (info.Type == MissionState.Sos) ? (ushort)0x00 : reader.ReadUInt16(10);
            info.ObjectID2      = (info.Type == MissionState.Sos) ? (ushort)0x00 : reader.ReadUInt16(10);
            info.RescuerUID     = reader.ReadUInt64(64);
            info.GameType       = (GameType)reader.ReadByte(2);

            return(info);
        }
Example #6
0
        private void btnScrambleEx_Click(object sender, EventArgs e)
        {
            try
            {
                checkSSN();
                validateKey();
                checkWW();
                checkWatsonW();
                if (showConfirm() == DialogResult.OK)
                {
                    _scr           = new Scramble();
                    _scr.FileName  = txtFileExcel.Text;
                    _scr.Key       = txtKey.Text;
                    _scr.SheetName = cboSheetnames.SelectedItem.ToString();

                    //create a backup copy
                    _scr.createExcelcopy();

                    if (_exr == null)
                    {
                        _exr = new ExcelReader();
                    }
                    int _colno  = _exr.ColNumber(txtColS.Text) + 1;
                    int _fcolno = 0;
                    int _lcolno = 0;

                    //set wageworks variables
                    if (_ww)
                    {
                        _lcolno            = _exr.ColNumber(txtLn.Text) + 1;
                        _scr.WageWorks     = true;
                        _scr.LastNameColNo = _lcolno;
                    }
                    //set watson wyatts variables
                    if (_watsonW)
                    {
                        int _estatcolno = _exr.ColNumber(txtEmplStat.Text) + 1;
                        _scr.WatsonWyatts = true;
                        _scr.EmpStatus    = _estatcolno;
                    }

                    //set ssn column number
                    _scr.ColumnNumber = _colno;

                    //scramble
                    _scr.scrambleExcelFile();

                    MessageBox.Show("Scrambled SSN Column successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #7
0
        public static Scramble ToString(this String parsestring)
        {
            var v  = parsestring.Split(' ');
            var se = new List <ScrambleElements>();

            for (int i = 0; i < v.Length; i++)
            {
                se.Add(Scramble.Replace(v[1]));
            }
            return(new Scramble(se.ToArray()));
        }
 private async Task <bool> SetScrambleAsDefaultAsync(Category category, Scramble scramble)
 {
     if (scramble.Category != category)
     {
         return(false);
     }
     else
     {
         scramble.Default = true;
         return(await _dbContext.SaveChangesAsync() > 0);
     }
 }
Example #9
0
        /// <summary>
        /// Converts a missiong information into a password.
        /// </summary>
        /// <param name="info">Mission to convert.</param>
        /// <returns>The password.</returns>
        public static string Convert(WonderSMail info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            // Serialize the structure into a bit stream
            DataStream stream = new DataStream();
            BitWriter  writer = new BitWriter(stream);

            writer.Write(info.MailType, 4);
            writer.Write(info.MissionType, 4);
            writer.Write(info.MissionSubType, 4);
            writer.Write(info.SourceClientId, 11);
            writer.Write(info.TargetClientId, 11);
            writer.Write(info.TargetClientFemale, 11);
            writer.Write(info.RewardObjectId, 10);
            writer.Write(info.RewardType, 4);
            writer.Write(info.RewardId, 11);
            writer.Write(info.RestrictionType, 1);
            writer.Write(info.RestrictionParam, 11);
            writer.Write(info.Random, 24);
            writer.Write(info.LocationId, 8);
            writer.Write(info.FloorNumber, 8);
            writer.Write(info.Requirement, 8);

            // Write the stream into an array for the rounds.
            // We allocate an extra space for the checksum (first uint)
            // and the null terminator (last byte).
            byte[] binary = new byte[stream.Length + 5];
            stream.Position = 0;
            stream.Read(binary, 4, (int)stream.Length);

            // Create checksum
            uint crc32 = Crc32.Calculate(binary, 4, binary.Length - 5);

            byte[] crc32Bytes = BitConverter.GetBytes(crc32);
            binary[0] = crc32Bytes[0];
            binary[1] = crc32Bytes[1];
            binary[2] = crc32Bytes[2];
            binary[3] = crc32Bytes[3];

            // Do encryption rounds
            // The key is the checksum, we don't encrypt the null terminator.
            Scramble.Encrypt(crc32Bytes[0], binary, 4, binary.Length - 5);
            string password = Substitution.Encrypt(binary, PasswordLength);

            password = Permutation.Encrypt(password, false);

            return(password);
        }
        public static Scramble ToScramble(this String str)
        {
            var      arg         = Scramble.Empty;
            var      split       = str.Split(' ');
            Scramble finalobject = new Scramble();

            foreach (var v in split)
            {
                M1(v, ref arg);
            }
            Task.WaitAll();
            return(arg);
        }
        /// <summary>
        /// Converts a missiong information into a password.
        /// </summary>
        /// <param name="info">Mission to convert.</param>
        /// <returns>The password.</returns>
        public static string Convert(MissionMail info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            // Serialize the structure into a bit stream
            DataStream stream = new DataStream();
            BitWriter  writer = new BitWriter(stream);

            writer.Write((byte)info.Type, 4);
            writer.Write(info.LocationId, 7);
            writer.Write(info.FloorNumber, 7);
            if (info.Type == MissionState.Sos)
            {
                writer.Write(info.Random, 24);
            }
            writer.Write(info.UID, 64);
            writer.Write((byte)info.ClientLanguage, 4);
            writer.Write(info.ClientName, 80, EncodingName);
            if (info.Type != MissionState.Sos)
            {
                writer.Write(info.ObjectID1, 10);
                writer.Write(info.ObjectID2, 10);
            }

            writer.Write(info.RescuerUID, 64);
            writer.Write((byte)info.GameType, 2);

            // Write the stream into an array for the rounds.
            // We allocate an extra space for the checksum (first byte)
            // and the null terminator (last byte).
            byte[] binary = new byte[stream.Length + 2];
            stream.Position = 0;
            stream.Read(binary, 1, binary.Length - 2);

            // Create checksum
            byte checksum = Checksum.Calculate(binary, 1, binary.Length - 1);

            binary[0] = checksum;

            // Do encryption rounds
            // The key is the checksum, we don't encrypt the null terminator.
            Scramble.Encrypt(checksum, binary, 1, binary.Length - 2);
            string password = Substitution.Encrypt(binary, PasswordLength);

            password = Permutation.Encrypt(password, true);

            return(password);
        }
 private async Task <IEnumerable <ScrambleMove> > GetScrambleMovesAsync(Scramble scramble)
 {
     if (scramble == null)
     {
         return(new List <ScrambleMove>());
     }
     else
     {
         return(await _dbContext.ScrambleMoves
                .Where(m => m.Scramble == scramble)
                .OrderBy(m => m.Move)
                .ToListAsync());
     }
 }
        private async Task <CompleteScramble> ProduceCompleteScrambleAsync(Scramble scramble)
        {
            IEnumerable <ScrambleMove> moves = new List <ScrambleMove>();

            if (scramble != null)
            {
                moves = await GetScrambleMovesAsync(scramble);
            }

            return(new CompleteScramble()
            {
                Scramble = scramble,
                Moves = moves,
            });
        }
        public void Scramble3x3_isCorrectLength()
        {
            Scramble tested = new Scramble(new ThreeByThreeScramble());

            Move prev = tested.Moves[0];

            for (int i = 1; i < tested.Moves.Count; ++i)
            {
                Move curr = tested.Moves[i];
                Assert.NotEqual(prev, curr);
                prev = curr;
            }

            string[] splitted = tested.Representation.Split(' ');

            Assert.Equal(20, tested.Moves.Count);
            Assert.Equal(20, splitted.Length);
        }
Example #15
0
        private void method()
        {
            Scramble.ResetText();
            Letterlist.Clear();


            ArrayList list = new ArrayList();

            list.Clear();
            string[] Word = File.ReadAllLines(Application.StartupPath + "\\ListOfWords.txt");

            List <string> Words = new List <string>();

            for (int i = 0; i < Word.Length; i++)
            {
                if (Word[i] != "")
                {
                    Words.Add(Word[i]);
                }
            }

            Random number = new Random();

            place = number.Next(0, Words.Count);
            Temp  = Words[place].ToLower();

            for (int i = 0; i < (Temp.Length); i++)
            {
                list.Add(Temp.Substring(i, 1));
            }
            int g = list.Count;

            while (g > 0)
            {
                letternumber = number.Next(0, list.Count - 1);
                Letterlist.Add(list[letternumber]);
                list.RemoveAt(letternumber);
                g--;
            }
            for (int i = 0; i < Letterlist.Count; i++)
            {
                Scramble.Text += Letterlist[i];
            }
        }
        public void Scramble2x2_isValid()
        {
            Scramble tested = new Scramble(new TwoByTwoScramble());

            Move prev = tested.Moves[0];

            for (int i = 1; i < tested.Moves.Count; ++i)
            {
                Move curr = tested.Moves[i];
                Assert.NotEqual(prev, curr);
                Assert.NotEqual(MoveType.D, curr.TypeOfMove);
                Assert.NotEqual(MoveType.L, curr.TypeOfMove);
                prev = curr;
            }

            string[] splitted = tested.Representation.Split(' ');

            Assert.Equal(10, tested.Moves.Count);
            Assert.Equal(10, splitted.Length);
        }
Example #17
0
 private void btnScrambleText_Click(object sender, EventArgs e)
 {
     try
     {
         validateKey();
         _scr          = new Scramble();
         _scr.FileName = txttextFile.Text;
         _scr.Key      = txtKey.Text;
         if (cbxPrism.Checked)
         {
             _scr.PrismImport = true;
         }
         _scr.scrambleTextFile();
         MessageBox.Show("Scrambled SSN Column successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #18
0
        static void Main(string[] args)
        {
            Scramble scramble = new Scramble();

            Console.WriteLine(scramble.ToString());
            //Timer = new CubingTimer(new User(1, "name", "lname")); // TODO: Fix to the current user
            Timer.LoadScramble(scramble);
            Timer.Started        += Timer_Started;
            Handlers.TimeChanged += CurrentTime_TimeChanged;
            Timer.TimerStoped    += Timer_TimerStoped;
            newThread             = new Thread(ThreadVoid);

            for (Int32 i = 3; i > 0; i--)
            {
                Console.WriteLine($"Timer starts in {i} sec");
                Thread.Sleep(1000);
            }
            Console.WriteLine("P.S. Pls, write something to stop timer!");
            Timer.Start();
            newThread.Start();
        }
Example #19
0
        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (Timer != null)
            {
                if (Timer.IsTimerWorking == false && CanTimerStart)
                {
                    Timer.Start();

                    CanTimerStart = false;
                    scramble1     = new Scramble();
                    scramble.Text = scramble1.ToString();
                    ScrambleShow(scramble1);
                    return;
                }
            }
            if (stoped == true)
            {
                textblock1.Text       = Time.History[Time.History.Count - 1].ToString();
                textblock1.Visibility = Visibility.Visible;
            }
        }
Example #20
0
        public async Task GetNextScrambleAsync()
        {
            if (_isCustom)
            {
                try
                {
                    CurrentScramble = _customScrambleGenerator?.GenerateScramble() ?? new Scramble();
                }
                catch
                {
                    CurrentScramble = new Scramble();
                }

                return;
            }

            if (_scrambles.Count == 0)
            {
                await ShutdownDialogHandleAsync("Nie można pobrać scrambli z serwera.");
            }

            CurrentScramble = _scrambles.Dequeue();
            if (_scrambles.Count < 3)
            {
                IsBusy = true;
                var generatedScrambles = await _scrambleGenerator.GenerateScrambles(_currentEvent, 5);

                if (generatedScrambles.IsSuccesfull is false)
                {
                    IsBusy = false;
                    return;
                }

                foreach (var scramble in generatedScrambles.Value !)
                {
                    _scrambles.Enqueue(scramble);
                }
                IsBusy = false;
            }
        }
        private ScrambleUpdateViewModel CreateScrambleUpdateModel(Category category, Scramble scramble = null)
        {
            if (scramble != null)
            {
                return(new ScrambleUpdateViewModel()
                {
                    IsModification = true,
                    Identity = scramble.Identity,
                    CategoryId = category.Identity,
                    CategoryName = category.Name,
                    ScrambleName = scramble.Name,
                    DefaultScrambleLength = scramble.DefaultScrambleLength,
                    MinimumScrambleLength = scramble.MinimumScrambleLength,
                    MaximumScrambleLength = scramble.MaximumScrambleLength,
                    EliminateDuplicates = scramble.EliminateDuplicates,
                    AllowRegenerate = scramble.AllowRegenerate,
                    Disabled = scramble.Disabled,
                    TopColor = scramble.TopColor,
                    FrontColor = scramble.FrontColor,
                });
            }

            return(new ScrambleUpdateViewModel()
            {
                IsModification = false,
                Identity = 0,
                CategoryId = category.Identity,
                CategoryName = category.Name,
                ScrambleName = _configuration["ScrambleDefinitionDefaults:DefaultName"],
                DefaultScrambleLength = Convert.ToInt32(_configuration["ScrambleDefinitionDefaults:DefaultLength"]),
                MinimumScrambleLength = Convert.ToInt32(_configuration["ScrambleDefinitionDefaults:MinLength"]),
                MaximumScrambleLength = Convert.ToInt32(_configuration["ScrambleDefinitionDefaults:MaxLength"]),
                EliminateDuplicates = Convert.ToBoolean(_configuration["ScrambleDefinitionDefaults:EliminateDuplicates"]),
                AllowRegenerate = Convert.ToBoolean(_configuration["ScrambleDefinitionDefaults:AllowRegenerate"]),
                Disabled = Convert.ToBoolean(_configuration["ScrambleDefinitionDefaults:Disabled"]),
                TopColor = _configuration["ScrambleDefinitionDefaults:TopColor"],
                FrontColor = _configuration["ScrambleDefinitionDefaults:FrontColor"],
            });
        }
        static void M1(String str, ref Scramble scramble)
        {
            switch (str)
            {
            case "R":
                scramble.AddElement(ScrambleElements.R);
                break;

            case "L":
                scramble.AddElement(ScrambleElements.L);
                break;

            case "U":
                scramble.AddElement(ScrambleElements.U);
                break;

            case "D":
                scramble.AddElement(ScrambleElements.D);
                break;

            case "F":
                scramble.AddElement(ScrambleElements.F);
                break;

            case "B":
                scramble.AddElement(ScrambleElements.B);
                break;

            case "R'":
                scramble.AddElement(ScrambleElements.R1);
                break;

            case "L'":
                scramble.AddElement(ScrambleElements.L1);
                break;

            case "U'":
                scramble.AddElement(ScrambleElements.U1);
                break;

            case "D'":
                scramble.AddElement(ScrambleElements.D1);
                break;

            case "F'":
                scramble.AddElement(ScrambleElements.F1);
                break;

            case "B'":
                scramble.AddElement(ScrambleElements.B1);
                break;

            case "R2":
                scramble.AddElement(ScrambleElements.R2);
                break;

            case "L2":
                scramble.AddElement(ScrambleElements.L2);
                break;

            case "U2":
                scramble.AddElement(ScrambleElements.U2);
                break;

            case "D2":
                scramble.AddElement(ScrambleElements.D2);
                break;

            case "F2":
                scramble.AddElement(ScrambleElements.F2);
                break;

            case "B2":
                scramble.AddElement(ScrambleElements.B2);
                break;
            }
        }
        private void ScrambleShow(Scramble scramble) // show it in grid1
        {
            CubeState cs = CubeState.Scramble(scramble);

            cs.PrepareForUI();
            int row    = 0 + 1;
            int column = 5;
            int index  = 0;             // of array of elements in Side.Elements property

            for (int i = 0; i < 3; i++) // white color
            {
                column = 6;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S2.Elements[index].ConvertToBrush();
                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);
                    column++;
                    index++;
                }
                row++;
            }
            row    = 4 + 1;
            column = 6;
            index  = 0;
            for (int i = 0; i < 3; i++) // green color
            {
                column = 6;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S1.Elements[index].ConvertToBrush();
                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);
                    column++;
                    index++;
                }
                row++;
            }
            row    = 4 + 1;
            column = 2;
            index  = 0;
            for (int i = 0; i < 3; i++) // orange color
            {
                column = 2;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S6.Elements[index].ConvertToBrush();
                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);
                    column++;
                    index++;
                }
                row++;
            }
            row    = 4 + 1;
            column = 10;
            index  = 0;
            for (int i = 0; i < 3; i++) // Red color
            {
                column = 10;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S5.Elements[index].ConvertToBrush();
                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);
                    column++;
                    index++;
                }
                row++;
            }
            row    = 4 + 1;
            column = 14;
            index  = 0;
            for (int i = 0; i < 3; i++) // blue color
            {
                column = 14;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S3.Elements[index].ConvertToBrush();
                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);
                    column++;
                    index++;
                }
                row++;
            }
            row    = 8 + 1;
            column = 6;
            index  = 0;
            for (int i = 0; i < 3; i++) // green color
            {
                column = 6;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S4.Elements[index].ConvertToBrush();
                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);
                    column++;
                    index++;
                }
                row++;
            }
        }
 public CompleteScramble()
 {
     Scramble = new Scramble();
     Moves    = new List <ScrambleMove>();
 }
Example #25
0
        private void ScrambleShow(Scramble scramble) // show it in grid1
        {
            CubeState cs = CubeState.Scramble(scramble);

            cs.PrepareForUI();
            int row    = 0 + 1;
            int column = 5;
            int index  = 0;             // of array of elements in Side.Elements property

            for (int i = 0; i < 3; i++) // white color
            {
                column = 5;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S2.Elements[index].ConvertToBrush();

                    Border border = new Border()
                    {
                        BorderThickness = new Thickness(3000), BorderBrush = Brushes.Black
                    };
                    Grid.SetRow(border, row);
                    Grid.SetColumn(border, column);

                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);


                    column++;
                    index++;
                }
                row++;
            }
            row    = 4 + 1;
            column = 5;
            index  = 0;
            for (int i = 0; i < 3; i++) // green color
            {
                column = 5;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S1.Elements[index].ConvertToBrush();
                    Border border = new Border()
                    {
                        BorderThickness = new Thickness(3), BorderBrush = Brushes.Black
                    };
                    Grid.SetRow(border, row);
                    Grid.SetColumn(border, column);

                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);

                    column++;
                    index++;
                }
                row++;
            }
            row    = 4 + 1;
            column = 1;
            index  = 0;
            for (int i = 0; i < 3; i++) // orange color
            {
                column = 1;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S6.Elements[index].ConvertToBrush();
                    Border border = new Border()
                    {
                        BorderThickness = new Thickness(3), BorderBrush = Brushes.Black
                    };
                    Grid.SetRow(border, row);
                    Grid.SetColumn(border, column);

                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);

                    column++;
                    index++;
                }
                row++;
            }
            row    = 4 + 1;
            column = 9;
            index  = 0;
            for (int i = 0; i < 3; i++) // Red color
            {
                column = 9;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S5.Elements[index].ConvertToBrush();
                    Border border = new Border()
                    {
                        BorderThickness = new Thickness(3), BorderBrush = Brushes.Black
                    };
                    Grid.SetRow(border, row);

                    Grid.SetColumn(border, column);
                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);

                    column++;
                    index++;
                }
                row++;
            }
            row    = 4 + 1;
            column = 13;
            index  = 0;
            for (int i = 0; i < 3; i++) // blue color
            {
                column = 13;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S3.Elements[index].ConvertToBrush();
                    Border border = new Border()
                    {
                        BorderThickness = new Thickness(3), BorderBrush = Brushes.Black
                    };
                    Grid.SetRow(border, row);
                    Grid.SetColumn(border, column);

                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);

                    column++;
                    index++;
                }
                row++;
            }
            row    = 8 + 1;
            column = 5;
            index  = 0;
            for (int i = 0; i < 3; i++) // green color
            {
                column = 5;
                for (int i2 = 0; i2 < 3; i2++)
                {
                    Canvas canvas = new Canvas();
                    canvas.Background = cs.S4.Elements[index].ConvertToBrush();
                    Border border = new Border()
                    {
                        BorderThickness = new Thickness(1), BorderBrush = Brushes.Black
                    };
                    Grid.SetRow(border, row);
                    Grid.SetColumn(border, column);

                    grid1.Children.Add(canvas);
                    Grid.SetRow(canvas, row);
                    Grid.SetColumn(canvas, column);

                    column++;
                    index++;
                }
                row++;
            }
        }
 public CompleteScramble(Scramble scramble, IEnumerable <ScrambleMove> moves)
 {
     Scramble = scramble;
     Moves    = moves;
 }