Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Bear {
- //toạ độ của gấu
- private int tileX, tileY;
- private int xPrevious, yPrevious;
- public Bear() {
- //khởi tạo toạ độ lần đầu, góc trên bên trái bản đồ
- tileX = 1;
- tileY = 1;
- }
- public void move(Direction direction) {
- int tx = 0;
- int ty = 0;
- switch (direction) {
- case UP:
- tx = 0;
- ty = -1;
- break;
- case DOWN:
- tx = 0;
- ty = 1;
- break;
- case LEFT:
- tx = -1;
- ty = 0;
- break;
- case RIGHT:
- tx = 1;
- ty = 0;
- break;
- }
- //thay đổi giá trị toạ độ dựa vào hướng di chuyển
- tileX += tx;
- tileY += ty;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement