Skip to content

Commit

Permalink
Implementierung Mulitplayer komplett
Browse files Browse the repository at this point in the history
  • Loading branch information
mnk7 committed Oct 8, 2014
1 parent ec3589e commit 37829a2
Show file tree
Hide file tree
Showing 70 changed files with 371 additions and 35 deletions.
Binary file modified bin/client/Client$1.class
Binary file not shown.
Binary file modified bin/client/Client.class
Binary file not shown.
Binary file modified bin/client/ModelMVC.class
Binary file not shown.
Binary file modified bin/client/Netzwerk.class
Binary file not shown.
Binary file modified bin/client/View.class
Binary file not shown.
Binary file modified bin/graphik/Gegenspieler.class
Binary file not shown.
Binary file modified bin/graphik/Graphik.class
Binary file not shown.
Binary file modified bin/graphik/KartenButton.class
Binary file not shown.
Binary file modified bin/graphik/KartenLabel.class
Binary file not shown.
Binary file modified bin/graphik/Meldungen.class
Binary file not shown.
Binary file modified bin/graphik/MenuGUI$1.class
Binary file not shown.
Binary file modified bin/graphik/MenuGUI$2.class
Binary file not shown.
Binary file modified bin/graphik/MenuGUI.class
Binary file not shown.
Binary file modified bin/graphik/Spieler$1.class
Binary file not shown.
Binary file modified bin/graphik/Spieler.class
Binary file not shown.
Binary file modified bin/graphik/Spielerhand.class
Binary file not shown.
Binary file added bin/graphik/SpielmodusDialog$1.class
Binary file not shown.
Binary file added bin/graphik/SpielmodusDialog.class
Binary file not shown.
Binary file modified bin/graphik/Tisch.class
Binary file not shown.
Binary file modified bin/ki/Geier.class
Binary file not shown.
Binary file modified bin/ki/Hochzeit.class
Binary file not shown.
Binary file modified bin/ki/KI.class
Binary file not shown.
Binary file modified bin/ki/NGeier.class
Binary file not shown.
Binary file modified bin/ki/NHochzeit.class
Binary file not shown.
Binary file modified bin/ki/NSauspiel.class
Binary file not shown.
Binary file modified bin/ki/NSolo.class
Binary file not shown.
Binary file modified bin/ki/NWenz.class
Binary file not shown.
Binary file modified bin/ki/Sauspiel.class
Binary file not shown.
Binary file modified bin/ki/Si.class
Binary file not shown.
Binary file modified bin/ki/Solo.class
Binary file not shown.
Binary file modified bin/ki/Spielauswahl.class
Binary file not shown.
Binary file modified bin/ki/Wenz.class
Binary file not shown.
Binary file modified bin/lib/Karte$farbe.class
Binary file not shown.
Binary file modified bin/lib/Karte$wert.class
Binary file not shown.
Binary file modified bin/lib/Karte.class
Binary file not shown.
Binary file modified bin/lib/Model$modus.class
Binary file not shown.
Binary file modified bin/lib/Model.class
Binary file not shown.
Binary file modified bin/lib/Netzwerk.class
Binary file not shown.
Binary file modified bin/regeln/Controll.class
Binary file not shown.
Binary file modified bin/regeln/Geier.class
Binary file not shown.
Binary file modified bin/regeln/Hochzeit.class
Binary file not shown.
Binary file modified bin/regeln/Regelwahl.class
Binary file not shown.
Binary file modified bin/regeln/Sauspiel.class
Binary file not shown.
Binary file modified bin/regeln/Solo.class
Binary file not shown.
Binary file modified bin/regeln/Wenz.class
Binary file not shown.
Binary file modified bin/server/Bot.class
Binary file not shown.
Binary file modified bin/server/Graphik$1.class
Binary file not shown.
Binary file modified bin/server/Graphik$2.class
Binary file not shown.
Binary file modified bin/server/Graphik$3.class
Binary file not shown.
Binary file modified bin/server/Graphik.class
Binary file not shown.
Binary file modified bin/server/Mensch.class
Binary file not shown.
Binary file modified bin/server/Netzwerk.class
Binary file not shown.
Binary file modified bin/server/Server.class
Binary file not shown.
Binary file modified bin/server/Spieler.class
Binary file not shown.
Binary file modified bin/tests/Clients$1.class
Binary file not shown.
Binary file modified bin/tests/Clients.class
Binary file not shown.
Binary file modified bin/tests/GUItest.class
Binary file not shown.
Binary file added bin/tests/SpielwahlTest.class
Binary file not shown.
7 changes: 4 additions & 3 deletions src/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public void run() {
private void listen() {
while(true) {
try {
//kleine Pause
Thread.sleep(100);

String steuerung = netzwerk.einlesen();

if(steuerung.equals("!NAME")) {
Expand Down Expand Up @@ -130,6 +133,7 @@ private void listen() {
} if(steuerung.equals("!ID")) {
//ID des Spielers empfangen
ID = Integer.parseInt(netzwerk.einlesen());

netzwerk.setID(ID);
graphik.setID(ID);
break;
Expand Down Expand Up @@ -165,9 +169,6 @@ private void listen() {
graphik.geklopft(geklopft);
break;
}

//kleine Pause
Thread.sleep(100);
} catch (Exception e) {
//Wenn ein Fehler auftritt aus der Schleife ausbrechen
e.printStackTrace();
Expand Down
80 changes: 68 additions & 12 deletions src/graphik/Graphik.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import regeln.Controll;
import regeln.Regelwahl;
import lib.Karte;
import lib.Model;
import lib.Model.modus;
Expand Down Expand Up @@ -47,14 +49,7 @@ public class Graphik extends JFrame implements View {
private Tisch tisch;

//Hintergrund
private JPanel hintergrund;

//Auswahldialoge
//Kontra
//Klopfen
//Spielmodus
//Hochzeit

private JPanel hintergrund;

public Graphik() {
super();
Expand Down Expand Up @@ -237,15 +232,34 @@ private void nachricht(int spielerID, String text) {
* Spielzug des Spielers durchführen
*/
public void spiel() {
Karte gespielt = spielerKarten.spiel();
Model m = model.gibModel();
boolean ok = false;

do {
try {
m.setTisch(ID, gespielt);
if(controll.erlaubt(m)) {
model.setzeModel(m);
ok = true;
} else
m.undo(ID);
} catch (Exception e) {
e.printStackTrace();
//nächster Versuch
m.undo(ID);
continue;
}

} while(!ok);
}

/**
* Ändert den Modus des Spiels und ändert die Controll
* @param mod
*/
public void setzeModus(modus mod) {

controll = new Regelwahl().wahl(mod, model.gibModel(), ID);
}

/**
Expand All @@ -254,15 +268,54 @@ public void setzeModus(modus mod) {
* @return
*/
public modus spielstDu() {
return null;
while(true) {
SpielmodusDialog dialog = new SpielmodusDialog();
modus m = dialog.modusWahl();

//Prüft Clien-seitig, ob ein Sauspiel oder ein Si gespielt werden können.
//Eine Hochzeit wird Server-seitig geprüft
//evtl. Verschiebung der Prüfung auf den Server
if(m.toString().substring(0, 7).equals("SAUSPIEL")) {
Karte.farbe f = dialog.farbe(m);
if(new Regelwahl().sauspielMoeglich(f, model.gibModel(), ID)) {
dialog.dispose();
return m;
}
} else {
if(m.equals(modus.SI)) {
if(new Regelwahl().siMoeglich(model.gibModel(), ID)) {
dialog.dispose();
return m;
}
else {
JOptionPane.showMessageDialog(this, "Des konnst ned spuiln!");
continue;
}
}
dialog.dispose();
return m;
}

JOptionPane.showMessageDialog(this, "Des konnst ned spuiln!");
try {
//Bremse
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
continue;
}
}

/**
* Gibt zurück, ob der Spieler klopft
* @return
*/
public boolean klopfstDu() {
return false;
if(javax.swing.JOptionPane.showConfirmDialog(this, "Woist klopfa?") == 0)
return false;
else
return true;
}

/**
Expand Down Expand Up @@ -297,6 +350,8 @@ else if(i == s2)
* @return
*/
public String hochzeit() {
if(JOptionPane.showConfirmDialog(this, "Woist klopfa?") == JOptionPane.OK_OPTION)
return "JA";
return null;
}

Expand All @@ -307,7 +362,8 @@ public String hochzeit() {
* @return
*/
public Karte hochzeitKarte() {
return null;
JOptionPane.showMessageDialog(this, "Welche gibst na her?");
return spielerKarten.spiel();
}

/**
Expand Down
165 changes: 165 additions & 0 deletions src/graphik/SpielmodusDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package graphik;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JRadioButton;

import lib.Karte.farbe;
import lib.Model.modus;

public class SpielmodusDialog extends JFrame {

private JButton[] spiele;
private JCheckBox tout;
private ButtonGroup farbwahl;
private JRadioButton[] farben;

private modus rueckgabe;

public SpielmodusDialog() {
super();

this.setVisible(true);
this.setLayout(null);

spiele = new JButton[6];

for(int i = 0; i < spiele.length; i++) {
spiele[i] = new JButton();
getContentPane().add(spiele[i]);
spiele[i].setVisible(true);
spiele[i].setBounds(0, i*40, 150, 30);
spiele[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
rueckgabe = auswahl(evt);
}
});
}

spiele[0].setText("Sauspiel");
spiele[1].setText("Hochzeit");
spiele[2].setText("Geier");
spiele[3].setText("Wenz");
spiele[4].setText("Solo");
spiele[5].setText("Si");

tout = new JCheckBox();
getContentPane().add(tout);
tout.setBounds(200, 0, 100, 30);
//Tout oder nicht Tout? Das ist hier die Frage!
tout.setText("Tout ?");
tout.setVisible(true);

farbwahl = new ButtonGroup();

farben = new JRadioButton[4];
for(int i = 0; i < 4; i++) {
farben[i] = new JRadioButton();
getContentPane().add(farben[i]);
farbwahl.add(farben[i]);
farben[i].setVisible(true);
farben[i].setBounds(200, 50 * (i + 1), 100, 30);
}

farben[0].setText("Eichel");
farben[1].setText("Gras");
farben[2].setText("Herz");
farben[3].setText("Schellen");

this.setSize(300, 270);
}

/**
* Gibt den ausgewählten Modus zurück
* @return Modus
*/
public modus modusWahl() {
//Wartet solange, bis ein Wert ausgewählt wurde
while(rueckgabe == null) {
try {
Thread.sleep(400);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return rueckgabe;
}

private modus auswahl(ActionEvent evt) {
JButton b = (JButton) evt.getSource();
String mod = b.getText();

switch(mod) {
case "Hochzeit":
return modus.HOCHZEIT;
case "Sauspiel":
if(farbwahl.isSelected(farben[0].getModel()))
return modus.SAUSPIELeichel;
if(farbwahl.isSelected(farben[1].getModel()))
return modus.SAUSPIELgras;
if(farbwahl.isSelected(farben[2].getModel()))
return modus.SAUSPIELherz;
if(farbwahl.isSelected(farben[3].getModel()))
return modus.SAUSPIELschellen;
case "Geier":
if(tout.isSelected())
return modus.GEIERdu;
else
return modus.GEIER;
case "Wenz":
if(tout.isSelected())
return modus.WENZdu;
else
return modus.WENZ;
case "Solo":
if(farbwahl.isSelected(farben[0].getModel())) {
if(tout.isSelected())
return modus.SOLOeichelDU;
return modus.SOLOeichel;
}
if(farbwahl.isSelected(farben[1].getModel())) {
if(tout.isSelected())
return modus.SOLOgrasDU;
return modus.SOLOgras;
}
if(farbwahl.isSelected(farben[2].getModel())) {
if(tout.isSelected())
return modus.SOLOherzDU;
return modus.SOLOherz;
}
if(farbwahl.isSelected(farben[3].getModel())) {
if(tout.isSelected())
return modus.SOLOschellenDU;
return modus.SOLOschellen;
}
case "SI":
return modus.SI;
}

return null;
}

/**
* Gibt die Farbe eines Sauspiels zurück
* @param m
* @return
*/
public farbe farbe(modus m) {
if(m.equals(modus.SAUSPIELeichel))
return farbe.EICHEL;
if(m.equals(modus.SAUSPIELgras))
return farbe.GRAS;
if(m.equals(modus.SAUSPIELherz))
return farbe.HERZ;
if(m.equals(modus.SAUSPIELschellen))
return farbe.SCHELLEN;

return null;
}

}
13 changes: 13 additions & 0 deletions src/lib/Karte.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,18 @@ public wert gibWert() {
public int gibPunkte() {
return punkte[w.ordinal()];
}

/**
* Vergleicht zwei Karten
* @param k
* @return gleich?
*/
public boolean vergleiche(Karte k) {
if(k.gibFarbe().equals(f)
&& k.gibWert().equals(w))
return true;

return false;
}

}
6 changes: 4 additions & 2 deletions src/lib/Netzwerk.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,16 @@ public void setID(int ID) {
public String einlesen() throws Exception {
String input = "error";
try {
//Solange nichts gesendet wird
do {
input = in.readLine();
} while(input.equals("") || input.equals(null));
} while(input.equals(null) || input.equals(""));
} catch(Exception e) {
throw e;
}

//[DEBUG]
System.out.println(input);

return input;
}
}
Loading

0 comments on commit 37829a2

Please sign in to comment.