diff --git a/MoveTheSquare/src/edu/ycp/cs320/movethesquare/controllers/GameController.java b/MoveTheSquare/src/edu/ycp/cs320/movethesquare/controllers/GameController.java deleted file mode 100644 index 9c20be9..0000000 --- a/MoveTheSquare/src/edu/ycp/cs320/movethesquare/controllers/GameController.java +++ /dev/null @@ -1,33 +0,0 @@ -package edu.ycp.cs320.movethesquare.controllers; - -import edu.ycp.cs320.movethesquare.model.Game; -import edu.ycp.cs320.movethesquare.model.Square; - -public class GameController { - public void computeSquareMoveDirection(Game game, Square square, double mouseX, double mouseY) { - if (mouseX >= 0 && mouseX < game.getWidth() && mouseY >= 0 && mouseY < game.getHeight()) { - double dx = mouseX - (square.getX() + square.getWidth()/2); - double dy = mouseY - (square.getY() + square.getHeight()/2); - - double moveX = 0, moveY = 0; - if (dx > 0) { - moveX = Game.MOVE_DIST; - } else { - moveX = -Game.MOVE_DIST; - } - if (dy > 0) { - moveY = Game.MOVE_DIST; - } else { - moveY = -Game.MOVE_DIST; - } - - game.setSquareDx(moveX); - game.setSquareDy(moveY); - } - } - - public void moveSquare(Game model, Square square) { - square.setX(square.getX() + model.getSquareDx()); - square.setY(square.getY() + model.getSquareDy()); - } -} diff --git a/MoveTheSquare/src/edu/ycp/cs320/movethesquare/controllers/GameController.py b/MoveTheSquare/src/edu/ycp/cs320/movethesquare/controllers/GameController.py new file mode 100644 index 0000000..4e9b039 --- /dev/null +++ b/MoveTheSquare/src/edu/ycp/cs320/movethesquare/controllers/GameController.py @@ -0,0 +1,38 @@ +import edu.ycp.cs320.movethesquare.model.Game; +import edu.ycp.cs320.movethesquare.model.Square; + + +class GameController: + def __init__(self, game, square, mouseX, mouseY): + game = game + square = square + mouseX = mouseX + mouseY = mouseY + self.control_game() + + def control_game(): + if mouseX >= 0 and mouseX < game.getWidth() and mouseY >= 0 and mouseY < game.getHeight(): + dx = mouseX - (square.getX() + square.getWidth()/2); + dy = mouseY - (square.getY() + square.getHeight()/2); + + moveX = 0 + moveY = 0 + if dx > 0: + moveX = Game.MOVE_DIST; + else: + moveX = -Game.MOVE_DIST; + if dy > 0: + moveY = Game.MOVE_DIST; + else: + moveY = -Game.MOVE_DIST; + + game.setSquareDx(moveX); + game.setSquareDy(moveY); + + + def moveSquare(Game model, Square square): + square.setX(square.getX() + model.getSquareDx()) + square.setY(square.getY() + model.getSquareDy()) + + +