private void strategyPatternBtn_Click(object sender, RoutedEventArgs e) { // Prepare strategies IBillingStrategy normalStrategy = new NormalStrategy(); IBillingStrategy happyHourStrategy = new HappyHourStrategy(); Customer firstCustomer = new Customer(normalStrategy); // Normal billing firstCustomer.Add(1.0, 1); // Start Happy Hour firstCustomer.Strategy = happyHourStrategy; firstCustomer.Add(1.0, 2); // New Customer Customer secondCustomer = new Customer(happyHourStrategy); secondCustomer.Add(0.8, 1); // The Customer pays firstCustomer.PrintBill(); // End Happy Hour secondCustomer.Strategy = normalStrategy; secondCustomer.Add(1.3, 2); secondCustomer.Add(2.5, 1); secondCustomer.PrintBill(); }
public void Configure(NormalStrategy strategy, Color color) { body.GetComponent <SpriteRenderer>().color = color; sight.GetComponent <SpriteRenderer>().color = color; this.strategy = strategy; strategy.Init(mover, handController, sight); typeSign.GetComponent <SpriteRenderer>().sprite = strategy.sprite; }
private void SpawnEnnemy(Vector3 position, NormalStrategy strategy, Color color) { GameObject ennemy = Instantiate(ennemyPrefab, position, Quaternion.identity); ennemy.transform.root.name = this.GetComponent <NameGenerator>().GetNextRandomName(); ennemy.GetComponentInChildren <EnnemyController>().Configure(Instantiate(strategy), color); gameController.AddPotentialWinner(ennemy.GetComponentInChildren <EnnemyController>()); }
public static IGameStrategy CreateInstance(GameStrategy strategy) { IGameStrategy gameStrategy = null; switch (strategy) { case GameStrategy.Normal: gameStrategy = new NormalStrategy(); break; case GameStrategy.Bottom: gameStrategy = new BottomStrategy(); break; case GameStrategy.Top: gameStrategy = new TopStrategy(); break; case GameStrategy.Left: gameStrategy = new LeftStrategy(); break; case GameStrategy.Right: gameStrategy = new RightStrategy(); break; case GameStrategy.LeftAndRight: gameStrategy = new LeftAndRightStrategy(); break; case GameStrategy.TopAndBottom: gameStrategy = new TopAndBottomStrategy(); break; case GameStrategy.XCenter: gameStrategy = new XCenterStrategy(); break; case GameStrategy.YCenter: gameStrategy = new YCenterStrategy(); break; } return(gameStrategy); }
public void TestMaximumIndexProblem() { MaxIndexStrategy strategy; strategy = new NormalStrategy(); int[] items = new int[] { 34, 8, 10, 3, 2, 80, 30, 33, 1 }; int final = StringProgramming.MaximumIndexProblem(items, strategy); Assert.IsTrue(final == 6); items = new int[] { 9, 2, 3, 4, 5, 6, 7, 8, 18, 0 }; final = StringProgramming.MaximumIndexProblem(items, strategy); Assert.IsTrue(final == 8); items = new int[] { 1, 2, 3, 4, 5, 6 }; final = StringProgramming.MaximumIndexProblem(items, strategy); Assert.IsTrue(final == 5); items = new int[] { 6, 5, 4, 3, 2, 1 }; final = StringProgramming.MaximumIndexProblem(items, strategy); Assert.IsTrue(final == -1); }
public void Test_Execute() { // Prepare strategies IBillingStrategy normalStrategy = new NormalStrategy(); IBillingStrategy happyHourStrategy = new HappyHourStrategy(); Customer firstCustomer = new Customer(normalStrategy); // Normal billing firstCustomer.Add(1.0, 1); // Start Happy Hour firstCustomer.Strategy = happyHourStrategy; firstCustomer.Add(1.0, 2); // New Customer Customer secondCustomer = new Customer(happyHourStrategy); secondCustomer.Add(0.8, 1); // End Happy Hour secondCustomer.Strategy = normalStrategy; secondCustomer.Add(1.3, 2); secondCustomer.Add(2.5, 1); // Check calculated bill Assert.Equal(2.0, firstCustomer.GetCurrentBill()); Assert.Equal(5.5, secondCustomer.GetCurrentBill()); // The Customers pay, clear bill firstCustomer.PrintBill(); secondCustomer.PrintBill(); // Check bill cleared Assert.Equal(0, firstCustomer.GetCurrentBill()); Assert.Equal(0, secondCustomer.GetCurrentBill()); }