forked from siqq/Java-Missle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.Added client ( there is still work to be done) 3.Added server (-||-)
- Loading branch information
Showing
15 changed files
with
604 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false"> | ||
<fileset name="all" enabled="true" check-config-name="Sun Checks (Eclipse)" local="false"> | ||
<file-match-pattern match-pattern="." include-pattern="true"/> | ||
</fileset> | ||
</fileset-config> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main; | ||
|
||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
import java.util.Date; | ||
|
||
import launcher.Launcher; | ||
import missile.Missile; | ||
|
||
|
||
public class Server { | ||
Socket socket = null; | ||
ServerSocket server; | ||
ObjectInputStream inputStream; | ||
ObjectOutputStream outputStream; | ||
Launcher launcher = null; | ||
Missile missile = null; | ||
public Server(){ | ||
try { | ||
server = new ServerSocket(7000); | ||
System.out.println(new Date() + " --> Server waits for client..."); | ||
socket = server.accept(); // blocking | ||
System.out.println(new Date() + " --> Client connected from " | ||
+ socket.getInetAddress() + ":" + socket.getPort()); | ||
|
||
outputStream = new ObjectOutputStream(socket.getOutputStream()); | ||
inputStream = new ObjectInputStream(socket.getInputStream()); | ||
|
||
do { | ||
if( inputStream.readObject() instanceof Missile) { | ||
missile = (Missile)inputStream.readObject(); | ||
outputStream.writeObject(missile); | ||
} | ||
else if( inputStream.readObject() instanceof Launcher) { | ||
launcher = (Launcher)inputStream.readObject(); | ||
outputStream.writeObject(launcher); | ||
} | ||
|
||
} while (launcher != null || missile != null); | ||
} catch (Exception e) { | ||
System.out.println(e); | ||
} finally { | ||
try { | ||
socket.close(); | ||
server.close(); | ||
System.out | ||
.println("Sever is closing after client is disconnected"); | ||
} catch (IOException e) { } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@CHARSET "windows-1255"; | ||
|
||
.label { | ||
-fx-font-size: 12px; | ||
-fx-font-weight: bold; | ||
-fx-text-fill: gray; | ||
} | ||
|
||
.button { | ||
-fx-text-fill: white; | ||
-fx-font-family: "Comic Sans MS"; | ||
-fx-font-weight: bold; | ||
-fx-background-color: linear-gradient(#61a2b1, #2A5058); | ||
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 ); | ||
} | ||
.tab { | ||
-fx-text-fill: white; | ||
-fx-font-family: "Comic Sans MS"; | ||
-fx-font-weight: bold; | ||
-fx-background-color: linear-gradient(#61a2b1, #2A5058); | ||
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 ); | ||
} | ||
.button:hover { | ||
-fx-background-color: linear-gradient(#2A5058, #61a2b1); | ||
} | ||
|
||
#survivor-name { | ||
-fx-font-size: 14px; | ||
-fx-font-family: "Comic Sans MS"; | ||
-fx-font-weight: bold; | ||
-fx-fill: #151515; | ||
} | ||
|
||
#survivor-background | ||
{ | ||
-fx-fill: #D8D8D8; | ||
} | ||
|
||
#tribe { | ||
-fx-background-color:beige; | ||
} | ||
#mainPane { | ||
-fx-background-color: #B2D1FF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package view; | ||
|
||
import java.util.List; | ||
|
||
import javafx.application.Application; | ||
import javafx.event.ActionEvent; | ||
import javafx.event.EventHandler; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.Tab; | ||
import javafx.scene.control.TabPane; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.layout.AnchorPane; | ||
import javafx.stage.Stage; | ||
|
||
import javax.swing.JOptionPane; | ||
|
||
import war.controller.WarUIEventsListener; | ||
|
||
public class ConsoleApp extends Application { | ||
// private List<WarUIEventsListener> allListeners; | ||
// private String launcherName; | ||
// public ConsoleApp(List<WarUIEventsListener> allListeners, WarGui warGui) { | ||
// this.allListeners = allListeners; | ||
// this.launcherName = launcherName; | ||
// main(null); | ||
// } | ||
|
||
|
||
|
||
|
||
|
||
public void start(Stage primaryStage) throws Exception { | ||
// Group root = new Group(); | ||
// primaryStage.setScene(new Scene(root)); | ||
final Tab tabMissile = new Tab(); | ||
// tabMissile.setId("tabMissile"); | ||
tabMissile.setText("Missile"); | ||
final Tab tabLauncher = new Tab(); | ||
// tabLauncher.setId("tabLauncher"); | ||
tabLauncher.setText("Launcher"); | ||
TabPane tabPane = new TabPane(); | ||
tabPane.setId("mainPane"); | ||
|
||
AnchorPane Missiletab = new AnchorPane(); | ||
AnchorPane LauncherTab = new AnchorPane(); | ||
final TextField missileID = new TextField(); | ||
final TextField destination = new TextField(); | ||
final TextField damage = new TextField(); | ||
final TextField flytime = new TextField(); | ||
Button add = new Button("Resquest & Add missile from server"); | ||
final Button connect = new Button("Connect to server"); | ||
Button connectLauncher = new Button("Connect to server"); | ||
TextField launcherId = new TextField(); | ||
Button addLauncher = new Button("Resquest & Add Launcher from server"); | ||
Missiletab.setMaxSize(285.0, 371.0); | ||
LauncherTab.setMaxSize(285.0, 371.0); | ||
|
||
missileID.setPromptText("missileID"); | ||
missileID.setMaxSize(221, 25); | ||
missileID.setLayoutX(14.0); | ||
missileID.setLayoutY(37.0); | ||
|
||
launcherId.setPromptText("LauncherID"); | ||
launcherId.setMaxSize(221, 25); | ||
launcherId.setLayoutX(14.0); | ||
launcherId.setLayoutY(37.0); | ||
|
||
destination.setPromptText("destination"); | ||
destination.setMaxSize(221, 25); | ||
destination.setLayoutX(14.0); | ||
destination.setLayoutY(69.0); | ||
|
||
damage.setPromptText("damage"); | ||
damage.setMaxSize(221, 25); | ||
damage.setLayoutX(14.0); | ||
damage.setLayoutY(101.0); | ||
|
||
flytime.setPromptText("flytime"); | ||
flytime.setMaxSize(221, 25); | ||
flytime.setLayoutX(14.0); | ||
flytime.setLayoutY(133.0); | ||
|
||
add.setLayoutX(14.0); | ||
add.setLayoutY(167.0); | ||
|
||
addLauncher.setLayoutX(14.0); | ||
addLauncher.setLayoutY(78.0); | ||
|
||
connect.setLayoutX(14.0); | ||
connect.setLayoutY(5.0); | ||
|
||
add.setOnAction(new EventHandler<ActionEvent>() { | ||
@Override | ||
public void handle(ActionEvent event) { | ||
System.out.println("Hello World!"); | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
// while (true) { | ||
|
||
String id = missileID.getText(); | ||
String dest = destination.getText(); | ||
String damageT = damage.getText(); | ||
String flyTime = flytime.getText(); | ||
if (id.isEmpty() || dest.isEmpty() || damageT.isEmpty()) { | ||
JOptionPane.showMessageDialog(null, | ||
"You must fill all details!"); | ||
return; | ||
} | ||
// for (WarUIEventsListener l : allListeners) { | ||
// l.addMessageThroughClient(id, dest, damageT, flyTime , launcherName); | ||
// } | ||
|
||
} | ||
}).start(); | ||
} | ||
}); | ||
|
||
|
||
connectLauncher.setLayoutX(14.0); | ||
connectLauncher.setLayoutY(5.0); | ||
|
||
Missiletab.getChildren().addAll(connect, missileID, destination, damage, flytime,add); | ||
LauncherTab.getChildren().addAll(connectLauncher, launcherId, addLauncher); | ||
tabMissile.setContent(Missiletab); | ||
tabLauncher.setContent(LauncherTab); | ||
tabPane.getTabs().addAll(tabMissile , tabLauncher); | ||
|
||
Scene scene = new Scene(tabPane, 255, 240); | ||
// primaryStage.setScene(scene); | ||
// root.getChildren().add(tabPane); | ||
scene.getStylesheets().add(this.getClass().getResource("ClientStyle").toExternalForm()); | ||
primaryStage.setScene(scene); | ||
primaryStage.show(); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public static void main(String[] args) { | ||
launch(args); | ||
} | ||
|
||
} |
Oops, something went wrong.