Advertisement
purshink

Re-Volt

Jun 13th, 2020
1,156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.07 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.sql.SQLOutput;
  5. import java.util.*;
  6.  
  7. public class Main {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  10.         int N = Integer.parseInt(bf.readLine());
  11.         String[][] matrix = new String[N][N];
  12.         int n = Integer.parseInt(bf.readLine());
  13.         int startRow = 0;
  14.         int startCol = 0;
  15.  
  16.         boolean hasWon = false;
  17.  
  18.         for (int i = 0; i < matrix.length ; i++) {
  19.             String[] rows = bf.readLine().split("");
  20.             for (int j = 0; j < matrix[i].length; j++) {
  21.                 matrix[i][j] = rows[j];
  22.  
  23.                 if (matrix[i][j].equals("f")){
  24.                   startRow = i;
  25.                  startCol = j;
  26.                 }
  27.             }
  28.         }
  29.         matrix[startRow][startCol] = "-";
  30.         String command = bf.readLine();
  31.  
  32.         for (int i = 0; i < n ; i++) {
  33.             int preciousRow = startRow;
  34.             int previousCol = startCol;
  35.             String field;
  36.  
  37.  
  38.             switch (command) {
  39.                 case "up":
  40.                  startRow--;
  41.                   if (startRow < 0){
  42.                       startRow = matrix.length-1;
  43.                   }
  44.  
  45.                     break;
  46.                 case "down":
  47.                  startRow++;
  48.                  if (startRow > matrix.length-1){
  49.                      startRow = 0;
  50.                  }
  51.                     break;
  52.  
  53.                 case "left":
  54.                   startCol--;
  55.                     if (startCol < 0){
  56.                         startCol = matrix.length -1;
  57.                     }
  58.                     break;
  59.  
  60.  
  61.                 case "right":
  62.                   startCol++;
  63.                     if (startCol > matrix.length-1){
  64.                         startCol = 0;
  65.                     }
  66.                     break;
  67.             }
  68.  
  69.             field = matrix[startRow][startCol];
  70.  
  71.             if (field.equals("F")){
  72.                 System.out.println("Player won!");
  73.                 hasWon = true;
  74.                 break;
  75.             }
  76.             else if (field.equals("B")){
  77.                 continue;
  78.             }
  79.             else if (field.equals("T")){
  80.                 startCol = previousCol;
  81.                 startRow = preciousRow;
  82.                 field = matrix[startRow][startCol];
  83.             }
  84.           command = bf.readLine();
  85.         }
  86.  
  87.         if (!hasWon) {
  88.             System.out.println("Player lost!");
  89.  
  90.         }
  91.         matrix[startRow][startCol] = "f";
  92.         for (int row = 0; row < matrix.length ; row++) {
  93.             for (int col = 0; col < matrix[row].length; col++) {
  94.                 System.out.print(matrix[row][col]);
  95.             }
  96.             System.out.println();
  97.         }
  98.  
  99.     }
  100. }
  101.  
  102.  
  103.  
  104. // upr define classes - to 2:00 gledano
  105. // lekciq FILES stignah do 2:11; serilization??
  106. // Uprajnenie files = do 2:02 = 9, 10, 11, 12 zadachi da se reshat.
  107. // Stack , queues = 8ma zadacha ot upr. video
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement