15 20 36 0000010 03 0 0 0 1 000 000 0002010 0 0 0 2 0 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1100010 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0000100010000 10000010 0 0 0 0 0 1 0 0 0 0 0 1 0 5 000000 000010500000 0001110 0 0 0 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0000100010000 ооооооо 0 0 0 1 1 1 1 1 0 0 0 0 10000000 10000000 10000000 * P 0 * @ O 00000 *00 0 0 0 * 0 0 $ * 000 0 0 * 00000 * ** * * 000 0 000 * 0 000 * * оооооооо 0 1 0 0 0 0 0 0 10000000 10000000 10000000 0 001000000000 0 оооооо 0 0 1 0 0 0 0 1 1 1 0 0 0 001000011100 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 111000000000 10000011 0 0 0 0 0 1 1 1 0 0 0 0 0 0 оооооо 100000000000 0 110000000 0000000000040 10000000 Press w to move up Press s to move down Press a to move left Press d to move right Press u to undo * * * * *** * ****
CREATE EACH WHOLE CODE FILE
The objective of this project is to develop an interactive ASCII-based game using C programming, specifically following the C89 standard. The game involves a player navigating through a 2D grid filled with various characters representing walls, treasure, lanterns, and a snake.
Game Elements:
•Player (P): The main character controlled by the user.
•Walls (O): Obstacles that the player cannot pass through.
•Treasure ($): The goal of the game, which the player must reach.
•Lantern (@): An item that enhances visibility.
•Snake (~): An enemy that chases the player.
Game Initialization:
The game begins by reading a configuration file specified as a command-line argument. This file contains:
•The dimensions of the playable area (rows and columns).
•The number of walls in the game.
•The grid layout represented by integers that correspond to the characters in the game.
Grid Representation:
Each integer in the grid file corresponds to:
•0: Empty space (' ')
•1: Wall ('O')
•2: Lantern ('@')
•3: Player ('P')
•4: Snake ('~')
•5: Treasure ('$')
User Interaction:
The player can control movement using the following keys:
•w: Move up
•s: Move down
•a: Move left
•d: Move right
Gameplay
•The game updates the grid and clears the terminal after each move.
•The snake moves randomly in one of eight directions after the player moves. It will chase the player if they are adjacent.
•The player wins by reaching the treasure and loses if the snake catches them.
Features:
1.Undo Functionality: Implemented using a linked list to track player and snake positions. Pressing u reverts the last move, provided it is not the initial state.
2.Visibility Management: When compiled with a specific flag, the player’s visibility is limited to a certain range, affecting gameplay strategy.
3.Memory Management: The program utilizes dynamic memory allocation. It is essential to free all allocated memory before program termination to prevent leaks.
Technical Requirements:
•Use of a Makefile for compilation that includes conditional compilation for different game modes.
•Proper handling of command-line arguments to ensure the file is opened correctly.
•Modular code structure, with separate files for different functionalities (e.g., main logic, game mechanics).
Assumptions:
•The game files are correctly formatted, and all necessary game elements are present.
•The game operates within reasonable dimensions suitable for terminal display.
Coding Standards:
•Avoid global variables and abrupt program exits.
•Maintain readability and structure through comments and organized code.
Step by step
Solved in 2 steps