Пример #1
0
        public void Run()
        {
            char[] stoneSymbols = {(char)StoneForm.Ampersand,(char)StoneForm.AT,(char) StoneForm.House, (char) StoneForm.Dollar,
                                  (char) StoneForm.Number, (char) StoneForm.Percent, (char) StoneForm.Section, (char) StoneForm.Increment };
            Random randomGenerator = new Random(Guid.NewGuid().GetHashCode());
            //Random stonePositiongenerator = new Random();
            //Random lifeStonePositionGenerator = new Random(Guid.NewGuid().GetHashCode());
            while (true)
            {
                gameRound++;

                this.userInterface.ProcessInput();

                if (gameRound % 20 == 0)
                {
                    Position lifeStoneStart = new Position(0, randomGenerator.Next(0, 60));
                    LifeStone lifeStone = new LifeStone(lifeStoneStart);
                    lifeStoneStart.Col = randomGenerator.Next(0, 60);
                    IndestructibleStone indestructStone = new IndestructibleStone(lifeStoneStart);
                    this.AddObject(indestructStone);
                    this.AddObject(lifeStone);
                }

                if (gameRound % 2 == 0)
                {
                    Position stoneStartPos = new Position(0, randomGenerator.Next(0, 60));
                    Stone stone = new Stone(stoneStartPos,
                    new char[,] { { stoneSymbols[randomGenerator.Next(0, 8)] } });
                    this.AddObject(stone);
                }

                for (int i = 0; i < this.allObjects.Count; i++)
                {
                    this.drawer.EnqueObject(allObjects[i]);
                }

                Lives();

                Thread.Sleep(gameSpeed);

                if (this.battleShip.IsDestroyed == true)
                {
                    this.drawer.Render();
                    //Console.SetCursorPosition((Console.WindowWidth / 2) - 6, Console.WindowHeight / 2);
                    //Console.ForegroundColor = ConsoleColor.Red;
                    //Console.WriteLine("GAME OVER");
                    GameOver.PrintGameOver();
                    //Console.CursorVisible = false;
                    //Console.ResetColor(); 
                    //Console.ReadKey();
                    break;
                }
                
                for (int i = 0; i < this.allStones.Count; i++)
                {
                    if (this.allStones[i].GetPosition.Row == Console.WindowHeight - 1)
                    {
                        this.allStones[i].IsDestroyed = true;
                        this.allStones.Remove(this.allStones[i]);
                    }
                }
                for (int i = 0; i < this.allBullets.Count; i++)
                {
                    if (this.allBullets[i].GetPosition.Row == 0)
                    {
                        this.allBullets[i].IsDestroyed = true;
                        this.allBullets.RemoveAt(i);
                    }
                }

                for (int i = 0; i < this.allObjects.Count; i++)
                {
                    this.allObjects[i].Move();
                    Collisions.CollisionsCheck(this.allStones, this.allBullets, this.battleShip);
                    this.allObjects.RemoveAll(x => x.IsDestroyed == true && x is DynamicObject);
                    this.allStones.RemoveAll(x => x.IsDestroyed == true);
                    this.allBullets.RemoveAll(x => x.IsDestroyed == true);
                }

                //this.allObjects.RemoveAll(x => x.IsDestroyed == true && x is DynamicObject);
                //this.allStones.RemoveAll(x => x.IsDestroyed == true);

                this.drawer.Render();
                this.drawer.ClearObjectsMatrix();

            }
        }
Пример #2
0
        public void Run()
        {
            char[] stoneSymbols = { (char)StoneForm.Ampersand, (char)StoneForm.AT,      (char)StoneForm.House,   (char)StoneForm.Dollar,
                                    (char)StoneForm.Number,    (char)StoneForm.Percent, (char)StoneForm.Section, (char)StoneForm.Increment };
            Random randomGenerator = new Random(Guid.NewGuid().GetHashCode());

            //Random stonePositiongenerator = new Random();
            //Random lifeStonePositionGenerator = new Random(Guid.NewGuid().GetHashCode());
            while (true)
            {
                gameRound++;

                this.userInterface.ProcessInput();

                if (gameRound % 20 == 0)
                {
                    Position  lifeStoneStart = new Position(0, randomGenerator.Next(0, 60));
                    LifeStone lifeStone      = new LifeStone(lifeStoneStart);
                    lifeStoneStart.Col = randomGenerator.Next(0, 60);
                    IndestructibleStone indestructStone = new IndestructibleStone(lifeStoneStart);
                    this.AddObject(indestructStone);
                    this.AddObject(lifeStone);
                }

                if (gameRound % 2 == 0)
                {
                    Position stoneStartPos = new Position(0, randomGenerator.Next(0, 60));
                    Stone    stone         = new Stone(stoneStartPos,
                                                       new char[, ] {
                        { stoneSymbols[randomGenerator.Next(0, 8)] }
                    });
                    this.AddObject(stone);
                }

                for (int i = 0; i < this.allObjects.Count; i++)
                {
                    this.drawer.EnqueObject(allObjects[i]);
                }

                Lives();

                Thread.Sleep(gameSpeed);

                if (this.battleShip.IsDestroyed == true)
                {
                    this.drawer.Render();
                    //Console.SetCursorPosition((Console.WindowWidth / 2) - 6, Console.WindowHeight / 2);
                    //Console.ForegroundColor = ConsoleColor.Red;
                    //Console.WriteLine("GAME OVER");
                    //GameOver.PrintGameOver();
                    //Console.CursorVisible = false;
                    //Console.ResetColor();
                    //Console.ReadKey();
                    break;
                }

                for (int i = 0; i < this.allStones.Count; i++)
                {
                    if (this.allStones[i].GetPosition.Row == Console.WindowHeight - 1)
                    {
                        this.allStones[i].IsDestroyed = true;
                        this.allStones.Remove(this.allStones[i]);
                    }
                }
                for (int i = 0; i < this.allBullets.Count; i++)
                {
                    if (this.allBullets[i].GetPosition.Row == 0)
                    {
                        this.allBullets[i].IsDestroyed = true;
                        this.allBullets.RemoveAt(i);
                    }
                }

                for (int i = 0; i < this.allObjects.Count; i++)
                {
                    this.allObjects[i].Move();
                    Collisions.CollisionsCheck(this.allStones, this.allBullets, this.battleShip);
                    this.allObjects.RemoveAll(x => x.IsDestroyed == true && x is DynamicObject);
                    this.allStones.RemoveAll(x => x.IsDestroyed == true);
                    this.allBullets.RemoveAll(x => x.IsDestroyed == true);
                }

                //this.allObjects.RemoveAll(x => x.IsDestroyed == true && x is DynamicObject);
                //this.allStones.RemoveAll(x => x.IsDestroyed == true);

                this.drawer.Render();
                this.drawer.ClearObjectsMatrix();
            }
        }