Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
  2. import java.awt.Color;
  3.  
  4. /**
  5. * Write a description of class R here.
  6. *
  7. * @author (your name)
  8. * @version (a version number or a date)
  9. */
  10. public class Room extends Actor {
  11.  
  12. static int count = 0;
  13.  
  14. public static final int N=0, E=1, S=2, W=3;
  15. int myNr;
  16. String[] vecini;
  17.  
  18. public Room(){
  19. super();
  20. vecini = new String[4];
  21. myNr = count++;
  22. updateImage(myNr);
  23. }
  24. public void setWall(int dir){
  25. vecini[dir] = "W";
  26. if (dir == W) updateW();
  27. if (dir == N) updateN();
  28. if(dir == S) updateS();
  29. if(dir == E) updateE();
  30. }
  31. /**
  32. * Act - do whatever the R wants to do. This method is called whenever
  33. * the 'Act' or 'Run' button gets pressed in the environment.
  34. */
  35. public void act()
  36. {
  37. // Add your action code here.
  38. }
  39.  
  40. private void updateImage(int n)
  41. {
  42. GreenfootImage img = new GreenfootImage(50,50);
  43. img.setColor(Color.GRAY);
  44. img.fill();
  45. img.setColor(Color.RED);
  46. img.drawString(Integer.toString(n),10,15);
  47. setImage(img);
  48. }
  49.  
  50. private void updateW()
  51. {
  52. GreenfootImage img = getImage();
  53. img.drawLine(1,49,1,1);
  54. setImage(img);
  55. }
  56.  
  57. private void updateN()
  58. {
  59. GreenfootImage img = getImage();
  60. img.drawLine(49,1,1,1);
  61. setImage(img);
  62. }
  63.  
  64. private void updateE()
  65. {
  66. GreenfootImage img = getImage();
  67. img.drawLine(49,49,49,1);
  68. setImage(img);
  69. }
  70. private void updateS()
  71. {
  72. GreenfootImage img = getImage();
  73. img.drawLine(1,49,49,49);
  74. setImage(img);
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement