Reputation: 53
So hello,
I am trying to get some experience on C, im at bigginer level.
I need so help if you will..
1) id like to make a console based game, so I have a char 2d array and i want first of all my game to have some kind of border.. mean: 1st n' last row, 1st n'last line, I want to put some asterisks so I can make a simple border.
Here is what I've tried:
//include etc
//main..
//int i,j
char myarray[22][76]={{' '}};
for(i=0;i>22;i++){
for(j=0;j<76;j++){
if(i==0 || i==22)
myarray[i][j]='*';
else if(j==0 && i>0 || j==75 && i>0)
myarray[i][j]='*';
else
myarray[i][j]='';
}
printf("%d",myarray[i][j]);
printf("\n");
}
-I think that i must erase i>0 in the conditions since the program wont enter else if untill i>0, cause of the if condition. -it might be completelly wrong but thats what i thought.
2) since I will have a player and treasures and traps, I want everytime my player moves the whole screen to be redrawn. But I dont want to be redrawn from the start i want it to be redrawn so it can show the current state of the game. ex. if the player has found a treasure then the screen must be drawn without the treasure on it and with the player at his current position.
Do I need the (border,traps,treasures,player) in same function? and how I can achieve the redraw of the screen in each move?
I run windows 10 and codeblocks+netbeans doesn't work at 10, I dont know why and I cant fix it atm , I tried online complier but they have limitation of code lines and excecution.
Upvotes: 0
Views: 116
Reputation: 125
//include etc
//main..
//int i,j
char myarray[22][76] = { { ' ' } };
for (i = 0; i<22; i++){
for (j = 0; j<76; j++){
if (i == 0 || i == 21)
myarray[i][j] = '*';
else if (j == 0 || j == 75)
myarray[i][j] = '*';
printf("%c", myarray[i][j]);
}
printf("\n");
}
Upvotes: 1