Пример #1
0
 public State(Player player, string mapString, StateChange[] changes, Player[] players)
 {
     Player = player;
     MapString = mapString;
     Changes = changes;
     Players = players;
 }
Пример #2
0
        public void MovePlayer(Direction direction, Player player)
        {
            Cell currentCell = Cells[player.Y, player.X];
            Cell newCell = NewCell(direction, player);

            if (newCell != null) {
                var newPlayer = newCell.GetPlayer(this);
                var newPotion = newCell.GetPotion(this);
                var newMonster = newCell.GetMonster(this);

                List<StateChange> changes = new List<StateChange>();

                if (newPlayer != null) {
                    newPlayer.Health -= player.Damage;
                    if (newPlayer.Health <= 0) {
                        player.Gold += newPlayer.Gold;
                        newPlayer.Gold = 0;
                        SpawnCharacters(newPlayer);
                        player.X = newCell.X;
                        player.Y = newCell.Y;

                        changes.Add(StateChange.Update(player));
                    }

                    changes.Add(StateChange.Update(newPlayer));
                } else if (newMonster != null) {
                    newMonster.Health -= player.Damage;
                    if (newMonster.Health <= 0) {
                        player.Gold = newMonster.Gold;
                        monsters.Remove(newMonster);
                        player.X = newCell.X;
                        player.Y = newCell.Y;

                        changes.Add(StateChange.Update(player));
                        changes.Add(StateChange.Remove(newMonster));
                    } else {
                        changes.Add(StateChange.Update(newMonster));
                    }
                } else if (newPotion != null) {
                    player.Health += newPotion.Health;
                    potions.Remove(newPotion);
                    player.X = newCell.X;
                    player.Y = newCell.Y;

                    changes.Add(StateChange.Update(player));
                    changes.Add(StateChange.Remove(newPotion));
                } else if (newCell.IsWalkable(this)) {
                    player.Gold += newCell.Gold;
                    newCell.Gold = 0;
                    player.X = newCell.X;
                    player.Y = newCell.Y;

                    changes.Add(StateChange.Update(player));
                    changes.Add(StateChange.Update(newCell));
                }

                if (changes.Count > 0) {
                    OnChanged(changes.ToArray());
                }
            }
        }