Advertisement
pastetumlum

bear1

Jul 16th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public class Bear {
  2.     //toạ độ của gấu
  3.     private int tileX, tileY;
  4.     private int xPrevious, yPrevious;
  5.  
  6.     public Bear() {
  7.         //khởi tạo toạ độ lần đầu, góc trên bên trái bản đồ
  8.         tileX = 1;
  9.         tileY = 1;
  10.  
  11.     }
  12.  
  13.     public void move(Direction direction) {
  14.         int tx = 0;
  15.         int ty = 0;
  16.         switch (direction) {
  17.         case UP:
  18.             tx = 0;
  19.             ty = -1;
  20.             break;
  21.         case DOWN:
  22.             tx = 0;
  23.             ty = 1;
  24.             break;
  25.         case LEFT:
  26.             tx = -1;
  27.             ty = 0;
  28.             break;
  29.         case RIGHT:
  30.             tx = 1;
  31.             ty = 0;
  32.             break;
  33.         }
  34.         //thay đổi giá trị toạ độ dựa vào hướng di chuyển
  35.         tileX += tx;
  36.         tileY += ty;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement