public void DrawMap(RLMap map) { Console.ForegroundColor = ConsoleColor.White; for (int x = 0; x < map.MaxWidth; x++) { for (int y = 0; y < map.MaxHeight; y++) { Console.SetCursorPosition(x, y); char characterToDisplay = new char(); ConsoleColor color; RLCell cell = map.Cells.Where(c => c.X == x && c.Y == y).FirstOrDefault(); if (cell.Items.Count == 0) { characterToDisplay = cell.DisplayCharacter; color = ConsoleColor.White; } else { characterToDisplay = cell.Items.First().DisplayChar; color = cell.Items.First().DisplayColor; } Console.ForegroundColor = color; Console.Write(characterToDisplay); } } }
public Ccity(bool frenz, int x, int y, RLMap m, Player p, MessageLog ml = null) { poppedleader = false; hp = hpmax; //copy the static list of distances spiral = new Spiral(m.width, m.height, x, y); unitlist = new List <mob>(); isfrenzleecity = frenz; if (ml != null) { log = ml; } player = p; if (isfrenzleecity) { numcities++; if (numcities > citynames.Count) { name = "No more names!"; } else { name = citynames[numcities]; } } else { numcitiesevil++; if (numcitiesevil > citynamesevil.Count) { name = "!"; } else { name = citynamesevil[numcitiesevil]; } } posx = x; posy = y; map = m; map.citylist.Add(this); map.citythathasinfluence[player.posx, player.posy] = this; //log.Printline("The city of " + citeh.name + " was founded!", Color.magenta); //influence grabinitialsquares(); //set up initial yields //recalcyield(); }
void cairntransport_effect(int xx, int yy) { for (int y = 0; y < map.height; y++) { for (int x = 0; x < map.width; x++) { map.gridflashcolour[x, y] = new Color(110f / 255f, 37f / 255f, 125f / 255f, 0.8f); map.gridflashtime[x, y] = Time.time + (0 + (float)(RLMap.Distance_Euclidean(x, y, xx, yy) / 10.0f)); //lil.randf(0f, 1f); } } }
public void DrawAgent(RLMap map, RLAgent agent, int x, int y) { RLCell oldCell = map.Cells.Where(c => c.X == agent.locationX && c.Y == agent.locationY).FirstOrDefault(); oldCell.Unoccupied = true; Console.SetCursorPosition(oldCell.X, oldCell.Y); Console.ForegroundColor = ConsoleColor.White; Console.Write(oldCell.DisplayCharacter); Console.SetCursorPosition(x, y); Console.ForegroundColor = agent.DisplayColor; Console.Write(agent.DisplayChar); Console.ForegroundColor = ConsoleColor.White; map.Cells.Where(c => c.X == x && c.Y == y).FirstOrDefault().Unoccupied = false; }
public Spiral(int w, int h, int xp, int yp) { l = new List <Cellndist>(); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { l.Add(new Cellndist(new Cell(x, y), RLMap.Distance_EuclideanD(x, y, xp, yp))); } } l.Shuffle(); //not sure what happens here. will the ordering below change the relative order of items with the same value ? l = l.OrderBy(o => o.dist).ToList(); }
public void LoadGame() { RLGame loadedGame = ioService.LoadGame(); this.map = loadedGame.map; this.levelGenerator = loadedGame.levelGenerator; this.messages = loadedGame.messages; this.renderer = loadedGame.renderer; this.ioService = loadedGame.ioService; this.monsters = loadedGame.monsters; this.messages = loadedGame.messages; this.playerActionsService = loadedGame.playerActionsService; this.aiService = loadedGame.aiService; this.hero = loadedGame.hero; this.dice = loadedGame.dice; }
public RLGame(Interfaces.IRLRenderer renderer = null, Interfaces.IRLLevelGenerator levelGenerator = null, IJsonGameIOService jsonService = null, RLMap map = null, List<RLMonster> monsters = null, Stack<Tuple<ConsoleColor, string>> messages = null, RLPlayerActionsService playerActionsService = null, RLAIService aiService = null, RLHero hero = null, RLDice injectedDice = null) { this.renderer = renderer != null ? renderer : new RLRenderer(); this.levelGenerator = levelGenerator != null ? levelGenerator : new RLLevelGenerator(); this.ioService = jsonService != null ? jsonService : new JsonGameIOService(); this.map = map; this.monsters = monsters != null ? monsters : new List<RLMonster>(); this.messages = messages != null ? messages : new Stack<Tuple<ConsoleColor, string>>(); this.playerActionsService = playerActionsService != null ? playerActionsService : new RLPlayerActionsService(); this.dice = injectedDice != null ? injectedDice : new RLDice(); this.aiService = aiService != null ? aiService : new RLAIService(dice); this.hero = hero != null ? hero : this.levelGenerator.GetDefaultHero(); }
public bool CanSeeEachOther(RLAgent first, RLAgent second, RLMap map) { Func<int, int> moveTowardsX = null; Func<int, int> moveTowardsY = null; if (first.locationX > second.locationX) { moveTowardsX = x => x - 1; } else { moveTowardsX = x => x + 1; } if (first.locationY > second.locationY) { moveTowardsY = y => y - 1; } else { moveTowardsY = y => y + 1; } int checkX = first.locationX; int checkY = first.locationY; do { checkX = (checkX != second.locationX) ? moveTowardsX(checkX) : checkX; checkY = (checkY != second.locationY) ? moveTowardsY(checkY) : checkY; var cellToCheck = map.Cells.Where(c => c.X == checkX && c.Y == checkY).FirstOrDefault(); if (!cellToCheck.Transparent) { return false; } } while (second.locationX != checkX || second.locationY != checkY); return true; }
private void PlaceMonster(RLMap map, RLMonster monster) { Tuple<int, int> destination = null; //if monster can see hero, move according to monster behaviour if (aiService.CanSeeEachOther(monster, hero, map)) { switch (monster.monsterBehaviour) { case RLMonster.MonsterBehaviour.aggressive: destination = aiService.moveTowards(monster, hero); break; case RLMonster.MonsterBehaviour.passive: destination = aiService.moveRandom(monster); break; case RLMonster.MonsterBehaviour.cowardly: destination = aiService.moveAway(monster, hero); break; default: break; } } else //otherwise, move at random { destination = aiService.moveRandom(monster); } if (destination != null) { if (destination.Item1 == hero.locationX && destination.Item2 == hero.locationY) { //redraw in the same location renderer.DrawAgent(map, monster, monster.locationX, monster.locationY); //attack hero var attackResults = hero.attackedBy(monster, dice); foreach (var attackMessage in attackResults) { messages.Push(new Tuple<ConsoleColor, string>(ConsoleColor.Red, attackMessage)); } } else if (map.isLocationPassable(destination.Item1, destination.Item2)) { renderer.DrawAgent(map, monster, destination.Item1, destination.Item2); monster.locationX = destination.Item1; monster.locationY = destination.Item2; } else { //redraw in the same location renderer.DrawAgent(map, monster, monster.locationX, monster.locationY); } } }
internal void SetUp() { //map = levelGenerator.DrawMap //agents = levelGenerator.GenerateAgents(agentGenerationBehaviour.IncludeHero) // Once we get on to additional levels, we can call GenerateAgents with ExcludeHero set if (map == null || map.Cells.Count == 0) { map = levelGenerator.GenerateMap(); } //draw dungeon renderer.DrawMap(map); if (monsters == null || monsters.Count == 0) { monsters = levelGenerator.GenerateMonsters(); } ProcessInput(RLPlayerAction.EmptyAction); }