commit
ca492d7fd3
|
@ -12,6 +12,8 @@ public class Graph {
|
|||
KnotenGraph.add(k);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Knote getKnote(String name) {
|
||||
for (Knote kAusKnotenGraph: KnotenGraph) {
|
||||
if (kAusKnotenGraph.getName().equalsIgnoreCase(name))
|
||||
|
|
|
@ -1,22 +1,61 @@
|
|||
package Graphen;
|
||||
|
||||
public class Kanten {
|
||||
//jede Kante verbindet zwei Knoten
|
||||
Knote anfangsKnote; // mannheim
|
||||
Knote endeKnote; // heidelberg
|
||||
// jede Kante verbindet zwei Knoten
|
||||
private Knote anfangsKnote;
|
||||
private Knote endeKnote;
|
||||
private boolean UndirectedGraph;
|
||||
private int gewicht;
|
||||
|
||||
// Kante verbindet zwei Knoten (Undirected Graph)
|
||||
public Kanten(Knote anfangsKnote, Knote endeKnote, boolean UndirectedGraph) {
|
||||
this.anfangsKnote = anfangsKnote;
|
||||
this.endeKnote = endeKnote;
|
||||
this.UndirectedGraph = UndirectedGraph;
|
||||
anfangsKnote.addKante(this); //speichert dann zu ihrem ArrayList diese Kante
|
||||
endeKnote.addKante(this);//speichert dann auch zu ihrem ArrayList diese gleiche Kante
|
||||
}
|
||||
|
||||
// Kante verbindet eine Knote (Directed Graph)
|
||||
public Kanten(Knote anfangsKnote, Knote endeKnote) {
|
||||
this.anfangsKnote = anfangsKnote;
|
||||
this.endeKnote = endeKnote;
|
||||
anfangsKnote.addKante(this);
|
||||
endeKnote.addKante(this);
|
||||
}
|
||||
|
||||
// Kante verbindet eine Knoten und mit Gewicht (Weighted Directed Graph)
|
||||
public Kanten(Knote anfangsKnote, Knote endeKnote, int gewicht) {
|
||||
this.anfangsKnote = anfangsKnote;
|
||||
this.endeKnote = endeKnote;
|
||||
//anfangsKnote.addkanteMitGewicht(this,gewicht);
|
||||
}
|
||||
|
||||
// Kante verbindet zwei Knoten und mit Gewicht (Weighted UnDirected Graph)
|
||||
public Kanten(Knote anfangsKnote, Knote endeKnote, int gewicht, boolean UndirectedGraph) {
|
||||
this.anfangsKnote = anfangsKnote;
|
||||
this.endeKnote = endeKnote;
|
||||
// anfangsKnote.addkanteMitGewicht(this, gewicht);
|
||||
// endeKnote.addkanteMitGewicht(this, gewicht);
|
||||
this.UndirectedGraph = UndirectedGraph;
|
||||
}
|
||||
|
||||
public Knote getPartner(Knote k) {
|
||||
Knote partner = (k == anfangsKnote) ? endeKnote : anfangsKnote;
|
||||
|
||||
return partner;
|
||||
return (k == anfangsKnote) ? endeKnote : anfangsKnote;
|
||||
}
|
||||
|
||||
public int getGewicht() {
|
||||
return gewicht;
|
||||
}
|
||||
|
||||
public Knote getAnfangsKnote() {
|
||||
return anfangsKnote;
|
||||
}
|
||||
|
||||
public Knote getEndeKnote() {
|
||||
return endeKnote;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
package Graphen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Knote {
|
||||
String name;
|
||||
ArrayList<Kanten> kantenList = new ArrayList<>();
|
||||
private String name;
|
||||
private ArrayList<Kanten> kantenList = new ArrayList<>();
|
||||
|
||||
|
||||
Knote(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//add kante zu this (knote)
|
||||
public void addKante(Kanten k) {
|
||||
kantenList.add(k);
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -24,13 +28,12 @@ public class Knote {
|
|||
return kantenList;
|
||||
}
|
||||
|
||||
ArrayList<Knote> verbindeteKnoten;
|
||||
public void getPartner() {
|
||||
ArrayList<Kanten> merker = getKantenList();
|
||||
if (merker == null)
|
||||
return ;
|
||||
|
||||
verbindeteKnoten = new ArrayList<>();
|
||||
ArrayList<Knote> verbindeteKnoten = new ArrayList<>();
|
||||
for (Kanten m : merker)
|
||||
verbindeteKnoten.add(m.getPartner(this));
|
||||
|
||||
|
|
|
@ -4,12 +4,15 @@ public class Test {
|
|||
|
||||
public static void main(String[] args) {
|
||||
Graph graph = new Graph();
|
||||
|
||||
Knote mannheim = new Knote("Mannheim");
|
||||
Knote heidelberg = new Knote("Heidelberg");
|
||||
Knote frankfourt = new Knote("Frankfourt");
|
||||
Knote Maiz = new Knote("Maiz");
|
||||
graph.addknoten(mannheim);
|
||||
graph.addknoten(heidelberg);
|
||||
graph.addknoten(frankfourt);
|
||||
graph.addknoten(Maiz);
|
||||
|
||||
new Kanten(graph.getKnote("Mannheim"),graph.getKnote("Heidelberg"));
|
||||
new Kanten(graph.getKnote("Mannheim"),graph.getKnote("Frankfourt"));
|
||||
|
@ -18,8 +21,9 @@ public class Test {
|
|||
mannheim.getPartner();
|
||||
heidelberg.getPartner();
|
||||
frankfourt.getPartner();
|
||||
|
||||
Kanten k3 = new Kanten(graph.getKnote("Heidelberg"),graph.getKnote("Maiz"),25,true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package Übungen.Excel;
|
||||
|
||||
public class Excell {
|
||||
private static char[] buchstaben;
|
||||
public static void main(String[] args) {
|
||||
fülleTabell();
|
||||
printTabelle();
|
||||
}
|
||||
|
||||
public static void fülleTabell() {
|
||||
buchstaben = new char[26];
|
||||
int i = 0;
|
||||
for (char b = 'A'; b <= 'Z';b++) {
|
||||
buchstaben[i++] = b;
|
||||
}
|
||||
}
|
||||
|
||||
public static void printTabelle() {
|
||||
for (char a: buchstaben)
|
||||
System.out.print("| " + a + " |");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package Übungen.TicTac;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Controller {
|
||||
static Scanner scan = new Scanner(System.in);
|
||||
static String[][] spielField = new String[3][3];
|
||||
private Modell spieler1;
|
||||
private Modell spieler2;
|
||||
private View view;
|
||||
|
||||
public Controller(Modell spieler1, Modell spieler2, View view) {
|
||||
this.spieler1 = spieler1;
|
||||
this.spieler2 = spieler2;
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public static boolean checkSet(String X_O, int x, int y) {
|
||||
if (x < 0 || x > 2 || y < 0 || y > 2)
|
||||
return false;
|
||||
|
||||
if (!(spielField[x][y].equals("-")))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static boolean checkGewinner(String player) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (spielField[i][0].equals(player) && spielField[i][1].equals(player) && spielField[i][2].equals(player))
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (spielField[0][i].equals(player) && spielField[1][i].equals(player) && spielField[2][i].equals(player))
|
||||
return true;
|
||||
}
|
||||
if (spielField[0][0].equals(player) && spielField[1][1].equals(player) && spielField[2][2].equals(player))
|
||||
return true;
|
||||
|
||||
if (spielField[0][2].equals(player) && spielField[1][1].equals(player) && spielField[2][0].equals(player))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void ausgabeSpielFeld(String X_O, int x, int y) {
|
||||
spielField[x][y] = X_O;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
System.out.print(spielField[i][j] + "|");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
public static void printSpielfeld() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (j == 2) {
|
||||
spielField[i][j] = "-";
|
||||
System.out.print(spielField[i][j]);
|
||||
} else {
|
||||
spielField[i][j] = "-";
|
||||
System.out.print(spielField[i][j]);
|
||||
System.out.print("|");
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package Übungen.TicTac;
|
||||
|
||||
public class Modell {
|
||||
|
||||
private String name;
|
||||
private String vorname;
|
||||
private int anzahlGewinn;
|
||||
private String zeichen;
|
||||
|
||||
public Modell(String name, String vorname, int anzahlGewinn,String zeichen) {
|
||||
this.name = name;
|
||||
this.vorname = vorname;
|
||||
this.anzahlGewinn = anzahlGewinn;
|
||||
this.zeichen = zeichen;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getVorname() {
|
||||
return vorname;
|
||||
}
|
||||
public void setVorname(String vorname) {
|
||||
this.vorname = vorname;
|
||||
}
|
||||
public int getAnzahlGewinn() {
|
||||
return anzahlGewinn;
|
||||
}
|
||||
public void setAnzahlGewinn(int anzahlGewinn) {
|
||||
this.anzahlGewinn = anzahlGewinn;
|
||||
}
|
||||
|
||||
public String getZeichen() {
|
||||
return zeichen;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package Übungen.TicTac;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Tic_Tac_Toe {
|
||||
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
//
|
||||
// printSpielfeld();
|
||||
// while (true) {
|
||||
// System.out.println("Bitte geben Sie 'x' und neue Position ein: ");
|
||||
// String playerx =scan.nextLine();
|
||||
// int x = scan.nextInt();
|
||||
// int y = scan.nextInt();
|
||||
// while (!checkSet(playerx, x, y)) {
|
||||
// scan.nextLine();
|
||||
// System.out.println("Falsche Eingabe! Versuchen Sie nochmal: ");
|
||||
// playerx =scan.nextLine();
|
||||
// x = scan.nextInt();
|
||||
// y = scan.nextInt();
|
||||
// if (checkSet(playerx, x, y))
|
||||
// break;
|
||||
// }
|
||||
// ausgabeSpielFeld(playerx, x, y);
|
||||
// if (checkGewinner(playerx)) {
|
||||
// System.out.println("Spieler X hat gewonnen!");
|
||||
// break;
|
||||
// }
|
||||
// scan.nextLine();
|
||||
//
|
||||
// System.out.println("Bitte geben Sie 'O' und neue Position ein: ");
|
||||
// String playero =scan.nextLine();
|
||||
// x = scan.nextInt();
|
||||
// y = scan.nextInt();
|
||||
// while (!checkSet(playero, x, y)) {
|
||||
// scan.nextLine();
|
||||
// System.out.println("Falsche Eingabe! Versuchen Sie nochmal: ");
|
||||
// playero =scan.nextLine();
|
||||
// x = scan.nextInt();
|
||||
// y = scan.nextInt();
|
||||
// }
|
||||
// ausgabeSpielFeld(playero, x, y);
|
||||
// if (checkGewinner(playero)) {
|
||||
// System.out.println("Spieler O hat gewonnen!");
|
||||
// break;
|
||||
// }
|
||||
// scan.nextLine();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package Übungen.TicTac;
|
||||
|
||||
public class View {
|
||||
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
package Übungen;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Tic_Tac_Toe {
|
||||
static Scanner scan = new Scanner(System.in);
|
||||
static String[][] spielField = new String[3][3];
|
||||
static final String playerx = "x" ;
|
||||
static final String playero = "o" ;
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
|
||||
printSpielfeld();
|
||||
while (true) {
|
||||
System.out.println("Bitte geben Sie 'x' und neue Position ein: ");
|
||||
String playerx =scan.nextLine();
|
||||
int x = scan.nextInt();
|
||||
int y = scan.nextInt();
|
||||
while (!checkSet(playerx, x, y)) {
|
||||
scan.nextLine();
|
||||
System.out.println("Falsche Eingabe! Versuchen Sie nochmal: ");
|
||||
playerx =scan.nextLine();
|
||||
x = scan.nextInt();
|
||||
y = scan.nextInt();
|
||||
if (checkSet(playerx, x, y))
|
||||
break;
|
||||
}
|
||||
ausgabeSpielFeld(playerx, x, y);
|
||||
if (checkGewinner(playerx)) {
|
||||
System.out.println("Spieler X hat gewonnen!");
|
||||
break;
|
||||
}
|
||||
scan.nextLine();
|
||||
|
||||
System.out.println("Bitte geben Sie 'O' und neue Position ein: ");
|
||||
String playero =scan.nextLine();
|
||||
x = scan.nextInt();
|
||||
y = scan.nextInt();
|
||||
while (!checkSet(playero, x, y)) {
|
||||
scan.nextLine();
|
||||
System.out.println("Falsche Eingabe! Versuchen Sie nochmal: ");
|
||||
playero =scan.nextLine();
|
||||
x = scan.nextInt();
|
||||
y = scan.nextInt();
|
||||
}
|
||||
ausgabeSpielFeld(playero, x, y);
|
||||
if (checkGewinner(playero)) {
|
||||
System.out.println("Spieler O hat gewonnen!");
|
||||
break;
|
||||
}
|
||||
scan.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkSet(String X_O, int x, int y){
|
||||
if ( x < 0 || x > 2 || y < 0 || y > 2)
|
||||
return false;
|
||||
|
||||
if (!(spielField[x][y].equals("-")) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean checkGewinner(String player){
|
||||
for(int i = 0 ; i < 3; i++){
|
||||
if (spielField[i][0].equals(player) && spielField[i][1].equals(player) && spielField[i][2].equals(player))
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < 3; i++){
|
||||
if (spielField[0][i].equals(player) &&spielField[1][i].equals(player) &&spielField[2][i].equals(player))
|
||||
return true;
|
||||
}
|
||||
if (spielField[0][0].equals(player)&& spielField[1][1].equals(player)&& spielField[2][2].equals(player))
|
||||
return true;
|
||||
|
||||
if (spielField[0][2].equals(player)&& spielField[1][1].equals(player)&& spielField[2][0].equals(player))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void ausgabeSpielFeld(String X_O, int x, int y){
|
||||
spielField[x][y] = X_O;
|
||||
for (int i = 0; i < 3; i++){
|
||||
for (int j = 0; j < 3; j++){
|
||||
System.out.print(spielField[i][j] + "|");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
public static void printSpielfeld(){
|
||||
for (int i = 0; i < 3; i++){
|
||||
for (int j = 0; j < 3; j++){
|
||||
if (j == 2){
|
||||
spielField[i][j] = "-";
|
||||
System.out.print(spielField[i][j]);
|
||||
}else{
|
||||
spielField[i][j] = "-";
|
||||
System.out.print(spielField[i][j]);
|
||||
System.out.print("|");
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue