Пример #1
0
        public void GameProcess(LodeRunner GameForm, string name)
        {
            Panel MainPanel = new Panel()
            {
                Size      = new Size(1100, 650),
                Location  = new Point(20, 70),
                BackColor = Color.Blue
            };
            GameField GameField1 = new GameField();

            GameForm.Controls.Add(MainPanel);
            Player.AmountOfSteps = 0;
            Gold.SetGoldCount();
            GameField.TeleportCoords.Clear();
            Player.SetPrivateFields();
            SecondPlayer.SetSecondPrev();
            GameField1.GenerateField(MainPanel, name);
            Player.SetThreadFlag(true);
            GameCell[,] field = GameField1.curField;
            Gold.GetAmount(GameForm);
            GameForm.KeyUp += new KeyEventHandler(Key);
            void Key(object sender, KeyEventArgs e)
            {
                if (GameCell.FindPosition(field, "SecondPlayer")[0] != 0)
                {
                    SecondPlayer.MoveSecondHero(e, field, GameField1.curPics, MainPanel);
                    new Thread(() => Fall("SecondPlayer", new SecondPlayer())).Start();
                }
                if (_fallingDown == false)
                {
                    Player.MoveHero(e, field, GameField1.curPics, MainPanel);
                }
                Gold.GetAmount(GameForm);
                new Thread(() => Fall("Player", new Player())).Start();
                void Fall(string type, Player person)
                {
                    int[] coords = GameCell.FindPosition(field, type);
                    int   i      = coords[0];
                    int   j      = coords[1];

                    while (field[i + 1, j].Type == "FreeArea" || field[i + 1, j].Type == "Destructed" || field[i + 1, j].Type == "Gold")
                    {
                        _fallingDown = true;
                        Thread.Sleep(250);
                        Player.Falling(field, GameField1.curPics, i, j, person, MainPanel);
                        i++;
                    }
                    _fallingDown = false;
                }
            }

            if (GameCell.FindPosition(field, "SimpleEnemy")[0] != 0 && GameCell.FindPosition(field, "SimpleEnemy")[1] != 0)
            {
                SimpleEnemy.SetSimplePrev();
                new Thread(() => SimpleEnemy.ForThread(field, GameField1.curPics, MainPanel)).Start();
            }
            if (GameCell.FindPosition(field, "BlindEnemy")[0] != 0 && GameCell.FindPosition(field, "BlindEnemy")[1] != 0)
            {
                BlindEnemy.SetPrevBlind();
                new Thread(() => BlindEnemy.SimpleMovement(field, GameField1.curPics, "BlindEnemy", MainPanel)).Start();
            }
            if (GameCell.FindPosition(field, "Coin")[0] != 0 && GameCell.FindPosition(field, "Coin")[1] != 0)
            {
                Coin.SetPrevCoin();
                new Thread(() => Coin.ForThread(field, GameField1.curPics, MainPanel)).Start();
            }
        }
Пример #2
0
 public static void SimpleMovement(GameCell[,] gameField, PictureBox[,] pictureField, string type, Panel MainPanel)
 {
     while (ThreadFlag)
     {
         int[] enemyCoords  = FindPosition(gameField, "BlindEnemy");
         int[] playerCoords = FindPosition(gameField, "Player");
         if (gameField[enemyCoords[0], enemyCoords[1] + 1].Type == "Ground" &&
             gameField[enemyCoords[0], enemyCoords[1] - 1].Type == "Ground")
         {
             return;
         }
         if (gameField[enemyCoords[0], enemyCoords[1] - 1].Type == "RopeTrap")
         {
             Die(gameField, pictureField, enemyCoords[0], enemyCoords[1], -1, MainPanel);
             return;
         }
         if (gameField[enemyCoords[0], enemyCoords[1] + 1].Type == "RopeTrap")
         {
             Die(gameField, pictureField, enemyCoords[0], enemyCoords[1], 1, MainPanel);
             return;
         }
         if (gameField[enemyCoords[0] + 1, enemyCoords[1]].Type == "Destructed")
         {
             SkipElements(gameField, pictureField, enemyCoords[0], enemyCoords[1], 0, 1, MainPanel);
             _prevBlindEnemy = new FreeArea();
             continue;
         }
         if (GameField.GetRecover() < 6 && gameField[enemyCoords[0], enemyCoords[1] + 1].Type == "Ground" && gameField[enemyCoords[0], enemyCoords[1] - 1].Type == "Ground")
         {
             Thread.Sleep(300);
             if (enemyCoords[1] > playerCoords[1])
             {
                 SkipElements(gameField, pictureField, enemyCoords[0], enemyCoords[1], 1, -1, MainPanel);
             }
             else
             {
                 SkipElements(gameField, pictureField, enemyCoords[0], enemyCoords[1], -1, -1, MainPanel);
             }
             continue;
         }
         if (enemyCoords[0] != playerCoords[0])
         {
             SimpleMovement(gameField, pictureField, "BlindEnemy", Func, MainPanel);
             Thread.Sleep(400);
         }
         else if (enemyCoords[0] == playerCoords[0] && enemyCoords[1] < playerCoords[1])
         {
             UsePlayersItems(gameField, pictureField, enemyCoords[0], enemyCoords[1], 1, MainPanel);
             SkipElements(gameField, pictureField, enemyCoords[0], enemyCoords[1], 1, 0, MainPanel);
             Thread.Sleep(200);
         }
         else if (enemyCoords[0] == playerCoords[0] && enemyCoords[1] > playerCoords[1])
         {
             UsePlayersItems(gameField, pictureField, enemyCoords[0], enemyCoords[1], 1, MainPanel);
             SkipElements(gameField, pictureField, enemyCoords[0], enemyCoords[1], -1, 0, MainPanel);
             Thread.Sleep(200);
         }
         if (FindPosition(gameField, "Player")[0] != 0)
         {
             continue;
         }
         Killed = true;
         break;
     }
 }