static void DoOef2() { if (!ValidateCoordinate()) { return; } Console.WriteLine(); Console.Write("Enter an X coordinate: "); float x = Convert.ToSingle(Console.ReadLine()); Console.Write("Enter an Y coordinate: "); float y = Convert.ToSingle(Console.ReadLine()); Console.WriteLine(); var coord1 = new Utils.Object("First.Coordinate"); coord1.Prop("X").Set(x); coord1.Prop("Y").Set(y); Console.WriteLine("When using X and Y properties, the values of your object are "); Console.WriteLine("X: " + coord1.Prop("X").Get()); Console.WriteLine("Y: " + coord1.Prop("Y").Get()); var coord2 = new Utils.Object("First.Coordinate"); coord2.Method("Set", new Type[] { typeof(float), typeof(float) }).Invoke(new object[] { x, y }); Console.WriteLine("When using the Set method, the values of your object are "); Console.WriteLine("X: " + coord2.Prop("X").Get()); Console.WriteLine("Y: " + coord2.Prop("Y").Get()); }
static void DoOef3() { if (!ValidateCoordinate()) { return; } if (!ValidateCircle()) { return; } Console.WriteLine(); var circle = new Utils.Object("First.Circle"); Console.WriteLine("Setting the radius of your circle to 4.5 ..."); circle.Prop("Radius").Set(4.5f); Console.WriteLine("Settings the position of your circle to (3, 4) ..."); var coord = new Utils.Object("First.Coordinate"); coord.Method("Set", new Type[] { typeof(float), typeof(float) }).Invoke(new object[] { 3, 4 }); circle.Prop("Pos").Set(coord.Instance); Console.WriteLine(); Console.WriteLine("The area should be 63.61725"); Console.WriteLine("Your value is " + circle.Prop("Area").Get()); Console.WriteLine(); Console.WriteLine("The perimeter should be 28.27433"); Console.WriteLine("Your value is " + circle.Prop("Perimeter").Get()); }
static string ToString(Utils.Object coord) { string result = "("; result += coord.Prop("X").Get(); result += ", "; result += coord.Prop("Y").Get(); result += ")"; return(result); }
static void DoOef4() { if (!ValidateCoordinate()) { return; } if (!ValidateRectangle()) { return; } Console.WriteLine(); var rectangle = new Utils.Object("First.Rectangle"); Console.WriteLine("Setting the width of your rectangle to 4 ..."); rectangle.Prop("Width").Set(4f); Console.WriteLine("Setting the height of your rectnagle to 6 ..."); rectangle.Prop("Height").Set(6f); Console.WriteLine("Settings the position of your rectangle to (3, 4) ..."); var coord = new Utils.Object("First.Coordinate"); coord.Method("Set", new Type[] { typeof(float), typeof(float) }).Invoke(new object[] { 3, 4 }); rectangle.Prop("Pos").Set(coord.Instance); Console.WriteLine(); Console.WriteLine("Value\t\tExpected\tYours"); Console.WriteLine("UpperLeft\t(1, 7)\t\t" + ToString(new Utils.Object(rectangle.Prop("UpperLeft").Get()))); Console.WriteLine("UpperRight\t(5, 7)\t\t" + ToString(new Utils.Object(rectangle.Prop("UpperRight").Get()))); Console.WriteLine("LowerLeft\t(1, 1)\t\t" + ToString(new Utils.Object(rectangle.Prop("LowerLeft").Get()))); Console.WriteLine("LowerRight\t(5, 1)\t\t" + ToString(new Utils.Object(rectangle.Prop("LowerRight").Get()))); Console.WriteLine(); Console.WriteLine("Area\t\t24\t\t" + rectangle.Prop("Area").Get()); Console.WriteLine("Perimeter\t16\t\t" + rectangle.Prop("Perimeter").Get()); }
public void PointToPlayer2() { var board = new Utils.Object("First.ScoreBoard"); board.AssertMethod("PointToPlayer2", typeof(void)); board.Method("PointToPlayer2").Invoke(); Assert.That(board.Prop("Player2Score").Get(), Is.EqualTo(1), "PointToPlayer1 verhoogt het aantal punten niet met 1"); board.Method("PointToPlayer2").Invoke(); Assert.That(board.Prop("Player2Score").Get(), Is.EqualTo(2), "PointToPlayer1 verhoogt het aantal punten niet met 1"); }
public void Reset() { var board = new Utils.Object("First.ScoreBoard"); board.AssertMethod("Reset", typeof(void)); // increase scores board.Method("PointToPlayer1").Invoke(); board.Method("PointToPlayer2").Invoke(); // reset and check if all are zero board.Method("Reset").Invoke(); Assert.That(board.Prop("Player1Score")?.Get(), Is.EqualTo(0), "Reset does not reset all scores"); Assert.That(board.Prop("Player2Score")?.Get(), Is.EqualTo(0), "Reset does not reset all scores"); }
static void DoOef1() { if (!ValidateCustomer()) { return; } var customer = new Utils.Object("First.Customer"); Console.Write("Your Name: "); customer.Prop("FirstName").Set(Console.ReadLine()); Console.Write("Your Last Name: "); customer.Prop("LastName").Set(Console.ReadLine()); Console.Write("Your date of birth (dd/mm/yyyy): "); customer.Prop("DateOfBirth").Set(DateTime.Parse(Console.ReadLine())); Console.WriteLine(); Console.WriteLine("Your name is " + customer.Prop("Name").Get()); Console.WriteLine("You are " + customer.Prop("Age").Get() + " years old."); }
public void Age() { var person = new Utils.Object("First.Person"); if (person.AssertClass()) { person.AssertMethod("Age", typeof(int)); } Random gen = new Random(); for (int i = 0; i < 10; i++) { DateTime start = new DateTime(1900, 1, 1); int range = (DateTime.Today - start).Days; var myDate = start.AddDays(gen.Next(range)); person.Prop("DateOfBirth")?.Set(myDate); int expectedAge = (DateTime.Now.Year - myDate.Year) - 1; if (DateTime.Now.Month > myDate.Month) { expectedAge++; } else if (DateTime.Now.Month == myDate.Month && DateTime.Now.Day >= myDate.Day) { expectedAge++; } var calculatedAge = (int)person.Method("Age")?.Invoke(); Assert.That(calculatedAge, Is.EqualTo(expectedAge), "De berekening van de leeftijd is niet juist"); if (calculatedAge != expectedAge) { break; // no need to continue after an error } } }
static void StartScoreBoard() { if (!Utils.Object.DoesClassExist("First.ScoreBoard")) { Console.WriteLine("Er bestaat geen class 'ScoreBoard'."); return; } var board = new Utils.Object("First.ScoreBoard"); if (board.IsValid) { var menu = new Utils.Menu(); menu.AddOption('1', "Geef een punt aan Player 1", () => { board.Method("PointToPlayer1")?.Invoke(); Console.WriteLine("Player 1 heeft nu " + board.Prop("Player1Score")?.Get() + " punten."); } ); menu.AddOption('2', "Geef een punt aan Player 2", () => { board.Method("PointToPlayer2")?.Invoke(); Console.WriteLine("Player 2 heeft nu " + board.Prop("Player2Score")?.Get() + " punten."); } ); menu.AddOption('3', "Reset de scores", () => { board.Method("Reset")?.Invoke(); Console.WriteLine("Player 1 heeft nu " + board.Prop("Player1Score")?.Get() + " punten."); Console.WriteLine("Player 2 heeft nu " + board.Prop("Player2Score")?.Get() + " punten."); } ); menu.AddOption('4', "Geef de spelers een naam", () => { Console.Write("Naam voor speler 1: "); string player1 = Console.ReadLine(); board.Prop("Player1Name")?.Set(player1); Console.Write("Naam voor speler 2: "); string player2 = Console.ReadLine(); board.Prop("Player2Name")?.Set(player2); } ); menu.AddOption('5', "Toon het scorebord", () => { Console.WriteLine( board.Prop("Player1Name")?.Get() + " heeft " + board.Prop("Player1Score")?.Get() + " punten." ); Console.WriteLine( board.Prop("Player2Name")?.Get() + " heeft " + board.Prop("Player2Score")?.Get() + " punten." ); if ((bool)board.Method("IsPlayer1Winning")?.Invoke() == true) { Console.WriteLine( board.Prop("Player1Name")?.Get() + " wint." ); } else if ((bool)board.Method("IsPlayer2Winning")?.Invoke() == true) { Console.WriteLine( board.Prop("Player2Name")?.Get() + " wint." ); } else { Console.WriteLine("Gelijkspel!"); } Console.WriteLine( "Het verschil bedraagt " + board.Method("Distance")?.Invoke() + " punten." ); } ); menu.Start(); } }