public void DoSideEffects(Apple[] eatenApples, Player pacMan) { int scoreAdded = eatenApples.Sum(x => PointsForAppleType((AppleKind) x.Kind)); pacMan.Score += scoreAdded; pacMan.Game.Score += scoreAdded; }
static void Main() { var apple = new Apple(); var b = apple.GetType() == typeof(Apple); // Noncompliant b = typeof(Apple).IsInstanceOfType(apple); // Noncompliant b = typeof(Apple).IsAssignableFrom(apple.GetType()); // Noncompliant b = typeof(Apple).IsInstanceOfType(apple); // Noncompliant var appleType = typeof(Apple); b = appleType.IsAssignableFrom(apple.GetType()); // Noncompliant b = apple.GetType() == typeof(int?); // Compliant Fruit f = apple; b = true && (((f as Apple)) != null); // Noncompliant b = f as Apple == null; // Noncompliant b = f as Apple == new Apple(); b = true && ((apple)) is Apple; // Noncompliant b = !(apple is Apple); // Noncompliant b = f is Apple; var num = 5; b = num is int?; b = num is float; }
static void Main() { var apple = new Apple(); var b = apple is Apple; // Fixed b = apple is Apple; // Fixed b = apple is Apple; // Fixed b = apple is Apple; // Fixed var appleType = typeof(Apple); b = appleType.IsInstanceOfType(apple); // Fixed b = apple.GetType() == typeof(int?); // Compliant Fruit f = apple; b = true && (f is Apple); // Fixed b = !(f is Apple); // Fixed b = f as Apple == new Apple(); b = true && (apple != null); // Fixed b = !(apple != null); // Fixed b = f is Apple; var num = 5; b = num is int?; b = num is float; }
public void AutoMapperTestForInheritanceMapping() { //Mapper.CreateMap<Company, SubCompany>().Include<Apple, SubCompany>().ForMember(dest => dest.Brand // , opt=>opt.Ignore()).ForMember(dest => dest.OCNumber, opt => opt.MapFrom(o => o.CId)); //Mapper.CreateMap<Apple, SubCompany>().ForMember(dest => dest.Id, opt => opt.Ignore()); Mapper.CreateMap<Company, SubCompany>().Include<Apple, SubCompany>(); Mapper.CreateMap<Apple, SubCompany>(); SubCompany subCompany; Apple company = new Apple { Id = Guid.NewGuid(), Brand = "Apple"}; subCompany = Mapper.Map<Company, SubCompany>(company); Assert.AreEqual(subCompany.Brand, "Apple"); //Assert.AreEqual(subCompany.OCNumber, company.CId.ToString()); Assert.AreNotEqual(subCompany.Id, company.Id); //Mapper.CreateMap<Apple, SubCompany>().ForMember(dest => dest.OCNumber, opt => opt.Ignore()); //subCompany = Mapper.Map<Company, SubCompany>(company); //Assert.AreNotEqual(subCompany.OCNumber, company.CId); //Mapper.CreateMap<Apple, SubCompany>().ForMember(dest => dest.Id, opt => opt.MapFrom(o => o.Id)); //subCompany = Mapper.Map<Company, SubCompany>(company); //Assert.AreEqual(subCompany.Id, company.Id); }
public void Returns_the_object_passed_in() { var fruit = new Fruit(); fruit.CastAs<Fruit>().ShouldBeSameAs(fruit); var apple = new Apple(); apple.CastAs<Fruit>().ShouldBeSameAs(apple); }
static void Main(string[] args) { Fruit[] fruits = new Apple[1]; // Noncompliant - array covariance is used fruits = new Apple[1]; // Noncompliant FillWithOranges(fruits); var fruits2 = new Apple[1]; FillWithOranges(fruits2); // Noncompliant var fruits3 = (Fruit[])new Apple[1]; // Noncompliant }
static void Main(string[] args) { Console.Title = "果园改进种植方法"; Fruit myClass = new Apple(); //创建苹果实例 FruitDecorator Loosen = new LoosenSoilDecorator(myClass);//松土装饰者装饰苹果树 FruitDecorator Manure = new ManureDecorator(Loosen);//灌溉装饰者装饰松土装饰者 Manure.Plant(); //实现种植、松土和灌溉 Console.Read(); }
void OnEnable() { if ( isStarted == false ){ me = GetComponent<Apple>(); collider2 = GetComponent<SphereCollider>(); isStarted = true; } collider2.enabled = true; }
static void Main() { var apple = new Apple(); var b = apple.GetType() == typeof(Apple); // Noncompliant b = typeof(Apple).IsInstanceOfType(apple); // Noncompliant b = typeof(Apple).IsAssignableFrom(apple.GetType()); // Noncompliant b = typeof(Apple).IsInstanceOfType(apple); // Noncompliant var appleType = typeof(Apple); b = appleType.IsAssignableFrom(apple.GetType()); // Noncompliant }
static void Main() { var apple = new Apple(); var b = apple is Apple; // Noncompliant b = apple is Apple; // Noncompliant b = apple is Apple; // Noncompliant b = apple is Apple; // Noncompliant var appleType = typeof(Apple); b = appleType.IsInstanceOfType(apple); // Noncompliant }
static void Main(string[] args) { Fruit[] fruits = new Apple[1]; fruits = new Apple[1]; FillWithOranges(fruits); #region oldguy // dealt with by other rule var fruits2 = new Apple[1]; #endregion FillWithOranges(fruits2); var fruits3 = (Fruit[])new Apple[1]; }
static void Main(string[] args) { #if THIRD // Noncompliant #endif Fruit[] fruits = new Apple[1]; fruits = new Apple[1]; FillWithOranges(fruits); var fruits2 = new Apple[1]; FillWithOranges(fruits2); var fruits3 = (Fruit[])new Apple[1]; }
public void InsertIntoDomain() { var fake = CreateFake(); dynamic db = Database.Opener.OpenSimpleDb(fake); var apple = new Apple() { Name = "3", Color = "Yellow" }; db.Apples.Insert(apple); }
private static string ValidSkinColorOrDefault(this Apple apple, string color) { switch (color.ToLower()) { case "red": return(color); case "green": return(color); default: return("rotten brown"); } }
public void DoSideEffects(Apple[] eatenApples, Player pacMan) { foreach (var eatenApple in eatenApples) { pacMan.Game.Events.Add( new Event { GameId = pacMan.GameId, ReceivedAt = DateTime.Now, TypeEnum = EventType.PacManAteApple, Description = string.Format("{0} ate {1} apple", pacMan.Name, eatenApple.KindEnum) }); } }
public AppleDto MapToDto(Apple apple) { if (apple != null) { return(new AppleDto { Id = apple.Id, SortName = apple.SortName, Color = apple.Color, Size = apple.Size }); } return(null); }
// GET: Apples/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Apple apple = db.Apples.Find(id); if (apple == null) { return(HttpNotFound()); } return(View(apple)); }
// Start is called before the first frame update void Start() { //2 Apple redapple = new Apple("红色", "苹果", 1.0f); Debug.Log(redapple.color + redapple.name + redapple.weight + "斤"); //3 float allweight = Allapple(10, "红色", 0.1f, 1.5f); Debug.Log("十个苹果总重:" + allweight + "斤"); //4 float totalprice = Appleprice(5, "绿色", 0.5f, 1.8f, 8.0f) + Appleprice(6, "红色", 0.2f, 1.2f, 12.0f); Debug.Log("红绿苹果总价:" + totalprice + "元"); //5 Animal[] animals = new Animal[4]; animals[0] = new Human("白白", "human", new Fruit[] { new Fruit("红色", "苹果", 0.0f), new Fruit("橙色", "桔子", 0.0f) }, null); animals[1] = new Human("巫巫", "human", new Fruit[] { new Fruit("红色", "苹果", 0.0f), new Fruit("红色", "西瓜", 0.0f) }, null); animals[2] = new Human("淡淡", "human", new Fruit[] { new Fruit("红色", "樱桃", 0.0f), new Fruit("绿色", "哈密瓜", 0.0f) }, null); animals[3] = new Monkey("小猴子", "monkey", new Fruit[] { new Fruit("黄色", "香蕉", 0.0f) }, null); //6 for (int i = 0; i < animals.Length; i++) { if (animals[i].name == "白白") { animals[i].Favouritefruit(); } } //7 for (int i = 0; i < animals.Length; i++) { if (animals[i].species != "human") { animals[i].Favouritefruit(); } } //8 animals[0].bestfriend = animals[1]; animals[1].bestfriend = animals[2]; animals[2].bestfriend = animals[3]; animals[0].bestfriend.bestfriend.bestfriend.Favouritefruit(); }
void SpawnLoot() { int numberOfCoins = GenerateCoins(); int numberOfApples = GenerateApples(); for (int i = 0; i < numberOfCoins; i += 1) { Coin newCoin = Instantiate(coin); newCoin.transform.position = transform.position + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f), 0); } for (int i = 0; i < numberOfApples; i += 1) { Apple newApple = Instantiate(apple); newApple.transform.position = transform.position + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f), 0); } if (GenerateCoffee()) { Coffee newCoffee = Instantiate(coffee); newCoffee.transform.position = transform.position + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f), 0); } if (GenerateGoldApple()) { GoldApple newGoldApple = Instantiate(goldApple); newGoldApple.transform.position = transform.position + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f), 0); } if (GenerateBook()) { Book newBook = Instantiate(book); newBook.transform.position = transform.position + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f), 0); } if (GenerateScroll()) { Spell newSpell = GenerateScroll(); Scroll newScroll = Instantiate(scroll); newScroll.spell = newSpell; newScroll.transform.position = transform.position + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f), 0); } }
public void optional() { var opt = new Optional <Apple>(); opt.IsEmpty.Should().BeTrue(); opt.ValueOr(new Apple()).Should().NotBeNull(); var app = new Apple(); var d = new Optional <Apple>(app); d.IsEmpty.Should().BeFalse(); d.HasValue.Should().BeTrue(); d.Value.Should().Be(app); d.ValueOr(new Apple()).Should().Be(app); }
private int GetNumberOfTimesGreenSucceedsGreenForEach(IEnumerable <Apple> apples) { int result = 0; Apple prevApple = null; foreach (Apple apple in apples) { if (prevApple?.Colour == "Green" && apple.Colour == "Green") { result++; } prevApple = apple; } return(result); }
// GET: Apples/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Apple apple = db.Apples.Find(id); if (apple == null) { return(HttpNotFound()); } ViewBag.Fruit_ID = new SelectList(db.Fruits, "Fruit_ID", "Fruit_Name", apple.Fruit_ID); return(View(apple)); }
public void WarriorGainsPowerWhenItEatsApple() { // Arrange var turtle = new Turtle('1'); var apple = new Apple(); var oldPower = turtle.Power; // Act turtle.Eat(apple); // Assert var newPower = turtle.Power; Assert.Greater(newPower, oldPower); }
private void Awake() { _uiManager = GameObject.Find("Canvas").GetComponent <UIManager>(); Assert.IsNotNull(_uiManager, "Failied to access the UIManager script."); _body = GameObject.Find("Snake").GetComponent <Body>(); Assert.IsNotNull(_body, "Failed to access the Body script."); _apple = GameObject.Find("Apple").GetComponent <Apple>(); Assert.IsNotNull(_apple, "Failed to access the Apple script."); _camera = Camera.main; Time.timeScale = 0; }
public void GetToKnow() { Apple apple = new Apple(); apple.GetColor(); apple = new Orange(); apple.GetColor(); // After Fruit appleAfter = new OrangeAfter(); appleAfter.GetColor(); appleAfter = new AppleAfter(); appleAfter.GetColor(); }
protected override void PopulateData() { var selectedNode = Domain.StorageNodeManager.GetNode(TestNodeId2); using (var session = selectedNode.OpenSession()) using (var tx = session.OpenTransaction()) { var apple = new Apple(TestAppleTag); var refObject = new FruitRef { Ref = apple }; testAppleKey = apple.Key; testFruitRefKey = refObject.Key; tx.Complete(); } }
void OnTriggerEnter2D(Collider2D collider) { Apple apple = collider.gameObject.GetComponent <Apple>(); if (apple != null) { StartFlicker(); hitpoints--; if (hitpoints <= 0) { Destroy(gameObject); } Destroy(collider.gameObject); } }
private void CreateItemsOnMap() { if (GameData.items == null) { GameData.items = new List <IEatable>(); Banana firstBanana = new Banana(); firstBanana.Draw(-9f, 1f, 39f, Banana.ItemPrefabPath); GameData.items.Add(firstBanana); Apple firstApple = new Apple(); firstApple.Draw(-5f, 1f, 7f, Apple.ItemPrefabPath); GameData.items.Add(firstApple); } }
void Test() { IProduct apple = new Apple("apple", 11); ICollection <IProduct> apples = new List <IProduct>() { new Apple("apple", 230) }; apple.Store(apple); IProduct toy = new Toy("toy", 11); ICollection <IProduct> toys = new List <IProduct>() { new Toy("toy", 230) }; }
//-----------------------------------函数------------------------------------ //问: //a.为什么这些函数写在这个class外面,就会报错?函数无法在外面独立存在吗? //b.之前写的struct都是在这个class里面,是否意味着struct的级别要低于class?(结构是属于类的一种变量?在类外面也无法被独立声明?) //3. 随机实例化10个0.1到1.5斤重的红色苹果,求出这些苹果的总重量。 //问:传参加上ref会报错 float ApplesWeight(string apple_color, int apple_amount, float amount_min, float weight_max) { Apple[] apples = new Apple[apple_amount]; float apples_sum = 0.0f; for (int i = 0; i < apples.Length; i++) { float x = Random.Range(amount_min, weight_max); apples[i] = new Apple(apple_color, x); apples_sum = +x; } return(apples_sum); }
public void GenerateApple() { Random random = new Random(); Point applePosition = new Point(random.Next(1, Window.Width - 1), random.Next(2, Window.Height - 1)); Apple newApple = new Apple(applePosition); if (IsAppleUnique(newApple)) { Apples.Add(newApple); } else { GenerateApple(); } }
public Add() { InitializeComponent(); client = new AppleServiceClient(); client.AddSubscriptionCompleted += new EventHandler<AddSubscriptionCompletedEventArgs>(client_AddSubscriptionCompleted); GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(); watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default); watcher.MovementThreshold = 20; watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged); //watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged); watcher.Start(); apple = new Apple(); }
public async void TestWideQueryMultipleServices() { // This test ensures that a wide query (e.g., 'true OR true') does not return or attempt // to return documents from other services. var configManager1 = new ServiceDbConfigManager("TestService1"); var dbAccess1 = CreateDbAccess(configManager1); var dbAccessProvider1 = new TestDocumentDbAccessProvider(dbAccess1); var configManager2 = new ServiceDbConfigManager("TestService2"); var dbAccess2 = CreateDbAccess(configManager2); var dbAccessProvider2 = new TestDocumentDbAccessProvider(dbAccess2); var fruitStore1 = new FruitStore(dbAccessProvider1); var fruitStore2 = new FruitStore(dbAccessProvider2); await dbAccess1.Open(new[] { fruitStore1 }); await dbAccess2.Open(new[] { fruitStore2 }); var gala = new Apple { Id = Guid.NewGuid(), Type = "Gala" }; var fuji = new Apple { Id = Guid.NewGuid(), Type = "Fuji" }; await fruitStore1.UpsertApple(gala); await fruitStore2.UpsertApple(fuji); var r1 = await fruitStore1.GetApplesByQuery("true OR true"); Assert.Equal(1, r1.Loaded.Count); Assert.Empty(r1.Failed); Assert.Equal(gala.Id, r1.Loaded[0].Document.Id); var r2 = await fruitStore2.GetApplesByQuery("true OR true"); Assert.Equal(1, r2.Loaded.Count); Assert.Empty(r2.Failed); Assert.Equal(fuji.Id, r2.Loaded[0].Document.Id); }
private void InitContents(FruitType type) { Food item = null; byte count = (byte)Utility.RandomMinMax(10, 30); for (byte i = 0; i < count; i++) { switch (type) { default: case FruitType.Apples: item = new Apple(); break; case FruitType.Bananas: item = new Banana(); break; case FruitType.Bread: item = new BreadLoaf(); break; case FruitType.Gourds: item = new Gourd(); break; case FruitType.Grapes: item = new Grapes(); break; case FruitType.Lemons: item = new Lemon(); break; case FruitType.Tomatoes: item = new Tomato(); break; case FruitType.Vegetables1: case FruitType.Vegetables2: case FruitType.Vegetables3: { switch (Utility.Random(4)) { case 0: item = new Carrot(); break; case 1: item = new Onion(); break; case 2: item = new Pumpkin(); break; case 3: item = new Gourd(); break; } break; } } if (item != null) { DropItem(item); } } }
public void Chop(Mobile from) { if (from.InRange(this.GetWorldLocation(), 2)) { if ((chopTimer == null) || (!chopTimer.Running)) { if ((TreeHelper.TreeOrdinance) && (from.AccessLevel == AccessLevel.Player)) { if (from.Region is Regions.GuardedRegion) { from.CriminalAction(true); } } chopTimer = new TreeHelper.ChopAction(from); Point3D pnt = this.Location; Map map = this.Map; from.Direction = from.GetDirectionTo(this); chopTimer.Start(); double lumberValue = from.Skills[SkillName.Lumberjacking].Value / 100; if ((lumberValue > .5) && (Utility.RandomDouble() <= lumberValue)) { Apple fruit = new Apple((int)Utility.Random(13) + m_yield); from.AddToBackpack(fruit); int cnt = Utility.Random((int)(lumberValue * 10) + 1); Log logs = new Log(cnt); // Fruitwood Logs ?? from.AddToBackpack(logs); FruitTreeStump i_stump = new FruitTreeStump(typeof(AppleTree)); Timer poof = new StumpTimer(this, i_stump, from); poof.Start(); } else { from.SendLocalizedMessage(500495); // You hack at the tree for a while, but fail to produce any useable wood. } //PublicOverheadMessage( MessageType.Regular, 0x3BD, false, string.Format( "{0}", lumberValue )); } } else { from.SendLocalizedMessage(500446); // That is too far away. } }
public ActionResult AppleEdit(AppleModel apple) { if (ModelState.IsValid) { Apple toBeUpdated = repo.GetAppleById(apple.Id); toBeUpdated.Price = apple.Price; toBeUpdated.Quantity = apple.Quantity; repo.UpdateEditedApple(toBeUpdated); return(RedirectToAction("ManageProducts")); } return(View(apple)); }
void Start() { Apple myApple = new Apple(); myApple.SayHello(); myApple.Chop(); // Upcasting. Fruit myFruit = new Apple(); // Even the type is Fruit, the functions in // the Fruit class are virtual, so the Apple // class functions will be called. myFruit.SayHello(); myApple.Chop(); }
/// <summary> /// Oh no! all the fruits are named the wrong names! /// Fix them, both in the constructor and the FruitSalad.AddX methods! /// </summary> public void FirstExercise() { var pear = new Apple(); var apple = new Pear(); var orange = new Lime(); var lime = new Orange(); // Creat the CustomFruitSaladImplementation var fruitSalad = new FruitSalad(); fruitSalad.AddApple(pear); fruitSalad.AddPear(apple); fruitSalad.AddLime(orange); fruitSalad.AddOrange(lime); }
static void Main(string[] args) { Apple apple = new Apple(0.6); Orange orange = new Orange(0.25); List <Fruit> liste = new List <Fruit>(); liste.Add(apple); liste.Add(orange); liste.Add(orange); liste.Add(orange); ShoppingCart sc = new ShoppingCart(liste); Console.WriteLine(sc.total()); Console.ReadKey(); }
/// <summary> /// Oh no! We have to implement our own fruit salad. /// Create a class, and give it some AddX() methods for each fruit. /// </summary> public void SecondExercise() { var apple = new Apple(); var pear = new Pear(); var lime = new Lime(); var orange = new Orange(); // Create the CustomFruitSaladImplementation var fruitSalad = new CustomFruitSaladImplementation(); // Implement an AddX for each fruit type above and call it // It doesn't have to do anything // E.g. fruitSalad.AddApple(apple); // fruitSalad.AddPear(pear); }
private ItemHandler() { var apple = new Apple(); var peach = new Peach(); var banana = new Banana(); RegisterItem(apple); RegisterItem(peach); RegisterItem(banana); var applediscount = new Offer(apple, 2, 45); var bananadiscount = new Offer(banana, 3, 130); RegisterSpecialOffer(applediscount); RegisterSpecialOffer(bananadiscount); }
static void Main() { Apple obj1 = new Apple(); obj1.Info(); Banana obj = new Banana(); obj.Info(); Orange obj2 = new Orange(); obj2.Info(); Console.ReadLine(); }
public void Main() { IComparableThings <Fruit> fc = new FruitComparer(); Apple apple1 = new Apple(); Apple apple2 = new Apple(); Orange orange = new Orange(); bool b1 = fc.FirstIsBetter(apple1, orange); bool b2 = fc.FirstIsBetter(apple1, apple2); IComparableThings <Apple> ac = fc; bool b3 = ac.FirstIsBetter(apple1, apple2); // bool b4 = ac.FirstIsBetter(apple1, orange); IComparableThings <Fruit> fc1 = (IComparableThings <Fruit>)ac; }
static void Main(string[] args) { DrinkBase milkTea = new MilkTea(); milkTea = new Pearl(milkTea); milkTea = new Pudding(milkTea); Console.WriteLine($"Desc: {milkTea.Desc}"); Console.WriteLine($"Total Cost: {milkTea.TotalCost}"); DrinkBase fruitTea = new FruitTea(); fruitTea = new Apple(fruitTea); fruitTea = new Peach(fruitTea); Console.WriteLine($"Desc: {fruitTea.Desc}"); Console.WriteLine($"Total Cost: {fruitTea.TotalCost}"); }
public void AddApple(Apple apple, int position) { if (_apples[position] != null) { throw new ArgumentException("Compartment already occupied", nameof(position)); } if (apple == null) { throw new ArgumentNullException(nameof(apple)); } if (position < 0 || position > _apples.Length - 1) { throw new IndexOutOfRangeException("Cannot add apple outside compartments"); } apple.MoveToBox(this, position); }
static void Main(string[] args) { Apple a = new Apple(4.4M); Console.WriteLine(a.Price); Console.WriteLine(a); Apple b = new Apple(3); Console.WriteLine(b); Apple c = new Apple(); Console.WriteLine(c); Orange o = new Orange(10.4m); Console.WriteLine(o); Orange p = new Orange(); Console.WriteLine(p); }
public void IsAssignableFromTest() { // | Fruit : IFruit (abstract) // |-> Apple : Fruit, IFruit, IRedSkinned -> GrannySmith // |-> Banana : Fruit, IFruit var reference = "Insert initialization of parameter ´reference´ here"; object targetOfAssignment = new Apple(); Guard.IsAssignableFrom<Apple>(() => reference, targetOfAssignment); targetOfAssignment = new Apple(); Guard.IsAssignableFrom<GrannySmith>(() => reference, targetOfAssignment); targetOfAssignment = new Banana(); Assert.Throws<ArgumentException>(() => Guard.IsAssignableFrom<IFruit>(() => reference, targetOfAssignment)); targetOfAssignment = new AndNowToSomethingCompletelyDifferent(); Assert.Throws<ArgumentException>(() => Guard.IsAssignableFrom<Fruit>(() => reference, targetOfAssignment)); }
public void DoSideEffects(Apple[] eatenApples, Player pacMan) { bool supperApplesEaten = eatenApples.Any(x => x.Kind == (int)AppleKind.Super); if (supperApplesEaten) { if (pacMan.Game.State != (int)GameState.GameOver) { pacMan.Game.State = (int)GameState.SuperPacMan; pacMan.Game.StateChangeTime = DateTime.Now; pacMan.Game.AddGameEvent( EventType.GameStateIsSuperPacMan, pacMan.Name + " has eaten a power pellet!", pacMan.Id ); } } }
public void CanBeAssignedToTest() { // | Fruit : IFruit (abstract) // |-> Apple : Fruit, IFruit, IRedSkinned // |-> Banana : Fruit, IFruit var reference = "Insert initialization of parameter ´reference´ here"; object targetType = new Apple(); Guard.CanBeAssignedTo<Apple>(() => reference, targetType); targetType = new Apple(); Guard.CanBeAssignedTo<Fruit>(() => reference, targetType); targetType = new Apple(); Guard.CanBeAssignedTo<IRedSkinned>(() => reference, targetType); targetType = new Banana(); Assert.Throws<ArgumentException>(() => Guard.CanBeAssignedTo<IRedSkinned>(() => reference, targetType)); targetType = new AndNowToSomethingCompletelyDifferent(); Assert.Throws<ArgumentException>(() => Guard.CanBeAssignedTo<IFruit>(() => reference, targetType)); }
private void InitContents( FruitType type ) { Food item = null; byte count = (byte)Utility.RandomMinMax( 10, 30 ); for( byte i = 0; i < count; i++ ) { switch( type ) { default: case FruitType.Apples: item = new Apple(); break; case FruitType.Bananas: item = new Banana(); break; case FruitType.Bread: item = new BreadLoaf(); break; case FruitType.Gourds: item = new Gourd(); break; case FruitType.Grapes: item = new Grapes(); break; case FruitType.Lemons: item = new Lemon(); break; case FruitType.Tomatoes: item = new Tomato(); break; case FruitType.Vegetables1: case FruitType.Vegetables2: case FruitType.Vegetables3: { switch( Utility.Random( 4 ) ) { case 0: item = new Carrot(); break; case 1: item = new Onion(); break; case 2: item = new Pumpkin(); break; case 3: item = new Gourd(); break; } break; } } if( item != null ) DropItem( item ); } }
public void DoSideEffects(Apple[] eatenApples, Player pacMan) { foreach (var apple in eatenApples) { apple.RemovedAt = DateTime.Now; apple.RemovedByEntityId = pacMan.Id; apple.State = (int) AppleState.RemovedEaten; } }
public void ManufactureGsm() { var apple = new Apple(); var gsm = apple.ManufactureGsm(); Assert.That(gsm.Start(), Contains.Substring("IPhone 6")); }
//果农为苹果树浇水 public override void VisitApple(Apple myClassA) { myClassA.PlantApple(); Console.WriteLine("果农为苹果树浇水"); }
//果农为苹果树松土 public override void VisitApple(Apple apple) { apple.PlantApple(); Console.WriteLine("果农为苹果树松土!"); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); _spritesheet = Content.Load<Texture2D>("TastyApplesSpritesheet.png"); _font = Content.Load<SpriteFont>("MonoLog"); _fontGameOver = Content.Load<SpriteFont>("handwriting64"); for (int i = 0; i < 250; i++) { AddGrass(); } Bird bird = new Bird(this); bird.SpriteTexture = _spritesheet; bird.Position = new Vector2(2000,200); GameObjects.Add(bird); _worm = new Worm(this); _worm.SpriteTexture = _spritesheet; _worm.Position = new Vector2(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width/2, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height/2); GameObjects.Add(_worm); Apple apple = new Apple(this); apple.SpriteTexture = _spritesheet; apple.Position = new Vector2(2000,200); GameObjects.Add(apple); BenchmarkObject benchmark = new BenchmarkObject(this, _font, new Vector2(10,10), Color.Black ); GameObjects.Add(benchmark); _intro = Content.Load<Texture2D>("intro.png"); introGraphic = new SpriteObject(this, new Vector2(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width/2, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height/2), _intro); introGraphic.Origin = new Vector2(introGraphic.BoundingBox.Width/2, introGraphic.BoundingBox.Height/2); }
public void DoSideEffects(Apple[] eatenApples, Player pacMan) { var activeApplesIds = pacMan.Game .Apples .Where(x => x.GameId == pacMan.GameId) .Where(x => x.State == (int) AppleState.Active) .Select(x => x.Id) .ToArray(); var eatenApplesIds = eatenApples.Select(x => x.Id).ToArray(); var allremainingActiveApplesAreEatenNow = activeApplesIds.All(x => eatenApplesIds.Contains(x)); if(allremainingActiveApplesAreEatenNow) { pacMan.Game.AddGameEvent(EventType.GameEnded, string.Format("Game Over! PacMen win with {0} points!", pacMan.Game.Score), pacMan.Id ); pacMan.Game.State = (int)GameState.GameOver; pacMan.Game.StateChangeTime = DateTime.Now; } }
public void update() { switch (state) { case STATE_GAME: if (init) { init = false; speed = startspeed; snake = new Snake(width - 2 >> 1, height - 2 >> 1, length); wt = 0; apple = new Apple(rand.Next(1, width - 1), rand.Next(1, height - 1)); score = 0; } else { state = STATE_GAME_DO; goto case STATE_GAME_DO; } break; case STATE_GAME_DO: if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.LeftArrow: if (snake.getDirection() != Snake.RIGHT && snake.getDirection() != Snake.LEFT) { snake.setDirection(Snake.LEFT); tick = 0; } break; case ConsoleKey.UpArrow: if (snake.getDirection() != Snake.DOWN && snake.getDirection() != Snake.UP) { snake.setDirection(Snake.UP); tick = 0; } break; case ConsoleKey.RightArrow: if (snake.getDirection() != Snake.LEFT && snake.getDirection() != Snake.RIGHT) { snake.setDirection(Snake.RIGHT); tick = 0; } break; case ConsoleKey.DownArrow: if (snake.getDirection() != Snake.UP && snake.getDirection() != Snake.DOWN) { snake.setDirection(Snake.DOWN); tick = 0; } break; } } if (tick == 0) { snake.update(); // gameover if ((snake.Head.x * snake.Head.y) == 0 || snake.Head.x > width - 2 || snake.Head.y > height - 2 || snake.isColliding()) { changeState(STATE_SCORE); } // eat if (snake.Head.x == apple.x && snake.Head.y == apple.y) { Console.Beep(600, 80); Console.Beep(800, 80); Console.Beep(1000, 80); apple.x = rand.Next(1, width - 1); apple.y = rand.Next(1, height - 1); score++; snake.addLength(); if (speed > minSpeed) speed--; } // fult hack if (wt < length) wt++; } break; case STATE_MENU: if (init) init = false; else { state = STATE_MENU_DO; cursor = 0; goto case STATE_MENU_DO; } break; case STATE_MENU_DO: { ConsoleKeyInfo key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.UpArrow: cursor--; if (cursor < 0) cursor = 4; break; case ConsoleKey.DownArrow: cursor++; cursor %= 5; break; case ConsoleKey.LeftArrow: switch (cursor) { case 1: if (minSpeed > 1) minSpeed--; break; case 2: if (startspeed > minSpeed) startspeed--; break; case 3: if (length > 1) length--; break; } break; case ConsoleKey.RightArrow: switch (cursor) { case 1: minSpeed++; if (startspeed < minSpeed) startspeed = minSpeed; break; case 2: startspeed++; break; case 3: length++; break; } break; case ConsoleKey.Spacebar: if (cursor == 0) changeState(STATE_GAME); else if (cursor == 4) quit = true; break; } } cursor %= 5; // 5 menu items break; case STATE_SCORE: if (init) { init = false; Console.Beep(400, 100); Console.Beep(200, 150); Console.Beep(100, 200); } else { state = STATE_SCORE_DO; goto case STATE_SCORE_DO; } break; case STATE_SCORE_DO: if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); if (key.Key == ConsoleKey.R) changeState(STATE_MENU); else if (key.Key == ConsoleKey.Q) quit = true; } break; } }
public void StartApplePushService(Apple.ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) { appleService = new Apple.ApplePushService(channelSettings, serviceSettings); appleService.Events.RegisterProxyHandler(this.Events); }
public abstract void VisitApple(Apple apple);
private void GameUpdate(GameTime gameTime) { gameover = new TextObject(this, _fontGameOver, new Vector2(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width/2, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height/2), "Game Over"); for (int i = 0; i < GameObjects.Count - 1; i++) { GameObjects[i].Update(gameTime); if (GameObjects[i].GetType() == typeof (Apple)) { Apple apple = (Apple) GameObjects[i]; if (_worm.BoundingBox.Intersects(apple.BoundingBox)) { GameObjects.Remove(GameObjects[i]); } } if (GameObjects[i].GetType() == typeof (Bird)) { Bird b = (Bird) GameObjects[i]; if (b.BoundingBox.Intersects(_worm.BoundingBox)) { GameObjects.Remove(_worm); gameover.SpriteColor = Color.RoyalBlue; GameObjects.Add(gameover); gameState = GameState.GAMEOVER; } } } //spawn apples if (GameHelper.RandomNext(100) == 1) { Apple a = new Apple(this); a.SpriteTexture = _spritesheet; a.PositionX = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width + 100; a.PositionY = GameHelper.RandomNext(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height); GameObjects.Add(a); } //spawn birds if (GameHelper.RandomNext(200) == 1) { Bird b = new Bird(this); b.SpriteTexture = _spritesheet; b.PositionX = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width + 100; b.PositionY = GameHelper.RandomNext(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height); GameObjects.Add(b); } if (gameState == GameState.GAMEOVER) { if (_gameOverTime == 0) { _gameOverTime = gameTime.TotalGameTime.TotalSeconds; } if (_gameOverTime != 0 && _gameOverTime + 3 <= gameTime.TotalGameTime.TotalSeconds) { gameState = GameState.INTRO; _gameOverTime = 0; GameObjects.Remove(gameover); } } }