import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowListener;
import java.awt.*;
import javax.swing.*;
public class Engine extends Frame{
public final int[] tmp = new int[4]; // 1 = blau; 2 = grün; 3 = rot; 4 = gelb; 5 = orange; 6 = cyan;
public final int[] zufall = new int[4];
private GamePanel GamePanel = new GamePanel();
private Point mouseco;
protected int xh, yh;
private int chsnclr;
final private int random(){
return (int)(Math.random()*5)+1;
}
public Engine(){
super("Mastermind");
this.setSize(500, 700);
this.addWindowListener(GamePanel);
this.show();
}
public void paint(final Graphics g){
int zähl = 0;
for(int l = 0; l < 4; l++){
zufall[l] = random();
}
for(int i = 75; i <= 300; i += 70){
tmp[zähl] = zufall[zähl];
for(int a = 0; a <= zähl; a++){
for(int k = 0; k <= zähl; k++){
if(tmp[a] == zufall[k]){
zufall[k] = random();
}
}
}
switch(zufall[zähl]){
case 1:
g.setColor(Color.BLUE);
break;
case 2:
g.setColor(Color.green);
break;
case 3:
g.setColor(Color.red);
break;
case 4:
g.setColor(Color.yellow);
break;
case 5:
g.setColor(Color.ORANGE);
break;
case 6:
g.setColor(Color.CYAN);
break;
}
g.fillOval(i, 600, 25, 25);
zähl++;
}
g.setColor(Color.darkGray);
g.fillRect(75, 600, 235, 50);
for(int i = 0; i < 4; i++){
System.out.println(tmp);
}
g.setColor(Color.black);
for(int y = 75; y <= 525; y += 50){
for(int x = 75; x <= 300; x += 70){
g.drawOval(x, y, 25, 25);
}
}
for(int j = 75; j <= 550; j += 50){
for(int i = 350; i <= 400; i += 70){
g.drawOval(i, j, 10, 10);
}
}
for(int j = 90; j <= 540; j += 50){
for(int i = 350; i <= 400; i += 70){
g.drawOval(i, j, 10, 10);
}
}
for(int j = 90; j <= 540; j += 50){
for(int i = 365; i <= 400; i += 70){
g.drawOval(i, j, 10, 10);
}
}
for(int j = 75; j <= 550; j += 50){
for(int i = 365; i <= 400; i += 70){
g.drawOval(i, j, 10, 10);
}
}
g.drawRect(400, 0, 200, 400);
g.setColor(Color.blue);
g.fillOval(435, 60, 25, 25);
g.setColor(Color.green);
g.fillOval(435, 120, 25, 25);
g.setColor(Color.red);
g.fillOval(435, 180, 25, 25);
g.setColor(Color.yellow);
g.fillOval(435, 240, 25, 25);
g.setColor(Color.orange);
g.fillOval(435, 300, 25, 25);
g.setColor(Color.cyan);
g.fillOval(435, 360, 25, 25);
this.addMouseListener(new MouseListener(){
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
mouseco = e.getPoint();
xh = (int) mouseco.getX();
yh = (int) mouseco.getY();
System.out.println(xh + " | " + yh);
if(xh >= 435 && xh <= 460 && yh >= 60 && yh <= 85){
chsnclr = 1;
System.out.println(chsnclr);
}else if(xh >= 435 && xh <= 460 && yh >= 60*2 && yh <= 85*2){
chsnclr = 2;
System.out.println(chsnclr);
}else if(xh >= 435 && xh <= 460 && yh >= 60*3 && yh <= 85*3){
chsnclr = 3;
System.out.println(chsnclr);
}else if(xh >= 435 && xh <= 460 && yh >= 60*4 && yh <= 85*4){
chsnclr = 4;
System.out.println(chsnclr);
}else if(xh >= 435 && xh <= 460 && yh >= 60*5 && yh <= 85*5){
chsnclr = 5;
System.out.println(chsnclr);
}else if(xh >= 435 && xh <= 460 && yh >= 60*6 && yh <= 85*6){
chsnclr = 6;
System.out.println(chsnclr);
}
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
});
g.setColor(Color.blue);
if(xh >= 75 && yh >= 75){
g.fillOval(75, 75, 25, 25);
}
}
public static void main(String args[]){
Engine engine = new Engine();
}
}
das ist alles...also ich mach java auch erst seit nem halben jahr..deswegen könnts ein bischen falsch sein...