コード例 #1
0
ファイル: MainForm.cs プロジェクト: karolk98/Omino
        private void generateButton_Click(object sender, System.EventArgs e)
        {
            CancelRunningTask();
            var token = _tokenSource.Token;

            if (currentSize != (int)blockSizeBox.Value)
            {
                Task task = Task.Factory.StartNew(() =>
                {
                    blockSetGenerator = new IncrementalBlockSetGenerator((int)blockSizeBox.Value, token, new Random().Next());
                }, token).ContinueWith(_ => {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    currentSize  = (int)blockSizeBox.Value;
                    board.Blocks = blockSetGenerator.GenerateBlocks((int)blockCountBox.Value);

                    var bitmap = BitmapGenerator.DrawBlockList(board.Blocks);

                    pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                    pictureBox.Image      = bitmap;
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            else
            {
                board.Blocks = blockSetGenerator.GenerateBlocks((int)blockCountBox.Value);

                var bitmap = BitmapGenerator.DrawBlockList(board.Blocks);

                pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                pictureBox.Image      = bitmap;
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: karolk98/Omino
        private void enable_this(object sender, System.EventArgs e)
        {
            this.Enabled = true;
            var bitmap = BitmapGenerator.DrawBlockList(board.Blocks);

            pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
            pictureBox.Image      = bitmap;
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: karolk98/Omino
        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (board.Blocks != null && board.Blocks.Count > 0)
            {
                this.board.Blocks.RemoveAt(board.Blocks.Count - 1);
                var bitmap = BitmapGenerator.DrawBlockList(board.Blocks);

                pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                pictureBox.Image      = bitmap;
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: karolk98/Omino
        private void fromFileButton_Click(object sender, System.EventArgs e)
        {
            CancelRunningTask();
            var token = _tokenSource.Token;

            if (currentSize != (int)blockSizeBox.Value)
            {
                blockSetGenerator = new IncrementalBlockSetGenerator((int)blockSizeBox.Value, token, new Random().Next());
                currentSize       = (int)blockSizeBox.Value;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();
            DialogResult   result         = openFileDialog.ShowDialog(); // Show the dialog.

            if (result != DialogResult.OK)
            {
                return;
            }
            string file = openFileDialog.FileName;

            try
            {
                var lines = File.ReadAllLines(file);
                for (int i = 0; i < lines.Length;)
                {
                    List <Block> blocks = new List <Block>();
                    if (!int.TryParse(lines[i], out int size))
                    {
                        return;
                    }
                    string alg     = lines[i + 1];
                    string input   = lines[i + 2];
                    var    numbers = input.Split(' ');
                    if (numbers.Length == 1)
                    {
                        if (!int.TryParse(input, out int count))
                        {
                            return;
                        }
                        blocks = new IncrementalBlockSetGenerator(size, token, new Random().Next()).GenerateBlocks(count);
                    }
                    else
                    {
                        switch (size)
                        {
                        case 5:
                            for (var index = 0; index < numbers.Length; index++)
                            {
                                var num = numbers[index];
                                if (!int.TryParse(num, out int count))
                                {
                                    return;
                                }
                                for (int j = 0; j < count; j++)
                                {
                                    blocks.Add(new PredefinedBlockSet(5).Get(index));
                                }
                            }
                            break;

                        case 6:
                            for (var index = 0; index < numbers.Length; index++)
                            {
                                var num = numbers[index];
                                if (!int.TryParse(num, out int count))
                                {
                                    return;
                                }
                                for (int j = 0; j < count; j++)
                                {
                                    blocks.Add(new PredefinedBlockSet(6).Get(index));
                                }
                            }
                            break;

                        default:
                            return;
                        }
                    }
                    board.Blocks = blocks;
                    break;
                }

                var bitmap = BitmapGenerator.DrawBlockList(board.Blocks);

                pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                pictureBox.Image      = bitmap;
            }
            catch (IOException) { }
        }