1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
|
int [][]spielfeld=new int [4][4];
float a=random(1);
int spieler= (int)(a+0.5);
void setup() {
int i;
size(700, 500);
background(255);
//initialisiere Feld so dass die Koordinaten
//mit 0 immer -1 sind
for(i=0;i<3;i++){
spielfeld[0][i] = -1;
spielfeld[i][0] = -1;
}
PImage myImage = loadImage ("bunt.jpg");
image (myImage, 0, 0);
}
int getFeldY(){
int y;
y = (mouseY-150)/100 + 1;
//check ob gültiges Spielfeld
if(y>3||y<1){
y=0; //kein gültiges Feld
}
return y;
}
int getFeldX(){
int x;
x = (mouseX-200)/100 + 1;
//check ob gültiges Spielfeld
if(x>3||x<1){
x=0; //kein gültiges Feld
}
return x;
}
void drawCross(int x, int y){
line(125+(100*x), 75+(100*y), 175+(100*x), 125+(100*y));
line(175+(100*x), 75+(100*y), 125+(100*x), 125+(100*y));
}
void drawCircle(int x, int y){
noFill();
ellipse(150+(x*100), 100+(y*100), 50, 50);
}
int getSpielFeldWert(int x, int y){
return spielfeld[x][y];
}
void setSpielFeldWert(int x, int y, int wert){
spielfeld[x][y] = wert;
}
void draw() {
int x,y,wert;
textSize(60);
fill(0);
text("TIC TAC TOE", 150, 80);
stroke(0);
strokeWeight(5);
line(200, 250, 500, 250);
line(200, 350, 500, 350);
line(300, 150, 300, 450);
line(400, 150, 400, 450);
if (mousePressed) {
x = getFeldX();
y = getFeldY();
wert = getSpielFeldWert(x,y);
if(wert==0){
if(spieler==1 && mouseButton==LEFT){
drawCross(x,y);
setSpielFeldWert(x,y,1);
spieler = 0;
}
if(spieler==0 && mouseButton==RIGHT){
drawCircle(x,y);
setSpielFeldWert(x,y,2);
spieler = 1;
}
}
}
}
|