public static void SetApples() { Apples apples = new Apples(3, 4.5, 5000, "Apple"); sumOfAllProducts += apples.Price; apples.GetInfo(); }
private void CreateApples() { int x, y; while (Apples.Count < amountApples) { x = r.Next(6) * 40; y = r.Next(6) * 40; bool flag = true; foreach (Apple a in Apples) { if (a.X == x && a.Y == y) { flag = false; break; } } if (flag) { Apples.Add(new Apple(x, y)); } } }
private void CreateApple(int percent) { if (Apples.Count < appleCount && rnd.Next(100) <= percent) { int x = rnd.Next(view.MapWidth - BlockSize); int y = rnd.Next(view.MapHeight - BlockSize); var apple = new AppleViewModel(x, y, 12, 12); if (Player != null) { if (Walls.Find(wall => IsCollision(wall, apple)) == null && IsCollision(Player, apple) == false) { Apples.Add(apple); } } else { if (Walls.Find(wall => IsCollision(wall, apple)) == null && IsCollision(reservePlayer, apple) == false) { Apples.Add(apple); } } } }
private static void DrawLevel(Apples currentApples, Timer inkyTimer, Timer pinkyTimer, int inkyX, int inkyY, int pinkyX, int pinkyY, int pacmanX, int pacmanY) { _draw.HidePerson(_game.MyInky); _game.MyInky.X = inkyX; _game.MyInky.Y = inkyY; _draw.HidePerson(_game.MyPinky); _game.MyPinky.X = pinkyX; _game.MyPinky.Y = pinkyY; _draw.HidePerson(_game.MyPacman); _game.MyPacman.X = pacmanX; _game.MyPacman.Y = pacmanY; _draw.DrawMap(_game.Map.MyMap); _draw.DrawApples(currentApples); _draw.DrawPacman(_game); _draw.DrawInky(_game); _draw.DrawPinky(_game); WriteScores(35, 0, Game.Scores); WriteLives(35, 1, _game.MyPacman.Lives); inkyTimer.Start(); pinkyTimer.Start(); }
private void LoadData() { #region Apple Apples.Add(new Apple { Color = AppleColor.Green, Kind = "Gold", Price = 2.56 }); Apples.Add(new Apple { Color = AppleColor.Green, Kind = "Gold", Price = 3.90 }); Apples.Add(new Apple { Color = AppleColor.Yellow, Kind = "Double Sun", Price = 4.56 }); #endregion #region SoldApple SoldApples.Add(new SoldApple { Color = AppleColor.Green, Kind = "Gold", Price = 5.56 }); SoldApples.Add(new SoldApple { Color = AppleColor.Red, Kind = "Gold FD", Price = 13.90 }); SoldApples.Add(new SoldApple { Color = AppleColor.Yellow, Kind = "Double Sun", Price = 45.56 }); SoldApples.Add(new SoldApple { Color = AppleColor.Yellow, Kind = "Double Sun", Price = 15.56 }); SoldApples.Add(new SoldApple { Color = AppleColor.Red, Kind = "Double Sun", Price = 7.56 }); #endregion }
public void TestGetApples() { var apples = new Apples(); string expected = "apples"; string output = apples.GetApples(); Assert.AreEqual(expected, output); }
public void PutOn(IGameComponent item) { if (item.Type == GameComponentType.Apple) { Apples.Add((IFoodComponent)item); } _drawableObjs.Add(item); }
public void PickUp(IGameComponent item) { if (item.Type == GameComponentType.Apple) { Apples.Remove((IFoodComponent)item); } _drawableObjs.Remove(item); }
public void GetAppleTest() { string fruit = "apple"; var apples = new Apples(fruit); string output = apples.GetApple(); Assert.AreEqual(fruit, output); }
public void MoveOneStep_Default() { Apples currentapples = game.Map.GetApples(); game.MyInky.X = 14; game.MyInky.Y = 12; Direction AppleDirection = game.MyInky.MoveOneStep(game, Direction.None); Assert.AreEqual(AppleDirection, Direction.None); }
public void TestMethod1() { //arrange string message = "apple"; var apples = new Apples(message); //act string output = apples.PrintMessage(); //assert //zarojelben az elso az elvart eredmeny a masodik a tesztelt Assert.AreEqual(message, output); }
public void MoveOneStep_Left_NotEat() { Apples currentapples = game.Map.GetApples(); game.MyInky.X = 14; game.MyInky.Y = 12; game.MyPacman.X = 12; game.MyPacman.Y = 12; Direction AppleDirection = game.MyInky.Move(game); Assert.AreEqual(AppleDirection, Direction.None); }
public void MoveOneStep_Down_Eat() { Apples currentapples = game.Map.GetApples(); game.MyInky.X = 6; game.MyInky.Y = 27; game.MyPacman.X = 6; game.MyPacman.Y = 29; Direction AppleDirection = game.MyInky.Move(game); Assert.AreEqual(AppleDirection, Direction.Up); }
private static void MainCycle(ref ConsoleKeyInfo key, Apples currentApples, Direction direction, Timer inkyTimer, Timer pinkyTimer) { while (!_game.GameOver()) { if (Game.Scores == 325) { inkyTimer.Stop(); pinkyTimer.Stop(); Console.Clear(); Console.WriteLine("Congratulations. You win!"); return; } WriteScores(35, 0, Game.Scores); WriteLives(35, 1, _game.MyPacman.Lives); WriteMessage(35, 3, "Press Space to pause"); if (!_game.IfPacmanNotEated()) { inkyTimer.Stop(); pinkyTimer.Stop(); _game.MinusLive(); WriteResume(_game); if (!_game.GameOver()) { Console.Clear(); WriteResume(_game); while (key.Key != ConsoleKey.Enter) { Console.Clear(); WriteResume(_game); key = Console.ReadKey(); if (key.Key == ConsoleKey.Enter) { DrawLevel(currentApples, inkyTimer, pinkyTimer, 13, 12, 14, 12, 13, 26); } } } } PacmanMove(ref currentApples, _draw, _game, ref key, ref direction, inkyTimer, pinkyTimer); } }
public void DrawApples(Apples app) { Console.ForegroundColor = ConsoleColor.Yellow; for (int i = 0; i < app.Dots.GetLength(0); i++) { for (int j = 0; j < app.Dots.GetLength(1); j++) { if (app.Dots[i, j]) { Console.SetCursorPosition(j, i); Console.Write((char)8729); } } } Console.ForegroundColor = ConsoleColor.White; }
static void Main(string[] args) { Console.CursorVisible = false; WriteMessage(35, 0, "Press Enter to start the game"); ConsoleKeyInfo key = Console.ReadKey(); while (key.Key != ConsoleKey.Enter) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; WriteMessage(35, 0, "Press Enter to start the game"); key = Console.ReadKey(); } Apples currentApples = _game.Map.GetApples(); Console.Clear(); _game.Start(); _draw.DrawMap(_game.Map.MyMap); _draw.DrawApples(currentApples); _draw.DrawPacman(_game); _draw.DrawInky(_game); _draw.DrawPinky(_game); WriteScores(35, 0, Game.Scores); WriteLives(35, 1, _game.MyPacman.Lives); Direction direction = Direction.Left; var inkyTimer = new Timer(300); inkyTimer.Elapsed += InkyMove; inkyTimer.Start(); var pinkyTimer = new Timer(400); pinkyTimer.Elapsed += PinkyMove; pinkyTimer.Start(); MainCycle(ref key, currentApples, direction, inkyTimer, pinkyTimer); Console.WriteLine("Press Enter to Exit"); Console.ReadLine(); }
public void CheckApples(Vector2 nextPos) { foreach (var apple in Apples) { if (apple.Position == nextPos) { SpawnPart(); OnAppleEaten?.Invoke(apple, EventArgs.Empty); // Checks if the apple did not spawn on the next HeadPosition, which isn't updated to the BodyPart List yet and therefore not checked otherwise. while (Apples[Apples.Count - 1].Position == nextPos) { Apples.RemoveAt(Apples.Count - 1); OnAppleEaten?.Invoke(apple, EventArgs.Empty); } break; } } }
public void countApplesAndOrangesTest1() { /* * 7 11 * 5 15 * 3 2 * -2 2 1 * 5 -6 */ int s = 7; int t = 11; int a = 5; int b = 15; int[] apples = new int[] { -2, 2, 1 }; int[] oranges = new int[] { 5, -6 }; var actual = Apples.countApplesAndOranges(s, t, a, b, apples, oranges); CollectionAssert.AreEqual(new string[] { "1", "1" }, actual); }
public void countApplesAndOrangesTest2() { /* * 2 3 * 1 5 * 1 1 * 2 * -2 */ int s = 2; int t = 3; int a = 1; int b = 5; int[] apples = new int[] { 2 }; int[] oranges = new int[] { -2 }; var actual = Apples.countApplesAndOranges(s, t, a, b, apples, oranges); CollectionAssert.AreEqual(new string[] { "1", "1" }, actual); }
private void AddApple(int AppleCount) { var RandomGenerator = new Random(); for (int i = 0; i < AppleCount; i++) { int X = RandomGenerator.Next(FieldSize.Width - 2); int Y = RandomGenerator.Next(FieldSize.Height - 2); Point P = new Point(X + 1, Y + 1); bool Acceptable = true; foreach (LineSeg Obstacle in Obstacles) { if (Intersect(P, Obstacle)) { Acceptable = false; } } foreach (LineSeg Body in SnakeBody) { if (Intersect(P, Body)) { Acceptable = false; } } foreach (Point Q in Apples) { if (Math.Abs(P.X - Q.X) <= AppleSize / 2 && Math.Abs(P.Y - Q.Y) <= AppleSize / 2) { Acceptable = false; } } if (Acceptable) { Apples.Add(P); } else { i--; } } }
public XmlDocument GetApple() { Apples apples = Report.GetReport(); // this returns: // <Apples xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/"> // <Name>Smtih</Name> // <Size>11</Size> // <Weight>111</Weight> // <Color>Red</Color> // </Apples> // Serialization string serializedXML = SerializeObject(apples); string TemplatePath = Server.MapPath("~/Template.xml"); // this is: // <?xml version="1.0" encoding="utf-8" ?> // <applereport> // <moretags> // <july> // <report> // <DATA-GOES-HERE></DATA-GOES-HERE> // </report> // </july> // </moretags> // </applereport> // Read TemplatePath into a memory stream // find the node: <DATA-GOES-HERE></DATA-GOES-HERE> // // put serialixed output of Report.GetReport() where <DATA-GOES-HERE></DATA-GOES-HERE> is XmlDocument xdoc = new XmlDocument(); xdoc.Load(TemplatePath); XmlNodeList datagoeshere = xdoc.GetElementsByTagName("DATA-GOES-HERE"); if (datagoeshere != null && datagoeshere.Count > 0) { datagoeshere[0].InnerXml = serializedXML; } return(xdoc); }
public void RespOfApples() { while (Apples.Count < applesCount) { Apples.Add(new Apple()); foreach (var item in Obstacles) { if (Apples.Last().Collide(item)) { Apples.RemoveAt(Apples.Count - 1); break; } } for (int i = 0; i < Apples.Count; i++) { if (Apples.Last().Collide(Apples[i]) && Apples.Last() != Apples[i]) { Apples.RemoveAt(Apples.Count - 1); break; } } } }
private void CreateApples() { int _x; int _y; while (Apples.Count < _applesAmount) { _x = random.Next(_fieldWidth - 20); _y = random.Next(_fieldHeight - 20); bool flag = false; foreach (var a in Walls) { if (AllCollision.BoxCollides(_x, _y, 15, 15, a.XLeft, a.YUp, a.XRight - a.XLeft, a.YDown - a.YUp)) { flag = true; break; } } foreach (var a in Apples) { if (AllCollision.BoxCollides(_x, _y, 15, 15, a.X, a.Y, 20, 20)) { flag = true; break; } } if (flag == false) { Apples.Add(new Apple(_x, _y)); } } }
public void SpawnApples() { while (Apples.Count < applesCount) { Apples.Add(new Apple()); foreach (var item in Walls) { if (Apples.Last().CollidesWith(item)) { Apples.RemoveAt(Apples.Count - 1); break; } } for (int i = 0; i < Apples.Count; i++) { if (Apples.Last().CollidesWith(Apples[i]) && Apples.Last() != Apples[i]) { Apples.RemoveAt(Apples.Count - 1); break; } } } }
private void DoWithPackman() { //подбор яблок foreach (var a in Apples) { if (AllCollision.BoxCollides(kolobok.X, kolobok.Y, 20, 20, a.X, a.Y, 15, 15)) { Apples.Remove(a); GameCount++; CreateApples(); break; } } //столкновение пакмена с границей switch (kolobok.TankDirection) { case Direction.Left: if (kolobok.X - 1 < 0) { kolobok.TurnAround(); } break; case Direction.Right: if (kolobok.X + 21 > _fieldWidth) { kolobok.TurnAround(); } break; case Direction.Up: if (kolobok.Y - 1 < 0) { kolobok.TurnAround(); } break; case Direction.Down: if (kolobok.Y + 21 > _fieldHeight) { kolobok.TurnAround(); } break; } //столкновение пакмена со стеной foreach (var a in Walls) { bool wallFlag = false; switch (kolobok.TankDirection) { case Direction.Left: if (AllCollision.BoxCollides(kolobok.X - 1, kolobok.Y, 20, 20, a.XLeft, a.YUp, a.XRight - a.XLeft, a.YDown - a.YUp)) { wallFlag = true; } break; case Direction.Right: if (AllCollision.BoxCollides(kolobok.X + 1, kolobok.Y, 20, 20, a.XLeft, a.YUp, a.XRight - a.XLeft, a.YDown - a.YUp)) { wallFlag = true; } break; case Direction.Up: if (AllCollision.BoxCollides(kolobok.X, kolobok.Y - 1, 20, 20, a.XLeft, a.YUp, a.XRight - a.XLeft, a.YDown - a.YUp)) { wallFlag = true; } break; case Direction.Down: if (AllCollision.BoxCollides(kolobok.X, kolobok.Y + 1, 20, 20, a.XLeft, a.YUp, a.XRight - a.XLeft, a.YDown - a.YUp)) { wallFlag = true; } break; } if (wallFlag) { kolobok.TurnAround(); } } // столкновение пакмена с пулей или танком foreach (var a in Projectiles) { if (AllCollision.BoxCollides(kolobok.X, kolobok.Y, 20, 20, a.X, a.Y, 10, 10)) { GameOver(); } } foreach (var a in Tanks) { if (AllCollision.BoxCollides(kolobok.X, kolobok.Y, 20, 20, a.X, a.Y, 20, 20)) { GameOver(); } } }
public void TestingApples() { var apples = new Apples(); Assert.Equal("apple", apples.GetApple()); }
private static void PacmanMove(ref Apples currentApples, Drawing Draw, Game game, ref ConsoleKeyInfo key, ref Direction direction, Timer inkyTimer, Timer pinkyTimer) { key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.Spacebar: { inkyTimer.Stop(); pinkyTimer.Stop(); Console.Clear(); WriteMessage(0, 2, "The game is paused"); WriteMessage(0, 3, "Press Enter to continue"); ConsoleKeyInfo key1 = new ConsoleKeyInfo(); while (key1.Key != ConsoleKey.Spacebar) { Console.Clear(); WriteMessage(0, 2, "The game is paused"); WriteMessage(0, 3, "Press Space to continue"); key1 = Console.ReadKey(); } if (key.Key == ConsoleKey.Spacebar) { DrawLevel(currentApples, inkyTimer, pinkyTimer, game.MyInky.X, game.MyInky.Y, game.MyPinky.X, game.MyPinky.Y, game.MyPacman.X, game.MyPacman.Y); } } break; case ConsoleKey.LeftArrow: { if (game.MyPacman.CheckPosition(game.Map.MyMap, -1, 0) & game.IfPacmanNotEated()) { DrawPacman(game.MyPacman.X, game.MyPacman.Y, Direction.Left); } } break; case ConsoleKey.RightArrow: { if (game.MyPacman.CheckPosition(game.Map.MyMap, 1, 0) & game.IfPacmanNotEated()) { DrawPacman(game.MyPacman.X, game.MyPacman.Y, Direction.Right); } } break; case ConsoleKey.UpArrow: { if (game.MyPacman.CheckPosition(game.Map.MyMap, 0, -1) & game.IfPacmanNotEated()) { DrawPacman(game.MyPacman.X, game.MyPacman.Y, Direction.Up); } } break; case ConsoleKey.DownArrow: { if (game.MyPacman.CheckPosition(game.Map.MyMap, 0, 1) & game.IfPacmanNotEated()) { DrawPacman(game.MyPacman.X, game.MyPacman.Y, Direction.Down); } } break; } }
internal void Move(int Step) { Point From = new Point(SnakeBody[SnakeBody.Count - 1].End.X, SnakeBody[SnakeBody.Count - 1].End.Y); switch (CurrentDirection) { case Direction.LEFT: SnakeBody[SnakeBody.Count - 1].End.X -= Step; break; case Direction.RIGHT: SnakeBody[SnakeBody.Count - 1].End.X += Step; break; case Direction.UP: SnakeBody[SnakeBody.Count - 1].End.Y -= Step; break; case Direction.DOWN: SnakeBody[SnakeBody.Count - 1].End.Y += Step; break; } Point To = new Point(SnakeBody[SnakeBody.Count - 1].End.X, SnakeBody[SnakeBody.Count - 1].End.Y); bool WillGrow = false; for (int x = Math.Min(From.X, To.X); x <= Math.Max(From.X, To.X); x++) { for (int y = Math.Min(From.Y, To.Y); y <= Math.Max(From.Y, To.Y); y++) { if (x == From.X && y == From.Y) { continue; } Point P = new Point(x, y); foreach (LineSeg Obstacle in Obstacles) { if (Intersect(P, Obstacle)) { SnakeBody[SnakeBody.Count - 1].End = P; if (HitWallAndLose != null) { HitWallAndLose(); } Console.WriteLine("Hit the obstacle, P is " + P.X + ", " + P.Y + ", and Obstacle is" + Obstacle.Start.X + "," + Obstacle.Start.Y + ") and " + Obstacle.End.X + ", " + Obstacle.End.Y); return; } } for (int i = 0; i < SnakeBody.Count - 1; i++) { if (Intersect(P, SnakeBody[i])) { SnakeBody[SnakeBody.Count - 1].End = P; if (HitSnakeAndLose != null) { HitSnakeAndLose(); } Console.WriteLine("Hit the body: P is " + P.X + "," + P.Y + "body ends at" + SnakeBody[i].End.X + ", " + SnakeBody[i].End.Y); return; } } int Removed = -1; for (int i = 0; i < Apples.Count; i++) { if (Math.Abs(Apples[i].X - P.X) <= AppleSize / 2 && Math.Abs(Apples[i].Y - P.Y) <= AppleSize / 2) { Removed = i; Appleseaten = i; WillGrow = true; break; } } if (Removed >= 0) { Apples.RemoveAt(Removed); AddApple(1);//mumber of apple to be added after the snake eats one apple if (EatAndGrow != null) { EatAndGrow(); } } } } if (WillGrow) { return; } if (SnakeBody[0].Start.X == SnakeBody[0].End.X) { if (Math.Abs(SnakeBody[0].Start.Y - SnakeBody[0].End.Y) > Step) { SnakeBody[0].Start.Y += (SnakeBody[0].Start.Y > SnakeBody[0].End.Y) ? (-Step) : Step; } else { SnakeBody.RemoveAt(0); } } else { if (Math.Abs(SnakeBody[0].Start.X - SnakeBody[0].End.X) > Step) { SnakeBody[0].Start.X += (SnakeBody[0].Start.X > SnakeBody[0].End.X) ? (-Step) : Step; } else { SnakeBody.RemoveAt(0); } } }
public void IsAppleAdded() { Apples apple = new Apples(); Assert.Equal("apple", apple.GetApple()); }
public void Clear() { _drawableObjs.Clear(); Apples.Clear(); }