Page 1 of 1

Write a program with following options: 1. /h or /H : The following numeric value given will be the height of the grid.

Posted: Thu Jul 14, 2022 2:11 pm
by answerhappygod
Write A Program With Following Options 1 H Or H The Following Numeric Value Given Will Be The Height Of The Grid 1
Write A Program With Following Options 1 H Or H The Following Numeric Value Given Will Be The Height Of The Grid 1 (90.63 KiB) Viewed 49 times
Write a program with following options: 1. /h or /H : The following numeric value given will be the height of the grid. 2. I w or /W: The following numeric value given will be the width of the grid. 3. I p or /P: the following 2 numbers will be the player's initial x and y coordinate position on the grid. 4. Any incorrect command line arguments should cause an error message: >invalid parameter - If any of the parameters are not given, some reasonable default value should be used. For example: Tutorial3GameControls.exe/w 10/h7/p11 sets all values Tutorial3GameControls.exe/w 10/h7 may put the default player value at θ,θ - If you struggle with this task you can have the user type in values for these variables or just use default values to start. Come back to this later. Sending parameters to a program can be an extremely useful feature since it means someone else can run your code with different values and they don't need constantly ask you questions about it. The more hands-off you can be about your code in the long run, the better.
- Make a 2D array of characters representing the game grid. Do this in the main method. This grid should be the width and height values you input in the earlier section. - You should also make a new "position" struct that consists of two unsigned integers. - Write a function printGrid that takes the 2D char grid and the grid size (a position can store the maximum width and height of the grid). This function simply uses printf statements to output all the grid characters. - Make an array of positions where each position represents an enemy. These enemies won't move just yet. Each enemy can be positioned anywhere on the grid. - Make a position variable for storing the player position. This position will move. - Write a function updateGrid that takes the 2D array, the grid size, the player position and the array of enemy positions (plus the size of that array) as input. Change the values in the 2D array to match where the players and enemies are now. - Write a function userAction that takes a player position, the grid size, a character array buffer (to put what the user types into), and the size of that character array. Update the player's position appropriately if the correct command is written. For example, a user may write u3 which would move the player character Up 3 positions. The character's position cannot go outside the grid bounds. If it would go outside those bounds, make the position as close to the desired position as you can while still being valid. - Write a function gameLoop that calls printGrid, userAction, and updateGrid in a loop. The loop will stop when the user types q or Q instead of a new player instruction (so the q would be in the character buffer you keep using for user input). - Now you should be able to run your "game", move around your character and see the character position change. Make sure you test a variety of scenarios and make sure your program stops when you type q or Q.