Game schedule #14
|
@ -21,7 +21,7 @@ public class Factory {
|
|||
}
|
||||
|
||||
public void setTournament(Tournament tournament) {
|
||||
this.tournamentDecorator = tournamentDecorator;
|
||||
this.tournamentDecorator.setTournament(tournament);
|
||||
}
|
||||
|
||||
public BorderPane loadMainWindow(){
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
public class Game {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Game implements Serializable {
|
||||
private Participant participant1, Participant2;
|
||||
private int points1, points2;
|
||||
private Location location;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
public class InvalidNameException extends Exception {
|
||||
public InvalidNameException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidNameException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
public interface Participant {
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface Participant extends Serializable {
|
||||
String getName();
|
||||
void setName(String name);
|
||||
boolean equals(Participant participant);
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
public class Person {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Person implements Serializable {
|
||||
private String name;
|
||||
private String firstName;
|
||||
private String phoneNumber;
|
||||
|
||||
public Person(String firstName, String name, String phoneNumber){
|
||||
public Person(String firstName, String name, String phoneNumber) throws InvalidNameException, InvalidPhoneNumberException {
|
||||
if(!firstName.matches("^[a-zA-Z][a-zA-Z][-',.][a-zA-Z]{1,20}$")){
|
||||
throw new InvalidNameException("The First name is Invalid.");
|
||||
} else if(!name.matches("^[a-zA-Z][a-zA-Z][-',.][a-zA-Z]{1,20}$")){
|
||||
throw new InvalidNameException("The Last name is Invalid");
|
||||
} else if(!phoneNumber.matches("[\\+0-9]+")){
|
||||
throw new InvalidPhoneNumberException("The entered Phone Number is invalid.");
|
||||
}
|
||||
setFirstName(firstName);
|
||||
setName(name);
|
||||
setPhoneNumber(phoneNumber);
|
||||
|
@ -34,4 +43,16 @@ public class Person {
|
|||
public void setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
public class InvalidPhoneNumberException extends Exception {
|
||||
public InvalidPhoneNumberException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidPhoneNumberException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
public class Player extends Person implements Participant{
|
||||
|
||||
private Date dateOfBirth;
|
||||
private GregorianCalendar dateOfBirth;
|
||||
|
||||
public Player(String firstName, String name, String phoneNumber, Date dateOfBirth){
|
||||
public Player(String firstName, String name, String phoneNumber, String dateOfBirth) throws InvalidNameException, InvalidPhoneNumberException {
|
||||
super(firstName, name, phoneNumber);
|
||||
setDateOfBirth(dateOfBirth);
|
||||
}
|
||||
|
||||
public Date getDateOfBirth() {
|
||||
public GregorianCalendar getDateOfBirth() {
|
||||
return dateOfBirth;
|
||||
}
|
||||
|
||||
public void setDateOfBirth(Date dateOfBirth) {
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
public void setDateOfBirth(String dateOfBirth) {
|
||||
String[] date = dateOfBirth.split("\\.");
|
||||
this.dateOfBirth = new GregorianCalendar(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
|||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -17,7 +18,7 @@ public class Tournament implements Serializable {
|
|||
|
||||
public Tournament(String name, Type type) throws InvalidNameException, InvalidTypeException {
|
||||
if(!name.matches("[\\w]{1,20}")){
|
||||
throw new Tournament.InvalidNameException("Invalid Name entered"); //TODO handle en logging.
|
||||
throw new InvalidNameException("Invalid Name entered"); //TODO handle en logging.
|
||||
} else if(!Arrays.asList(Type.values()).contains(type)){
|
||||
throw new InvalidTypeException("Invalid Type selected"); //TODO handle en logging.
|
||||
}
|
||||
|
@ -42,6 +43,12 @@ public class Tournament implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public ObservableList<Participant> getParticipants() {
|
||||
ObservableList<Participant> participantsObservable = FXCollections.observableArrayList();
|
||||
participantsObservable.addAll(participants);
|
||||
return participantsObservable;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -79,17 +86,6 @@ public class Tournament implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public class InvalidNameException extends Exception {
|
||||
public InvalidNameException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidNameException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class InvalidTypeException extends Exception {
|
||||
public InvalidTypeException() {
|
||||
super();
|
||||
|
|
|
@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class TournamentDecorator implements IsObservable{
|
||||
|
@ -22,6 +23,10 @@ public class TournamentDecorator implements IsObservable{
|
|||
this.tournament = tournament;
|
||||
}
|
||||
|
||||
public Tournament getTournament() {
|
||||
return tournament;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(IsObserver observer) {
|
||||
listener.add(observer);
|
||||
|
@ -41,7 +46,7 @@ public class TournamentDecorator implements IsObservable{
|
|||
Tournament tournament = new Tournament(name, type);
|
||||
fileIO.saveTournament(tournament);
|
||||
informListener();
|
||||
} catch (Tournament.InvalidNameException e) {
|
||||
} catch (InvalidNameException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
} catch (Tournament.InvalidTypeException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
|
@ -59,6 +64,19 @@ public class TournamentDecorator implements IsObservable{
|
|||
}
|
||||
}
|
||||
|
||||
public void addPlayer(String firstName, String name, String phoneNumber, String dateOfBirth){
|
||||
try {
|
||||
tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
|
||||
informListener();
|
||||
} catch (Tournament.ParticipantExistsException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
} catch (InvalidNameException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
} catch (Person.InvalidPhoneNumberException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void informListener() {
|
||||
for(IsObserver observer : listener) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung.main.participantAddFormular;
|
||||
|
||||
import ch.zhaw.projekt2.turnierverwaltung.FXController;
|
||||
import ch.zhaw.projekt2.turnierverwaltung.Participant;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
|
@ -44,7 +45,7 @@ public class ParticipantFormularController extends FXController {
|
|||
private Label participantListTitle;
|
||||
|
||||
@FXML
|
||||
private ListView<?> participantListView;
|
||||
private ListView<Participant> participantListView;
|
||||
|
||||
@FXML
|
||||
private Label participantNameLabel;
|
||||
|
@ -63,7 +64,7 @@ public class ParticipantFormularController extends FXController {
|
|||
|
||||
@FXML
|
||||
void addParticipant(ActionEvent event) {
|
||||
|
||||
getTournamentDecorator().addPlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText());
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
@ -78,6 +79,6 @@ public class ParticipantFormularController extends FXController {
|
|||
|
||||
@Override
|
||||
public void loadContent() {
|
||||
|
||||
participantListView.setItems(getTournamentDecorator().getTournament().getParticipants());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ class FileIOTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void saveTournament() throws IOException, Tournament.InvalidNameException, Tournament.InvalidTypeException {
|
||||
void saveTournament() throws IOException, InvalidNameException, Tournament.InvalidTypeException {
|
||||
Tournament tournament = null;
|
||||
tournament = new Tournament("test1", Tournament.Type.KO);
|
||||
io.saveTournament(tournament);
|
||||
|
|
Loading…
Reference in New Issue