当前位置: 代码迷 >> 综合 >> 16-04-02(俄罗斯方块*)
  详细解决方案

16-04-02(俄罗斯方块*)

热度:29   发布时间:2023-11-21 21:47:26.0

import java.util.*;
public class Main{
    public static void main(String[] args) {
    csp_16_04_02.run();}public static void run() {
    Scanner scanner = new Scanner(System.in);int[][] arr = new int[15][10];int[][] arrSqu = new int[4][4];//将输入的方格图存入数组for (int i = 0; i < 15; i++) {
    for (int j = 0; j < 10; j++) {
    arr[i][j] = scanner.nextInt();}}//将输入的方块存入数组for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
    arrSqu[i][j] = scanner.nextInt();}}//获取方块将要下沉的位置,偏移int column = scanner.nextInt();scanner.close();//获取这个方块值为1的每个节点在4*4矩阵中的位置int[] x = new int[4];int[] y = new int[4];int z = 0;for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
    if (arrSqu[i][j] == 1) {
    x[z] = i;y[z] = j+column-1;z++;}}}boolean flag = true;int count = 0;int offset = 0;outer:while (flag) {
    for (int i = 0; i < 4; i++) {
    //判断最下面的边界,如果有一个方块到了最下面,直接结束下沉if ((x[i] + offset) == 14) {
    for (int j = 0; j < 4; j++) {
    arr[x[j] + offset][y[j]] =1;}break outer;}if (arr[x[i] + offset][y[i]]==0) {
    //不断下沉count++;}}if (count == 4) {
    offset++;count=0;}else {
    for (int i = 0; i < 4; i++) {
    arr[x[i] + offset -1][y[i]] = 1;}flag = false;}}//遍历下沉后的矩阵for(int i=0;i<15;i++){
    for(int j=0;j<10;j++){
    System.out.print(arr[i][j]+" ");}System.out.println();}}
}