Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void drawScreen();
- void main(){
- drawScreen();
- }
- void drawScreen() {
- //This function draws display screen with map boundary, snake and mouse
- int x; // loop counter for x axis
- int y; // loop counter for y axis
- int k; // loop counter to count length of snake tail
- int drawTail=0; //draw is set to TRUE when a tail is drawn at the coordinates
- int mapHeight=20;
- int mapWidth=20;
- int snakeHeadX=9;
- int snakeHeadY=8;
- system("cls"); // clears the entire screen
- printf("\n");
- //draw left and right boundary, top and bottom boundary, snake and mouse
- // Part 3: Complete the nested for loops
- for (y = 0; y < mapHeight; y++) { //loop from top to bottom, y=0 to y=mapHeight-1
- for (x = 0; x < mapWidth; x++){ //loop from left to right, x=0 to x=mapWidth-1
- if(x==0&&y>=5&&y<=14){
- printf("#");
- } else if(y==0&&x>=5&&x<=14){
- printf("#");
- }else if(x==19&&y>=5&&y<=14){
- printf("#");
- }else if(y==19&&x>=5&&x<=14){
- printf("#");
- }else if((y==4||y==15)&&(x==1||x==18)){
- printf("#");
- }else if((y==1||y==18)&&(x==4||x==15)){
- printf("#");
- }else if((y==3||y==16)&&(x==2||x==17)){
- printf("#");
- }else if((y==2||y==17)&&(x==3||x==16)){
- printf("#");
- } else if((x==snakeHeadX)&&(y==snakeHeadY)){
- printf("O");
- }else{
- drawTail=0;
- if(drawTail==0){
- printf(" ");
- }
- }
- }//end of inner for loop
- printf("\n");
- }//end of outer for loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement