/// <summary> /// Evaluates a turn, handling movement and combat, and removes any dead agents. /// </summary> /// <param name="cki">A consolekeyinfo object representing the last button press</param> /// <returns>a bool representing whether or not the game has ended. True means gameOver, false means the game will continue.</returns> public bool ProcessInput(RLPlayerAction action) { //movement PlacePlayer(map, action); foreach (var agent in monsters) { PlaceMonster(map, agent); } //remove dead agents foreach (var agent in monsters) { if (agent.HitPoints <= 0) { messages.Push(new Tuple<ConsoleColor, string>(ConsoleColor.DarkYellow, agent.Name + " died.")); map.Cells.Where(c => c.X == agent.locationX && c.Y == agent.locationY).FirstOrDefault().Unoccupied = true; } } monsters = monsters.Where(a => a.HitPoints > 0).ToList(); renderer.PostMessages(messages); if (hero.HitPoints == 0) { return true; } return false; }
private void PlacePlayer(GameLogic.RLMap map, RLPlayerAction action) { int playerDestinationX, playerDestinationY; playerDestinationX = hero.locationX; playerDestinationY = hero.locationY; var messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.White, ""); switch (action) { case RLPlayerAction.EmptyAction: break; case RLPlayerAction.MoveUp: playerDestinationY = hero.locationY - 1; messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Green, "You step north"); break; case RLPlayerAction.MoveDown: playerDestinationY = hero.locationY + 1; messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Green, "You step south"); break; case RLPlayerAction.MoveLeft: playerDestinationX = hero.locationX - 1; messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Green, "You step west"); break; case RLPlayerAction.MoveRight: playerDestinationX = hero.locationX + 1; messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Green, "You step east"); break; case RLPlayerAction.Wait: messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Cyan, "You wait"); break; case RLPlayerAction.Save: SaveGame(); break; case RLPlayerAction.Load: LoadGame(); playerDestinationX = hero.locationX; playerDestinationY = hero.locationY; renderer.DrawAgent(map, hero, hero.locationX, hero.locationY); break; default: break; } var destinationAgent = monsters .Where(a => a.locationX == playerDestinationX && a.locationY == playerDestinationY) .Where(a => a.GetType() != typeof(RLHero)) .FirstOrDefault(); if (map.isLocationPassable(playerDestinationX, playerDestinationY) || (hero.locationY == playerDestinationY && hero.locationX == playerDestinationX)) { renderer.DrawAgent(map, hero, playerDestinationX, playerDestinationY); hero.locationX = playerDestinationX; hero.locationY = playerDestinationY; } else if (destinationAgent != null) { var attackResults = destinationAgent.attackedBy(hero, dice); foreach (var attackMessage in attackResults) { messages.Push(new Tuple<ConsoleColor, string>(ConsoleColor.Red, attackMessage)); } renderer.DrawAgent(map, hero, hero.locationX, hero.locationY); } else { messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Red, DESTINATION_IMPASSABLE); renderer.DrawAgent(map, hero, hero.locationX, hero.locationY); } messages.Push(messageToAdd); }