Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pong command to user space #58

Open
mikesmith-23 opened this issue Sep 9, 2024 · 1 comment
Open

Add pong command to user space #58

mikesmith-23 opened this issue Sep 9, 2024 · 1 comment

Comments

@mikesmith-23
Copy link

Command: The "pong" command will run a terminal-based version of the classic Atari game Pong, providing users with an interactive experience within the terminal. Players will control paddles using keyboard inputs, aiming to keep the ball in play as it bounces back and forth across the screen.

Plan:

  1. Implementation: The pong command will launch a text-based version of Pong, rendering the paddles, ball, and boundary in the terminal. The paddles will be controlled by the arrow keys (or alternative keys if necessary), while the ball will move at a constant speed, bouncing off both the walls and paddles.

  2. Difficulty Modes: Flags will be added to adjust the difficulty by altering the ball's speed and refresh rate.

    • -e (easy - default mode): A slower refresh rate and reduced ball speed for beginner players.
    • -m (medium): Moderate ball speed and refresh rate, providing a balanced challenge.
    • -h (hard): Fast ball speed and high refresh rate, creating a more challenging gameplay experience.
  3. Key Input: Players will use keyboard input to move the paddles up or down. A key concern here is ensuring that the OS supports the necessary library calls to handle real-time keypresses, such as reading arrow key input or using an alternative method for key control if the OS lacks arrow key support.

  4. Game Logic: The game will continue until one player scores a set number of points or quits the game by pressing a designated key. Scoring will be displayed in the terminal, and the game will reset after each round.

  5. Future Enhancements:

    • Multiplayer Mode: Add a flag (e.g., -mp) for two-player gameplay, where one player controls each paddle using separate keys.
    • Obstacles: Consider introducing additional obstacles (e.g., bouncing blocks) to make the game more dynamic and unpredictable in future versions.

Files to be Added/Modified:

  • user/pong.c: Create the main implementation of the Pong game, including functions to handle game logic, key inputs, and difficulty modes.

  • Makefile: Modify to include pong.c so that it is compiled with the rest of the OS commands.

  • kernel/syscall.h: Review and ensure that system calls related to handling real-time input or refreshing the terminal are properly defined here if necessary.

  • kernel/syscall.c: Modify to ensure any new system calls are properly handled in the system call table.

  • user/user.h: Add function prototypes for the Pong game's system calls or utility functions for input handling and screen refresh.

Concerns: To achieve the desired cursor logic in the terminal, this might involve calling third-party libraries (which might not be feasible -- being that we haven't covered this in class yet).

@malensek
Copy link
Contributor

This sounds good to me. To make life easier, I would probably assume that you're going to clear and repaint the whole screen for each iteration of your game loop. It will probably be a bit slow, but you are right: we don't have libraries like ncurses here, so the alternative is manually sending escape codes to the terminal to selectively modify character cells (probably a decent amount of work on top of an already large project).

Will you be working with a teammate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants