Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. char[][] tab = {
  2. {'o','-','-','-','-','-','-','-','-','-','-'},
  3. {'x','x','x','x','x','x','x','x','x','x','-'},
  4. {'-','-','-','-','-','-','-','-','-','x','-'},
  5. {'-','x','x','x','x','x','x','x','-','x','-'},
  6. {'-','x','e','-','-','-','-','-','-','x','-'},
  7. {'-','x','x','x','x','x','x','x','x','x','-'},
  8. {'-','-','-','-','-','-','-','-','-','-','-'}
  9. };
  10.  
  11. int pozycjaX = 0;
  12. int pozycjaY = 0;
  13. boolean work = true;
  14. boolean horizontal = true;
  15. int way = 1;
  16.  
  17. while(work) {
  18. if(horizontal) {
  19. while(((way == 1 && pozycjaX != (tab[pozycjaY].length - 1)) || (way == -1 && pozycjaX != 0)) && tab[pozycjaY][pozycjaX + way] != 'x')
  20. pozycjaX += way;
  21. horizontal = false;
  22. } else {
  23. while(((way == 1 && pozycjaY != (tab.length - 1)) || (way == -1 && pozycjaY != 0)) && tab[pozycjaY + way][pozycjaX] != 'x')
  24. pozycjaY += way;
  25. horizontal = true;
  26. way *= -1;
  27. }
  28. work = (tab[pozycjaY][pozycjaX] == 'e') ? false : true;
  29. }
  30.  
  31. System.out.println("Done");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement