Verfügbare Informationen zu "Trisentis"
Qualität des Beitrags: Beteiligte Poster: alexander - Selflezz Forum: A-Welt Forum Forenbeschreibung: Das geile Forum aus dem Unterforum: Java-Forum Antworten: 4 Forum gestartet am: Freitag 04.03.2005 Sprache: deutsch Link zum Originaltopic: Trisentis Letzte Antwort: vor 18 Jahren, 10 Monaten, 19 Tagen, 23 Stunden, 2 Minuten
Alle Beiträge und Antworten zu "Trisentis"
Re: Trisentis
alexander - 03.06.2005, 13:32Trisentis
Die Vorversion:
Code: /*
Trisentis ist ein Spiel, bei dem das angezeigte Feld
aus n x n weissen Knoepfen durch Anklicken der Knoepfe
schwarz gefaerbt werden soll.
Bei jedem Anklicken eines Knopfes wechseln dessen
Nachbarn ihre Farbe.
Das Spiel ist z. B. fuer n = 2, 4, 6, 8, 10 loesbar,
fuer n = 3, 5, 7, 9, 11,... ist es nicht loesbar.
(Die naheliegende Vermutung ist noch unbewiesen!)
*/
import java.awt.*;
import java.awt.event.*;
class InputButton extends Button
{
// Attribute
protected ButtonPanel buttons;
protected int row, col;
protected boolean black;
public InputButton(int i,int j,ButtonPanel b)
{
buttons = b;
row = i;
col = j;
// Eventverarbeitung
}
public void changeColor()
{
setBackground(new Color(255,255,255));
}
public void reset()
{
setBackground(new Color(0,0,0));
}
}
class ButtonPanel extends Panel
{
protected int size;
protected InputButton[][] button;
public ButtonPanel(int n)
{
size = n;
setLayout(new GridLayout(n,n,2,2));
button = new InputButton[n][n];
for(int k=0;k<n;k++)
{
for(int l=0;l<n;l++)
{
button[k][l] = new InputButton(l,k,this);
add(button[k][l]);
}
}
}
public void changeNeighborsOf(int x,int y)
{
}
public void reset()
{
}
}
public class Trisentis extends Frame
{
// Attribute:
protected ButtonPanel buttons; // Eingabefeld
protected Button resetButton; // Reset-Knopf
// Konstruktor:
public Trisentis(int size)
{
super("Trisentis");
// Bestandteile konstruieren:
buttons = new ButtonPanel(size);
resetButton = new Button("Reset");
add("Center", buttons);
add("South", resetButton);
resetButton.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent e) { buttons.reset(); }
});
this.addWindowListener
(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
// Spiel sichtbar machen:
setSize(400, 440);
show();
}
// Methode:
// Fuer den Aufruf von einer Kommandozeile:
public static void main(String[] args) {
if (args.length != 1)
{
System.out.println("Trisentis benoetigt genau ein int-Argument");
} else
{
int size = Integer.parseInt(args[0]);
new Trisentis(size);
}
}
}
Re: Trisentis
alexander - 05.06.2005, 12:52
Na hatt es jemand raus? Nein? Ok, so sieht es bei mir aus:
Code: /*
Trisentis ist ein Spiel, bei dem das angezeigte Feld
aus n x n weissen Knoepfen durch Anklicken der Knoepfe
schwarz gefaerbt werden soll.
Bei jedem Anklicken eines Knopfes wechseln dessen
Nachbarn ihre Farbe.
Das Spiel ist z. B. fuer n = 2, 4, 6, 8, 10 loesbar,
fuer n = 3, 5, 7, 9, 11,... ist es nicht loesbar.
(Die naheliegende Vermutung ist noch unbewiesen!)
*/
import java.awt.*;
import java.awt.event.*;
class InputButton extends Button
{
// Attribute
protected ButtonPanel buttons;
protected int row, col;
protected boolean black;
public InputButton(int i,int j,ButtonPanel b)
{
buttons = b;
row = i;
col = j;
// Eventverarbeitung
setBackground(new Color(255,255,255));
}
public void changeColor()
{
if(getBackground().equals(new Color(0,0,0)))
setBackground(new Color(255,255,255));
else
setBackground(new Color(0,0,0));
}
public void reset()
{
setBackground(new Color(255,255,255));
}
}
class ButtonPanel extends Panel
{
protected int size;
protected InputButton[][] button;
public ButtonPanel(int n)
{
size = n;
setLayout(new GridLayout(n,n,2,2));
button = new InputButton[n][n];
for(int k=0;k<n;k++)
{
for(int l=0;l<n;l++)
{
button[k][l] = new InputButton(l,k,this);
button[k][l].addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent e){
changeNeighborsOf(((InputButton)e.getSource()).col,
((InputButton)e.getSource()).row);
}
});
add(button[k][l]);
}
}
}
public void changeNeighborsOf(int x,int y)
{
for(int k=-1;k<2;k++)
{
for(int l=-1;l<2;l++)
{
if(x+k>=0 && x+k<size && y+l>=0 && y+l<size &&(k!=0 || l!=0))
{
button[x+k][y+l].changeColor();
}
}
}
}
public void reset()
{
for(int k=0;k<size;k++)
{
for(int l=0;l<size;l++)
{
button[k][l].reset();
}
}
}
}
public class Trisentis extends Frame
{
// Attribute:
protected ButtonPanel buttons; // Eingabefeld
protected Button resetButton; // Reset-Knopf
// Konstruktor:
public Trisentis(int size)
{
super("Trisentis");
// Bestandteile konstruieren:
buttons = new ButtonPanel(size);
resetButton = new Button("Reset");
add("Center", buttons);
add("South", resetButton);
resetButton.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent e) { buttons.reset(); }
});
this.addWindowListener
(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
// Spiel sichtbar machen:
setSize(400, 440);
show();
}
// Methode:
// Fuer den Aufruf von einer Kommandozeile:
public static void main(String[] args) {
if (args.length != 1)
{
System.out.println("Trisentis benoetigt genau ein int-Argument");
} else
{
int size = Integer.parseInt(args[0]);
new Trisentis(size);
}
}
}
Hat es euch auch so leicht gefallen wie mir? :wink:
Re: Trisentis
alexander - 08.06.2005, 19:18
Applet Version:
Code: import java.awt.*;
import java.applet.*;
import java.awt.event.*;
class InputButton extends Button
{
// Attribute
protected ButtonPanel buttons;
protected int row, col;
protected boolean black;
public InputButton(int i,int j,ButtonPanel b)
{
buttons = b;
row = i;
col = j;
// Eventverarbeitung
setBackground(new Color(255,255,255));
}
public void changeColor()
{
if(getBackground().equals(new Color(0,0,0)))
setBackground(new Color(255,255,255));
else
setBackground(new Color(0,0,0));
}
public void reset()
{
setBackground(new Color(255,255,255));
}
}
class ButtonPanel extends Panel
{
protected int size;
protected InputButton[][] button;
public ButtonPanel(int n)
{
size = n;
setLayout(new GridLayout(n,n,2,2));
button = new InputButton[n][n];
for(int k=0;k<n;k++)
{
for(int l=0;l<n;l++)
{
button[k][l] = new InputButton(l,k,this);
button[k][l].addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent e){
changeNeighborsOf(((InputButton)e.getSource()).col,
((InputButton)e.getSource()).row);
}
});
add(button[k][l]);
}
}
}
public void changeNeighborsOf(int x,int y)
{
for(int k=-1;k<2;k++)
{
for(int l=-1;l<2;l++)
{
if(x+k>=0 && x+k<size && y+l>=0 && y+l<size &&(k!=0 || l!=0))
{
button[x+k][y+l].changeColor();
}
}
}
}
public void reset()
{
for(int k=0;k<size;k++)
{
for(int l=0;l<size;l++)
{
button[k][l].reset();
}
}
}
}
public class Trisentis extends Applet
{
boolean erstellen = true;
TextField tf;
Button b;
int groesse;
// Attribute:
protected ButtonPanel buttons; // Eingabefeld
protected Button resetButton; // Reset-Knopf
public void paint(Graphics g)
{
if(erstellen)
{
g.drawString("Bitte geben Sie die Größe ein", 20, 20);
}
}
public void init()
{
setLayout(null); // erst mal kein Layout
tf = new TextField();
tf.setBounds(20,40,80,30);
add(tf);
b = new Button();
b.setBounds(20,70,80,30);
b.setLabel("OK");
b.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent e){
verarbeiten();
}
});
add(b);
}
public void verarbeiten()
{
groesse = Integer.parseInt(tf.getText()); // Eingabe einlessen
if(groesse > 0)
{
remove(tf);
remove(b);
// Bestandteile konstruieren:
this.setLayout(new BorderLayout()); // wichtig das Layout setzen
buttons = new ButtonPanel(groesse);
resetButton = new Button("Reset");
add("Center", buttons);
add("South", resetButton);
resetButton.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent e) { buttons.reset(); }
});
erstellen = false;
repaint();
// ohne das wird nichts angezeigt
// beim Browser wird die Größe nicht geändert
resize(400,400);
}
}
}
Re: Trisentis
Selflezz - 09.06.2005, 10:20
vielen dank!
Mit folgendem Code, können Sie den Beitrag ganz bequem auf ihrer Homepage verlinken
Weitere Beiträge aus dem Forum A-Welt Forum
Verarsche bei Sammelpackungen - gepostet von alexander am Samstag 29.10.2005
Ähnliche Beiträge wie "Trisentis"