Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ginowangsh4 committed Jun 8, 2018
2 parents 956e8a9 + 4d05ec2 commit 83af3a5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
37 changes: 26 additions & 11 deletions fxml/EndGame.fxml
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="$CONTROLLER_NAME$"
prefHeight="400.0" prefWidth="600.0">

</AnchorPane>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="560.0" prefWidth="480.0" xmlns="http://javafx.com/javafx/9.0.4" xmlns:fx="http://javafx.com/fxml/1" fx:controller="tsuro.admin.EndGameController">
<center>
<ImageView fx:id="boardImageView" fitHeight="360.0" fitWidth="360.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER" />
</center>
<top>
<VBox prefHeight="160.0" prefWidth="480.0" style="-fx-border-color: black;" BorderPane.alignment="CENTER">
<children>
<Label alignment="CENTER" prefHeight="40.0" prefWidth="480.0" text="Here is the list of winners!" />
<Label fx:id="winnerList" alignment="CENTER" prefWidth="480.0" text="Label" textAlignment="CENTER" />
</children></VBox>
</top>
<left>
<VBox prefHeight="360.0" prefWidth="60.0" BorderPane.alignment="CENTER" />
</left>
<right>
<VBox prefHeight="360.0" prefWidth="60.0" BorderPane.alignment="CENTER" />
</right>
<bottom>
<HBox prefHeight="30.0" prefWidth="480.0" BorderPane.alignment="CENTER" />
</bottom>
</BorderPane>
22 changes: 22 additions & 0 deletions src/admin/EndGameController.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
package tsuro.admin;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import tsuro.parser.Parser;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class EndGameController {

@FXML
private ImageView boardImageView;

@FXML
private Label winnerList;

public void initialize() throws Exception {
boardImageView.setImage(new Image(new FileInputStream("image/board/board.png")));
String temp = App.socket.readInputFromServer();
winnerList.setText(temp);
}
}
14 changes: 13 additions & 1 deletion src/main/HPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashSet;
import java.util.List;

public class HPlayer implements IPlayer {
Expand Down Expand Up @@ -51,14 +52,25 @@ public Token placePawn(Board b) throws Exception {
public Tile playTurn(Board b, List<Tile> hand, int tilesLeft) throws Exception {
generateImages(b, hand);
out.println("<play-turn>");
// inform GUI about hand size
out.println(String.valueOf(hand.size()));
// format: [index of tile in hand, index of tile rotation]
String[] chosenTile = in.readLine().split(",");
return generateTile(hand, Integer.parseInt(chosenTile[0]), Integer.parseInt(chosenTile[1]));
}

public void endGame(Board b, List<Integer> colors) throws Exception {
generateBoardImage(parser.boardParser.buildXML(b), -1, -1);
out.print("<end-game>");
out.println("<end-game>");
String winnerList = "";
for (int i = 0; i < colors.size(); i++) {
String colorString = Token.colorMap.get(colors.get(i));
winnerList = winnerList + colorString;
if (i != colors.size() - 1) {
winnerList += ", ";
}
}
out.println(winnerList);
}

private Token findMyToken(Board b) {
Expand Down

0 comments on commit 83af3a5

Please sign in to comment.