BlueJ Wie programmiere ich das?

Hallo zusammen, ich habe mir vorgenommen ein Cardgame, ähnlich wie dieses TGC von Genshin Impact zu erstellen. (Natürlich in einer kleineren simpleren Variante).
ich verwende in BlueJ eine von der Schule gestellt Basis Bibliothek.

Nun möchte ich dass man in einem extra Menü (Klasse: Kartensammlung) seine Karten die man nutzen möchte auswählen kann und die dann in der Klasse: Arena (Der Ort wo das Spiel stattfindet) erscheinen.

Ich habe aber keinen Schimmer wie es geht :/ Ich habe bereits versucht jede Karte mit der Variable: Auswahl einen Wert zuzuteilen und diesen dann mit If(…){} abzufragen, ohne Erfolg.

Könnte mir jemand dabei Helfen? Ich kann den Code leider nicht hochladen, da ich diesen Text hier am Handy schreibe. Aber wenn jemand sich da auskennt, würde ich mich sehr freuen. LG

(Dass ist das erste mal das ich Gute Frage.de verwende, also seid nicht zu streng mit mir, wenn ich was falsch gemacht haben sollte.)

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
1 Answer
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
regex9
1 year ago

(…) I use a base library provided by the school in BlueJ.

I guess it’s the basicUTF8151026.jar.

Now I want you to select your maps you want to use in an extra menu (…)

You need a class that can describe/represent a card. For the selection menu, you can create an array that will then display all the cards that are available.

Visually, the cards could be displayed by means of buttons (Buttons) are shown. So you use a loop over the array and place a single entry Button and add it to the graphical surface. Each button will also be equipped with a Buttons in which the card associated with the button is inserted into a new array (or a list).

This is indicated as follows:

private int maximalErlaubteKartenanzahl = 10;
private Karte[] ausgewaehlteKarten = new Karte[maximalErlaubteKartenanzahl];
private int aktuellGewaehlteKartenzahl = 0;

/* ... */

for (Karte karte : auswahlKarten) {
  Knopf knopf = new Knopf(/* ... */);
  knopf.setzeKnopfLauscher(gedrueckterKnopf -> {
    if (aktuellGewaehlteKartenzahl < maximalErlaubteKartenanzahl) {
      ausgewaehlteKarten[aktuellGewaehlteKartenzahl++] = karte;
    }
  });
}

The setzebutton-Method is passed an anonymous function. This can remember the values from the current context. At the push of a button, it is executed and can insert the card object that it has noticed in its definition into the array that stores the selected cards.

(...) and then appear in the class: Arena (...).

If the player decides to start the game (e.g. by clicking on a start button), you can start a new game Arena- Create object and pass the selected cards. Either directly via the constructor or via a setter method.

Example:

class Arena {
  private Karte[] spielkarten;

  public Arena(Karte[] spielkarten) {
    this.spielkarten = spielkarten;
  }
}

// create Arena object
Karte[] karten = // get karten ...
Arena arena = new Arena(karten);