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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
import static java.lang.Math. *;
import static org.javascool.macros.Macros. *;
import static org.javascool.macros.Stdin. *;
import static org.javascool.macros.Stdout. *;
import static org.javascool.proglets.codagePixels.Functions. *;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
public class MyKeyListener implements KeyListener { // Le switch ecouteur
public void keyPressed(KeyEvent arg0) {
int t;
int v;
switch (arg0.getKeyCode()) {
case KeyEvent.VK_Z:
t=0; // variable t du joueur 1
break;
case KeyEvent.VK_S:
t=1;
break;
case KeyEvent.VK_Q:
t=2;
break;
case KeyEvent.VK_D:
t=3;
break;
case KeyEvent.VK_UP:
v=0; //variable v du joueur 2
break;
case KeyEvent.VK_DOWN:
v=1;
break;
case KeyEvent.VK_LEFT:
v=2;
break;
case KeyEvent.VK_RIGHT:
v=3;
break;
}
}
public void keyReleased(KeyEvent arg0) {
}
public void keyTyped(KeyEvent arg0) {
}
}
void rectangle(int lmin, int lmax, int hmin, int hmax, int r, int v, int b) {
for (int x = lmin; x < lmax + 1; x ++) {
for (int y = hmin; y < hmax + 1; y ++) {
// Code
setPixel(x, y, r, v, b);
}
} // Rectangle de l'interface graphique
}
int depart(int a, int b) { //Géneration d'un point aleatoire sur l'interface graphique
int rejet;
rejet = random(a, b);
return rejet;
}
int[] droite(int x, int y, int s, int joueur) { // fonction de deplacement sur la droite
int[] position = new int[2];
for (int j = 0; j < 5; j ++) {
if( joueur == 1){ setPixel(x + j, y, 250, 10, 10);
}
else { setPixel( x + j, y, 10 , 10, 250); }
position[0] = x+j ;
position[1]= y;
sleep(s);
int[] rgb = getPixelColor(position[0], position[1]);
print (rgb[0]+" ");
print (rgb[1]+" ");
println (rgb[2]+" ");
} return position ;
}
int[] gauche(int x, int y, int s, int joueur) { //fonction de deplacement vers la gauche
int[] position = new int[2] ;
for (int j = 0; j < 5; j ++) {
if( joueur == 1){ setPixel(x - j, y, 250, 10, 10);
}
else { setPixel( x - j, y, 10 , 10, 250); }
position[0] = x-j;
position[1]= y;
sleep(s);
int[] rgb = getPixelColor(position[0], position[1]);
print (rgb[0]+" ");
print (rgb[1]+" ");
println (rgb[2]+" ");
} return position ;
}
int[] haut(int x, int y, int s, int joueur) { //fonction de deplacement vers le haut
int[] position = new int[2];
for (int j = 0; j < 5; j ++) {
if( joueur == 1){ setPixel(x , y +j, 250, 10, 10);
}
else { setPixel( x , y + j, 10 , 10, 250); }
position[0] = x;
position[1]= y + j;
sleep(s);
int[] rgb = getPixelColor(position[0], position[1]);
print (rgb[0]+" ");
print (rgb[1]+" ");
println (rgb[2]+" ");
} return position ;
}
int[] bas(int x, int y, int s, int joueur) { //fonctio de deplacement vers le bas
int[] position = new int[2] ;
for (int j = 0; j < 5; j ++) {
if( joueur == 1){ setPixel(x , y - j, 250, 10, 10);
}
else { setPixel( x , y - j, 10 , 10, 250); }
position[0] = x;
position[1] = y - j;
sleep(s);
int[] rgb = getPixelColor(position[0], position[1]);
print (rgb[0]+" ");
print (rgb[1]+" ");
println (rgb[2]+" ");
}
return position ;
}
void main() {
JFrame jf = new org.javascool.widgets.MainFrame().reset("codagePixels", 600, 800, org.javascool.core.ProgletEngine.getInstance()
.setProglet("codagePixels").getProgletPane());//generation d'interface graphique sur la proglet javaprog avec les keylistener
jf.addKeyListener(new MyKeyListener());
int resultx;
int resulty;
int resultx2;
int resulty2;
int s=0 ;
reset(50, 50);
int width = getWidth();
int height = getHeight();
//int j;//
int positionx;
int positiony;
int[] positionpixel;
int[] newPosition;
int[] newPosition2;
int niveau = readInteger("choisissez le niveau du jeu, niveau 1, 2, ou 3");
switch (niveau ) //switch de la vitesse de deplacement
{
case 1 :
s = 100;
break;
case 2:
s = 40;
break;
case 3 :
s = 2 ;
break;
}
rectangle( - width, + width, - height, + height, 0, 0, 0);
resultx = depart( - 50, + 50);
resulty = depart( - 50, + 50);
resultx2 = depart( - 50, + 50);
resulty2 = depart( - 50, + 50); |
Partager