/// <summary> /// Creates new UniverseView for specified GameUniverse /// </summary> /// <param name="gameUniverse">GameUniverse to visualize</param> public UniverseView(GameUniverse gameUniverse) { this.gameUniverse = gameUniverse; blockPen = new Pen(Color.Black); gridPen = new Pen(ColorUtility.ColorFromRGB(25, 25, 25)); }
public void DeadCellWithThreeNeighboursSurvivesToNextGeneration() { //Implies there are other dead cells with two neighbours //thus all cases for dead cells have been accounted for //Setup const int _gridXAxisCount = 60; const int _gridYAxisCount = 70; //point [6,8] is the only one with three neighbours var aliveCellPoints = new List <Point> { new Point(5, 8), new Point(7, 9), new Point(6, 7) }; IGenerationSrategy generationSrategy = new CandidateDictionaryGenerationStrategy(); var gameUniverse = new GameUniverse(_gridXAxisCount, _gridYAxisCount, aliveCellPoints); var gameController = new GameController(generationSrategy, gameUniverse); //Act var newGenerationAliveCellPoints = gameController.RunNewGeneration(); //Assert Assert.AreEqual(gameUniverse.GridXAxisCount, _gridXAxisCount); Assert.AreEqual(gameUniverse.GridYAxisCount, _gridYAxisCount); Assert.AreEqual(newGenerationAliveCellPoints.Count, 1); Assert.IsTrue(newGenerationAliveCellPoints.Contains(new Point(6, 8))); }
private static void ResumeSavedGame() { GameUniverse g = new GameUniverse(); //todo: load from file here RunGame(g); }
static void Main(string[] args) { GameUniverse gameUniverse = null; IGenerationSrategy generationSrategy = new CandidateDictionaryGenerationStrategy(); var intialAliveCellsForOscillatorPattern = new List <Point> { new Point(7, 10), new Point(8, 10), new Point(9, 10), new Point(8, 9) }; try { gameUniverse = new GameUniverse(20, 20, intialAliveCellsForOscillatorPattern); } catch (Exception e) { DisplayErrorMessageAndCloseScreen(e); } var gameController = new GameController(generationSrategy, gameUniverse); while (!Console.KeyAvailable) { List <Point> aliveCells = gameController.RunNewGeneration(); DrawSimulation(aliveCells, gameUniverse); System.Threading.Thread.Sleep(refreshIntervalInMilliSeconds); } Console.ReadKey(); }
/// <summary> /// Creates new NextBlockView element for given GameUniverse /// </summary> /// <param name="gameUniverse">GameUniverse to visualize</param> public NextBlockView(GameUniverse gameUniverse) { this._universe = gameUniverse; _blockPen = new Pen(Color.Black); _linePen = new Pen(Colors.White, 4); _fillBrush = new SolidColorBrush(ColorUtility.ColorFromRGB(164, 164, 164)); }
private static void StartNewGame() { //todo, player name...check files, etc. GameUniverse g = new GameUniverse(); g.InitializeNewGame(); //todo seed RunGame(g); }
protected override async Task OnInitializedAsync() { var charMap = await Http.GetFromJsonAsync <char[][]>("DataFetcher/LoadMap?level=" + Level); PlayerScores = await Http.GetFromJsonAsync <List <PlayerScore> >("Score/GetScoreBoard?level=" + Level); GameUniverse.StartGame(charMap); GameUniverse.RenderMethod += Render; }
public GameRunUI(GameUniverse g) : base(g) { Messages = new MessageBuffer(this); Sidebar = new Sidebar(this); MapUI = new MapUI(this); MapRenderer = MapRenderer.Create(this); EscapeMenu = new EscapeMenu(this); CharacterScreens = new CharacterScreens(this); GameEventHandler = new GameEventHandler(this); UpdateSidebarOption(Option.IsSet(BoolOptionType.SidebarOnRight)); UpdateMessagesOption(Option.IsSet(BoolOptionType.MessagesAtBottom)); }
public void CanCreateGameOfLifeUniverseWithInitialParameters() { //Setup const int _gridXAxisCount = 50; const int _gridYAxisCount = 50; var aliveCellPoints = new List <Point> { new Point(25, 25) }; //Act var gameUniverse = new GameUniverse(_gridXAxisCount, _gridYAxisCount, aliveCellPoints); //Assert Assert.AreEqual(gameUniverse.GridXAxisCount, _gridXAxisCount); Assert.AreEqual(gameUniverse.GridYAxisCount, _gridYAxisCount); Assert.AreEqual(gameUniverse.AliveCells.Count, 1); }
public void CanCreateNewGenerationForSingleAlivePoint() { //Setup const int _gridXAxisCount = 50; const int _gridYAxisCount = 50; var aliveCellPoints = new List <Point> { new Point(25, 25) }; IGenerationSrategy generationSrategy = new CandidateDictionaryGenerationStrategy(); var gameUniverse = new GameUniverse(_gridXAxisCount, _gridYAxisCount, aliveCellPoints); var gameController = new GameController(generationSrategy, gameUniverse); //Act var newGenerationAliveCellPoints = gameController.RunNewGeneration(); //Assert Assert.AreEqual(gameUniverse.GridXAxisCount, _gridXAxisCount); Assert.AreEqual(gameUniverse.GridYAxisCount, _gridYAxisCount); Assert.AreEqual(newGenerationAliveCellPoints.Count, 0); }
private static void RunGame(GameUniverse g) { GameRunUI gameUI = new GameRunUI(g); g.Q.BeforeEventExecute = gameUI.GameEventHandler.BeforeGameEvent; g.Q.AfterEventExecute = gameUI.GameEventHandler.AfterGameEvent; (g.Player.CancelDecider as PlayerCancelDecider).DecideCancel = gameUI.GameEventHandler.DecideCancel; g.CreatureRules.OnStatusStart = gameUI.GameEventHandler.OnStatusStart; g.CreatureRules.OnStatusEnd = gameUI.GameEventHandler.OnStatusEnd; //todo, try/catch? do I want a thing where I can get to the exceptions before they reach this point? g.Run(); if (g.GameOver) { //todo } else if (g.Suspend) { //todo } }
public void AliveCellWithTwoNeighboursSurvivesToNextGeneration() { //Setup const int _gridXAxisCount = 50; const int _gridYAxisCount = 50; //point [25,25] is the only one with two neighbours var aliveCellPoints = new List <Point> { new Point(25, 25), new Point(24, 26), new Point(26, 24) }; IGenerationSrategy generationSrategy = new CandidateDictionaryGenerationStrategy(); var gameUniverse = new GameUniverse(_gridXAxisCount, _gridYAxisCount, aliveCellPoints); var gameController = new GameController(generationSrategy, gameUniverse); //Act var newGenerationAliveCellPoints = gameController.RunNewGeneration(); //Assert Assert.AreEqual(gameUniverse.GridXAxisCount, _gridXAxisCount); Assert.AreEqual(gameUniverse.GridYAxisCount, _gridYAxisCount); Assert.AreEqual(newGenerationAliveCellPoints.Count, 1); Assert.IsTrue(newGenerationAliveCellPoints.Contains(new Point(25, 25))); }
public void AliveCellWithFourNeighboursIsKilledInNextGeneration() { //Setup const int _gridXAxisCount = 60; const int _gridYAxisCount = 70; //point [17,25] is the only one with four neighbours var aliveCellPoints = new List <Point> { new Point(18, 24), new Point(17, 25), new Point(16, 26), new Point(16, 24), new Point(17, 26) }; IGenerationSrategy generationSrategy = new CandidateDictionaryGenerationStrategy(); var gameUniverse = new GameUniverse(_gridXAxisCount, _gridYAxisCount, aliveCellPoints); var gameController = new GameController(generationSrategy, gameUniverse); //Act var newGenerationAliveCellPoints = gameController.RunNewGeneration(); //Assert Assert.AreEqual(gameUniverse.GridXAxisCount, _gridXAxisCount); Assert.AreEqual(gameUniverse.GridYAxisCount, _gridYAxisCount); Assert.AreEqual(newGenerationAliveCellPoints.Count, 4); Assert.IsFalse(newGenerationAliveCellPoints.Contains(new Point(17, 25))); }
private static void DrawGameUniverse(List <Point> aliveCells, GameUniverse gameUniverse) { for (int rowCount = 0; rowCount < gameUniverse.GridXAxisCount; ++rowCount) { for (int columnCount = 0; columnCount < gameUniverse.GridYAxisCount; ++columnCount) { if (aliveCells.Contains(new Point(rowCount + 1, columnCount + 1))) { _output.Write(_block); } else { _output.Write(_whiteSpace); } } if (rowCount != gameUniverse.GridYAxisCount - 1) { _output.Write(Environment.NewLine); } } _output.Flush(); }
public void TwoSetsOfAliveCellWithThreeNeighboursSurvivesToNextGeneration() { //Setup const int _gridXAxisCount = 60; const int _gridYAxisCount = 70; //point [6,25] and [11,24] are the only one with three neighbours var aliveCellPoints = new List <Point> { new Point(7, 24), new Point(6, 25), new Point(5, 26), new Point(10, 25), new Point(11, 24), new Point(12, 23) }; IGenerationSrategy generationSrategy = new CandidateDictionaryGenerationStrategy(); var gameUniverse = new GameUniverse(_gridXAxisCount, _gridYAxisCount, aliveCellPoints); var gameController = new GameController(generationSrategy, gameUniverse); //Act var newGenerationAliveCellPoints = gameController.RunNewGeneration(); //Assert Assert.AreEqual(gameUniverse.GridXAxisCount, _gridXAxisCount); Assert.AreEqual(gameUniverse.GridYAxisCount, _gridYAxisCount); Assert.AreEqual(newGenerationAliveCellPoints.Count, 2); Assert.IsTrue(newGenerationAliveCellPoints.Contains(new Point(6, 25))); Assert.IsTrue(newGenerationAliveCellPoints.Contains(new Point(11, 24))); }
private static void DrawSimulation(List <Point> aliveCells, GameUniverse gameUniverse) { InitializeCanvas(); DrawGameUniverse(aliveCells, gameUniverse); }