![]() If you create 10 Random instances at the same millisecond they are probably all going to return the same values (they will all have the same "seed").Once the Key falls out, you can collect it. Random is only "random" enough if you keep calling next in the same instance. you should create only one and reuse it all the time. and then you could have lists of the appropriate types (a List or List).Įdit: Also, you shouldn't create a new Random instance at every StrikeSpan. The thing is, each class would know how to create the appropriate control, and how to deal with its animation. and if needed, these classes would create the atual controls (it is possible to do something similar to WPF's DataTemplates even in windows forms, but I wouldn't go that far). so, for this particular case, just avoiding the casts and putting the objects in appropriate lists should do the job.īut if we are to talk about "system design" you probably will want to have different classes for the different elements of the game (for example the PlayerCharacter, the Shot and the Alien class). The answer for this question can be quite complex. If (ctrl is PictureBox & ctrl.Name = " Alien") If (ct is PictureBox & ct.Name = " Laser") ![]() If (c is PictureBox & c.Name = " Bullet") Private void FireBullet( object sender, EventArgs e) Timer also checks if the bullet left the screen in which case it gets removed, or if it collided with some of the lasers. So when they reach the edge of the same side I destroyed the aliens from before, there won't be an empty space between aliens and the screen, and the sprites will change the direction correctly. Once they switched direction, I call Observer timer which then removes all the aliens from the aliens list and clear the delay list. I solved that problem by creating an additional global list called delay and a timer called Observer, so when I destroy aliens when they touched the edge, the bullet and alien controls are being removed, and instead of deleting the picture from the list aliens (from which they are moving on the screen), I add all destroyed pictures to delay list first so they still exist in aliens list to be able to switch direction. While testing the code, I figured out that when the aliens touch the edge of the screen and I destroy them, the condition from procedure SetDirection returns false and the procedure fails to switch direction properly, as there are no more aliens touching the edge, so they would just keep moving down which presents the logical issue. If ((alien.Bounds) & !Touched(alien))Įlse if ((alien.Bounds) & Touched(alien)) If everything is ok, the procedure which creates bullet sprite called Missile() is called: If the player pressed space to fire, the value fired is going to get set to true to prevent continuous firing when the button is pressed, and there is additional check if the value game is set to true checking if the game is still active. Private void PlayerMove( object sender, EventArgs e)Įlse if (moveRight & <= limit) ![]() Private void Released( object sender, KeyEventArgs e) If (e.Ke圜ode = Keys.A || e.Ke圜ode = Keys.Left)Įlse if (e.Ke圜ode = Keys.D || e.Ke圜ode = Keys.Right)Įlse if (e.Ke圜ode = Keys.Space & game & !fired) ![]() Private void Pressed( object sender, KeyEventArgs e) ![]()
0 Comments
Leave a Reply. |