Esempio n. 1
0
        static void Main()
        {
            int firstNumber;
            int secondNumber;

            Program p = new Program();
            Calculator c = new Calculator();

            // Get first numeric value.
            firstNumber = p.GetNumericValue();

            // Get second numeric value.
            secondNumber = p.GetNumericValue();

            // Use delegate method to call the Add method.
            CalculateMethod cm = new CalculateMethod(c.Add);

            //TODO:  Create an instance of the callback delegate passing
            //      in the callback method you implemented above.

            // Call the Add method stored in the delegate asynchronously.
            //TODO:  Include the instance of the callback delegate in the
            //      call below.
            IAsyncResult asyncResult = cm.BeginInvoke(firstNumber, secondNumber, null, null);

            System.Threading.Thread.Sleep(2500);

            Console.WriteLine("\nTotal value: {0}",
                p.TotalValue);

            Console.Write("\nPress any key to end.");
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main()
        {
            int totalValue = 0;
            int firstNumber;
            int secondNumber;

            Program p = new Program();
            Calculator c = new Calculator();

            // Get first numeric value.
            firstNumber = p.GetNumericValue();

            // Get second numeric value.
            secondNumber = p.GetNumericValue();

            //Create an instance of the delegate passing in
            //      the Add method of the Calculator class.
            CalculateMethod cm = new CalculateMethod(c.Add);

            // TODO: Call the CalculateMethod delegate, named "cm", asynchronously.

            // TODO: Capture the return value into the variable "totalValue" (declared above)
            //      from the asynchronous call to the CalculateMethod, named "cm".

            Console.WriteLine("\nTotal values: {0}",
                totalValue);

            Console.Write("\nPress any key to end.");
            Console.ReadLine();
        }
Esempio n. 3
0
        // This method is called with delegates for
        //      both the collection of calculate methods and the callback method.
        public void CallCalculator(CalculateMethod cm, CalculationComplete cc)
        {
            // TODO: Call the multicast CalculateMethod delegate.
            cm();

            // TODO: Call the callback method.
            cc();
        }
Esempio n. 4
0
 public static void DelegateBeginInvoke()
 {
     cm = new CalculateMethod(Calculate);
     Console.WriteLine("委托开始执行");
     cm.BeginInvoke(5, new AsyncCallback(TaskFinished), null);
     cm.BeginInvoke(7, new AsyncCallback(TaskFinished), null);
     cm.BeginInvoke(11, new AsyncCallback(TaskFinished), null);
     Thread.Sleep(2000);
     Console.WriteLine("委托执行结束");
 }
Esempio n. 5
0
 private void BeginCalculateResult()
 {
     if (InvokeRequired)
     {
         CalculateMethod aus = new CalculateMethod(BeginCalculateResult);
         Invoke(aus, null);
     }
     else
     {
         CalculateResult();
     }
 }
Esempio n. 6
0
 protected void BeginCalculateResult()
 {
     if (InvokeRequired)
     {
         CalculateMethod aus = new CalculateMethod(BeginCalculateResult);
         Invoke(aus, null);
     }
     else
     {
         CalculateResult();
     }
 }
Esempio n. 7
0
        // This method is called with delegates for
        //      both the calculate method and the callback method.
        public void CallCalculator(CalculateMethod cm, CalculationComplete cc)
        {
            // Get the input value.
            int inputInt = GetNumericValue();

            // Call the calculate method.
            // TODO: Call the CalculateMethod delegate  to call the
            //      calculate method that is stored in it passing in the
            //      value in the variable inputInt.

            // Call the callback method.
            // TODO: Call the CalculationComplete delegate to call
            //      the callback method that is stored in it.
        }
Esempio n. 8
0
        private ICalculator GetCalculator(CalculateMethod method)
        {
            switch (method)
            {
                case CalculateMethod.Add:
                    return new AddCalculator();

                case CalculateMethod.Minus:
                    return new MinusCalculator();

                default:
                    return null;
            }
        }
Esempio n. 9
0
        public decimal Calculate(CalculateMethod method, decimal firstNum, decimal secondNum)
        {
            switch (method)
            {
            case CalculateMethod.Add:
                return(firstNum + secondNum);

            case CalculateMethod.Minus:
                return(firstNum - secondNum);

            default:
                return(0);
            }
        }
Esempio n. 10
0
        static void Main()
        {
            string option = "";
            int valueInt;

            Program p = new Program();
            Calculator c = new Calculator();

            // TODO: Using the delegate you declared above for displaying
            //      a menu, create an anonymous method.  The code for the
            //      anonymous method is the code you copied in the
            //      DisplayMenu method at the previous TODO.

            while (option.ToUpper() != "X")
            {
                // TODO:  Call the anonymous method stored in the delegate.

                // Get the option from the user.
                option = Console.ReadLine();
                Console.WriteLine();

                switch (option.ToUpper())
                {
                    case "1":
                        // Get numeric value.
                        valueInt = p.GetNumericValue();

                        // Use delegate method to call calculate method.
                        CalculateMethod cm = new CalculateMethod(c.Add);
                        cm(valueInt);

                        break;

                    case "X":
                        break;

                    default:
                        Console.WriteLine("Menu option {0} is not valid.",
                            option);
                        break;
                }
            }

            Console.WriteLine("\nTotal values: {0}",
                c.TotalValues);

            Console.Write("\nPress any key to end.");
            Console.ReadLine();
        }
Esempio n. 11
0
        static void Main()
        {
            int totalValue = 0;
            int firstNumber;
            int secondNumber;

            Program p = new Program();
            Calculator c = new Calculator();

            // Get first numeric value.
            firstNumber = p.GetNumericValue();

            // Get second numeric value.
            secondNumber = p.GetNumericValue();

            // Use delegate method to call the Add method.
            CalculateMethod cm = new CalculateMethod(c.Add);

            // Call the Add method asynchronously.
            IAsyncResult asyncResult = cm.BeginInvoke(firstNumber, secondNumber, null, null);

            Console.WriteLine("\nWaiting for the task to complete.");
            //TODO:  Use the WaitOne method of the IAsyncResult instance
            //      to force the main thread to wait until the secondary thread
            //      is done executing.  Use a time out argument of 5000.
            //      If call completed on time, execute the two code lines below
            //          to display the results.
            //      If call did NOT complete on time, display a message and do not execute
            //          the two code lines below.
            bool inTimeBool = asyncResult.AsyncWaitHandle.WaitOne(5000);
            if (inTimeBool)
            {
                // Retrieve the return value from the Add method.
                totalValue = cm.EndInvoke(asyncResult);

                Console.WriteLine("\nTotal value: {0}",
                    totalValue);
            }
            else
            {
                Console.WriteLine("\n Call did NOT complete on time. No results. May need to stop application using Task Manager.");
            }

            Console.Write("\nPress any key to end.");
            Console.ReadLine();
        }
Esempio n. 12
0
        // This method is called with delegates for
        //      both the collection of calculate methods and the callback method.
        public void CallCalculator(CalculateMethod cm, CalculationComplete cc)
        {
            Console.WriteLine("Starting total is: {0}", TotalValues);

            // TODO: Code a foreach loop to loop through the multicast
            //      CalculateMethod delegate to execute one method at a
            //      time to capture the return value, which is the name of
            //      the calculate method that was called:
            //          Include the commented block of code below in the loop.
            //          Uncomment the block after inserting it into the loop.
            //          Give the reference name "m" to each instance of the
            //              delegate in the foreach loop.

                //Console.WriteLine("\nResult after {0}ing {1} is {2}.",
                //    m(), values[0], TotalValues);
                //values.RemoveAt(0);

            // Call the callback method.
            cc();
        }
Esempio n. 13
0
        static void Main()
        {
            int totalValue = 0;
            int firstNumber;
            int secondNumber;

            Program p = new Program();
            Calculator c = new Calculator();

            // Get first numeric value.
            firstNumber = p.GetNumericValue();

            // Get second numeric value.
            secondNumber = p.GetNumericValue();

            // Use delegate method to call the Add method.
            CalculateMethod cm = new CalculateMethod(c.Add);

            // Call the Add method asynchronously.
            IAsyncResult asyncResult = cm.BeginInvoke(firstNumber, secondNumber, null, null);

            //TODO:  Enclose the following code into a loop that is polling to
            //          determine when the asynchronous call is done.  After
            //          including the two lines of code below in the loop, then
            //          uncomment them.
            while (!asyncResult.IsCompleted)
            {
                System.Threading.Thread.Sleep(750);
                Console.WriteLine("\nSeeing if the asynchronous call is done.");
            }

            // Retrieve the return value from the Add method.
            totalValue = cm.EndInvoke(asyncResult);

            Console.WriteLine("\nTotal value: {0}",
                totalValue);

            Console.Write("\nPress any key to end.");
            Console.ReadLine();
        }
Esempio n. 14
0
    public static void Main(string[] args)
    {
        //实例化一个委托并为其赋值
        CalculateMethod method = Plus;
        //让用户从控制台输入两个数,赋值给x,y
        //需求:
        //若 x > y,x - y,否则 x + y
        int x = Convert.ToInt32(Console.ReadLine());
        int y = Convert.ToInt32(Console.ReadLine());

        if (x > y)
        {
            method = Minus;
        }
        else
        {
            method = Plus;
        }
        int result = method(x, y);

        Console.WriteLine(result);
    }
Esempio n. 15
0
        static void Main()
        {
            int firstNumber;
            int secondNumber;

            Program p = new Program();
            Calculator c = new Calculator();

            // Get first numeric value.
            firstNumber = p.GetNumericValue();

            // Get second numeric value.
            secondNumber = p.GetNumericValue();

            // Use delegate method to call the Add method.
            CalculateMethod cm = new CalculateMethod(c.Add);

            //Create an instance of the callback delegate passing
            //      in the callback method.
            AsyncCallback callbackMethod =
                new AsyncCallback(p.ComputationComplete);

            //Send the beginning time to the callback method.
            DateTime beginTime = DateTime.Now;

            // Call the Add method stored in the delegate asynchronously.
            // TODO: 1. Include in the asychronous call below the instance of
            //      of the callback delegate (callbackMethod) and the
            //      variable (beginTime).
            IAsyncResult asyncResult = cm.BeginInvoke(firstNumber, secondNumber, callbackMethod, beginTime);

            System.Threading.Thread.Sleep(3000);

            Console.WriteLine("\nTotal value: {0}",
                p.TotalValue);

            Console.Write("\nPress any key to end.");
            Console.ReadLine();
        }
Esempio n. 16
0
        private static void Calculate(CalculateMethod delegateMethond, string methodInfo = null)
        {
            if (!string.IsNullOrWhiteSpace(methodInfo))
            {
                Console.WriteLine(methodInfo);
            }

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    Console.Write($"f({i},{j}) = {delegateMethond(i, j)};");
                    if (j == 5)
                    {
                        Console.WriteLine();
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
            }
        }
Esempio n. 17
0
        public decimal Calculate(CalculateMethod method, decimal firstNum, decimal secondNum)
        {
            ICalculator calculator = GetCalculator(method);

            return calculator.Calculate(firstNum, secondNum);
        }
Esempio n. 18
0
		private List<List<double>> ComparerCalculateHandler()
		{
			if (sectionsData.Items.Count <= 1)
			{
				State.IsSectionEnough = false;
			}
			else { State.IsSectionEnough = true; }
			UpdateArgsState();
			UpdateSectionsDataState();

			List<double> positions = new List<double>();
			List<double> rayleighYList = new List<double>();
			List<double> iterationYList = new List<double>();
			List<double> rayleighFreq = new List<double>(1);
			List<double> iterationFreq = new List<double>(1);

			if (State.CanRun)
			{
				//run
				FullSectionsDepartor(Impeller.Sections, Impeller.InnerImpeller);
				positions = Impeller.Sections.Select(sec => sec.Position).ToList();

				try
				{
					ResultMethod = CalculateMethod.Rayleigh;
					Impeller.InnerImpeller = Checker.Rayleigh(Impeller.InnerImpeller, 9.793);
					rayleighYList = Impeller.InnerImpeller.Y;
					rayleighFreq.Add(Impeller.InnerImpeller.LegacyVibrationFrequency);
					var maxRayleighY = rayleighYList.Max();
					for (int i = 0; i < rayleighYList.Count; i++)
					{
						rayleighYList[i] /= maxRayleighY;
					}

					ResultMethod = CalculateMethod.Iteration;
					Impeller.InnerImpeller = Checker.Iteration(Impeller.InnerImpeller);
					iterationYList = Impeller.InnerImpeller.Y;
					iterationFreq.Add(Impeller.InnerImpeller.LegacyVibrationFrequency);

					UpdateArgsBindings();
				}
				catch (Exception ex)
				{
					Impeller.InnerImpeller.Comment = "计算失败\n请检测参数和截面是否有错\n可能的原因:\n*叶片参数有误;\n*计算参数有误;\n*截面参数有误;\n*存在相同位置的截面。";
					ShowStatusMsg("异常:" + ex.Message);
				}
			}
			else
			{
				CalcAbortedMessageShower();
				ShowStatusMsg("计算已中止");
			}

			List<List<double>> param = new List<List<double>>(5);
			param.Add(positions);
			param.Add(rayleighYList);
			param.Add(iterationYList);
			param.Add(rayleighFreq);
			param.Add(iterationFreq);
			return param;
		}
Esempio n. 19
0
		private string ShowResult(Impeller impeller, CalculateMethod method)
		{
			string resultString = "";
			StringBuilder yString = new StringBuilder();

			switch (method)
			{
				case CalculateMethod.Rayleigh:
					for (int i = 0; i < Impeller.InnerImpeller.Y.Count; i++)
					{
						yString
							.Append(Impeller.InnerImpeller.MSections[i].Position.ToString())
							.Append(" : ")
							.Append(Impeller.InnerImpeller.Y[i].ToString())
							.Append("\n");
					}
					resultString = "计算方法:Rayleigh法"
						+ "\n一阶固有频率:" + Impeller.InnerImpeller.LegacyVibrationFrequency.ToString() + " Hz"
						+ "\n\n振型(位置,单位m : 振幅,单位m)\n"
						+ yString.ToString();
					break;
				case CalculateMethod.Iteration:
					for (int i = 0; i < Impeller.InnerImpeller.Y.Count; i++)
					{
						yString
							.Append(Impeller.InnerImpeller.PSections[i].Position.ToString())
							.Append(" : ")
							.Append(Impeller.InnerImpeller.Y[i].ToString())
							.Append("\n");
					}
					resultString = "计算方法:振型迭代法"
						+ "\n迭代次数:" + Impeller.InnerImpeller.IterationCount
						+ "\n一阶固有频率: " + Impeller.InnerImpeller.LegacyVibrationFrequency.ToString() + " Hz"
						+ "\n\n振型(位置,单位m : 振幅,相对值)\n"
						+ yString.ToString();
					break;
				case CalculateMethod.Prohl:
					int power = 1;
					resultString = "计算方法:Prohl传递矩阵法"
						+ "\n检测次数:" + (Impeller.InnerImpeller.IterationCount + 1).ToString();
					foreach (var freq in Impeller.InnerImpeller.VibrationFrequency)
					{
						resultString += "\n" + (power++) + "阶固有频率: " + freq + " Hz";
					}
					break;
				default:
					break;
			}

			return resultString;
		}
Esempio n. 20
0
		private void ResultCanvasPainter(CalculateMethod method)
		{
			resultCanvas.Children.Clear();
			Brush fillBrush = (Brush)FindResource("ResultLineGradientBlue");
			double height = resultCanvas.ActualHeight;
			double width = resultCanvas.ActualWidth;
			double dotDiameter = width * 0.05;
			if (dotDiameter > 20) dotDiameter = 20;
			double axisGap = 18;
			int power = 0;

			Polyline yLine = new Polyline();
			yLine.Stroke = fillBrush;
			List<Ellipse> dots = new List<Ellipse>();
			List<AxisItem> xAxisItems = new List<AxisItem>();
			List<AxisItem> yAxisItems = new List<AxisItem>();

			Polyline xAxis = new Polyline();
			Polyline yAxis = new Polyline();
			xAxis.Points.Add(new Point(0, height - axisGap));
			xAxis.Points.Add(new Point(width, height - axisGap));
			xAxis.Stroke = new SolidColorBrush(Colors.Black);
			yAxis.Points.Add(new Point(axisGap, 0));
			yAxis.Points.Add(new Point(axisGap, height));
			yAxis.Stroke = new SolidColorBrush(Colors.Black);

			TextBlock yHeader = new TextBlock();
			TextBlock xAxisHeader = new TextBlock();
			xAxisHeader.FontSize = 12;
			TextBlock yAxisHeader = new TextBlock();
			yAxisHeader.FontSize = 12;
			
			Canvas.SetLeft(yHeader, width * 0.382);
			Canvas.SetLeft(yLine, axisGap);
			Canvas.SetBottom(xAxisHeader, axisGap + 3);
			Canvas.SetRight(xAxisHeader, 0);
			Canvas.SetTop(yAxisHeader, -axisGap);
			switch (method)
			{
				case CalculateMethod.Rayleigh:
					if (Impeller.InnerImpeller.Y.Count <= 0) return;
					yLine.Points = GetPointsFromY(Impeller.InnerImpeller, height - axisGap, width - axisGap);
					xAxisItems = GetAxisItemsFromDoubleList(Impeller.Sections.Select(sec => sec.Position).ToList(), AxisType.X, new Point(axisGap, height - axisGap), width - axisGap, showMin:false);
					yAxisItems = GetAxisItemsFromDoubleList(Impeller.InnerImpeller.Y, AxisType.Y, new Point(axisGap, height - axisGap), height - axisGap, showMax:false);
					yHeader.Text = "振型曲线";
					xAxisHeader.Text = "Position(m)";
					yAxisHeader.Text = "Y(m)";
					break;
				case CalculateMethod.Iteration:
					if (Impeller.InnerImpeller.Y.Count <= 0) return;
					yLine.Points = GetPointsFromY(Impeller.InnerImpeller, height - axisGap, width - axisGap);
					xAxisItems = GetAxisItemsFromDoubleList(Impeller.Sections.Select(sec => sec.Position).ToList(), AxisType.X, new Point(axisGap, height - axisGap), width - axisGap, showMin: false);
					yAxisItems = GetAxisItemsFromDoubleList(Impeller.InnerImpeller.Y, AxisType.Y, new Point(axisGap, height - axisGap), height - axisGap);
					yHeader.Text = "振型曲线";
					xAxisHeader.Text = "Position(m)";
					yAxisHeader.Text = "Y(1)";
					break;
				case CalculateMethod.Prohl:
					if (Impeller.InnerImpeller.VibrationFrequency.Count <= 0) return;
					double heightScale = (height - axisGap - dotDiameter) / (Impeller.State.CheckToOmega / (2 * Math.PI));
					List<double> freqRange = new List<double>(100);
					for (int i = 0; i <= 100; i++)
					{
						freqRange.Add(Impeller.State.CheckFromOmega / (2 * Math.PI) 
							+ i * (Impeller.State.CheckToOmega - Impeller.State.CheckFromOmega) / (2 * Math.PI * 100));
					}
					yAxisItems = GetAxisItemsFromDoubleList(freqRange, AxisType.Y, new Point(axisGap, height - axisGap), height - axisGap);
					yHeader.Text = "各阶固有频率分布";
					xAxisHeader.Text = "阶数";
					yAxisHeader.Text = "频率(Hz)";

					foreach (var freq in Impeller.InnerImpeller.VibrationFrequency)
					{
						var freqDot = new Ellipse();
						var axisItem = new AxisItem();
						double xPosition = 0;
						freqDot.Height = dotDiameter;
						freqDot.Width = dotDiameter;
						freqDot.Fill = fillBrush;
						freqDot.ToolTip = "第" + (++power) + "阶\n" + freq + " Hz";
						freqDot.MouseEnter += new MouseEventHandler(freqDot_MouseEnter);
						freqDot.MouseLeave += new MouseEventHandler(freqDot_MouseLeave);

						xPosition = axisGap + (width - axisGap - dotDiameter) * power / (Impeller.InnerImpeller.VibrationFrequency.Count + 1);
						Canvas.SetLeft(freqDot, xPosition);
						Canvas.SetBottom(freqDot, freq * heightScale + axisGap);
						xAxisItems.Add(GetAxisItemFromPoint(AxisType.X, new Point(xPosition + dotDiameter / 2, height - axisGap), power.ToString()));
						dots.Add(freqDot);
					}
					break;
				default:
					break;
			}
			resultCanvas.Children.Add(xAxis);
			resultCanvas.Children.Add(yAxis);
			resultCanvas.Children.Add(xAxisHeader);
			resultCanvas.Children.Add(yAxisHeader);
			resultCanvas.Children.Add(yHeader);
			resultCanvas.Children.Add(yLine);
			foreach (var item in xAxisItems)
			{
				resultCanvas.Children.Add(item.Label);
				resultCanvas.Children.Add(item.Mark);
			}
			foreach (var item in yAxisItems)
			{
				resultCanvas.Children.Add(item.Label);
				resultCanvas.Children.Add(item.Mark);
			}
			foreach (var dot in dots)
			{
				resultCanvas.Children.Add(dot);
			}
		}
Esempio n. 21
0
 public static int Calc(CalculateMethod method, out long timeElapsed, params int[] arr)
 {
     return(method(out timeElapsed, arr));
 }
Esempio n. 22
0
        static void Main()
        {
            string option = "";

            CalculateMethod cm = null;     // Delegate for calculation methods.

            Program p = new Program();
            Calculator c = new Calculator();

            // Declare an anonymous method.
            DisplayMenu menu = delegate
            {
                Console.WriteLine("\nCalculator for Add and Subtract");
                Console.WriteLine("\n\t1. Add");
                Console.WriteLine("\t2. Subtract");
                Console.WriteLine("\tX. Exit Calculator");
                Console.Write("\nEnter option: ");
            };

            // Declare the CalculationComplete delegate and load it with
            //      the CalculationCompleteCallback method.
            CalculationComplete cc = new CalculationComplete(p.CalculationCompleteCallback);

            while (option.ToUpper() != "X")
            {
                // Call the anonymous method.
                menu();

                // Get the option from the user.
                option = Console.ReadLine();
                Console.WriteLine();

                switch (option.ToUpper())
                {
                    case "1":

                        // Load delegate to call Add method.
                        cm += new CalculateMethod(c.Add);
                        c.values.Add(c.GetNumericValue());

                        break;

                    case "2":

                        // Load delegate to call Subtract method.
                        cm += new CalculateMethod(c.Subtract);
                        c.values.Add(c.GetNumericValue());

                        break;

                    case "X":
                        break;

                    default:
                        Console.WriteLine("Menu option {0} is not valid.",
                            option);
                        break;
                }
            }

            // Call the method in the Calculator class
            //      to pass in the two loaded delegates for the calculate
            //      methods and the callback method.  Do this ONLY if
            //      the CalculateMethod delegate has any calculate methods
            //      loaded into it.
            if (cm == null)
            {
                Console.WriteLine("\nNo calculations were requested.");
            }
            else
            {
                c.CallCalculator(cm, cc);
            }

            Console.WriteLine("\nFinal Total is: {0}",
                c.TotalValues);

            Console.Write("\nPress any key to end.");
            Console.ReadLine();
        }
Esempio n. 23
0
    void InitMapData()
    {
        int bossNum    = CalculateMethod.GetRandomValue(mapInfo.BossRange);
        int monsterNum = CalculateMethod.GetRandomValue(mapInfo.MonsterRange);
        int eventNum   = CalculateMethod.GetRandomValue(mapInfo.EventRange);
        int blockNum   = CalculateMethod.GetRandomValue(mapInfo.BlockRange);

        List <Grid> gridPicked;
        Stack       gridStack;
        Grid        thisGrid;
        Grid        nextGrid;
        List <Grid> neighbours;
        List <Grid> ends;


        UnityEngine.Random.InitState((int)Time.time);
        do
        {
            InitGridList();

            int r1 = CalculateMethod.GetRandomValue(0, rowsCount);
            int r2 = CalculateMethod.GetRandomValue(0, columnsCount);
            gridStack         = new Stack();
            gridPicked        = new List <Grid>();
            thisGrid          = gridList[r1, r2];
            thisGrid.isPicked = true;
            gridPicked.Add(thisGrid);
            gridStack.Push(thisGrid);

            for (int i = 0; i < rowsCount * columnsCount - blockNum; i++)
            {
                neighbours = new List <Grid>();
                do
                {
                    thisGrid   = gridStack.Pop() as Grid;
                    neighbours = UnpickedGridNeighbour(thisGrid);
                } while(neighbours.Count == 0);
                nextGrid = RandomGrid(neighbours);
                gridStack.Push(thisGrid);
                gridStack.Push(nextGrid);

                nextGrid.isPicked = true;
                gridPicked.Add(nextGrid);
            }
            ends = EndPoints(gridPicked);
        } while(ends.Count < bossNum);



        //这一部分直接把数据存到gridList里面即可
        List <Grid> bossPoints = SetGridType(ref ends, bossNum, GridType.Boss);

        RemoveExist(ref gridPicked, bossPoints);
        List <Grid> enterPoints = SetGridType(ref gridPicked, 1, GridType.Enter);

        enterGrid = enterPoints [0];
        RemoveExist(ref gridPicked, enterPoints);
        List <Grid> monsterPoints = SetGridType(ref gridPicked, monsterNum, GridType.Monster);

        RemoveExist(ref gridPicked, monsterPoints);
        List <Grid> eventPoints = SetGridType(ref gridPicked, eventNum, GridType.Event);

        RemoveExist(ref gridPicked, eventPoints);
        List <Grid> emptyPoints = SetGridType(ref gridPicked, gridPicked.Count, GridType.Road);
    }
Esempio n. 24
0
    Grid RandomGrid(List <Grid> gridPool)
    {
        int r = CalculateMethod.GetRandomValueForNewGrid(gridPool.Count);

        return(gridPool [r]);
    }
Esempio n. 25
0
		private void runBtn_Click(object sender, RoutedEventArgs e)
		{
			if (sectionsData.Items.Count <= 1)
			{
				State.IsSectionEnough = false;
			}
			else { State.IsSectionEnough = true; }
			UpdateArgsState();
			UpdateSectionsDataState();

			if (State.CanRun)
			{
				//run
				progressBar.Minimum = Impeller.State.CheckFromOmega;
				progressBar.Value = progressBar.Minimum;
				progressBar.Maximum = Impeller.State.CheckToOmega;
				progressBar.Visibility = System.Windows.Visibility.Visible;
				this.Cursor = Cursors.Wait;
				runBtn.IsEnabled = false;
				setToDefaultBtn.IsEnabled = false;

				resultBox.Text = "";

				FullSectionsDepartor(Impeller.Sections, Impeller.InnerImpeller);

				try
				{
					switch ((CalculateMethod)methodChoice.SelectedItem)
					{
						case CalculateMethod.Rayleigh:
							ResultMethod = CalculateMethod.Rayleigh;
							Impeller.InnerImpeller = Checker.Rayleigh(Impeller.InnerImpeller, 9.793);
							break;
						case CalculateMethod.Iteration:
							ResultMethod = CalculateMethod.Iteration;
							Impeller.InnerImpeller = Checker.Iteration(Impeller.InnerImpeller);
							break;
						case CalculateMethod.Prohl:
							ResultMethod = CalculateMethod.Prohl;
							Impeller.InnerImpeller = Checker.Prohl(Impeller.InnerImpeller, Impeller.State);
							break;
						default:
							break;
					}
					UpdateArgsBindings();
					Impeller.InnerImpeller.Comment = ShowResult(Impeller.InnerImpeller, (CalculateMethod)methodChoice.SelectedItem);
					ResultCanvasPainter((CalculateMethod)methodChoice.SelectedItem);
					ShowStatusMsg("计算已完成");
				}
				catch(Exception ex)
				{
					Impeller.InnerImpeller.Comment = "计算失败\n请检测参数和截面是否有错\n可能的原因:\n*叶片参数有误;\n*计算参数有误;\n*截面参数有误;\n*存在相同位置的截面。";
					ShowStatusMsg("异常:" + ex.Message);
				}
				resultBox.Text = Impeller.InnerImpeller.Comment;

				this.Cursor = Cursors.Arrow;
				runBtn.IsEnabled = true;
				setToDefaultBtn.IsEnabled = true;
				progressBar.Value = progressBar.Maximum;

				HideProgressBarAtDelay();
			}
			else
			{
				CalcAbortedMessageShower();
				ShowStatusMsg("计算已中止");
			}
		}
Esempio n. 26
0
 public Bank(CalculateMethod calculateMethod)
 {
     _method = calculateMethod;
 }
Esempio n. 27
0
        static void Main()
        {
            string option = "";

            // TODO:  Take note that the CalculateMethod delegate is being
            //      declared here.  It will be loaded in the TODOs below.  Its
            //      reference name is "cm".
            CalculateMethod cm;

            Program p = new Program();
            Calculator c = new Calculator();

            // Declare an anonymous method.
            DisplayMenu menu = delegate
            {
                Console.WriteLine("\nCalculator for Add and Subtract");
                Console.WriteLine("\n\t1. Add");
                Console.WriteLine("\t2. Subtract");
                Console.WriteLine("\tX. Exit Calculator");
                Console.Write("\nEnter option: ");
            };

            // TODO: Declare the CalculationComplete delegate and load it with
            //      the CalculationCompleteCallback method. Give the reference
            //      name of the delegate "cc".
            CalculationComplete cc = new CalculationComplete(p.CalculationCompleteCallback);

            while (option.ToUpper() != "X")
            {
                // Call the anonymous method.
                menu();

                // Get the option from the user.
                option = Console.ReadLine();
                Console.WriteLine();

                switch (option.ToUpper())
                {
                    case "1":

                        // Load delegate method to call Add method.
                        // TODO: Load the already declared CalculateMethod delegate (name is cm)
                        //      with the Add method in the Calculator class.
                        cm = new CalculateMethod(c.Add);

                        // TODO:  Take note that the CallCalculator method in the Calculator class is being
                        //      called here to pass in the two loaded delegates for the calculate
                        //      method and the callback method.
                        c.CallCalculator(cm, cc);

                        break;

                    case "2":

                        // Load delegate method to call Subtract method.
                        // TODO: Load the already declared CalculateMethod delegate (name is cm)
                        //      with the Subtract method in the Calculator class.
                        cm = new CalculateMethod(c.Subtract);

                        // TODO:  Take note that the CallCalculator method in the Calculator class is being
                        //      called here to pass in the two loaded delegates for the calculate
                        //      method and the callback method.
                        c.CallCalculator(cm, cc);

                        break;

                    case "X":
                        break;

                    default:
                        Console.WriteLine("Menu option {0} is not valid.",
                            option);
                        break;
                }
            }

            Console.WriteLine("\nTotal values: {0}",
                c.TotalValues);

            Console.Write("\nPress any key to end.");
            Console.ReadLine();
        }