Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pls using C program to finish this game, trying to get your Frogger to the other side of the river. now we go for Stage

Pls using C program to finish this game, trying to get your Frogger to the other side of the river.

image text in transcribed

now we go for Stage 3, already finish the Stage 1 and 2

The code for we finish in Stage 1 and 2

#include

//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// CONSTANTS ///////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

// Provided constants #define SIZE 9 #define TRUE 1 #define FALSE 0

// TODO: you may choose to add additional #defines here.

// Provided Enums enum tile_type {LILLYPAD, BANK, WATER, TURTLE, LOG};

//////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// STRUCTS ////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

// Provided structs struct board_tile { enum tile_type type; // The type of piece it is (water, bank, etc.) int occupied; // TRUE or FALSE based on if Frogger is there. };

//////////////////////////////////////////////////////////////////////////////// ///////////////////////////// FUNCTION PROTOTYPES //////////////////////////// ////////////////////////////////////////////////////////////////////////////////

// TODO: Your function prototypes here

// Prints out the current state of the board. void print_board(struct board_tile board[SIZE][SIZE]); char type_to_char(enum tile_type type); void initialize_board(struct board_tile board[SIZE][SIZE]); void place_turtles(struct board_tile board[SIZE][SIZE], int row, int col); int can_logs_be_placed(struct board_tile board[SIZE][SIZE], int row); void place_logs(struct board_tile board[SIZE][SIZE], int row, int start_col, int end_col);

//////////////////////////////////////////////////////////////////////////////// ////////////////////////// FUNCTION IMPLEMENTATIONS ////////////////////////// ////////////////////////////////////////////////////////////////////////////////

int main(void) {

printf("Welcome to CSE Frogger! "); struct board_tile game_board[SIZE][SIZE];

// TODO (Stage 1.1) Initialise the gameboard. initialize_board(game_board); // Read user input and place turtles. printf("How many turtles? "); // TODO (Stage 1.2): Scan in the turtles, and place them on the map. int total_turtles; fscanf(stdin, " %d", &total_turtles);

// ask for coordinates only if the user enters a positive number if (total_turtles > 0) { printf("Enter pairs: "); int row, col; for (int i = 0; i

printf("Enter command: "); // TODO (Stage 1.3): Create a command loop, to read and execute commands! char command;

while (TRUE) {

// so when the command is to place the logs we only one command

printf("Enter command: ");

int res = scanf(" %c", &command);

if (res == TRUE) {

if (command == 'l' || command == 'L') { int log_row, log_start_col, log_end_col; scanf(" %d %d %d", &log_row, &log_start_col, &log_end_col);

if (can_logs_be_placed(game_board, log_row) == TRUE) { place_logs(game_board, log_row, log_start_col, log_end_col); }

// print the board after every command print_board(game_board); } } else { break; } } printf("Thank you for playing CSE Frogger! "); return 0; }

//////////////////////////////////////////////////////////////////////////////// ///////////////////////////// ADDITIONAL FUNCTIONS ///////////////////////////// ////////////////////////////////////////////////////////////////////////////////

// TODO: Add more functions here!

void initialize_board(struct board_tile board[SIZE][SIZE]) { for (int i = 0; i

int can_logs_be_placed(struct board_tile board[SIZE][SIZE], int row) {

// making the row 0-indexed along with the col indexes // since rows 1 to 7 are considered // so proper mapping is required if (row >= 1 && row

void place_logs(struct board_tile board[SIZE][SIZE], int row, int start_col, int end_col) {

for (int col = start_col; col = 0 && col

//////////////////////////////////////////////////////////////////////////////// ////////////////////////////// PROVIDED FUNCTIONS ////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

void print_board(struct board_tile board[SIZE][SIZE]) { for (int row = 0; row

void place_turtles(struct board_tile board[SIZE][SIZE], int row, int col) { // checking if the coordinates are valid or not if (row >= 1 && row = 0 && col

char type_to_char(enum tile_type type) { char type_char = ' '; if (type == LILLYPAD) { type_char = 'o'; } else if (type == BANK) { type_char = 'x'; } else if (type == WATER) { type_char = '~'; } else if (type == TURTLE) { type_char = 'T'; } else if (type == LOG) { type_char = 'L'; } return type_char; }

Please go on to complete this code to finish stage 3

sorry we got 3 part for Stage 3

stage 3.1 : Three Lives

image text in transcribed

image text in transcribed

image text in transcribed

for Stage 3.2: Adding Bugs

image text in transcribed

image text in transcribed

image text in transcribed

for Stage 3.3: Moving Bugs

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Thank you for helping me with this problem!! :)

Diagrams Key: - Rows are horizontal going left to right. - Columns are vertical going from the top to the bottom. - Blue is the water. - Green is the bank. - Purple are the lillypads. - Orange are turtles. - Brown are logs. - F denotes that Frogger is on that tile. - (for Stage 3 onwards) B denotes that a bug is on that tile. - (for Stage 4 onwards) 5 denotes that a superbug is on that tile. stop the game. Overview Like in other video games, there is a way for you to win or instant-lose a game. In the actual Frogger game you need to get a Frogger on each lillypad to win, but for CSE Frogger, you only need to get one Frogger on any lillypad. When Frogger gets to a lillypad, your program should print out the win message and stop the game. The win message is: with a newline above and below. Frogger also has three lives and once they are all used up, you lose the game. Frogger loses a life if they end up in the water. When Frogger loses a life, your program should print out the number of lives left, move Frogger back to their starting position to try again, and print the updated board. If Frogger loses all of their lives your program should print out the losing message and stop the game. The losing message is: with a newline above and below. Clarifications - When Frogger moves onto a tile that a bug is on, Frogger will lose a life as well. The gameboard setup remains the same after losing a life, ie. reset Frogger position, but the remainder of the board remains unchanged. \$./cs_frogger Welcome to cse Frogger! How many turtles? 7 Enter pairs: 14 24 34 44 54 64 74 Gante started Enter conmand: TT+TF Enter conmand: - Example 3.1.2: Losing $./cs_frogger Welcome to CSE Frogger! How many turtles? 3 Enter pairs: 74 64 65 Garte started 00000 +,+ ++ ++ Enter connand: 00000 +, ++ +,+ T T F Enter conmand: a 00+00+0 +, ++ +,+ F A LIVES LEFT: 2 A 00+00+0 ++ ++ +, T T At the moment Frogger is at the top of the foodchain on the board and only loses a life when they drown - it's time to change that! In this stage we will introduce a natural predator for Frogger. Command Overview To make the game more interesting, your code needs to add in an enemy for Frogger. This will be in the form of a When the command is entered, the two numbers that follow this command are the row and column position, respectively. This will provide the position for the bug on the gameboard. A bug can only be placed on a TURTLE or LOG, and CANNOT go on LILYPADs, WATER, or the BANK. Bugs also can't be placed on Frogger or other bugs. You will also need to make sure the coordinates are on the board. You will need to modify the struct to include the handling of bugs. Similar to printing out Frogger's position on the board, the bug is not a tile but a field (or fields depending on how you decide to store bugs) in the struct. When printing, a bug is represented by a and takes priority over printing the board tile. If Frogger and the bug are on the same tile, Frogger takes priority and should be printed instead, and a life should be taken off Frogger. The same steps should be taken for losing a life to a bug as to the river, ie, reset Frogger, the remainder of the gameboard will remain unchanged. NOTE We would recommend creating another struct to store information about the bug and adding a field inside the struct to store a bug. This might make it. easier for you when you move the bugs around in the next part of this Stage. Clarifications - You can assume the input will be of the right types (char int int), but you are not guaranteed the coordinates are valid. - Unlike Frogger, logs and rows can be cleared when there are bugs on then. - Bugs are not their own tile, similar to Frogger they are a field/s inside the tile struct. - You will need to update how you print the gameboard to include bugs. - Example 3.2.1: Adding Bugs $./ cs_frogger Welcome to cse Frogger! How many turtles? 1 Enter pairs: 22 Game started 00000 ++ T ++ + + + Enter command: 1427 00000 ++ L L L L L L ++ ++ + Enter command: b 44 00000 ++ L L B L L L + + Enter conmand: b 62 00000 ++ T L L L L L ++ ++ Enter conmand: b 202 00000 ++ L L B L L L + + F - Example 3.2.2: Running into Bugs $./ cs_frogger Welcome to cse Frogger! How many turtles? 2 Enter pairs: 64 66 Game started 00000 +, + Enter conmand: 1746 00000 +++ +TT L L F Enter connand: b 64 00000 ++ ++ L L L x Enter connand: b 66 00000 , + BB L L Enter conmand: 0000>0 ++ ++ + B FL Overview To make the bugs a little bit more exciting, everytime Frogger moves the bug(s) should move as well. Checking to see if Frogger has lost a life should be done after Frogger and the bugs have moved. Frogger's movement is not impacted by bugs (ie. if Frogger is to the left. of a bug that is moving left and Frogger moves right, Frogger and the bug will have swapped position and Frogger will not have lost a life). Bugs start by moving right and when they can't go right anymore (ie. edge of the board, end of a log, another bug) they should change direction to left and move that way instead until they can't go left anymore, and vice versa. If the bug is on a single turtle or log, it shouldn't move (until a log is added to extend it if the tile is a log). Its first move should still be to the right once it it able to move. The order in which your program moves bugs (ie. which bug your program moves first, then which one second, and so on) should start from the top left of the board and work across the first row from left to right, then move down a row and go left to right again. The order of bugs moving on a potential board is demomnstrated in the diagram below: If the bug has been moving and then is stuck on a single tile (this will become relevant when the board starts moving in Stage 4), then when they can move again their mmovement. direction should be preserved, ie. if it moved left onto the log, then becomes stranded, it should continue trying to move left when it is no longer "stranded". If a bug's next position is occupied by another bug, it should be treated like the edge of a log/ turtle. 50 if a bug is "trapped" between water and another bug, it shouldn't move and should preserve its movement direction for when it can move again. Note that if a bug is moving right and its position is occupied by a bug, it will move left. If the bug that was blocking the original bug is moving left, it will be able to move left as the rightmost bug has since vacated the original spot (since bugs are moved starting from the left of each row). Refer to the examples and sample implementation for more explanation. Remember to update the previous commands to be bug compatable, ie. printing the board, clear log, clear row. Clarifications - Bugs ONLY moves when Frogger movement commands are entered - so w, a , s , or - Bugs will move even if Frogger didn't change tiles - ie. when Frogger is at the edge of the - Example 3.3.1: Moving Bugs $./cs_frogger Welcome to cse frogger! How many turtles? 2 Enter pairs: 22 23 Gane started 00000 +, TT + F Enter conntand: b 22 00000 ++ BT + ++ +, Enter command: 1622 00000 + BT= ++ +,+ +L, ++ Enter conntand: 1647 00000 BT ++ LL L L + F - Example 3.3.2: Moving into/past - Example 3.3.3: Bugs Colliding $./ cs_frogger Welcome to cse Frogger! How many turtles? Garte started 00000 ++ ++ ++ ++ ++ F66 Enter connand: 1327 00000 LLLLLL ++ +++ ++ ++ Enter conmand: b 33 00000 ++ ++ LBLLL ++ + ++ Enter conmand: b 36 00000 ++ ++ LBLLBL + + ++ Enter conmand: a 00000 + + LLBLLB= + {++++ ++ xFx

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions

Question

What is human nature?

Answered: 1 week ago