Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. package src;
  2. import java.util.Scanner;
  3.  
  4. public class app2 {
  5.  
  6. public static void main(String[] args) {
  7. Scanner scan = new Scanner(System.in);
  8.  
  9. String input[] = scan.nextLine().split(",");
  10. int rows = Integer.parseInt(input[0]);
  11. int cols = Integer.parseInt(input[1]);
  12.  
  13. int[][] battlefield = new int[rows][cols];
  14. for (int i = 0; i < rows; i++) {
  15. for (int j = 0; j < cols; j++) {
  16. battlefield[i][j] = 100;
  17. }
  18. }
  19. while (true) {
  20. String comand = scan.nextLine();
  21. if (comand.equals("GAME OVER")) {
  22. break;
  23. }
  24. String[] cmd = comand.split(",");
  25. int x = Integer.parseInt(cmd[0]);
  26. int y = Integer.parseInt(cmd[1]);
  27. int power = Integer.parseInt(cmd[2]);
  28. int neighDamage= 0;
  29.  
  30. if(power<=30){
  31. neighDamage=5;
  32. }else if(power<=70) {
  33. neighDamage=70;
  34. }else {
  35. neighDamage=(power*20)/100;
  36. }
  37. if(x<=0||x>=rows||y<0||y>=cols) {
  38. continue;
  39. }
  40. for (int a = -1; a <= 1; a++) {
  41. for (int b = -1; b <= 1; b++) {
  42. if (x + a >= 0 && x + a < rows && y + b >= 0 && y + b < cols) {
  43. if (a == 0 && b == 0) {
  44. battlefield[x + a][y + b] -= power;
  45. } else {
  46. battlefield[x + a][y + b] -= neighDamage;
  47. }
  48. if (battlefield[x + a][y + b] < 0) {
  49. battlefield[x + a][y + b] = 0;
  50. }
  51. }
  52. }
  53.  
  54. }
  55.  
  56. for (int i = 0; i < rows; i++) {
  57. for (int j = 0; j < cols; j++) {
  58. System.out.print(battlefield[i][j] + " ");
  59. }
  60. System.out.println();
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement