package com.lanou.homework0;
import java.util.Scanner;
public class GuanDeng {
public static void main(String[] args) {
/*
* 创建一个二维的数组,作为游戏的地图
* */
int [ ][ ] map = {
{0,0,0,0,0},
{0,0,1,0,0},
{0,1,1,1,0},
{0,0,1,0,0},
{0,0,0,0,0}
};
/*-----------------------地图初始化结束-------------------------------------------*/
/*-----------------------关灯逻辑---------------------------------------------------*/
//输出一下这个二维的数组
for(int i = 0 ; i < map.length ; i++){
for(int j = 0; j < map[i].length ; j++){
System.out.print(map[i][j] + " ");
}
System.out.println();
}
Scanner scanner = new Scanner(System.in);
while(true){
System.out.println("请输入您要点击的行数");
int row = scanner.nextInt();
while(row > map.length-1 || row < 0){
System.out.println("您输入的行数有误,请重新输入您要点击的行数");
row = scanner.nextInt();
}
System.out.println("请输入您要点击的列数");
int col = scanner.nextInt();
while(col > map[row].length - 1|| col < 0){
System.out.println("您输入的行数有误,请重新输入您要点击的列数");
col = scanner.nextInt();
}
//自己这个位置在变化
if(map[row][col] == 1){
map[row][col] = 0;
}else{
map[row][col] = 1;
}
//头顶的位置的变化
if(row <= 0){
}else {
if(map[row - 1][col] == 1){
map[row - 1][col] = 0;
}else{
map[row - 1][col] = 1;
}
}
//脚底位置的变化
if(row >= map.length -1){
}else{
if(map[row + 1][col] == 0){
map[row + 1][col] = 1;
}else{
map[row + 1][col] = 0;
}
}
//左边位置的变化
if(col <= 0){
}else{
if(map[row][col - 1] ==1){
map[row][col-1] = 0;
}else{
map[row][col - 1] = 1;
}
}
//右边位置的变化
if(col >= map[row].length - 1){
}else{
if(map[row][col + 1] == 1){
map[row][col + 1] = 0;
}else{
map[row][col] = 1;
}
}
int sum = 0;
for(int i = 0 ; i < map.length ; i++){
for(int j = 0; j < map[i].length ; j++){
System.out.print(map[i][j] + " ");
sum = sum + map[i][j];
}
System.out.println();
}
if(sum == 0){
System.out.println("哇哦~你真是个小天才");
return;
}
}
}
}