• Guides
  • Api Documentation
Show / Hide Table of Contents
  • Discord.Addons.MpGame
    • CurrentlyPlaying
    • GameBase<TPlayer>
    • IMpGameData
    • MpGameModuleBase<TService, TGame, TPlayer>
    • MpGameService<TGame, TPlayer>
    • MpGameService<TGame, TPlayer>.MpGameData
    • Player
  • Discord.Addons.MpGame.Collections
    • CircularLinkedList<T>
    • Hand<T>
    • IWrapper<T>
    • Node<T>
    • Pile<T>
    • WrappingPile<T, TWrapper>
  • Discord.Addons.Preconditions
    • Measure
    • MinimumOnlineUsersAttribute
    • RatelimitAttribute
    • RatelimitFlags
    • RequireLowerHierarchyAttribute
    • RequireRoleAttribute
    • UserMustBeInVoiceAttribute

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)

Inheritance
Object
GameBase<TPlayer>
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 Source

GameBase(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 Source

Channel

The channel where the public-facing side of the game is played.

Declaration
protected IMessageChannel Channel { get; }
Property Value
Type Description
IMessageChannel
| Improve this Doc View Source

Players

Represents all the players in this game.

Declaration
protected CircularLinkedList<TPlayer> Players { get; }
Property Value
Type Description
CircularLinkedList<TPlayer>
| Improve this Doc View Source

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 Source

EndGame(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
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

IsTurnPlayerFirstPlayer()

Indicates whether or not the current TurnPlayer is the first player in the list.

Declaration
protected bool IsTurnPlayerFirstPlayer()
Returns
Type Description
Boolean
| Improve this Doc View Source

IsTurnPlayerLastPlayer()

Indicates whether or not the current TurnPlayer is the last player in the list.

Declaration
protected bool IsTurnPlayerLastPlayer()
Returns
Type Description
Boolean
| Improve this Doc View Source

NextTurn()

Perform all actions that are part of starting a new turn.

Declaration
public abstract Task NextTurn()
Returns
Type Description
Task
| Improve this Doc View Source

OnGameEnd()

Gets called when the game ends.

Declaration
protected virtual Task OnGameEnd()
Returns
Type Description
Task
| Improve this Doc View Source

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
| Improve this Doc View Source

StartGame()

Perform the one-time actions that happen at the start of the game.

Declaration
public abstract Task StartGame()
Returns
Type Description
Task
  • Improve this Doc
  • View Source
Back to top Generated by DocFX