private void StartGameLoop() { bool needToRender = true; do { // isvalom ekrana Console.Clear(); while (Console.KeyAvailable) { ConsoleKeyInfo pressedChar = Console.ReadKey(true); int hashCode = pressedChar.Key.GetHashCode(); switch (pressedChar.Key) { case ConsoleKey.Escape: needToRender = false; break; case ConsoleKey.RightArrow: myGame.MoveHeroRight(); break; case ConsoleKey.LeftArrow: myGame.MoveHeroLeft(); break; } } myGame.Render(); // padarom pause. (parodom ekrana). System.Threading.Thread.Sleep(50); } while (needToRender); }
public void StartGame() { bool needToRender = true; GameScreen myGame = new GameScreen(80, 80); Hero hero = new Hero(10, 10, "Herojus"); myGame.SetHero(hero); int enemyCount = 0; Random rnd = new Random(); List <Enemy> enemiesList = new List <Enemy>(); for (int i = 0; i < 10; i++) { myGame.AddEnemy(new Enemy(enemyCount, rnd.Next(0, 10), rnd.Next(0, 10), "enemy" + enemyCount)); enemyCount++; } myGame.Render(); myGame.GetHero().MoveRight(); myGame.MoveAllEnemiesDown(); Enemy secondEnemy = myGame.GetEnemyById(1); if (secondEnemy != null) { secondEnemy.MoveDown(); } myGame.Render(); do { Console.Clear(); while (Console.KeyAvailable) { ConsoleKeyInfo pressedChar = Console.ReadKey(true); switch (pressedChar.Key) { case ConsoleKey.Escape: needToRender = false; GuiController gui = new GuiController(); gui.ShowMenu(); break; case ConsoleKey.RightArrow: hero.MoveRight(); break; case ConsoleKey.LeftArrow: hero.MoveLeft(); break; } } myGame.Render(); System.Threading.Thread.Sleep(250); } while (needToRender); }