Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package src;
- import java.util.Scanner;
- public class app2 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String input[] = scan.nextLine().split(",");
- int rows = Integer.parseInt(input[0]);
- int cols = Integer.parseInt(input[1]);
- int[][] battlefield = new int[rows][cols];
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < cols; j++) {
- battlefield[i][j] = 100;
- }
- }
- while (true) {
- String comand = scan.nextLine();
- if (comand.equals("GAME OVER")) {
- break;
- }
- String[] cmd = comand.split(",");
- int x = Integer.parseInt(cmd[0]);
- int y = Integer.parseInt(cmd[1]);
- int power = Integer.parseInt(cmd[2]);
- int neighDamage= 0;
- if(power<=30){
- neighDamage=5;
- }else if(power<=70) {
- neighDamage=70;
- }else {
- neighDamage=(power*20)/100;
- }
- if(x<=0||x>=rows||y<0||y>=cols) {
- continue;
- }
- for (int a = -1; a <= 1; a++) {
- for (int b = -1; b <= 1; b++) {
- if (x + a >= 0 && x + a < rows && y + b >= 0 && y + b < cols) {
- if (a == 0 && b == 0) {
- battlefield[x + a][y + b] -= power;
- } else {
- battlefield[x + a][y + b] -= neighDamage;
- }
- if (battlefield[x + a][y + b] < 0) {
- battlefield[x + a][y + b] = 0;
- }
- }
- }
- }
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < cols; j++) {
- System.out.print(battlefield[i][j] + " ");
- }
- System.out.println();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement