Step 7 : change Rack implemented and working sucessfully

master
Cemal Odabasioglu 2022-06-01 14:50:01 +02:00
parent 625db82e12
commit 149f49f7f8
3 changed files with 112 additions and 42 deletions

View File

@ -33,6 +33,7 @@ import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.ImagePattern; import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font; import javafx.scene.text.Font;
@ -65,9 +66,6 @@ public class LaticeApplicationWindow extends Application {
Image image = new Image("backgroundLatice.png"); Image image = new Image("backgroundLatice.png");
ImageView imageView = new ImageView(image); ImageView imageView = new ImageView(image);
Tile blueBird = new Tile(Color.NAVYBLUE, Shape.BIRD);
Tile greenLeaf = new Tile(Color.GREEN, Shape.FEATHER);
Tile redFlower = new Tile(Color.RED, Shape.FLOWER);
ArrayList<Tile> listRackTile; ArrayList<Tile> listRackTile;
ArrayList<Image> listTileImage; ArrayList<Image> listTileImage;
@ -86,10 +84,10 @@ public class LaticeApplicationWindow extends Application {
StackPane stackPane = new StackPane(); StackPane stackPane = new StackPane();
static Stage primaryStageCopy; static Stage primaryStageCopy;
StackPane parentStackPane = new StackPane(); StackPane parentStackPane = new StackPane();
Label moonErrorLabel = new Label();
int validateBtnClickedCount; int validateBtnClickedCount;
public static void main(String[] args) { public static void main(String[] args) {
Application.launch(args); Application.launch(args);
@ -106,10 +104,15 @@ public class LaticeApplicationWindow extends Application {
//Title //Title
VBox topVbox = new VBox();
Text title = new Text("Latice"); Text title = new Text("Latice");
title.setFont(new Font(30)); title.setFont(new Font(30));
root.setTop(title); topVbox.getChildren().add(title);
root.setAlignment(title, Pos.CENTER); topVbox.setAlignment(Pos.CENTER);
moonErrorLabel.setFont(new Font(20));
moonErrorLabel.setTextFill(realColor.RED);
topVbox.getChildren().add(moonErrorLabel);
root.setTop(topVbox);
//Image //Image
Pane pane = new Pane(); Pane pane = new Pane();
@ -170,7 +173,8 @@ public class LaticeApplicationWindow extends Application {
System.out.println("-----------------"); System.out.println("-----------------");
//deck.displayListTile(); //deck.displayListTile();
//Confirm Button //Confirm Button
Image checkMark = new Image("checkMark.png"); Image checkMark = new Image("checkMark.png");
@ -182,18 +186,46 @@ public class LaticeApplicationWindow extends Application {
@Override @Override
public void handle(MouseEvent arg0) { public void handle(MouseEvent arg0) {
validateBtnClickedCount++;
System.out.println("confirmed placement"); System.out.println("confirmed placement");
validateBtnClickedCount++;
} }
}); });
//With Image //With Image
Rack rack2 = new Rack(deck); Rack rack2 = new Rack(deck);
HBox rackImage = rack2.createTileImage(); HBox rackImage = rack2.createTileImage();
rackImage.getChildren().add(confirmButton);
rackImage.setMargin(rackImage.getChildren().get(4), new Insets(0,150,0,0));
//RackChange Button
Image changeIconImage = new Image("changeIcon.png");
ImageView changeIconView = new ImageView(changeIconImage);
Button changeButton = new Button("Change Rack", changeIconView);
changeButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent arg0) {
System.out.println("Changing Rack");
rack2.changeRack();
rackImage.getChildren().clear();
rackImage.getChildren().addAll(rack2.createTileImage(), confirmButton, changeButton);
//Setting drag n drop on tiles
setDragnDropOnRack(rackImage);
}
});
rackImage.getChildren().addAll(confirmButton, changeButton);
root.setBottom(rackImage); root.setBottom(rackImage);
//Adding lists to Arraylists //Adding lists to Arraylists
@ -205,34 +237,8 @@ public class LaticeApplicationWindow extends Application {
//------------------------------------------------------------------------ //------------------------------------------------------------------------
//Setting drag n drop on tiles
//Setting OnDragDetected on tiles setDragnDropOnRack(rackImage);
for (int i=0; i<5; i++) {
int a = i;
rackImage.getChildren().get(a).setOnDragDetected(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent arg0) {
Dragboard dragboard = rackImage.getChildren().get(a).startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
dragboard.setDragView(listTileImage.get(a));
content.putString("Hello !");
setIndexTileClicked(a);
dragboard.setContent(content);
arg0.consume();
}
});
rackImage.getChildren().get(a).setOnDragDone(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent arg0) {
}
});
}
System.out.println((indexTileClicked)); System.out.println((indexTileClicked));
ImagePattern imagePattern = new ImagePattern(listTileImage.get(getIndexTileClicked())); ImagePattern imagePattern = new ImagePattern(listTileImage.get(getIndexTileClicked()));
@ -286,11 +292,20 @@ public class LaticeApplicationWindow extends Application {
arg0.setDropCompleted(true); arg0.setDropCompleted(true);
assocRectangleTile.put(r[a][b], listRackTile.get(getIndexTileClicked())); assocRectangleTile.put(r[a][b], listRackTile.get(getIndexTileClicked()));
System.out.println(assocRectangleTile.toString()); System.out.println(assocRectangleTile.toString());
moonErrorLabel.setText("");
if (validateBtnClickedCount == 0){ if (validateBtnClickedCount == 0){
if (r[a][b] == r[4][4]) { if (r[a][b] == r[4][4]) {
System.out.println("MOON valid placement"); System.out.println("MOON valid placement");
}else { }else {
moonErrorLabel.setText("Error ! Please place the first tile on the moon");
//removing all tiles from gameboard
for(int i=0; i<NUMBER_OF_BOX_ON_ONE_LINE; i++) {
for(int j=0; j<NUMBER_OF_BOX_ON_ONE_LINE; j++) {
r[i][j].setFill(realColor.TRANSPARENT);
}
}
System.out.println("Please place first Tile on MOON"); System.out.println("Please place first Tile on MOON");
} }
} }
@ -321,6 +336,38 @@ public class LaticeApplicationWindow extends Application {
primaryStage.show(); primaryStage.show();
} }
private void setDragnDropOnRack(HBox rackImage) {
//Setting drag n drop on tiles
for (int i=0; i<5; i++) {
int a = i;
rackImage.getChildren().get(a).setOnDragDetected(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent arg0) {
Dragboard dragboard = rackImage.getChildren().get(a).startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
dragboard.setDragView(listTileImage.get(a));
content.putString("Hello !");
setIndexTileClicked(a);
dragboard.setContent(content);
arg0.consume();
}
});
rackImage.getChildren().get(a).setOnDragDone(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent arg0) {
}
});
}
}
public static void setRootLayout(StackPane root) { public static void setRootLayout(StackPane root) {
rootLayout = root; rootLayout = root;
} }
@ -364,5 +411,10 @@ public class LaticeApplicationWindow extends Application {
MSC.setParentStackPane(parentStackPane); MSC.setParentStackPane(parentStackPane);
primaryStageCopy.setTitle("working"); primaryStageCopy.setTitle("working");
} }
public void displayMoonError() {
}
} }

View File

@ -1,8 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?> <?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<BorderPane xmlns:fx="http://javafx.com/fxml/1">
<!-- TODO Add Nodes --> <BorderPane prefHeight="241.0" prefWidth="386.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/17">
<center>
<Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="replayBtn" layoutX="42.0" layoutY="163.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="127.0" textFill="TRANSPARENT" />
<Button fx:id="quitBtn" layoutX="221.0" layoutY="163.0" mnemonicParsing="false" prefHeight="51.0" prefWidth="129.0" textFill="TRANSPARENT" />
<ImageView fitHeight="241.0" fitWidth="386.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../resources/GameFinishedImage.png" />
</image>
</ImageView>
<Label alignment="CENTER_RIGHT" layoutX="4.0" layoutY="73.0" prefHeight="22.0" prefWidth="154.0" textAlignment="CENTER" />
</children>
</Pane>
</center>
</BorderPane> </BorderPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 393 B