Untitled
unknown
plain_text
a year ago
1.4 kB
5
Indexable
#include <stdio.h>
#define WIDTH 20
#define HEIGHT 10
// Function to print the game world
void printWorld(char world[HEIGHT][WIDTH]) {
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
printf("%c", world[i][j]);
}
printf("\n");
}
}
// Function to initialize the game world with blocks
void initializeWorld(char world[HEIGHT][WIDTH]) {
// Fill the world with spaces initially
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
world[i][j] = ' ';
}
}
// Add blocks using '#'
for (int i = HEIGHT - 2; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
world[i][j] = '#'; // Create a row of blocks near the bottom
}
}
}
// Function to place Mario in the world
void placeMario(char world[HEIGHT][WIDTH], int x, int y) {
if (y < HEIGHT && x < WIDTH) {
world[y][x] = 'M'; // Place Mario's body
world[y-1][x] = 'O'; // Place Mario's head above his body
}
}
int main() {
char world[HEIGHT][WIDTH];
// Initialize the game world with blocks
initializeWorld(world);
// Place Mario at a specific position
placeMario(world, 5, HEIGHT - 3); // Mario's position (x=5, y=HEIGHT-3)
// Print the world to the console
printWorld(world);
return 0;
}
Editor is loading...
Leave a Comment