Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using C program to make a CS Frogger game - trying to get your Frogger to the other side of the river the Base code

using C program to make a CS Frogger game

- trying to get your Frogger to the other side of the river

the Base code

#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);

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

int main(void) {

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

// TODO (Stage 1.1) Initialise the gameboard.

// Read user input and place turtles. printf("How many turtles? "); // TODO (Stage 1.2): Scan in the turtles, and place them on the map.

// Start the game and print out the gameboard. printf("Game Started "); print_board(game_board);

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

printf("Thank you for playing CSE Frogger! "); return 0; }

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

// TODO: Add more functions here!

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

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

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; }

for Stage 1

image text in transcribed

image text in transcribed

Stage 1.2: Adding Turtles

image text in transcribed

Clarifications

You can assume that the number of turtles to scan in will be valid (ie. an integer between 0 and 63 inclusive)

If the coordinate pair for the turtles is out of bounds, the program should not attempt to place that turtle, but still count it as one of the total turtles (ie. there are 4 turtles to place but 3 are out of bounds should only place the one valid turtle and then start the rest of the game).

You can assume the coordinate pairs will be unique

image text in transcribed

Stage 1.3: The Command Loop and Adding Logs.

From this stage onwards the game is in the command mode. This means that commands should be read in until one of three events occurs:

the game is won,

the game is lost, or

CTRL+D is pressed.

You should scan in the first character from the terminal and check scanf's return value to see if CTRL+D was pressed.

After each command is entered you should print the updated gameboard. The first command you need to implement is adding logs.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

thank you very much!! :)

This assignment operates in 3 modes: the setup mode, command mode, and game mode. Please ensure you are familiar with the starter code, as it contains the basis for this task (and the whole assignment). You should initialise the variable so that the BANK, the WATER, and the LILLYPADs are on the game board. The set up will look the same each time, where: - the BANK is the bottom row with the FROG in the middle, - the LILLYPADs are in the top row and alternating. - and the rest should be the WATER. It may look like the image below: - Example 1.1.1: Initialization of game board $./ cs_frogger Welcome to CSE Frogger! How many turtles? 0 Game started 00000 xFxx Enter command: Thank you for playing CSE Frogger! Now it's time to start building Frogger a path through the water to the lillypads! Overview Once you have initialised the board, your program should then ask the user how many turtles they are adding to the board. You will then need to scan in the integer pairs (row, column) and place turtles at those locations on the board. Turtles can only be placed on water between the bank and the lillypads, ie. from row 1 to row 7 . After adding some turtles with the coordinates: the board might look like this: - Example 1.2.1: Initialization with turtles $./c5_frogger Welcome to CSE Frogger! How many turtles? 4 Enter pairs: 13 26 01 84 Game started 00000 T T - Example 1.2.2: Out of Bounds $./cs frogger Welcome to CSE Frogger! How many turtles? 4 Enter pairs: 45 126 104 325 Game started 00000 T xFxx Enter command: Thank you for playing CSE Frogger! Overview A single log can occupy multiple consecutive tiles in a row on the board. The command is detailed above and might look something like: This would add a log on row three that goes from the fourth to the sixth column inclusive. On the board it would look like: Similar to adding turtles, logs cannot go in the top or bottom row. Logs also cannot go in a row that has turtles in it. So, if the row is only water (or has logs in it) and the column range is between 0 and 8 inclusive, then the log can be added. If the column range given is out of bounds (less than 0 or greater than 8), then only the parts of that log that fall on the gameboard should be placed. For example, falls on the board from column 0 to 5 inclusive. If the entire log falls out of the bounds of the board, nothing should be placed (this is demonstrated in example 1.3.1). Example 1.3.1: Addinga a log - Example 1.3.2: Adding to a turtle row \$./cs_frogger Welcome to CSE Frogger! How many turtles? 3 Enter pairs: 34 51 11 Game started 00000 T T T xFxx Enter command: 1548 00000 T T T xxFxx Enter command: Thank you for playing CSE Frogger! - Example 1.3.3: Adding Multiple Logs $./ cs_frogger Welcome to CSE Frogger! How many turtles? 3 Enter pairs: 34 68 02 Game started 00000 T T T xxFxx Enter command: 11412 00000 LLLLL T T XXFXXX Enter command: 1125 00000 LLLLLLL T T xFxx Enter command: 1503 00000 LLLLLLL T LLLL T F

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

Students also viewed these Databases questions