Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make a simple game where a shape moves around the screen every x seconds (use a

ID: 3838684 • Letter: M

Question

Make a simple game where a shape moves around the screen every x seconds (use a Timer, try a few different numbers for x to see where it is challenging) and if the person can click the mouse in the shape before it moves again, they get a point. After 10 seconds, show them their score. Call the files ClickBaitRunner and ClickBaitComponent

Consider:
Don't let the rectangle go off the screen.
Check to see if they clicked the Rectangle, not the ClickBaitComponent.
Both the size of the box and the speed of the Timer will determine difficulty.

Explanation / Answer

//these set out the current position of your rectangle double recX, reYy, recH, recW; //this gives something to manage speed int speed; public void paintComponent(Graphics g) { g.drawRectangle(recX,rexY,recH,recW); } //here we work out the movement public void clickedScreen(double x, double y){ double newX = x; double newY = y; //calculate the speed to move at vX = newX - recX; vY = newY - recY; //get the distance length = Math.sqrt((v1*v1)+(v2*v2)); //make it a unit vector v1 = v1/length; v2 = v2/length; } public moveRec(){ recX = recX+(v1*speed); recY = recY+(v2*speed); } while(true) { moveRec(); repaint(); }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote