示例#1
0
        // Handle command written in chat
        public static void HandleCommand(string command, ClientGame game)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                ListCommands(game);
                return;
            }

            int commandDelimiter = command.IndexOf(" ");
            var cmd = commandDelimiter > 0 ? command.Substring(0, commandDelimiter).ToLower() : command;

            switch (commands.FirstOrDefault(x => x.StartsWith(cmd)))
            {
            case "game":
                game.Chat.SetActiveChat(ChatTypes.Game);
                if (commandDelimiter > 0)
                {
                    game.SendChatMessage(command.Substring(commandDelimiter).Trim(), ChatTypes.Game);
                }
                break;

            case "global":
                game.Chat.SetActiveChat(ChatTypes.Global);
                if (commandDelimiter > 0)
                {
                    game.SendChatMessage(command.Substring(commandDelimiter).Trim(), ChatTypes.Global);
                }
                break;

            case "help":
                ListCommands(game);
                break;

            case "whisper":
                HandleWhisperCommand(game, commandDelimiter > 0 ? command.Substring(commandDelimiter).Trim() : "");
                break;

            default:
                WriteInvalidCommand(game);
                break;
            }
        }
示例#2
0
        // Sends whisper message to server
        private static void HandleWhisperCommand(ClientGame game, string arg)
        {
            int commandDelimiter = arg.IndexOf(" ");

            if (string.IsNullOrWhiteSpace(arg) || (commandDelimiter <= 0))
            {
                FormatSyntaxError(game, "/whisper [name] [message]");
                return;
            }

            string receiverName = arg.Substring(0, commandDelimiter);
            string message      = arg.Substring(commandDelimiter).Trim();

            if (!message.Any())
            {
                FormatSyntaxError(game, "/whisper [name] [message]");
                return;
            }

            game.SendChatMessage(message, ChatTypes.Whisper, receiverName);
        }
示例#3
0
 // Lists all commands in chat
 private static void ListCommands(ClientGame game)
 {
     game.Chat.Write($"Possible commands:{LineSeparator}{string.Join(LineSeparator, commands)}", ChatTypes.Info);
 }
示例#4
0
 // Writes invalid command into chat
 private static void WriteInvalidCommand(ClientGame game)
 {
     game.Chat.Write("Invalid command", ChatTypes.Info);
 }
示例#5
0
 // Writes syntax error into chat
 private static void FormatSyntaxError(ClientGame game, string correctSyntax)
 {
     game.Chat.Write($"Invalid syntax. Use: {correctSyntax}", ChatTypes.Info);
 }
示例#6
0
 public Player(ClientGame clientGame, params Image[] imageLocations)
 {
     game     = clientGame;
     cardDeck = new (PlayableCard, Image)[imageLocations.Length];
示例#7
0
 public ChatHandler(ClientGame game)
 {
     clientGame = game;
     ActiveChat = ChatTypes.Global;
 }