Trong chương trước, chúng tôi đi qua bằng cách sử dụng API đồ thị Facebook để cung cấp dữ liệu cho một trò chơi đố. Bây giờ mà chúng tôi có một trò chơi người có thể chơi, nó là thời gian để mang nó đến cấp độ tiếp theo. Chúng tôi sẽ tận dụng một số các API Facebook khác để nhận ra những thành tựu để chơi các trò chơi và theo dõi thời gian nhanh nhất để hoàn thành một câu đố. Để làm điều này, chúng tôi cần phải tương tác với hệ thống Heroku và phụ trợ cơ sở dữ liệu của nó. Tôi cũng sẽ bao gồm một số khái niệm cơ bản cho việc triển khai, bao gồm cả minifying codebase của bạn, đối phó với gian lận, và bảo vệ trò chơi của bạn từ trộm cắp. Nếu bạn di chuyển trò chơi của bạn với một nền tảng khác hơn so với Heroku, bạn có thể cần phải điều chỉnh một số các lệnh cơ sở dữ liệu, nhưng bạn sẽ có thể đến cảng mã này với các nền tảng khác. Thêm mức độIf you recall, the code in the last chapter was written to allow you to dynamically generate a grid. The examples in that chapter defaulted to a 3 3–grid, but by changing the instantiation parameter, you can easily change this to 4 4, 5 5, and so on. Each time you add a grid column and row, you add a magnitude of complexity and challenge to the game. Not only does the number of tiles grow exponentially but picking out details to properly order the tiles becomes more difficult. We can use this fact to implement a level system, though some thought needs to go in to capping the maximum number of tiles that are playable as a maximum level. For instance, while technically possible, a 400 400–grid would give us a total of 160,000 tiles, with each tile being 1 2 pixels. While this grid may provide some interesting art, the game would be nearly impossible to play. After some experimentation at passing different values to the grid generation, the game (at least for me) was impossible with a grid larger than 5 5 (25 tiles). Although there are people out there who could not only do but enjoy more complex puzzles, I do want to place some limits on the top level to ensure that a majority of people can finish in a reasonable time period. I also want to have easy, intermediate, and hard levels for the game; each level of difficulty corresponds to a grid value: 3 3–grid is easy, 4 4 intermediate, and 5 5 hard. In your game, and depending on feedback you get from your players, you may want to adjust this and maybe allow the hard mode to go up to even a 10 10–grid (100 tiles). However, for the purposes of this chapter, I will constrain each level to one grid size. For the first iteration of the code, I will let people choose the levels they want to try. Feedback from the user will then be used to instantiate the puzzle with the appropriate number of grids. Since this is an HTML application, we can use both DOM and canvas elements to easily add this effect. We want to present the player with a screen that first prompts the user to select a level. The technique that I will employ here will create a DOM element on the page that is the same size as the canvas and then add an event listener with jQuery that will instantiate the game and show the canvas element. Open the index.php file for your project, and add a new DOM element with an id of "splash". We also need to hide the canvas element with a CSS element that sets its initial display to "none". The revised code is shown in Listing 11–1.
đang được dịch, vui lòng đợi..
