for loop for the update method and paint method

will reduce the code length and complexity