Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
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 |
public class Test{ public static void main(String[] args){ JFrame fenster = new JFrame("Flappys-Dream-remake_from_Me"); fenster.setSize(550, 650); fenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fenster.setLocationRelativeTo(null); fenster.setVisible(true); Zeichnung zeichnung = new Zeichnung(); fenster.add(zeichnung); } } class Zeichnung extends JPanel {//Kann kein Mauslistener implementieren Rectangle bird; ActionListener action; MouseListener maus; int röhre = 450; boolean start = true; ArrayList<Rectangle> columns; Timer time; public void addColumn(boolean start){ if(start){ columns.add(new Rectangle(röhre, 0, 50, 200)); columns.add(new Rectangle(röhre, 300, 50, 250)); } } public void paintColumn(Graphics g, Rectangle column) { g.setColor(Color.green.darker()); g.fillRect(column.x, column.y, column.width, column.height); } public void jump(){ bird.y = bird.y -= 20; } public Zeichnung(){ columns = new ArrayList<Rectangle>(); bird = new Rectangle(180, 80, 20, 20); action = new ActionListener(){ public void actionPerformed(ActionEvent e){ if(bird.y <= 550){ bird.y = bird.y +1; } if (start) { for (int i = 0; i < columns.size(); i++) { Rectangle column = columns.get(i); column.x -= 1; } } repaint(); } }; maus = new MouseListener(){ public void mouseClicked(MouseEvent e){ jump(); // nur ein kleiner Test int al = e.getX(); System.out.println(al ); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }; addColumn(true); time = new Timer(10, action); time.start(); } public void paintComponent(Graphics g){ super.paintComponent(g); g.setColor(Color.BLUE); g.fillRect(0, 0, 550, 650); g.setColor(Color.ORANGE); g.fillRect(0, 550, 550, 100); for (Rectangle column : columns) { paintColumn(g, column); } g.setColor(Color.RED); g.fillRect(bird.x, bird.y, bird.width, bird.height); } } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Slenderguy« (27.11.2015, 14:15)
Administrator
Quellcode |
|
1 |
addMouseListener(maus); |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 |
maus = new MouseAdapter(){ @Override public void mouseClicked(MouseEvent e){ jump(); // nur ein kleiner Test int al = e.getX(); System.out.println(al ); } }; |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »InselÄffchen« (21.11.2015, 13:29) aus folgendem Grund: Tipp zum MouseAdapter hinzugefügt.
Quellcode |
|
1 2 3 |
int[] Zahl = new int[10]; int Zufall = 1; int Anzahl = 5; |
Quellcode |
|
1 2 3 4 5 6 7 8 |
for(int Nr = 1; Nr <= Anzahl; Nr++){ while(Zahl[Zufall] == 1){ Zufall = (int)(Math.random()*9)+1; } Zahl[Zufall] = 1; System.out.println(Nr -1 + ". Zahl lautet = " +Zufall); |
Quellcode |
|
1 2 3 4 5 6 7 8 |
for(int Nr = 1; Nr <= Anzahl; Nr++){ while(Zahl[Zufall] != 1){ Zufall = (int)(Math.random()*9)+1; } Zahl[Zufall] = 1; System.out.println(Nr -1 + ". Zahl lautet = " +Zufall); |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige