0% found this document useful (0 votes)
14 views4 pages

Text (Copy) (Copy)

This document provides a step-by-step guide for setting up and running a Pokémon game in Eclipse. It includes instructions for downloading Eclipse, creating a new Java project, setting up packages and classes, and adding code for the main game functionality. The guide concludes with instructions on how to run the project and interact with the game in the console.

Uploaded by

mrsamykoffi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Text (Copy) (Copy)

This document provides a step-by-step guide for setting up and running a Pokémon game in Eclipse. It includes instructions for downloading Eclipse, creating a new Java project, setting up packages and classes, and adding code for the main game functionality. The guide concludes with instructions on how to run the project and interact with the game in the console.

Uploaded by

mrsamykoffi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Sure! Here's a step-by-step guide to set up and run your Pokémon game in Eclipse.

### Step-by-Step Guide to Set Up Pokémon Game in Eclipse

#### Step 1: Download and Install Eclipse

1. Download Eclipse IDE from the [Eclipse official


website](https://www.eclipse.org/downloads/).
2. Install Eclipse by following the on-screen instructions.

#### Step 2: Create a New Java Project

1. Open Eclipse.
2. Go to `File` -> `New` -> `Java Project`.
3. Enter the project name (e.g., `PokemonGame`) and click `Finish`.

#### Step 3: Create the Package

1. Right-click on `src` in the Project Explorer.


2. Select `New` -> `Package`.
3. Enter the package name (e.g., `com.pokemon`) and click `Finish`.

#### Step 4: Create the Java Classes

1. Right-click on the package `com.pokemon`.


2. Select `New` -> `Class`.

Repeat the following steps for each class (`Main`, `Game`, `Player`, `Pokemon`, and
`BattleSystem`):

- Enter the class name (`Main`, `Game`, `Player`, `Pokemon`, `BattleSystem`).


- Make sure `public static void main(String[] args)` is checked for the `Main`
class only.
- Click `Finish`.

#### Step 5: Add Code to Each Class

##### Main.java

```java
package com.pokemon;

public class Main {


public static void main(String[] args) {
Game game = new Game();
game.start();
}
}
```

##### Game.java

```java
package com.pokemon;

import java.util.Scanner;

public class Game {


Player player;
boolean running;
Scanner scanner;

public Game() {
player = new Player("Ash");
running = true;
scanner = new Scanner(System.in);
}

public void start() {


System.out.println("Welcome to the Pokémon Game!");
while (running) {
System.out.println("1. Catch Pokémon");
System.out.println("2. Start Battle");
System.out.println("3. Exit");

int choice = scanner.nextInt();


scanner.nextLine(); // Consume newline

switch (choice) {
case 1:
catchPokemon();
break;
case 2:
startBattle();
break;
case 3:
running = false;
break;
default:
System.out.println("Invalid choice, please try again.");
}
}
scanner.close();
}

private void catchPokemon() {


Pokemon wildPokemon = new Pokemon("Bulbasaur", 5, 30);
player.catchPokemon(wildPokemon);
}

private void startBattle() {


BattleSystem battleSystem = new BattleSystem();
Pokemon wildPokemon = new Pokemon("Charmander", 5, 30);
battleSystem.startBattle(player, wildPokemon);
}
}
```

##### Player.java

```java
package com.pokemon;

public class Player {


String name;
Pokemon[] pokemons;

public Player(String name) {


this.name = name;
this.pokemons = new Pokemon[6]; // Player can hold up to 6 Pokémon
}

public void catchPokemon(Pokemon pokemon) {


for (int i = 0; i < pokemons.length; i++) {
if (pokemons[i] == null) {
pokemons[i] = pokemon;
System.out.println(name + " caught " + pokemon.getName());
return;
}
}
System.out.println("No more room to catch new Pokémon!");
}
}
```

##### Pokemon.java

```java
package com.pokemon;

public class Pokemon {


String name;
int level;
int hp;

public Pokemon(String name, int level, int hp) {


this.name = name;
this.level = level;
this.hp = hp;
}

public String getName() {


return name;
}

public int getLevel() {


return level;
}

public int getHp() {


return hp;
}

public void attack(Pokemon opponent) {


int damage = (int)(Math.random() * 10) + 1; // Random damage between 1 and
10
opponent.hp -= damage;
System.out.println(name + " attacked " + opponent.getName() + " for " +
damage + " damage!");
}
}
```

##### BattleSystem.java

```java
package com.pokemon;
public class BattleSystem {
public void startBattle(Player player, Pokemon wildPokemon) {
System.out.println("A wild " + wildPokemon.getName() + " appeared!");
Pokemon playerPokemon = player.pokemons[0]; // Assume the first Pokémon is
used for battle

while (playerPokemon.getHp() > 0 && wildPokemon.getHp() > 0) {


playerPokemon.attack(wildPokemon);
if (wildPokemon.getHp() > 0) {
wildPokemon.attack(playerPokemon);
}
}

if (playerPokemon.getHp() <= 0) {
System.out.println(playerPokemon.getName() + " fainted!");
} else {
System.out.println("You defeated the wild " + wildPokemon.getName() +
"!");
}
}
}
```

#### Step 6: Run the Project

1. In Eclipse, right-click on the `Main.java` file.


2. Select `Run As` -> `Java Application`.

This should start your Pokémon game in the console. You can interact with the game
by entering the corresponding choices.

If you encounter any errors or issues, please let me know, and I can help
troubleshoot them.

You might also like