Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. public class Main{
  2. public static void main(String[] args){
  3. MovementLoop();
  4. }
  5. public static void MovementLoop(){
  6.  
  7. Scanner input = new Scanner(System.in);
  8.  
  9. int pos=10, linepos=2;
  10. String keypressed;
  11. boolean playing = true;
  12.  
  13. while(playing == true){
  14. display dObj = new display(linepos, pos);
  15. dObj.drawImage();
  16. keypressed=input.nextLine();
  17. if(keypressed.equals("w")){
  18. linepos -= 1;
  19. }
  20. else if(keypressed.equals("s")){
  21. linepos += 1;
  22. }
  23. else if(keypressed.equals("a")){
  24. pos -= 1;
  25. }
  26. else if(keypressed.equals("d")){
  27. pos += 1;
  28. }
  29. else if(keypressed.equals("q")){
  30. System.out.println("You have quit the game.");
  31. playing = false;
  32. }
  33. else{
  34. System.out.println("nplease use w a s dn");
  35. }
  36. }
  37. }
  38. }
  39.  
  40. public class display{
  41.  
  42. private String lines[][] = new String[4][20];
  43. private String hWalls = "+--------------------+";
  44. private String vWalls = "|";
  45. private int linepos, pos;
  46.  
  47.  
  48. public display(int linepos1, int pos1){
  49. pos = pos1 - 1;
  50. linepos = linepos1 - 1;
  51. }
  52. public void drawImage(){
  53.  
  54. for(int x1=0;x1<lines.length;x1++){
  55. for(int x2=0;x2<lines[x1].length;x2++){
  56. lines[x1][x2]="#";
  57. }
  58. }
  59. lines[linepos][pos]="O";
  60.  
  61. System.out.println(hWalls);
  62. for(int x2=0;x2<lines.length;x2++){
  63. System.out.print(vWalls);
  64. for(int x3=0;x3<lines[x2].length;x3++){
  65. System.out.print(lines[x2][x3]);
  66. }
  67. System.out.println(vWalls);
  68. }
  69. System.out.println(hWalls);
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement