Example #1
0
        public void SetWall(Wall w, int index)
        {
            if (this.WallsChanging != null)
                this.WallsChanging(this, GenericEventArgs.Create(index));

            this.Walls[index] = w;

            if (w != null)
            {
                w.UI.SetValue(Canvas.LeftProperty,
                    index >= 6 ? 390.0
                    : index >= 3 ? 320.0
                    : 250.0
                );

                double bottom;
                switch (index % 3)
                {
                    case 0:
                        bottom = 0.0;
                        break;
                    case 1:
                        bottom = 100.0;
                        break;
                    default:
                        bottom = 200.0;
                        break;
                }
                w.UI.SetValue(Canvas.BottomProperty, bottom);
            }

            if (this.WallsChanged != null)
                this.WallsChanged(this, GenericEventArgs.Create(index));
        }
        private void BuyWall(string wallName, Wall wall, int price)
        {
            if (!this.CheckMoney(price)) return;

            if (this.vm.Field.Walls.All(w => w != null))
            {
                MessageBox.Show("設置できる場所がありません。", "壁を買う");
                return;
            }

            var dialog = new TaskDialog();
            dialog.Caption = "壁を買う";
            dialog.InstructionText = wallName;
            dialog.Text = "設置場所を選択してください。";
            dialog.Cancelable = true;
            dialog.OwnerWindowHandle = new WindowInteropHelper(Window.GetWindow(this)).Handle;

            if (this.vm.Field.Walls[2] == null)
            {
                var left = new TaskDialogButton();
                left.Text = "左";
                left.Click += (_, __) =>
                {
                    for (var i = 0; i < 3; i++)
                    {
                        if (this.vm.Field.Walls[i] == null)
                        {
                            this.vm.Field.SetWall(wall, i);
                            break;
                        }
                    }
                    dialog.Close(TaskDialogResult.Ok);
                };
                dialog.Controls.Add(left);
            }

            if (this.vm.Field.Walls[5] == null)
            {
                var center = new TaskDialogButton();
                center.Text = "中央";
                center.Click += (_, __) =>
                {
                    for (var i = 3; i < 6; i++)
                    {
                        if (this.vm.Field.Walls[i] == null)
                        {
                            this.vm.Field.SetWall(wall, i);
                            break;
                        }
                    }
                    dialog.Close(TaskDialogResult.Ok);
                };
                dialog.Controls.Add(center);
            }

            if (this.vm.Field.Walls[8] == null)
            {
                var right = new TaskDialogButton();
                right.Text = "右";
                right.Click += (_, __) =>
                {
                    for (var i = 6; i < 9; i++)
                    {
                        if (this.vm.Field.Walls[i] == null)
                        {
                            this.vm.Field.SetWall(wall, i);
                            break;
                        }
                    }
                    dialog.Close(TaskDialogResult.Ok);
                };
                dialog.Controls.Add(right);
            }

            if (dialog.Show() == TaskDialogResult.Ok)
                this.vm.Field.Money -= price;
        }