Пример #1
0
        private void AddUnitFromWidnowContext(AddUnitWindow addUnitWindow)
        {
            var addUnitWindowViewModel =
                addUnitWindow.DataContext as AddUnitWindowViewModel;

            UnitType unitType      = addUnitWindowViewModel.SelectedUnitType;
            int      numberOfUnits = addUnitWindowViewModel.NumberOfUnits;

            switch (unitType)
            {
            case UnitType.Swordsman:
                SelectedCell.UnitImage = SelectedPlayer.SwordsmanImage;
                break;

            case UnitType.Archer:
                SelectedCell.UnitImage = SelectedPlayer.ArcherImage;
                break;

            case UnitType.Peasant:
                SelectedCell.UnitImage = SelectedPlayer.PeasantImage;
                break;

            default:
                break;
            }

            SelectedPlayer.UnitStacks.Add(new UnitStack(unitType, numberOfUnits, SelectedCell));
            SelectedPlayer.UnitStacks[SelectedPlayer.UnitStacks.Count - 1].CellIndex = GameFieldCells.IndexOf(SelectedCell);
            SelectedCell.UnitStack = SelectedPlayer.UnitStacks.Last();
        }
Пример #2
0
        private void AddUnitClick(object sender, RoutedEventArgs e)
        {
            if (SelectedCell.UnitStack != null)
            {
                if (SelectedPlayer.UnitStacks.Contains(SelectedCell.UnitStack))
                {
                    var addUnitWindow = new AddUnitWindow();

                    if (addUnitWindow.ShowDialog() == false)
                    {
                        return;
                    }

                    AddUnitFromWidnowContext(addUnitWindow);

                    var remUnit = SelectedCell.UnitStack;
                    SelectedPlayer.UnitStacks.Remove(remUnit);
                }
            }
            else
            {
                var addUnitWindow = new AddUnitWindow();

                if (addUnitWindow.ShowDialog() == false)
                {
                    return;
                }

                AddUnitFromWidnowContext(addUnitWindow);
            }
        }
Пример #3
0
        public void OnAddUnit(Object obj, EventArgs args)
        {
            // Quickly build the array of strings\
            int tempCount = MainVM.UnitEditor.NameList.Count;

            string[] tempNames = new string[tempCount];
            for (int i = 0; i < tempCount; i++)
            {
                tempNames[i] = MainVM.UnitEditor.NameList[i].ViewName;
            }

            AddUnitWindow addDlg = new AddUnitWindow(tempNames);

            // And don't forget to pass along the ValidationRules!
            //addDlg.NameRules.SetUnitList(MainVM.UnitEditor.NameList);

            bool?addRes = addDlg.ShowDialog();

            // Push results if the user hit "Okay"
            if (addRes == true)
            {
                MainVM.AddUnit(addDlg.UnitIndex, addDlg.NewUnitName);
            }
        }