当前位置: 首页>>代码示例>>C#>>正文


C# Shape.CompareTo方法代码示例

本文整理汇总了C#中Shape.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Shape.CompareTo方法的具体用法?C# Shape.CompareTo怎么用?C# Shape.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shape的用法示例。


在下文中一共展示了Shape.CompareTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckPosition

 /// Method Check position - I accept Main area consist of invisible Shape elements
 public void CheckPosition(Shape elementTopBar, Shape elementMainArea)
 {
     if (elementTopBar.CompareTo(elementMainArea) == 0)
     {
         this.Update(elementTopBar, elementMainArea);
     }
     else
     {
         this.livesCount--;
         if (this.livesCount == 0)
         {
             this.State = GameState.Lose;
         }
     }
 }
开发者ID:TekerikAcademyTest,项目名称:Puzzle,代码行数:16,代码来源:GameLogic.cs

示例2: compareEllips

 private static void compareEllips(Shape obj, Shape obje)
 {
     obj.CompareTo(obje);
 }
开发者ID:JosefineRutgerson,项目名称:Objectoriented-programming,代码行数:4,代码来源:Program.cs

示例3: Main


//.........这里部分代码省略.........
                             
                    break;
                case ConsoleKey.R:
                    Shape newRectangle = CreateShape(ShapeType.Rectangle);
                    Console.WriteLine("\nStep 1. Write the length of the rectangle:\nStep 2. Press enter \nStep 3. Write the width of the rectangle: ");
                        try
                        {
                            readLengthAndWidth(out currentLength, out currentWidth);
                        }
                        catch (FormatException e)
                        {
                            Console.WriteLine("Error: " + e.Message + " Write numbers.\n");

                        }
                        catch(Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.Message);
                        }
                    newRectangle.Length = currentLength;
                    newRectangle.Width = currentWidth;
                    ViewShapeInfo(newRectangle);
                    Console.WriteLine("Press enter");
                    savedRectangle = newRectangle;          
                    Console.ReadKey();
                    break;
                case ConsoleKey.S:
                        var resizeRectangle = CreateShape(ShapeType.ResizableRectangle);// as ResizableRectangle;
                        Console.WriteLine("\nStep 1. Write the length of the rectangle:\nStep 2. Press enter \nStep 3. Write the width of the rectangle:\nStep 4. Write how many percent you wish to resize with ");
                        try
                        {
                            readLengthAndWidth(out currentLength, out currentWidth);
                        }
                        catch (FormatException e)
                        {

                            Console.WriteLine("Error: " + e.Message);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.Message);
                        }
                        resizeRectangle.Length = currentLength;
                        resizeRectangle.Width = currentWidth;
                        ViewShapeInfo(resizeRectangle);
                        try
                        {
                            int percent = Int32.Parse(Console.ReadLine());
                            IResizable r = resizeRectangle as IResizable;
                            r.resize(percent);
                            ViewShapeInfo(resizeRectangle);
                            Console.ReadKey();
                        }
                        
                        catch (FormatException e)
                        {
                            Console.WriteLine("Error: " + e.Message);

                        }
                        break;

                case ConsoleKey.C:
                        Console.WriteLine("\nIf you got 1 your Ellips is bigger than your Rectangle\nIf you got -1 your rectangle is bigger than your Ellips\nIf you got a 0 they were the same");
                        try
                        {
                            Console.WriteLine(savedEllips.CompareTo(savedRectangle));
                            Console.ReadKey();

                        }
                        catch (Exception ex)
                        {

                            Console.WriteLine("\nError: " + ex.Message + ", you need to create your Ellips and Rectangle before comparing them");
                            Console.ReadKey();
                        }
                        break;
                case ConsoleKey.J:
                        Console.WriteLine("\nIf you got 1 your Rectangle is bigger than your Ellips\nIf you got - 1 your Ellips is bigger than your Rectangle\nIf you got a 0 they were the same");
                        try
                        {                         
                            Console.WriteLine(savedRectangle.CompareTo(savedEllips));
                            Console.ReadKey();

                        }
                        catch (Exception ex)
                        {

                            Console.WriteLine("\nError: " + ex.Message + "\nYou need to create your Ellips and Rectangle before comparing them");
                            Console.ReadKey();                        }
                        Console.ReadKey();
                        break;
                case ConsoleKey.Escape:
                    start = false;
                    break;


            }


        }
     }
开发者ID:JosefineRutgerson,项目名称:Objectoriented-programming,代码行数:101,代码来源:Program.cs


注:本文中的Shape.CompareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。