Jump to content

Simuleaza Miscarea Unei Bile


skyler_sdf

Recommended Posts

Probl: sa se simuleze miscarea unei bile pe o masa de biliard, fara frecare.

Bila va fi caracterizata de 4 variabile intregi: x si y vor indica coordonatele bilei(1<=x<=80; 1<=y<=24); vx si vy vor reprezenta directiile de deplasare ale bilei. Astfel, la fiecare pas, bila se va deplasa din pozitia (x, y), in pozitia (x+vx, y+vy), unde vx si vy pot lua valorile 1 sau -1. O deplasare in directia stanga-jos este data de vx=-1 si vy=1;

Se pot scrie in textul C secvente de program in limbaj de asamblare, folosind declaratia asm { }, ca in functiile hidecursor() si showcursor().

#include<conio.h>

#include<dos.h>

void hidecursor()

{

	asm{

		mov ax, 0x0100

		mov cx, 0x2607

		int 0x10

	}

}

void showcursor()

{

	asm{

		mov, ax, 0x0100

		mov cx, 0x0506

		int 0x10

	}

}

void main()

{


	clrsrc();

	hidecursor();

	char x=40, y=12, vx=1, vy=1;

	while(!kbhit())

	{


		gotoxy(x, y);

		putch(' ');

		if((x==1) || (x==80))

			vx=-vx;

		if((y==1) || (y==24))

			vy=-vy;

		x+=vx;

		y+=vy;

		gotoxy(x, y);

		putch('o');

		delay(50);


	}

	showcursor();

}

Functia kbhit() returneaza 1 daca a fost apasata o tasta, respectiv 0 in caz contrar.

Cursorul "palpaitor" din modul text se poate ascunde cu prima funtie si reafisa cu cea de a doua functie.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.