Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char[][] tab = {
- {'o','-','-','-','-','-','-','-','-','-','-'},
- {'x','x','x','x','x','x','x','x','x','x','-'},
- {'-','-','-','-','-','-','-','-','-','x','-'},
- {'-','x','x','x','x','x','x','x','-','x','-'},
- {'-','x','e','-','-','-','-','-','-','x','-'},
- {'-','x','x','x','x','x','x','x','x','x','-'},
- {'-','-','-','-','-','-','-','-','-','-','-'}
- };
- int pozycjaX = 0;
- int pozycjaY = 0;
- boolean work = true;
- boolean horizontal = true;
- int way = 1;
- while(work) {
- if(horizontal) {
- while(((way == 1 && pozycjaX != (tab[pozycjaY].length - 1)) || (way == -1 && pozycjaX != 0)) && tab[pozycjaY][pozycjaX + way] != 'x')
- pozycjaX += way;
- horizontal = false;
- } else {
- while(((way == 1 && pozycjaY != (tab.length - 1)) || (way == -1 && pozycjaY != 0)) && tab[pozycjaY + way][pozycjaX] != 'x')
- pozycjaY += way;
- horizontal = true;
- way *= -1;
- }
- work = (tab[pozycjaY][pozycjaX] == 'e') ? false : true;
- }
- System.out.println("Done");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement