From f24706daf19b8b98a2ee7359688be27094a9bd75 Mon Sep 17 00:00:00 2001 From: Jean Luo <luoj3@mcmaster.ca> Date: Wed, 16 Nov 2016 20:43:55 -0500 Subject: [PATCH] bug fixed for the ball not hitting the paddles --- Game_Code/src/model/Player.java | 4 ++++ Game_Code/src/startGame/GameController.java | 14 +++++--------- Game_Code/src/view/GameView.java | 3 +++ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Game_Code/src/model/Player.java b/Game_Code/src/model/Player.java index 740c7eb..95a7a68 100644 --- a/Game_Code/src/model/Player.java +++ b/Game_Code/src/model/Player.java @@ -56,4 +56,8 @@ public class Player { if(score==NOLIFE){ return true;} else{ return false; } } + + public void resetScore(){ + score = LIFE; + } } diff --git a/Game_Code/src/startGame/GameController.java b/Game_Code/src/startGame/GameController.java index d36c0a9..e05f3b0 100644 --- a/Game_Code/src/startGame/GameController.java +++ b/Game_Code/src/startGame/GameController.java @@ -388,13 +388,13 @@ public class GameController{ gameDisplay.setBottomScore(scoreBottom); ai.decrementLife(); - } else if(ballY+2.5*ballSize>frameHeight-inset-2*padHeight && velY > 0 && ballX + ballSize >= bottomPadX && ballX <= bottomPadX + padWidth){ + } else if(ballY+2.5*ballSize>frameHeight-inset-padHeight && velY > 0 && ballX + ballSize >= bottomPadX && ballX <= bottomPadX + padWidth){ /** * If the ball is touching the bottom paddle * - reverse the direction */ velY = -velY; - } else if(ballY<=inset+2*padHeight && velY < 0 && ballX + ballSize >= topPadX && ballX <= topPadX + padWidth){ + } else if(ballY<=inset+padHeight && velY < 0 && ballX + ballSize >= topPadX && ballX <= topPadX + padWidth){ /** * If the ball is touching the top paddle * - reverse the direction @@ -594,16 +594,12 @@ public class GameController{ endTime = System.currentTimeMillis(); timeElapsed = (endTime-startTime)/1000.0; - System.out.println(timeElapsed); +System.out.println(timeElapsed); } private void resetGame(){ - scoreTop = 0; - scoreBottom = 0; - - - - + player.resetScore(); + ai.resetScore(); } diff --git a/Game_Code/src/view/GameView.java b/Game_Code/src/view/GameView.java index f3d47aa..6381021 100644 --- a/Game_Code/src/view/GameView.java +++ b/Game_Code/src/view/GameView.java @@ -96,6 +96,9 @@ public class GameView{ public void createGame(){ gameFrame = new JFrame("FaultInOurPong"); gameFrame.setContentPane(ponggame); + + + gameFrame.setSize(FRAMEWIDTH,FRAMEHEIGHT); gameFrame.setResizable(false); gameFrame.setLocationRelativeTo(null); -- GitLab