im trying to build a game of monopoly i have a problem with moving the players on board the func that calls for the playermover that has the timer continues before timer has a chance to end unless i put a message box that waits for user input....i tried thread.sleep(); but it wont work with it...
Code://call for playerMover class playerMover.movePlayer(steps, DataBase.players[currentPlayerIndexInArr], currentPlayerIndexInArr,waiting);Code:public void movePlayer( int steps,Player pl, int playersIndexInArr,toWait waiting) { toWait Waiting=waiting; currentPlayer = pl; setIndex(currentPlayer.getIndex()); setSteps(steps);//why need this? setCurrentPlayerIndexInArr(playersIndexInArr);//this too counter = 0; Timer timer = new Timer(); timer.Start(); timer.Interval = 500; timer2 = timer; timer.Tick+=new EventHandler(timer_Tick); // with this box it works like it should MessageBox.Show(" "); } private void timer_Tick(object sender, EventArgs e) { if (counter < steps) { if (indexInLocationsArr == DataBase.pointsArr.Length - 1) indexInLocationsArr = 0; else indexInLocationsArr++; board.setLocationToPlayerButton(DataBase.pointsArr[indexInLocationsArr], currentPlayerIndexInArr); currentPlayer.setIndex(indexInLocationsArr); if (indexInLocationsArr == 0) { //getSalary function MessageBox.Show(currentPlayer.getName() + " get salary 200$"); currentPlayer.addCash(DataBase.salary); } counter++; } timer2.Stop(); }




Reply With Quote