dimanche 8 mai 2022

how to make a magic chest in the game with c# windows form

i am making item drop game and i am trying to make a magic chest ,When the chest comes down and touches the player, there are two random possibilities, either a loss or an advantage in the score. i wrote the code like this but the game never started after that . the cest has to go down every 10 sec ( i made another objects going down and it worked but the chest did not so i think the problem in the code of random )


     foreach (Control X in this.Controls)
            {
 while (X.Tag == "kah" && player.Bounds.IntersectsWith(chest.Bounds)){
                 chest.Top = -600;

                        Index = magicchest.Next(0, 2);
                        if (Index == 0) { score -= 3; }
                        else { score += 3; }
                        while (seconds % 10 == 0)
                        {
                            chest.Left = rnd2.Next(213, this.ClientSize.Width - chest.Width);
                            chest.Top = rnd2.Next(0, 700) * -1;
                            chest.Top += compspeed;
                        }

                    }
}




     private void resetGame()
        {
timer1.Start();
            gametime.Start()
            do
            {
                chest.Left = rnd.Next(23, this.ClientSize.Width -chest.Width);
                chest.Top = rnd.Next(0, 670) * -1;

            }

            while (seconds % 10 == 0);

            chest.Top += compspeed;
}




Aucun commentaire:

Enregistrer un commentaire