Dzaco

KOLOS1.0

Mar 21st, 2019
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.concurrent.atomic.AtomicBoolean;
  3.  
  4. public class MainClass {
  5.  
  6.  
  7.     static void clear()
  8.     {
  9.         System.out.flush();
  10.     }
  11.  
  12.     static String readMove()
  13.     {
  14.         System.out.println("Podaj regułe poruszania");
  15.         Scanner read = new Scanner( System.in );
  16.         String rule = read.nextLine();
  17.         rule = rule.toUpperCase();
  18.         return rule;
  19.     }
  20.  
  21.     static boolean checkRule1( String rule )
  22.     {
  23.  
  24.         for( char c : rule.toCharArray() )
  25.         {
  26.             if( c != 'U' && c != 'D' && c != 'L' && c != 'R')
  27.                 return false;
  28.         }
  29.  
  30.         return true;
  31.     }
  32.  
  33.     static boolean checkRule2( String rule )
  34.     {
  35.  
  36.         String str = new String(rule);
  37.  
  38.         while( !str.isEmpty() )
  39.         {
  40.             int index = str.indexOf("UP");
  41.         }
  42.  
  43.         return true;
  44.     }
  45.  
  46.     static void makeMove( String rule , int[] coordinates )
  47.     {
  48.         int _x = 0;
  49.         int _y = 0;
  50.  
  51.         for( char c : rule.toCharArray() )
  52.         {
  53.                  if( c == 'U' ) _y++;
  54.             else if( c == 'D' ) _y--;
  55.             else if( c == 'L' ) _x--;
  56.             else if( c == 'R' ) _x++;
  57.         }
  58.  
  59.         coordinates[0] += _x;
  60.         coordinates[1] += _y;
  61.     }
  62.  
  63.     static void print( int[] coordinates )
  64.     {
  65.         System.out.println("(x,y) = (" + coordinates[0] + "," + coordinates[1] + ")" );
  66.     }
  67.  
  68.  
  69.     /**
  70.      * program wyswietla współrzedne robota
  71.      * @param args
  72.      */
  73.     public static void main(String[] args) {
  74.  
  75.         int[] coordinates = new int[2];
  76.         coordinates[0] = 0;
  77.         coordinates[1] = 0;
  78.  
  79.         print(coordinates);
  80.         String rule = readMove();
  81.  
  82. //        while( !rule.equals("0") && !rule.equals("EXIT") )
  83. //        {
  84. //            if( !checkRule1(rule) )
  85. //            {
  86. //                System.out.println("Niepoprawna reguła");
  87. //                return;
  88. //            }
  89. //
  90. //            makeMove(rule , coordinates );
  91. //            print(coordinates);
  92. //            rule = readMove();
  93. //        }
  94.  
  95.     }
  96. }
Add Comment
Please, Sign In to add comment