void Gameplayint x 记录为空 if recorditemssize == 0 return; 从历史记录条目中读取到的参数信息 speed_value = recorditemsxspeed; GHOST_SPEED = 1000 50 speed_value; int ghost_num = recorditemsxghost_num; 一般初始化 init; 在ini
The play function in the Game class is used to play a recorded game from the history record.
Here is the explanation of the code:
- First, it checks if the record is empty. If the record is empty, it returns and the function ends.
- It retrieves the speed, ghost number, and steps from the history record based on the given parameter
x. - It initializes the game and sets the
play_flagto true to indicate that it is in playback mode. - It checks if the ghost number in the record matches the current map. If they don't match, it displays an error message and exits the program.
- It sets the direction of the pacman and ghosts based on the recorded steps.
- It moves the ghosts and the pacman based on their respective directions.
- If the map is in the freeze time state, it decreases the freeze time and changes the color of the pacman.
- It checks for collisions between the pacman and ghosts.
- It checks for user input and handles different key presses.
- It records the directions of the pacman and ghosts.
- If the user presses a direction key during playback, it exits the playback mode and enters the normal game mode.
- It updates the UI to display the current game state.
- It increments the time counter and checks if the playback is finished.
- If the playback is finished, it marks the final position of the pacman, displays a message, and waits for any key press before returning to the main menu.
Overall, the play function plays a recorded game step by step based on the recorded steps and updates the game state and UI accordingly
原文地址: http://www.cveoy.top/t/topic/iSJo 著作权归作者所有。请勿转载和采集!