Deplacer mon ocean et poisson
matt2421
Messages postés
16
Date d'inscription
Statut
Membre
Dernière intervention
-
KX Messages postés 16761 Date d'inscription Statut Modérateur Dernière intervention -
KX Messages postés 16761 Date d'inscription Statut Modérateur Dernière intervention -
salut! Voici trois classes que j'ai cree via Eclipse (Fish, ocean ,oceanlifemain) et je n'arrive pas a deplacer mon ocean et mon poisson de 5++.
besoin d'aide svp! Il y a un peu d'allemand dedans mais c'est pas important!
besoin d'aide svp! Il y a un peu d'allemand dedans mais c'est pas important!
package infpp.oceanlife; public class Fish { private int x; private int y; private String name; public Fish(int x, int y, String name) { this.x = x; this.y = y; this.name = name; } public int getX() { return this.x; } public void setX(int x) { this.x = x; } public int getY() { return this.y; } public void setY(int y) { this.y = y; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } /** * * Rückgabewert eines Fisches * */ public String toString() { return "Fish [x=" + x + ", y=" + y + ", name=" + name + "]"; } }
package infpp.oceanlife; public class Ocean { private int width; private int depth; private Fish fish; public Ocean (int width, int depth, Fish fish) { this.width = width; this.depth = depth; this.fish = fish; } public int getwidth () { return this.width; } public void setwidth (int width) { this.width = width; } public int getdepth () { return this.depth; } public void setdepth (int depth) { this.depth = depth; } public Fish getfish () { return this.fish; } public void setfish (Fish fish) { this.fish = fish; } public void move () { int H = fish.getX(); int V = fish.getY(); System.out.println("Die aktuell position von dem Fische " + H + " " + V); } public String toString () { return "Ocean [width = " + width + ", depth = " + depth + ", fish = " + fish + "]"; } }
package infpp.oceanlife; public class OceanLifeMain { public static void main(String[] args) { int width = 1024; int depth = 768; Ocean ocean = new Ocean(width, depth, new Fish(4 , 6 , "nemo")); for (int i = 0; i < 5; i++) { ocean.move (); System.out.println(ocean); } } }
A voir également:
- Deplacer mon ocean et poisson
- Déplacer colonne excel - Guide
- Symbole poisson voiture - Accueil - Maison
- Déplacer barre des taches windows 11 - Guide
- Déplacer dossier onedrive - Guide
- Deplacer icone iphone - Guide
Par exemple, si tu veux aller à droite (x+1) tu peux faire :
Remarque : je pense que c'est encore mieux de passer deux paramètres à la méthode move pour savoir de combien il faut se déplacer sur chaque axe.
Que signifie ce fish.setX (next X); et ne pourrait -on pas l'ecrire de la meme forme que int previousX = fish.getX ()? Du genre int nextX =fish.setX (nextX); ?
Merci encore!!!!!!