二维数组递归(2D array Recursion)

编程入门 行业动态 更新时间:2024-10-16 16:44:46
二维数组递归(2D array Recursion)

所以我正在尝试建立一个泡沫破碎机程序。 游戏的工作方式是它有一个有多种颜色的棋盘。 所有斑点从那个地方(水平和垂直)脱落而不是diaganol和那些你在新斑点附近咀嚼的斑点直到没有斑点

public void setSurroundingSimilarToTrue(int row, int col, int correctColor){ if(row >= 0 && row < this.myBoard.length && col >= 0 && col < this.myBoard.length) if(this.myBoard[row][col].getColorValue() == correctColor){ this.myBoard[row][col].setStatusTrue(); //System.out.println(row); setSurroundingSimilarToTrue(row - 1, col, correctColor); setSurroundingSimilarToTrue(row + 1, col, correctColor); setSurroundingSimilarToTrue(row, col - 1, correctColor); setSurroundingSimilarToTrue(row, col + 1, correctColor); } }

这就是我所做的,我不知道什么是错的。

So I am trying to build a bubble breaker program. The way the game works is that it has a board with several colors. all spots coming off that spot (horizontal and vertical) not diaganol and off those you chech all around the new spot until no spots left

public void setSurroundingSimilarToTrue(int row, int col, int correctColor){ if(row >= 0 && row < this.myBoard.length && col >= 0 && col < this.myBoard.length) if(this.myBoard[row][col].getColorValue() == correctColor){ this.myBoard[row][col].setStatusTrue(); //System.out.println(row); setSurroundingSimilarToTrue(row - 1, col, correctColor); setSurroundingSimilarToTrue(row + 1, col, correctColor); setSurroundingSimilarToTrue(row, col - 1, correctColor); setSurroundingSimilarToTrue(row, col + 1, correctColor); } }

This is what I did and I cant see whats wrong.

最满意答案

你的代码有无限的递归。 在进行递归之前,检查当前row, col位置是否尚未设置为True 。

You have infinite recursion with your code. Before doing recursion, check if the current row, col position isn't already set to True.

更多推荐

本文发布于:2023-08-07 14:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464538.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   数组   Recursion   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!