public PenguinMob(GameModel model, int x, int y) : base(model, ImagePath, x, y) { Action WaterToIce = () => { if (Model.BackMap[X, Y] is WaterBackground) { Model.BackMap[X, Y] = new IceBackground(Model, X, Y); } }; OnMoveStart += () => { if (Model.BackMap[X, Y] is LavaBackground || Model.BackMap[MX, MY] is LavaBackground) { Destroy(); return; } WaterToIce(); }; OnCantMove += (key) => { WaterToIce(); var newDirection = Useful.ReverseDirection(key); GoTo(newDirection); }; }
public Level LevelFromFile(string file) { var t = File.ReadAllText(file).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); var size = t[0].Split(); var width = int.Parse(size[0]); var height = int.Parse(size[1]); var backIndex = findStr(t, "//back") + 1; var itemList = new List <string[]>(); for (int i = 0; i < t.Length; i++) { if (t[i] == "//item") { itemList.Add(Useful.CutArray(t, i + 1, i + height)); } } var mobIndex = findStr(t, "//mob") + 1; var switcherIndex = findStr(t, "//switcher") + 1; return(new Level( Useful.CutArray(t, backIndex, backIndex + height - 1), itemList, Useful.CutArray(t, mobIndex, mobIndex + height - 1), Useful.CutArray(t, switcherIndex, t.Length - 1) )); }
public FrogMob(GameModel model, int x, int y) : base(model, ImagePath, x, y) { Action IceToWater = () => { if (Model.BackMap[X, Y] is IceBackground) { Model.BackMap[X, Y] = new WaterBackground(Model, X, Y); } }; OnMoveStart += () => { if (Model.BackMap[X, Y] is WaterBackground || Model.BackMap[MX, MY] is WaterBackground) { Destroy(); return; } IceToWater(); }; OnCantMove += (key) => { IceToWater(); var newDirection = Useful.ReverseDirection(key); GoTo(newDirection); }; OnStop += base.ForStop; }
public void CreateSpell(Func <int, int, ISpell> spell) { var newX = 0; var newY = 0; Useful.XyPlusKeys(X, Y, this.GazeDirection, ref newX, ref newY); Model.Spells.AddLast(spell(newX, newY)); }
private void KeyDownInGame(object sender, KeyEventArgs args) { var keyCode = args.KeyCode; switch (keyCode) { case Keys.Tab: model.CurrentHero.KeyMap.TurnOff(); model.SwitchHero(); break; case Keys.Escape: GetOut(); break; case Keys.Space: if (!model.CurrentHero.KeyMap.Enable) { break; } if (model.CurrentHero.KeyMap.GetAnyOnDirection() == Keys.None && !model.CurrentHero.CurrentAnimation.IsMoving) { model.CurrentHero.CreateSpell(); } break; case Keys.ControlKey: switch (model.CurrentHero.GazeDirection) { case Keys.Up: model.CurrentHero.GazeDirection = Keys.Right; break; case Keys.Down: model.CurrentHero.GazeDirection = Keys.Left; break; case Keys.Right: model.CurrentHero.GazeDirection = Keys.Down; break; case Keys.Left: model.CurrentHero.GazeDirection = Keys.Up; break; } break; } if (!model.CurrentHero.KeyMap.Enable) { return; } if (Useful.KeyIsMove(keyCode)) { model.CurrentHero.KeyMap.TurnOn(keyCode); model.CurrentHero.MakeMove(keyCode); } }
public bool IsInsideMap(int x, int y, Keys key) { var newX = 0; var newY = 0; Useful.XyPlusKeys(x, y, key, ref newX, ref newY); return (IsInsideMap(newX, newY)); }
public MatthiusSpell(IHero hero, int X, int Y, string imageFile) : base(hero, X, Y, imageFile) { var dict = new Dictionary <IMob, Action>(); var willDie = new List <IMob>(); foreach (var mob in Model.Mobs.Where(mob => mob.DestroyByMatthiusSpell)) { if (Useful.CheckTouch(mob, X, Y)) { willDie.Add(mob); continue; } dict.Add(mob, () => { if (mob.MX == X && mob.MY == Y) { mob.Destroy(); } }); mob.OnMoveStart += dict[mob]; } foreach (var mob in willDie) { mob.Destroy(); } foreach (var mob in Model.Mobs.Where(mob => Math.Abs(mob.X - X) <= 1 && Math.Abs(mob.Y - Y) <= 1)) { if (mob is PenguinMob && !mob.CurrentAnimation.IsMoving) { var direction = GetOppositeDirection(this, mob); if (direction != Keys.None) { mob.GoTo(direction); } break; } } OnDestroy += () => { var ItemStack = Model.ItemsMap[X, Y]; if (ItemStack.Count > 0 && ItemStack.Peek() is ThreeItem) { Model.ItemsMap[X, Y].Peek().Destroy(); } foreach (var act in dict) { act.Key.OnMoveStart -= act.Value; } }; }
private bool checkThree(int x, int y, Keys direction) { Useful.XyPlusKeys(x, y, direction, ref x, ref y); if (!Model.IsInsideMap(x, y)) { return(false); } return (Model.ItemsMap[x, y].Count > 0 && Model.ItemsMap[x, y].Peek() is ThreeItem); }
public override void ForMoveStart() { var newX = X; var newY = Y; Useful.XyPlusKeys(newX, newY, GazeDirection, ref newX, ref newY); var willDie = Model.MobMap[newX, newY].Where(mob => mob != this && !(mob is SporeMob)).ToArray(); for (var i = 0; i < willDie.Length; i++) { willDie[i].Destroy(); } }
public override void onTick() { if (Model.TickCount % 10 == 0) { this.ChangeSlide(); if (this.animationCounter == 3) { if (!checkDirection(lastDirection)) { lastDirection = findTarget(); } if (Useful.KeyIsMove(lastDirection)) { Shoot(Model, X, Y, lastDirection); } } } }
private bool checkDirection(Keys key) { var x = X; var y = Y; for (int i = 0; i < 2; i++) { Useful.XyPlusKeys(x, y, key, ref x, ref y); if (!Model.IsInsideMap(x, y)) { return(false); } if (Model.MobMap[x, y].Count > 0) { return(true); } } return(false); }
public bool CanStep(MovableBase mob) => !(mob is IHero && Useful.ReverseDirection(mob.GazeDirection) == Direction);
private void PaintGameState(object sender, PaintEventArgs args) { var g = args.Graphics; //Отрисовка фона model.BackMap.Foreach((x, y) => { g.DrawImage( model.BackMap[x, y].Picture, x * DrawingScope, y * DrawingScope, DrawingScope, DrawingScope); }); //Отрисовка предметов model.ItemsMap.Foreach((x, y) => { Useful.ForeachReverse(model.ItemsMap[x, y], (item) => { g.DrawImage( item.Picture, item.X * DrawingScope, item.Y * DrawingScope, DrawingScope, DrawingScope); }); }); //Обводка героя g.DrawRectangle(new Pen(Color.Gold, 2), GetPaintX(model.CurrentHero), GetPaintY(model.CurrentHero), DrawingScope, DrawingScope); //Отрисовка героев foreach (var hero in model.Heroes) { g.DrawImage(hero.Image, GetPaintX(hero), GetPaintY(hero), DrawingScope, DrawingScope); } //Отрисовка мобов foreach (var mob in model.Mobs) { g.DrawImage(mob.Image, GetPaintX(mob), GetPaintY(mob), DrawingScope, DrawingScope); } //Отрисовка магии foreach (var spell in model.Spells) { g.DrawImage(spell.Picture, spell.X * DrawingScope, spell.Y * DrawingScope, DrawingScope, DrawingScope); } //Отрисовка смертей foreach (var death in model.Deaths) { g.DrawImage(death.Picture, death.X * DrawingScope, death.Y * DrawingScope, DrawingScope, DrawingScope); } g.DrawString(perfomance, new Font("Arial", 10, FontStyle.Regular), Brushes.Black, FPSRectangle); //g.DrawImage(model.CurrentHero.Image, new Rectangle(new Point(200, 200), new Size(50, 50))); //g.DrawImage(model.CurrentHero.Image, 100, 200, 100, 200); }