CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

Petit jeu en Java besoin d'aide

kissan
kissan
Niveau 1
23 février 2017 à 16:29:23

Bonjour,
je travail sur un projet juste pour m'occuper et j'ai besoin d'aide :

import java.awt.Color;
import java.awt.Graphics;
import java.applet.Applet;
import java.awt.*;
import java.util.Arrays;
import java.awt.event.*;

public class PJ extends Applet implements KeyListener,Runnable{
boolean gagne;
int largeur=600, bordure=50,xClick=-1000,yClick=-1000,Score;
int nbBilles = 25,hits;
int xposj, yposj;

Color coloriage[]=new Color[nbBilles];
Color temp;
int xPos[]=new int[nbBilles],yPos[]=new int[nbBilles],rayon[]=new int[nbBilles];
boolean droite[]=new boolean[nbBilles],haut[]=new boolean[nbBilles],aff[]=new boolean[nbBilles];
String s="Jhon Project";
Thread bille;
Image sprite;
Graphics h;

public void init() {

setBackground(Color.white);
xposj= 10;
yposj= 10;
setSize(largeur+2*bordure,largeur+2*bordure);
sprite=createImage(largeur+2*bordure,largeur+2*bordure);
h=sprite.getGraphics();
bille=null;
for(int i=0;i<nbBilles;i++)
{
coloriage[i] = new Color((int)(Math.round(Math.random()*250)),(int)(Math.round(Math.random()*250)),(int)(Math.round(Math.random()*250)) );
rayon[i]=i+1;
xPos[i]=(int)(Math.round(Math.random()*(largeur-2*rayon[i])+bordure));
yPos[i]=(int)(Math.round(Math.random()*(largeur-2*rayon[i])+bordure));
droite[i]=i%2==0?true:false;
haut[i]=i%2==0?true:false;
aff[i]=true;
}
gagne=false;
addKeyListener ( this );
}

public void start(){
if(bille==null){
bille=new Thread(this);
bille.start();

}
}

public void stop() {
if(bille!=null) {
bille.stop();
bille = null;

}
}

public void run(){
while(true){
gagne=true;
for(int i=0; i<nbBilles; i++) if (aff[i])
gagne=false;

for(int i=0;i<nbBilles;i++){
if(xPos[i]+rayon[i]>=bordure+largeur)droite[i]=false;
if(yPos[i]+rayon[i]>=bordure+largeur)haut[i]=false;
if(xPos[i]-rayon[i]<=bordure)droite[i]=true;
if(yPos[i]-rayon[i]<=bordure)haut[i]=true;
if(droite[i])xPos[i]+=1*(1+i%1);else xPos[i]+=-1*(1+i%1);
if(haut[i])yPos[i]+=1*(1+i%1);else yPos[i]+=-1*(1+i%1);

}

try{
repaint();

Thread.sleep(50);
}
catch(InterruptedException e){
stop();

}
}
}
public void keyPressed ( KeyEvent e ) {}
public void keyReleased( KeyEvent e ) {}
public void keyTyped( KeyEvent e ) {
char c=e.getKeyChar();
if ( c != KeyEvent.CHAR_UNDEFINED){
/*s = s + c;*/
if (c=='z') yposj -=5;
if (c=='q') xposj -=5;
if (c=='s') yposj +=5;
if (c=='d') xposj +=5;
repaint();
e.consume();
}
}

/*public boolean mouseDown(Event evt, int x, int y){
hits =0;
if(bille!=null){
for (int i=0;i<nbBilles;i++){
if(Math.sqrt(Math.pow(xPos[i]-x,2)+Math.pow(yPos[i]-y,2))<=rayon[i]){
gagne=false;
if (aff[i]==true){
hits++;
aff[i]=false;
}
}

if(hits != 0)
Score += hits;
else
Score += -1;
}

xClick=x;
yClick=y;

return true

}*/
public void update (Graphics g){
paint(g);
}

public void paint (Graphics g){
g.drawImage(sprite,0,0,Color.white,this);
g.drawString(" Jhon",xposj,yposj);
g.drawString("I",xposj,yposj+11);
g.drawString("o",xposj-2,yposj+6);
g.drawString("]",xposj-1,yposj+16);
g.drawString("[",xposj+1,yposj+16);
g.drawString("_", xposj-2,yposj+4);
g.drawString(s,300,300);

h.clearRect(0,0,largeur+2*bordure,largeur+2*bordure);
h.setColor(Color.black);
h.drawLine(bordure, bordure, bordure, bordure+largeur);
h.drawLine(bordure, bordure, bordure+largeur, bordure);
h.drawLine(bordure+largeur, bordure, bordure+largeur,bordure+largeur);
h.drawLine(bordure,bordure+largeur, bordure+largeur,bordure+largeur);
h.drawString("Score : "+Score, 100,100);
for (int i=0;i<nbBilles;i++){
h.setColor(coloriage[i]);
if(aff[i])h.fillOval(xPos[i]-rayon[i],yPos[i]-rayon[i],2*rayon[i], 2*rayon[i]);
}
h.setColor(Color.black);
if (gagne){
h.setFont(new Font("default",Font.BOLD,40));
h.drawString("Gagné!",largeur/2,bordure+largeur/2);
}

repaint();

}
public void destroy(){
h.dispose();
sprite.flush();
}
}

Le code si dessus permet d'afficher plusieurs Billes mais le petit personnage clignote et si vous avez une solution je suis preneur !

Merci Kissan.

kissan
kissan
Niveau 1
23 février 2017 à 16:30:11

oui je sais sa fais saigner les yeux.... je suis un débutant
lol

Miku_Hatsunee
Miku_Hatsunee
Niveau 4
24 février 2017 à 18:07:23

Salut
J'y connais rien en Java par contre je te conseil de mettre ton code ici http://pastebin.com/ et de mettre le liens sur ton post, ce sera plus lisible et augmentera donc tes chances d'être aidé. https://image.noelshack.com/fichiers/2016/38/1474490323-risitas596.png

Sous forums
  • Aide à l'achat Mac
  • Création de sites web
  • Création de Jeux
  • Linux
  • Programmation
  • Internet
  • Steam Deck
  • Macintosh
  • Hardware
La vidéo du moment