Uploadfiles.io - PA4.pdf (pdf file is here). i coded a lot of stuff. the place where the shooter is gonna shoot is ready. but hardest part is to shoot with a direction,explosions etc. i will share my code just to show you that i'm putting effort into that. what i want from you is just to guide me .if you tell me how to write the algorithm i would be grateful. thank you.
Code:
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
int r,c,i,j,a=1,b=1,ct=0,m,n;
char **brick;
char colour;
float x,y;
void printbrick(char **x);
int main(){
char command;
scanf("%d %d",&c,&r);
brick=malloc(sizeof(char*)*c);
for(i=0;i<c;i++){
brick[i]=malloc(sizeof(char)*r);
}
for(i=0;i<r;i++){
for(j=0;j<c;j++){
if(i==0&&(j!=0&&j!=c-1)){
brick[i][j]='~';}
else if(j==0|| j==c-1){
brick[i][j]='|';}
else{
brick[i][j]=' ';
}
}
}
while(scanf("%c",&command)!=EOF){
if(command=='e'||command=='n'||command=='d'){
ct++;
if(ct==3){
break;} }
if(command=='R'){
if(brick[a][b]==' '){
brick[a][b]='R';
b++; }
if(brick[a][b]=='|'){
b=1;a++; }
}
if(command=='B'){
if(brick[a][b]==' '){
brick[a][b]='B';
b++; }
if(brick[a][b]=='|'){
b=1;a++; }
}
if(command=='Y'){
if(brick[a][b]==' '){
brick[a][b]='Y';
b++; }
if(brick[a][b]=='|'){
b=1;a++; }
}
if(command=='G'){
if(brick[a][b]==' '){
brick[a][b]='G';
b++; }
if(brick[a][b]=='|'){
}
}
if(command==' '){
if(brick[a][b]==' '){
brick[a][b]=' ';
b++; }
if(brick[a][b]=='|'){
b=1;a++; }
}
}
scanf("%d %d",&m,&n);
brick[n][m]='_';
printbrick(brick);
while(scanf("%c %f %f",&colour,&x,&y )!=EOF)
{
if(colour='q'){
break;
}
}
}
void printbrick(char **x){
for( i = 0 ;i<r ;i++)
{
for( j = 0 ;j<c ;j++)
{
printf("%c",x[i][j]);
}
printf("\n");
}
}