Example #1
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 private static void Main(string[] args)
 {
     using (var game = new PacManGame())
     {
         game.Run();
     }
 }
Example #2
0
        public PacManServer(int gameSpeed, int numberPlayers, string url)
        {
            this.gameSpeed     = gameSpeed;
            this.numberPlayers = numberPlayers;
            myUrl           = url;
            pacManClients   = new List <ClientWithInfo <IPacManClient> >();
            game            = new PacManGame(numberPlayers);
            pacmanServers   = new List <ServerWithInfo <IPacmanServer> >();
            tolerenceServer = new FaultTolerenceServer(url, this.gameSpeed, 5, RegisterClient, UpdatePacManServers,
                                                       updateClientsServer, RemovePacManServers);
            RemotingServices.Marshal(tolerenceServer, "FTServer", typeof(FaultTolerenceServer));

            gameTimer          = new Timer();
            gameTimer.Elapsed += TimeEvent;
            gameTimer.Interval = gameSpeed;

            InitializePuppet();
        }
Example #3
0
        public static async Task AddControls(PacManGame game, IUserMessage message)
        {
            try
            {
                var requestOptions = game.RequestOptions; // So the edit can be cancelled

                foreach (var input in PacManGame.GameInputs.Keys)
                {
                    if (game.State != State.Active)
                    {
                        break;
                    }
                    await message.AddReactionAsync(input, DefaultOptions);
                }

                await message.ModifyAsync(game.UpdateMessage, requestOptions); // Restore display to normal
            }
            catch (Exception e) when(e is HttpException || e is TimeoutException || e is OperationCanceledException)
            {
            }                                                                                                             // Ignore
        }
Example #4
0
 public StartMenu(PacManGame game, SpriteFont MenuFont)
 {
     this.game = game;
     this.menufont = MenuFont;
 }
Example #5
0
 public GameScreen(PacManGame game)
 {
     this.game = game;
     addPoints = new Coins.AddPoints(AddPoints);
 }
Example #6
0
        public async Task StartGameInstance([Remainder] string args = "")
        {
            if (!Context.BotCan(ChannelPermission.SendMessages))
            {
                return;
            }

            var existingGame = Storage.GetChannelGame(Context.Channel.Id);

            if (existingGame != null)
            {
                await ReplyAsync(existingGame.UserId.Contains(Context.User.Id)?
                                 $"You're already playing a game in this channel!\nUse `{Prefix}cancel` if you want to cancel it." :
                                 $"There is already a different game in this channel!\nWait until it's finished or try doing `{Prefix}cancel`");

                return;
            }

            string[] argSplice  = args.Split("```");
            string   preMessage = "";

            bool mobile = false;

            if (argSplice[0].StartsWith("m"))
            {
                mobile = true;
            }
            else if (!string.IsNullOrWhiteSpace(argSplice[0]))
            {
                preMessage = $"Unknown game argument \"{argSplice[0]}\".";
            }

            string customMap = null;

            if (args.Contains("```"))
            {
                customMap = argSplice[1].Trim('\n', '`').Replace('.', '·').Replace('o', '●');
            }

            PacManGame newGame;

            try
            {
                newGame = new PacManGame(Context.Channel.Id, Context.User.Id, customMap, mobile, Services);
            }
            catch (InvalidMapException e) when(customMap != null)
            {
                await Logger.Log(LogSeverity.Debug, LogSource.Game, $"Failed to create custom game: {e.Message}");

                await ReplyAsync($"The provided map is invalid: {e.Message}.\nUse the `{Prefix}custom` command for more info.");

                return;
            }
            catch (Exception e)
            {
                await Logger.Log(LogSeverity.Error, LogSource.Game, $"{e}");
                await ReplyAsync("There was an error starting the game. " +
                                 $"Please try again or contact the author of the bot using `{Prefix}feedback`");

                return;
            }

            Storage.AddGame(newGame);

            var gameMessage = await ReplyAsync(preMessage + newGame.GetContent(showHelp: false) + "```diff\n+Starting game```");

            newGame.MessageId = gameMessage.Id;

            await AddControls(newGame, gameMessage);
        }
Example #7
0
 public EndScreen(PacManGame game, SpriteFont menuFont)
 {
     this.game = game;
     this.menuFont = menuFont;
 }
Example #8
0
 /// <summary>
 /// Constructs a new screen manager component.
 /// </summary>
 public ScreenManager(PacManGame game)
     : base(game)
 {
     // we must set EnabledGestures before we can query for them, but
     // we don't assume the game wants to read them.
 }