mirror of
https://github.com/zoriya/PluginSDG.git
synced 2025-12-06 06:46:09 +00:00
Starting to implement basic methods for mini game & team mini game
This commit is contained in:
@@ -1,20 +1,43 @@
|
||||
package moe.sdg.PluginSDG;
|
||||
|
||||
public interface MiniGame
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class MiniGame
|
||||
{
|
||||
private final ArrayList<Player> _players;
|
||||
|
||||
public MiniGame()
|
||||
{
|
||||
this._players = new ArrayList<Player>();
|
||||
}
|
||||
|
||||
//! @brief Return the current count of players in the game.
|
||||
int getCurrentPlayers();
|
||||
public int getCurrentPlayers()
|
||||
{
|
||||
return this._players.size();
|
||||
}
|
||||
|
||||
//! @brief Maximum number of player in the game.
|
||||
int getMaxPlayers();
|
||||
public abstract int getMaxPlayers();
|
||||
|
||||
///! @brief Method called when a player wants to join the game.
|
||||
//! @param player The player who will join
|
||||
//! @return True if the player has joined the game, false otherwise.
|
||||
boolean join();
|
||||
public boolean join(Player player)
|
||||
{
|
||||
if (this.getMaxPlayers() < this.getCurrentPlayers() + 1)
|
||||
return false;
|
||||
this._players.add(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
//! @brief Method called when a player wants to leave the game.
|
||||
void leave();
|
||||
public abstract void leave();
|
||||
|
||||
//! @brief Start the game.
|
||||
void start();
|
||||
public abstract void start();
|
||||
//! @brief End the game.
|
||||
void end();
|
||||
public abstract void end();
|
||||
}
|
||||
|
||||
49
src/main/java/moe/sdg/PluginSDG/TeamMiniGame.java
Normal file
49
src/main/java/moe/sdg/PluginSDG/TeamMiniGame.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package moe.sdg.PluginSDG;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import java.util.ArrayList;
|
||||
|
||||
class Team
|
||||
{
|
||||
public String name;
|
||||
private final ArrayList<Player> _players;
|
||||
public int maxPlayer;
|
||||
|
||||
public Team(String name, int maxPlayer)
|
||||
{
|
||||
this.name = name;
|
||||
this.maxPlayer = maxPlayer;
|
||||
this._players = new ArrayList<Player>();
|
||||
}
|
||||
|
||||
//! @brief Make a player join the team.
|
||||
//! @param player The player who will join.
|
||||
public boolean join(Player player)
|
||||
{
|
||||
if (this.playerCount() + 1 > this.maxPlayer)
|
||||
return false;
|
||||
this._players.add(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int playerCount()
|
||||
{
|
||||
return this._players.size();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class TeamMiniGame extends MiniGame
|
||||
{
|
||||
private final ArrayList<Team> _teams;
|
||||
|
||||
public TeamMiniGame()
|
||||
{
|
||||
this._teams = new ArrayList<Team>();
|
||||
}
|
||||
|
||||
//! @brief Get the number of teams.
|
||||
public int getTeamCount()
|
||||
{
|
||||
return this._teams.size();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user