c# - While loop not working as intended in Pong game -


i attempting create pong game in c# visual c# express 2010. part, have main idea of game finished, have issue ball moving. have create loop, this:

public void ballset() {     if (!values.ispaused)     {         while(true)         {             if (values.totaltime.elapsed.seconds > 1)             {                 values.totaltime.restart();                 ballmove(50, 50);             }         }     } }  public void ballmove(int factorx, int factory) {     values.balllastx = ball.location.x;     values.balllasty = ball.location.y;       this.ball.location = new point(this.ball.location.x + factorx, this.ball.location.y + factory); } 

the "ballmove(50, 50);" testing purposes @ moment. issue when ballset() called, form seems close code of 0, meaning there no error. call ballset() on here.

public pong() {     initializecomponent();     ballset();     values.totaltime.start(); } 

i have checked , program work when remove while loop in ballset(), if statement checking stopwatch (values.totaltime stopwatch). since while loop commented out, ballmove() called once, , the ball moves once , stops.

does know how fix this? want ball moving constantly, while still having possible perform other tasks such moving bat in pong.

this output can give while running pong.

http://pastebin.com/nj1pdg3u

from looking @ code, while loop never end. know that's not reported behaviour, try swapping ballset() , values.totaltime.start(); around.

like so:

 values.totaltime.start();  ballset(); 

this because (in theory) call ballset() wait return, , totaltime counter never start, therefore never entering if block in loop.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -