void Cmd_start(string nick, string message) { Channel channel = p_manager.GetChannel(); LGameChannel game = GetLChannel(channel.GetName()); if (game == null || game.GetPlayer(nick) == null) { E.Notice(nick, "You are not part of the game."); return; } if (game.is_active) { E.Notice(nick, "The game is already running."); return; } int total_players = game.players.Count; if (total_players < 3) { channel.Say(nick + ": At least 3 players are required to start the game."); return; } var cards = new List <string>(); foreach (string card in CARD_TYPES) { int amount = (card == "Q") ? 3 : 4; while (amount > 0) { cards.Add(card); amount--; } } Utils.Shuffle(ref cards); foreach (string card in cards) { game.NextPlayer().cards.Add(card); } game.is_active = true; foreach (LGPlayer n in game.players) { E.Notice(n.nick, "Your cards: " + FormatCards(n.cards, true)); Thread.Sleep(300); } game.CleanStack(); channel.Say("Game started! Player " + game.GetPlayer().nick + " can play the first card using \"$add <'main card'> <card nr.> [<card nr.> [<card nr.>]]\"" + " (Card nr. from your hand)"); CheckCards(); }
void Cmd_check(string nick, string message) { Channel channel = p_manager.GetChannel(); LGameChannel game = GetLChannel(channel.GetName()); #region Sanity check if (game == null || !game.is_active) { E.Notice(nick, "There's no game or it did not start yet."); return; } LGPlayer player = game.GetPlayer(nick); if (player == null) { E.Notice(nick, "You are not part of the game."); return; } if (player != game.GetPlayer()) { E.Notice(nick, "It's not your turn yet. Please wait for " + game.GetPlayer().nick); return; } if (game.main_card == "") { E.Notice(nick, "You cannot check an empty stack."); return; } #endregion player = null; string main_card = game.main_card; bool contains_invalid = game.stack_top.FindIndex(item => item != main_card) >= 0; string card_msg = ""; if (contains_invalid) { card_msg = "One or more top cards were not a [" + main_card + "]. "; } else { card_msg = "The top cards were correct! "; game.NextPlayer(); } card_msg += "(" + FormatCards(game.stack_top) + ") "; // Add cards to previous player game.GetPlayer(-1).cards.AddRange(game.stack_all); game.CleanStack(); CheckCards(); // "channel" reference is not updated after deleting the channel! if (GetLChannel(channel.GetName()) == null) { channel.Say(card_msg); return; } var prev_player = game.GetPlayer(-1); var curr_player = game.GetPlayer(0); card_msg += "Complete stack goes to " + prev_player.nick + ". " + curr_player.nick + " can start with an empty stack."; channel.Say(card_msg); E.Notice(prev_player.nick, FormatCards(prev_player.cards, true)); E.Notice(curr_player.nick, FormatCards(curr_player.cards, true)); }