我正在尝试制作一个在网格窗格中显示 4 个图像的简单程序。我在那里得到一个没问题,但是一旦我尝试添加第二个,我就遇到了一些问题。这是我的代码:
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
GridPane gridPane = new GridPane();
gridPane.add(new ImageView(new Image ("http://gifimage.net/wp-content/uploads/2017/06/american-flag-gif-13.gif")), 1,1);
gridPane.add(new ImageView(new Image ("http://bestanimations.com/Flags/Asia/china/chinese-flag-waving-gif-animation-10.gif")), 2,2);
Scene scene = new Scene(gridPane, 1000, 500);
primaryStage.setTitle("Flags");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这可能是图像后的行和列的问题,但我尝试了一些方法但没有成功。任何帮助是极大的赞赏。谢谢
我正在写一个连接4游戏,你可以在其中选择板的大小.对于大多数电路板尺寸而言,游戏可以完美运行,但是当电路板较高而宽度较大时,会给我带来问题.我不断得到索引超出范围错误,我不知道我做错了什么.就我的检查功能而言,这就是我现在所拥有的,因为它是唯一给我问题的部分.
def checkOWin(board):
boardHeight = len(board)
boardWidth = len(board[0])
tile = 'O'
# check horizontal spaces
for y in range(boardHeight):
for x in range(boardWidth - 3):
if board[x][y] == tile and board[x+1][y] == tile and board[x+2][y] == tile and board[x+3][y] == tile:
return True
# check vertical spaces
for x in range(boardWidth):
for y in range(boardHeight - 3):
if board[x][y] == tile and board[x][y+1] == tile and board[x][y+2] == tile and board[x][y+3] == tile:
return True
# check / diagonal …Run Code Online (Sandbox Code Playgroud) 我必须编写一个递归函数来搜索特定值的列表。该函数应该查找该数字是否在列表中,如果是,它将返回该值的列表索引。
例如:
search([1,2,3,4,5],3)
Run Code Online (Sandbox Code Playgroud)
应该返回:
2
Run Code Online (Sandbox Code Playgroud)
因为 3 出现在列表索引 2 中。
现在我有:
def search(myList, number):
if myList[0] == number:
return myList[0]
return search(myList[1:], number)
Run Code Online (Sandbox Code Playgroud)
并且它一直为我之前的同一个函数调用返回 3。任何帮助将不胜感激。