Quellcode
- package de.jpp.minigo;
- public enum Zustand {
- LEER, WEISS, SCHWARZ;
- public Zustand komplement(){
- if(this.equals(Zustand.WEISS.komplement())){
- return Zustand.SCHWARZ;
- }
- package de.jpp.minigo;
- public class Spielbrett {
- Zustand[][] spielbrett;
- public Spielbrett() {
- Zustand[][] spielbrett = new Zustand[10][10];
- for (int x = 0; x < 10; x++) {
- for (int y = 0; y < 10; y++) {
- spielbrett[x][y] = Zustand.LEER;
- }
- }
- }
- public Zustand getFeld(int x, int y) {
- if (x < 0 || y < 0) {
- throw new IllegalArgumentException("x und y nicht enthalten!");
- } else if (x > 9 || y > 9) {
- throw new IllegalArgumentException("x und y nicht enthalten!");
- }
- return spielbrett[x][y];
- }
- public void setFeld(int x, int y, Zustand zustand) {
- if (x < 0 || y < 0 || x > 9 || y > 9) {
- throw new IllegalArgumentException("x und y nicht enthalten!");
- }
- else if (zustand != Zustand.LEER) {
- throw new IllegalArgumentException();
- } else if (zustand != Zustand.SCHWARZ) {
- throw new IllegalArgumentException();
- } else if (zustand != Zustand.WEISS) {
- throw new IllegalArgumentException();
- }
- spielbrett[x][y] = zustand;
- }
- public String toString() {
- [String kopf = "y\\x 0 1 2 3 4 5 6 7 8 9";
- String felder = "\n1\n2\n3\n4\n5\n6\n7\n8\n9";
- for (int x = 0; x < 9; x++) {
- for (int y = 0; y < 9; y++) {
- if (spielbrett[x][y].equals(Zustand.WEISS)) {
- felder += "O" + "";
- } else if (spielbrett[x][y].equals(Zustand.SCHWARZ)) {
- felder += "X" + "";
- } else {
- felder += "." + "";
- }
- }
- }
- return kopf + felder;
- }
- public boolean equals(Object objekt) {
- Object[][] vergleich = new Zustand[10][10];
- if (spielbrett.equals(vergleich)) {
- return true;
- }
- vergleich = null;
- if (spielbrett.equals(vergleich)) {
- return false;
- } else
- return false;
- }
- public Object clone() {
- Object[][] spielbrettgeklont = new Zustand[10][10];
- for (int x = 0; x < 9; x++) {
- for (int y = 0; y < 9; y++) {
- spielbrettgeklont[x][y] = spielbrett[x][y];
- }
- }
- return spielbrettgeklont;
- }
- public static void main(String[] args) {
- Spielbrett spiel = new Spielbrett();
- System.out.println(spiel.toString());
- }
- }
- else if(this.equals(Zustand.SCHWARZ.komplement())){
- return Zustand.WEISS;
- }
- else return Zustand.LEER;
- }
- }
// edit by vince - code highlighting