public void AddTest() { Scoreboard target = new Scoreboard(); string fileName = "AddTest.txt"; Player player = new Player(); player.Name = "nakov"; player.Points = 10; target.Add(fileName, player); }
public void ShowTest() { Scoreboard target = new Scoreboard(); string fileName = "ShowTest.txt"; Player player = new Player(); player.Name = "nakov"; player.Points = 10; target.Add(fileName, player); string expected = "1: nakov -> 10" + Environment.NewLine; string actual; actual = target.Show(fileName); Assert.AreEqual(expected, actual); }
public Engine(ObjectRenderer renderer, Player player, Playfield playfield, Scoreboard scoreboard) { this.renderer = renderer; this.player = player; this.playfield = playfield; this.scoreboard = scoreboard; }
public void Render(Playfield playfield, Player player) { for (int row = 0; row < 7; row++) { for (int col = 0; col < 7; col++) { if (player.GetPosition.Row == row && player.GetPosition.Col == col) { Console.Write("*"); } else { if (playfield.Labyrinth[row, col] == 0) { Console.Write("-"); } else { Console.Write("X"); } } } Console.WriteLine(Message.PrintNewLine()); } }
static void Main() { ObjectRenderer renderer = new ObjectRenderer(); Player player = new Player(); Playfield playfield = new Playfield(); Scoreboard scoreboard = new Scoreboard(); Engine engine = new Engine(renderer, player, playfield, scoreboard); engine.Run(); Console.Write("Good Bye!"); Console.ReadKey(); }
private bool IsVisitedPosition(Player player, Direction direction) { Position pos = new Position(player.GetPosition.Row, player.GetPosition.Col); Player bot = new Player(pos); bot.Move(direction); if (labyrinth[bot.GetPosition.Row, bot.GetPosition.Col] == -1) { return true; } return false; }
public void IsVisitedPosition_Test_False() { BindingFlags eFlags = BindingFlags.Instance | BindingFlags.NonPublic; Playfield palyfield = new Playfield(); Player player = new Player(); Direction direction = Direction.Left; Object[] arguments = new object[] { player, direction }; MethodInfo testedMethod = typeof(Playfield).GetMethod("IsVisitedPosition", eFlags); bool actual = (bool)testedMethod.Invoke(palyfield, arguments); bool expected = false; Assert.AreEqual(expected, actual); }
public void Add(string fileName, Player player) { var players = new List<Player>(); ReadScores(fileName, players); players.Add(new Player(new Position(Configuration.GameFieldSize / 2, Configuration.GameFieldSize / 2)) { Name = player.Name, Points = player.Points }); CreateFile(fileName, players); }
public World(Game1 game, IWorldLoader worldLoader) { this.Game = game; this._wl = worldLoader; // Create a new content manager to load content used just by this World. this._contentManager = new ContentManager(game.Services, "Content"); var gameItems = worldLoader.GetGameObjects(this).ToList(); this.GameObjects = new GameObjectCollection(worldLoader.Width, worldLoader.Height, gameItems); this.Player = gameItems.OfType<Player>().Single(); this._itemsToDrawByZOrder = new List<StaticItem>[10]; for (int i = 0; i < this._itemsToDrawByZOrder.GetLength(0); i++) this._itemsToDrawByZOrder[i] = new List<StaticItem>(); }
public void CreateLabyrinth() { Player bot = new Player(); for (int i = 0; i < PlayfieldRows; i++) { for (int j = 0; j < PlayfieldCols; j++) { labyrinth[i, j] = -1; } } labyrinth[bot.GetPosition.Row, bot.GetPosition.Col] = 0; Direction direction = Direction.Blank; Random randomGenerator = new Random(); while (!bot.HasWon()) { do { int randomNumber = randomGenerator.Next() % 4; direction = (Direction)(randomNumber); } while (!IsVisitedPosition(bot, direction)); bot.Move(direction); labyrinth[bot.GetPosition.Row, bot.GetPosition.Col] = 0; } for (int i = 0; i < PlayfieldRows; i++) { for (int j = 0; j < PlayfieldCols; j++) { if (labyrinth[i, j] == -1) { int randomNumber = randomGenerator.Next(); if (randomNumber % 3 == 0) labyrinth[i, j] = 0; else labyrinth[i, j] = 1; } } } }
public MovingItemAndMovingItemInteraction(World world, MovingItem movingItem1, MovingItem movingItem2) { if (world == null) throw new ArgumentNullException("world"); if (movingItem1 == null) throw new ArgumentNullException("movingItem1"); if (movingItem2 == null) throw new ArgumentNullException("movingItem2"); if (movingItem1 is Shot) throw new ArgumentOutOfRangeException("movingItem1"); if (movingItem2 is Shot) throw new ArgumentOutOfRangeException("movingItem2"); this._world = world; var items = new[] {movingItem1, movingItem2}; this._player = items.OfType<Player>().SingleOrDefault(); this._boulder = items.OfType<Boulder>().SingleOrDefault(); this._mine = items.OfType<Mine>().SingleOrDefault(); this._monster1 = items.OfType<Monster.Monster>().FirstOrDefault(); this._monster2 = items.OfType<Monster.Monster>().Skip(1).FirstOrDefault(); this._moveableObject = items.FirstOrDefault(item => item.Solidity == ObjectSolidity.Moveable); this._insubstantialObject = items.FirstOrDefault(item => item.Solidity == ObjectSolidity.Insubstantial); }
public IEnumerable<StaticItem> GetGameObjects(World world) { var exceptions = new List<TileException>(); Tile[,] tiles; var result = new List<StaticItem>(); var walls = GetLayout(world, out tiles); result.AddRange(walls); int initialWorldId = GetStartingWorldAreaId(); StartState ss = GetStartStateForWorldAreaId(initialWorldId); var player = new Player(world, ss.PlayerPosition.ToPosition(), ss.PlayerEnergy); result.Add(player); var playerStartPositions = this._worldAreas.Where(wa => wa.StartState != null).Select(wa => new Grave(world, wa.StartState.PlayerPosition.ToPosition())); exceptions.AddRange(SetTileOccupation(ref tiles, playerStartPositions, false)); var objects = this._xmlDoc.SelectNodes("World/Objects/*"); if (objects == null) throw new InvalidOperationException("No Objects node in world definition."); foreach (XmlElement definition in objects) { StaticItem[] newItems; switch (definition.LocalName) { case "Boulder": { newItems = new StaticItem[] { GetBoulder(world, definition) }; break; } case "Monster": { newItems = new StaticItem[] { GetMonster(world, definition) }; break; } case "Crystal": { newItems = new StaticItem[] { GetCrystal(world, definition) }; break; } case "ForceField": { newItems = GetForceFields(world, definition).Cast<StaticItem>().ToArray(); break; } case "CrumblyWall": { newItems = new StaticItem[] { GetCrumblyWall(world, definition) }; break; } default: throw new InvalidOperationException("Unknown object " + definition.LocalName); } result.AddRange(newItems); exceptions.AddRange(SetTileOccupation(ref tiles, newItems.Where(item => !(item is Monster.Monster) || ((Monster.Monster) item).IsStill), false)); } var fruit = GetListOfFruit(world, ref tiles); result.AddRange(fruit); exceptions.AddRange(SetTileOccupation(ref tiles, result.OfType<Monster.Monster>().Where(m => !m.IsStill), true)); ReviewPotentiallyOccupiedTiles(ref tiles, exceptions); if (exceptions.Count != 0) { string message = string.Empty; var errors = exceptions.Where(te=>te.Type == TileExceptionType.Error).ToList(); var warnings = exceptions.Where(te=>te.Type == TileExceptionType.Warning).ToList(); foreach (TileException te in errors) { if (message.Length != 0) message += "\r\n"; message += string.Format("{0} - {1}", te.Type, te.Message); } if (warnings.Any()) { if (message.Length != 0) message += "\r\n"; foreach (TileException te in warnings) { if (message.Length != 0) message += "\r\n"; message += string.Format("{0} - {1}", te.Type, te.Message); } } if (errors.Any()) throw new InvalidOperationException(message); Trace.WriteLine(message); var dr = MessageBox.Show(message, "Warnings", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (dr == DialogResult.Cancel) throw new InvalidOperationException(message); } this._tiles = tiles; return result; }