static void Main(string[] args)
 {
     var p = new Point(3, 5);
     System.Console.WriteLine("original point: " + p.ToString());
     BadSwapPoint(p);
     System.Console.WriteLine("after bad swap: " + p.ToString());
     GoodSwapPoint(ref p);
     System.Console.WriteLine("after good swap: " + p.ToString());
     //GoodSwapPoint(ref localPoint);
 }
 public void Convert_to_a_string()
 {
     var p = new Point(1, 2);
     var p2 = new Point(1, 1);
     Assert.That(p.ToString(), Is.EqualTo("(1,2)"));
     Assert.That(p2.ToString(), Is.EqualTo("(1,1)"));
 }
Example #3
0
 public static void Main3()
 {
     // Create two Point instances on the stack. 
     Point p1 = new Point(10, 10);
     Point p2 = new Point(20, 20);
     // p1 does NOT get boxed to call ToString (a virtual method). 
     Console.WriteLine(p1.ToString());// "(10, 10)" 
     // p DOES get boxed to call GetType (a non-virtual method). 
     Console.WriteLine(p1.GetType());// "Point" 
     // p1 does NOT get boxed to call CompareTo. 
     // p2 does NOT get boxed because CompareTo(Point) is called. 
     Console.WriteLine(p1.CompareTo(p2));// "-1" 
     // p1 DOES get boxed, and the reference is placed in c. 
     IComparable c = p1;
     Console.WriteLine(c.GetType());// "Point" 
     // p1 does NOT get boxed to call CompareTo. 
     // Since CompareTo is not being passed a Point variable, 
     // CompareTo(Object) is called which requires a reference to 
     // a boxed Point. 
     // c does NOT get boxed because it already refers to a boxed Point. 
     Console.WriteLine(p1.CompareTo(c));// "0" 
     // c does NOT get boxed because it already refers to a boxed Point. 
     // p2 does get boxed because CompareTo(Object) is called. 
     Console.WriteLine(c.CompareTo(p2));// "-1" 
     // c is unboxed, and fields are copied into p2. 
     p2 = (Point)c;
     // Proves that the fields got copied into p2. 
     Console.WriteLine(p2.ToString());// "(10, 10)" 
 }
Example #4
0
    static void Main()
    {
        // Point p = new Point(); // uma instância em Stack => IL initobj

        Point p = new Point(7,9); // uma instância em Stack => call Point::.ctor(int32, int32)

        Console.WriteLine(p.ToString());

        object o = p; // box

        Console.WriteLine(o.ToString());
        Console.WriteLine(o.GetHashCode());

        // ((Point) o).y = 11; // Não se pode modificar uma versão temporária unbox
        // <=>

        // ((Point) o).SetY(11);// O objecto o NÃO foi modificado

        Setter i = (Setter) o;
        i.SetY(11);

        /*
        Point p2 = (Point) o; // unbox
        p2.y = 11; // modificar o objecto em Stack
        o = p2; // o passa a referenciar um novo objecto resultante do boxing
        */

        Console.WriteLine(o.ToString());
        Console.WriteLine(o.GetHashCode());
    }
Example #5
0
    static void FindAllPaths(Point currentPoint, string path)
    {
        for (int i = 0; i < direction.GetLength(0); i++)
        {
            int newRow = currentPoint.Row + direction[i, 0];
            int newCol = currentPoint.Col + direction[i, 1];

            if (InBouds(labyrinth, newRow, newCol))
            {
                if (IsEnd(new Point(newRow, newCol)))
                {
                    Console.WriteLine("Path found: " + path);
                    PrintLabyrinth(labyrinth);
                }
                if (IsFree(labyrinth, newRow, newCol))
                {
                    labyrinth[newRow, newCol] = "X";
                    path += currentPoint.ToString();

                    FindAllPaths(new Point(newRow, newCol), path);
                    labyrinth[newRow, newCol] = "-";
                }
            }
        }
    }
Example #6
0
 public static void Main()
 {
     Point p = new Point(7, 3);
     p.Print();
     Console.WriteLine(p.ToString()); // Redefinido em Point
     Console.WriteLine(p.GetType()); // box + call
     Console.WriteLine(p.GetHashCode()); // Herdado de Object
 }
Example #7
0
    static void Main() 
    {
        Point p1 = new Point(1,2);      // создаем объект Point

        Point p2 = p1.Copy();           // создаем копию первого объекта 
       
        Point p3 = p1;                  // создаем ссылку на первый объект

        
        Say("{0}\n", Object.ReferenceEquals(p1, p2));   // если ссылки неравны
        
        Say("{0}\n", Object.Equals(p1, p2));            // если объекты равны
        
        Say("{0}\n", Object.ReferenceEquals(p1, p3));   // если ссылки равны
        
        Say("p1's value is: {0}\n", p1.ToString());     // печать объект в строчном виде: (1, 2)
    }
Example #8
0
    protected void OnPaint(object sender, PaintEventArgs e)
    {
        GraphicsUnit gUnit = GraphicsUnit.Pixel;

        Point renderingOrgPt = new Point(0, 0);
        renderingOrgPt.X = 100;
        renderingOrgPt.Y = 100;

        Graphics g = e.Graphics;

        g.PageUnit = gUnit;

        g.TranslateTransform(renderingOrgPt.X, renderingOrgPt.Y);
        g.DrawRectangle(new Pen(Color.Red, 1), 0, 0, 100, 100);

        this.Text = string.Format("PageUnit: {0}, Origin: {1}", gUnit, renderingOrgPt.ToString());
    }
Example #9
0
        public void DrawDirectEdge(Point p1, Point p2, Color c)
        {
            Console.WriteLine("DrawDirecEdge with p1 = {0}, p2 = {1}, color = {2}", p1.ToString(), p2.ToString(), c.ToString());
            //Graphics g = this.CreateGraphics();

            // стрелка
            Pen p = new Pen(c);
            //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            //g.ScaleTransform(
            p.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            p.CustomStartCap = new System.Drawing.Drawing2D.AdjustableArrowCap(8, 5, true);
            //p.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            //p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

            g.DrawLine(p, p1.X, p1.Y, p2.X, p2.Y);

            //g.DrawLine(new Pen(c), p)
            //g.DrawLine(new Pen(c), p)
        }
Example #10
0
        /// <summary>
        /// Add a monster with a random patrol. Needs the mapgenerator of the level in question
        /// </summary>
        /// <param name="monster"></param>
        /// <param name="mapGen"></param>
        private bool AddMonsterFarFromLocation(Monster monster, Point location, int level, MapGenerator mapGen)
        {
            //Offset location

            int maxLoops = 50;
            int loops = 0;

            Point toPlaceLoc = new Point(location);

            int distance = 40;

            do
            {
                toPlaceLoc = new Point(location.x + (int)Gaussian.BoxMuller(distance, 5), location.y + (int)Gaussian.BoxMuller(distance, 5));

                loops++;
                distance--;

            } while (!Game.Dungeon.AddMonster(monster, level, toPlaceLoc) && loops < maxLoops);

            if (loops == maxLoops)
            {
                LogFile.Log.LogEntryDebug("Failed to place: " + monster.Representation + " far from to: " + location + " reverting to random placement", LogDebugLevel.Medium);

                loops = 0;

                do
                {
                    toPlaceLoc = Game.Dungeon.RandomWalkablePointInLevel(level);
                    loops++;

                } while (!Game.Dungeon.AddMonster(monster, level, toPlaceLoc) && loops < maxLoops);

                LogFile.Log.LogEntryDebug("Failed to place: " + monster.Representation + " giving up", LogDebugLevel.High);
                return false;
            }

            LogFile.Log.LogEntryDebug("Item " + monster.Representation + " placed at: " + location.ToString(), LogDebugLevel.High);

            return true;
        }
Example #11
0
        /// <summary>
        /// Tries to add an item close to a location, puts it anywhere if that's not possible
        /// </summary>
        /// <param name="item"></param>
        /// <param name="level"></param>
        /// <param name="location"></param>
        private bool AddItemCloseToLocation(Item item, int level, Point location)
        {
            //Offset location

            int maxLoops = 50;
            int loops = 0;

            Point toPlaceLoc = new Point(location);

            do
            {
                toPlaceLoc = new Point(location.x + (int)Gaussian.BoxMuller(2, 2), location.y + (int)Gaussian.BoxMuller(2, 2));
                loops++;

            } while (!Game.Dungeon.AddItem(item, level, toPlaceLoc) && loops < maxLoops);

            if (loops == maxLoops)
            {
                LogFile.Log.LogEntryDebug("Failed to place: " + item.Representation + " close to: " + location + " reverting to random placement", LogDebugLevel.Medium);

                loops = 0;

                do
                {
                    toPlaceLoc = Game.Dungeon.RandomWalkablePointInLevel(level);
                    loops++;

                } while (!Game.Dungeon.AddItem(item, level, toPlaceLoc) && loops < maxLoops);

                LogFile.Log.LogEntryDebug("Failed to place: " + item.Representation + " giving up", LogDebugLevel.High);
                return false;
            }

            LogFile.Log.LogEntryDebug("Item " + item.Representation + " placed at: " + location.ToString(), LogDebugLevel.High);

            return true;
        }
Example #12
0
    private void parseTypeL()
    {
        string[] life = msg.Split(':', '#');
        string[] position = life[1].Split(',');
        string lifeTime = life[2];

        Point p = new Point(int.Parse(position[0]), int.Parse(position[1]));
        gameInstance.addLifePack(p, int.Parse(lifeTime));

        Debug.Log("Life pack appears at " + p.ToString() + ". It will be there for " + lifeTime.ToString() + " time.");
    }
Example #13
0
    private void parseTypeC()
    {
        string[] coins = msg.Split(':', '#');
        string[] position = coins[1].Split(',');
        string lifeTime = coins[2];
        int value = int.Parse(coins[3]);

        Point p = new Point(int.Parse(position[0]), int.Parse(position[1]));
        gameInstance.addCoin(p, int.Parse(lifeTime));

        Debug.Log("Coin appears at " + p.ToString() + ". It will be there for " + lifeTime.ToString() + " time. Coin value is " + value);
    }
Example #14
0
	private string PrintResultTable(ICoordinateSystem fromCoordSys, ICoordinateSystem toCoordSys, Point fromPnt, Point toPnt, Point refPnt, Point backPnt, string header)
	{
		string table = "<table style=\"border: 1px solid #000; margin: 10px;\">";
		table += "<tr><td colspan=\"2\"><h3>" + header + "</h3></td></tr>";
		table += "<tr><td width=\"130px\" valign=\"top\">Input coordsys:</td><td>" + fromCoordSys.WKT + "</td></tr>";
		table += "<tr><td valign=\"top\">Output coordsys:</td><td>" + toCoordSys.WKT + "</td></tr>";
		table += "<tr><td>Input coordinate:</td><td>" + fromPnt.ToString() + "</td></tr>";
		table += "<tr><td>Ouput coordinate:</td><td>" + toPnt.ToString() + "</td></tr>";
		table += "<tr><td>Expected coordinate:</td><td>" + refPnt.ToString() + "</td></tr>";
		table += "<tr><td>Difference:</td><td>" + (refPnt-toPnt).ToString() + "</td></tr>";
		table += "<tr><td>Reverse transform:</td><td>" + backPnt.ToString() + "</td></tr>";
		table += "<tr><td>Difference:</td><td>" + (backPnt - fromPnt).ToString() + "</td></tr>";
		table += "</table>";
		return table;
	}
Example #15
0
        public void TestRoverEncountersObstacleMovingNegatively()
        {
            var obstructionPoint = new Point { X = 2, Y = 2 };
            var planetWithObstacles = new Planet(50, new Point[] { obstructionPoint });
            var rover = new Rover(new Point { X = 3, Y = 2 }, 'W', stateFactory, planetWithObstacles);
            rover.MoveForward();

            Assert.That(rover.IsObstructed, Is.EqualTo(true));
            Assert.That(rover.Obstruction.ToString(), Is.EqualTo(obstructionPoint.ToString()));
            Assert.That(rover.GetCurrentPosition().ToString(), Is.EqualTo("3,2"));
        }
Example #16
0
 Chunk InstantiateChunk(Chunk corridorChunk, Chunk chamberChunk, double chamberProbability, Point currentPoint)
 {
     Debug.Log ("-------Instantiating Chunk!------");
     Chunk c = null;
     if (random.NextDouble() < chamberProbability) {
         c = Instantiate(chamberChunk) as Chunk;
     } else {
         c = Instantiate(corridorChunk) as Chunk;
     }
     c.name = currentPoint.ToString();
     return c;
 }
Example #17
0
 public void PointToString()
 {
     var p = new Point(3, 4);
     Assert.AreEqual("(3, 4)", p.ToString());
 }
Example #18
0
 public override void DrawEllipse(Point Center, double R)
 {
     Console.WriteLine(" : center=" + Center.ToString() + " , R=" + R);
 }
Example #19
0
        public void ToString (int px, int py, string str)
        {
            var p = new Point(px, py);

            p.ToString().Should().Be(str);
        }
Example #20
0
 public void PointToStringAndFromString()
 {
     var p = new Point(2.23f, 3.45f);
     string pointString = p.ToString();
     Assert.AreEqual(p, new Point(pointString));
     Assert.Throws<Point.InvalidNumberOfComponents>(() => new Point("0.0"));
 }
Example #21
0
 public void ToStringTest()
 {
     Point p = new Point(0, 0);
     Assert.Equal(string.Format(CultureInfo.CurrentCulture, "{{X={0},Y={1}}}", p.X, p.Y), p.ToString());
 }
Example #22
0
    static void Main(string[] args)
    {
        string[] inputs;
        inputs = Console.ReadLine().Split(' ');
        int W = int.Parse(inputs[0]); // number of columns.
        int H = int.Parse(inputs[1]); // number of rows.
        var map = new List<string[]>();
        for (int i = 0; i < H; i++)
        {
            string LINE = Console.ReadLine(); // represents a line in the grid and contains W integers. Each integer represents one room of a given type.
            map.Add(LINE.Split(' '));
        }
        int EX = int.Parse(Console.ReadLine()); // the coordinate along the X axis of the exit (not useful for this first mission, but must be read).

        //var tree = buildTree(map);

        // game loop
        while (true)
        {
            inputs = Console.ReadLine().Split(' ');
            int XI = int.Parse(inputs[0]);
            int YI = int.Parse(inputs[1]);
            string POS = inputs[2];

            var type = int.Parse(map[YI][XI]);
            var direction = nextStepOf(type, POS);

            var expectedPosition = new Point(XI, YI) + direction;
            Console.WriteLine(expectedPosition.ToString());
        }
    }
Example #23
0
 public static string GetName(Point p)
 {
     return p.ToString();
 }
Example #24
0
    /// <summary>
    /// Prints out the map data to the console
    /// </summary>
    private void _printMap()
    {
#if false
        Debug.Log("Start = " + m_startPoint.ToString());
        Debug.Log("Exit = " + m_exitPoint.ToString());
        Debug.Log("Shop = " + m_shopPoint.ToString());
        Debug.Log("Is Actually exit = " + m_worldMapData[m_exitPoint.x, m_exitPoint.y].RoomType);

        for (int i = 0; i < m_worldMaxXSize; i++)
        {
            for (int j = 0; j < m_worldMaxYSize; j++)
            {
                Point currentPoint = new Point(i, j);
                RoomData currentRoom = m_worldMapData[i, j];
                Debug.Log("Position = " + currentPoint.ToString());
                Debug.Log("Current Room: NorthDoor = " + currentRoom.IsNorthDoorActive + "| East Door = " + currentRoom.IsEastDoorActive +
                    "| South Door = " + currentRoom.IsSouthDoorActive + "| West Door = " + currentRoom.IsWestDoorActive);
            }
        } 
#endif
    }