[Привет, как упоминалось в названии, мне было поручено выполнить проект Java OOP (своего рода настольная игра 9x9 - где каждый игрок получает 21 покемон и борьбу друг с другом), я получил движение, и все, когда два Pokemon находятся рядом друг с другом, и, например, его ход. быть Я не знаю, в чем проблема ?? Вот полный код, если бы кто -нибудь мог мне помочь, я был бы очень благодарен. < /P>
import MG2D.Fenetre;
public class PokemonBoardGame {
public static void main(String[] args) {
Game game = new Game();
game.start();
}
}
class Pokemon {
private int pokedexNumber;
private String name;
private int hp;
private int boardX;
private int boardY;
private MG2D.geometrie.Texture sprite;
private MG2D.geometrie.Texte hpLabel;
public Pokemon(int pokedexNumber, String name, int hp) {
this.pokedexNumber = pokedexNumber;
this.name = name;
this.hp = hp;
this.boardX = -1;
this.boardY = -1;
}
public int getPokedexNumber() { return pokedexNumber; }
public String getName() { return name; }
public int getHp() { return hp; }
public int getBoardX() { return boardX; }
public int getBoardY() { return boardY; }
public MG2D.geometrie.Texture getSprite() { return sprite; }
public MG2D.geometrie.Texte getHpLabel() { return hpLabel; }
public void setBoardPosition(int x, int y) {
this.boardX = x;
this.boardY = y;
}
public void setSprite(MG2D.geometrie.Texture sprite) { this.sprite = sprite; }
public void setHpLabel(MG2D.geometrie.Texte hpLabel) { this.hpLabel = hpLabel; }
public void attack(Pokemon target) {
target.hp -= 10;
if (target.hp < 0) target.hp = 0;
this.hp -= 5;
if (this.hp < 0) this.hp = 0;
}
}
class Player {
private java.util.ArrayList pokemonList;
private boolean isPlayer1;
public Player(boolean isPlayer1) {
this.pokemonList = new java.util.ArrayList();
this.isPlayer1 = isPlayer1;
}
public void addPokemon(Pokemon p) {
pokemonList.add(p);
}
public void removePokemon(Pokemon p) {
pokemonList.remove(p);
}
public boolean hasPokemon(Pokemon p) {
return pokemonList.contains(p);
}
public java.util.ArrayList getPokemonList() {
return pokemonList;
}
public boolean isPlayer1() {
return isPlayer1;
}
}
class Board {
private Pokemon[][] grid;
private static final int SIZE = 9;
public Board() {
grid = new Pokemon[SIZE][SIZE];
}
public boolean isValidPosition(int x, int y) {
return x >= 0 && x < SIZE && y >= 0 && y < SIZE;
}
public Pokemon getPokemonAt(int x, int y) {
if (!isValidPosition(x, y)) return null;
return grid[x][y];
}
public void setPokemonAt(int x, int y, Pokemon p) {
if (isValidPosition(x, y)) {
grid[x][y] = p;
if (p != null) p.setBoardPosition(x, y);
}
}
public void movePokemon(int fromX, int fromY, int toX, int toY) {
if (isValidPosition(fromX, fromY) && isValidPosition(toX, toY)) {
Pokemon p = grid[fromX][fromY];
grid[fromX][fromY] = null;
grid[toX][toY] = p;
if (p != null) p.setBoardPosition(toX, toY);
}
}
public void removePokemon(int x, int y) {
if (isValidPosition(x, y)) {
grid[x][y] = null;
}
}
}
class Game {
private static final int BOARD_SIZE = 9;
private static final int SQUARE_SIZE = 75;
private static final int GRID_LINE_THICKNESS = 1;
private static final int WINDOW_WIDTH = BOARD_SIZE * SQUARE_SIZE + (BOARD_SIZE + 1) * GRID_LINE_THICKNESS;
private static final int WINDOW_HEIGHT = BOARD_SIZE * SQUARE_SIZE + (BOARD_SIZE + 1) * GRID_LINE_THICKNESS + 50;
private static final int POKEMON_PER_PLAYER = 21;
private static final int HIGHLIGHT_RADIUS = SQUARE_SIZE / 2; // Radius for the circle highlights
private Fenetre window;
private MG2D.Souris mouse;
private Board board;
private Player player1;
private Player player2;
private boolean player1Turn;
private Pokemon selectedPokemon;
private boolean gameOver;
private MG2D.geometrie.Texte turnIndicator;
private MG2D.geometrie.Texte winnerMessage;
private MG2D.geometrie.Rectangle cursor;
private int cursorX;
private int cursorY;
private java.util.ArrayList hpLabels;
private java.util.ArrayList moveHighlights; // Changed to Cercle
public Game() {
window = new Fenetre("Pokemon Board Game", WINDOW_WIDTH, WINDOW_HEIGHT);
mouse = window.getSouris();
board = new Board();
player1 = new Player(true);
player2 = new Player(false);
player1Turn = true;
selectedPokemon = null;
gameOver = false;
cursorX = 0;
cursorY = 0;
hpLabels = new java.util.ArrayList();
moveHighlights = new java.util.ArrayList();
}
public void start() {
initialize();
while (true) {
try {
Thread.sleep(50);
} catch (Exception e) {
System.out.println(e);
}
handleInput();
window.rafraichir();
if (gameOver && mouse.getClicGauche()) {
break;
}
}
}
private void initialize() {
for (int i = 0; i
Подробнее здесь: https://stackoverflow.com/questions/795 ... ng-pokemon
Пожалуйста, помогите мне понять, почему некоторые части этого кода не функционируют !! Pokemon Board Game ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как реализовать функцию рекурсивного расстояния для оценки AI Game Game Game?
Anonymous » » в форуме Python - 0 Ответы
- 12 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как реализовать функцию рекурсивного расстояния для оценки AI Game Game Game?
Anonymous » » в форуме Python - 0 Ответы
- 14 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как реализовать функцию рекурсивного расстояния для оценки AI Game Game Game? [закрыто]
Anonymous » » в форуме Python - 0 Ответы
- 11 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как реализовать функцию рекурсивного расстояния для оценки AI Game Game Game?
Anonymous » » в форуме Python - 0 Ответы
- 13 Просмотры
-
Последнее сообщение Anonymous
-