Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.concurrent.atomic.AtomicBoolean;
- public class MainClass {
- static void clear()
- {
- System.out.flush();
- }
- static String readMove()
- {
- System.out.println("Podaj regułe poruszania");
- Scanner read = new Scanner( System.in );
- String rule = read.nextLine();
- rule = rule.toUpperCase();
- return rule;
- }
- static boolean checkRule1( String rule )
- {
- for( char c : rule.toCharArray() )
- {
- if( c != 'U' && c != 'D' && c != 'L' && c != 'R')
- return false;
- }
- return true;
- }
- static boolean checkRule2( String rule )
- {
- String str = new String(rule);
- while( !str.isEmpty() )
- {
- int index = str.indexOf("UP");
- }
- return true;
- }
- static void makeMove( String rule , int[] coordinates )
- {
- int _x = 0;
- int _y = 0;
- for( char c : rule.toCharArray() )
- {
- if( c == 'U' ) _y++;
- else if( c == 'D' ) _y--;
- else if( c == 'L' ) _x--;
- else if( c == 'R' ) _x++;
- }
- coordinates[0] += _x;
- coordinates[1] += _y;
- }
- static void print( int[] coordinates )
- {
- System.out.println("(x,y) = (" + coordinates[0] + "," + coordinates[1] + ")" );
- }
- /**
- * program wyswietla współrzedne robota
- * @param args
- */
- public static void main(String[] args) {
- int[] coordinates = new int[2];
- coordinates[0] = 0;
- coordinates[1] = 0;
- print(coordinates);
- String rule = readMove();
- // while( !rule.equals("0") && !rule.equals("EXIT") )
- // {
- // if( !checkRule1(rule) )
- // {
- // System.out.println("Niepoprawna reguła");
- // return;
- // }
- //
- // makeMove(rule , coordinates );
- // print(coordinates);
- // rule = readMove();
- // }
- }
- }
Add Comment
Please, Sign In to add comment