Class GameBase<TPlayer>
Base class to represent a game between Discord users.
uid: Discord.Addons.MpGame.GameBase1.#ctor(Discord.IMessageChannel,System.Collections.Generic.IEnumerable{
0},System.Boolean)
syntax:
content: |
protected GameBase(IMessageChannel channel, IEnumerable players,
bool setFirstPlayerImmediately = false)
Namespace: Discord.Addons.MpGame
Assembly: Discord.Addons.MpGame.dll
Syntax
public abstract class GameBase<TPlayer>
where TPlayer : Player
Type Parameters
Name | Description |
---|---|
TPlayer | The type of this game's kind of Player object. |
Constructors
| Improve this Doc View SourceGameBase(IMessageChannel, IEnumerable<TPlayer>, Boolean)
Sets up the common logic for a multiplayer game.
Declaration
protected GameBase(IMessageChannel channel, IEnumerable<TPlayer> players, bool setFirstPlayerImmediately = false)
Parameters
Type | Name | Description |
---|---|---|
IMessageChannel | channel | The channel where the public-facing side of the game is played. |
IEnumerable<TPlayer> | players | The players for this game instance. |
Boolean | setFirstPlayerImmediately | When set to true, will set the TurnPlayer to the first player before the game begins, otherwise it will be set to an empty Node and you will have to set it to Turnplayer.Next when starting the first turn. |
Properties
| Improve this Doc View SourceChannel
The channel where the public-facing side of the game is played.
Declaration
protected IMessageChannel Channel { get; }
Property Value
Type | Description |
---|---|
IMessageChannel |
Players
Represents all the players in this game.
Declaration
protected CircularLinkedList<TPlayer> Players { get; }
Property Value
Type | Description |
---|---|
CircularLinkedList<TPlayer> |
TurnPlayer
The current turn's player.
Declaration
public Node<TPlayer> TurnPlayer { get; protected set; }
Property Value
Type | Description |
---|---|
Node<TPlayer> |
Methods
| Improve this Doc View SourceEndGame(String)
Perform all actions that happen when the game ends (e.g.: a win condition is met, or the game is stopped early).
Declaration
public async Task EndGame(string endmsg)
Parameters
Type | Name | Description |
---|---|---|
String | endmsg | The message that should be displayed announcing the win condition or forced end of the game. |
Returns
Type | Description |
---|---|
Task |
GetGameState()
Get a string that represents the state of the game.
Declaration
public abstract string GetGameState()
Returns
Type | Description |
---|---|
String |
Remarks
implement
Does not need to be implemented if only GetGameStateEmbed() is used.
GetGameStateEmbed()
Get an embed that represents the state of the game.
Declaration
public abstract Embed GetGameStateEmbed()
Returns
Type | Description |
---|---|
Embed |
Remarks
implement
Does not need to be implemented if only GetGameState() is used.
IsTurnPlayerFirstPlayer()
Indicates whether or not the current TurnPlayer is the first player in the list.
Declaration
protected bool IsTurnPlayerFirstPlayer()
Returns
Type | Description |
---|---|
Boolean |
IsTurnPlayerLastPlayer()
Indicates whether or not the current TurnPlayer is the last player in the list.
Declaration
protected bool IsTurnPlayerLastPlayer()
Returns
Type | Description |
---|---|
Boolean |
NextTurn()
Perform all actions that are part of starting a new turn.
Declaration
public abstract Task NextTurn()
Returns
Type | Description |
---|---|
Task |
OnGameEnd()
Gets called when the game ends.
Declaration
protected virtual Task OnGameEnd()
Returns
Type | Description |
---|---|
Task |
OnPlayerAdded(TPlayer)
Gets called when a player is added into an ongoing game, allowing an opportunity to add properties to the player.
Declaration
protected virtual Task OnPlayerAdded(TPlayer player)
Parameters
Type | Name | Description |
---|---|---|
TPlayer | player | The player that is added. |
Returns
Type | Description |
---|---|
Task |
Examples
protected override async Task OnPlayerAdded(CardPlayer player)
{
for (var i = 0; i < 5; i++)
player.AddCard(Deck.Draw());
await Channel.SendMessageAsync($"**{player.User.Username}** has joined.");
}
|
Improve this Doc
View Source
OnPlayerKicked(TPlayer)
Gets called when a player is forcibly kicked, allowing an opportunity to access some of their properties to put back into the game.
Declaration
protected virtual Task OnPlayerKicked(TPlayer player)
Parameters
Type | Name | Description |
---|---|---|
TPlayer | player | The player that is removed. |
Returns
Type | Description |
---|---|
Task |
Examples
protected override async Task OnPlayerKicked(CardPlayer player)
{
var card = player.TakeCard(0);
while (card != null)
{
Deck.PutBottom(card);
card = player.TakeCard(0);
}
await Channel.SendMessageAsync($"**{player.User.Username}** has left.");
}
|
Improve this Doc
View Source
SetupGame()
Perform the actions that are part of the initial setup.
Declaration
public abstract Task SetupGame()
Returns
Type | Description |
---|---|
Task |
StartGame()
Perform the one-time actions that happen at the start of the game.
Declaration
public abstract Task StartGame()
Returns
Type | Description |
---|---|
Task |