chatGPT答: |
8v6.cn |
(C语言)
```c
//include the necessary libraries
#include <stdio.h>
#include <stdlib.h>
//define constants
unsigned short const WORLD_WIDTH = 10;
unsigned short const WORLD_HEIGHT = 8;
// define enumerations
typedef enum {
EMPTY=0,
BRICK=1,
QUESTION_MARK=2,
COIN=3
} world_block;
// define containers
world_block world[WORLD_HEIGHT][WORLD_WIDTH];
// define functions
void setup_world(){
// set up world
int i,j;
for (i = 0; i < WORLD_HEIGHT; i++){
for (j = 0; j < WORLD_WIDTH; j++){
world[i][j] = EMPTY;
}
}
// add bricks
for (i = 0; i < WORLD_HEIGHT; i++){
world[i][0] = BRICK;
world[i][WORLD_WIDTH-1] = BRICK;
}
for (j = 0; j < WORLD_WIDTH; j++){
if (j % 2 == 0){
world[0][j] = BRICK;
world[WORLD_HEIGHT-1][j] = BRICK;
}
}
// add coins
for (i = 1; i < WORLD_HEIGHT-1; i++){
for (j = 1; j < WORLD_WIDTH-1; j++){
if (j % 2 == 1)
world[i][j] = COIN;
}
}
}
int main() {
setup_world();
// the rest of the code goes here
return 0;
}
```
|