3.1 Workshop Lec2 Summary PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Workshop:

Drawing Rackets and Ball


Choosing “Colors”
Drawing is made by printing characters.

Character encoding is described by the ASCII table. I chose to use the symbol represented by the
numeric code 178 in the ASCII table. For more information – there’s a section dedicated to text
representation in the second part – “C Programming Language STEP by STEP – Part 2” course.

We chose to represent the ball using the capital ‘O’ letter.

int racket_color = 178;


int ball_color = 'O';

The Drawing itself:


I draw the rackets with loops.

for (int y = 0; y < racket_size; y++)

Pay attention that I try to give a name to each number by defining an appropriate variable:

int racket_size = 8;
int racket_color = 178;
int ball_color = 'O';
int max_x = 79;
int min_x = 0;

in total the main() looks like this:

int main()
{
int racket_size = 8;
int racket_color = 178;
int ball_color = 'O';
int max_x = 79;
int min_x = 0;
for (int y = 0; y < racket_size; y++)
{
gotoxy(min_x, y);
printf("%c", racket_color);
}

for (int y = 0; y < racket_size; y++)


{
gotoxy(max_x, y);
printf("%c", racket_color);
}

gotoxy(max_x / 2, racket_size / 2);


printf("%c", ball_color);

return 0;
}

)the comes in addition to the includes and the definition of gotoxy that come before the main – see
in the previous lecture summary the code for them!)

Go ahead and try it at home !!!

Cheers!
Shmuel.

You might also like