Tabbas, zan bi jagororin ku a hankali. Mu fara!
Harshen C ya kasance ginshiฦi a duniyar shirye-shirye shekaru da yawa. Daga cikin fa'idodinsa da yawa, wanda sau da yawa yakan tabbatar da amfani shine aikin 'gotoxy' a cikin C. Wannan aikin, wanda ke cikin ษakin karatu na `conio.h`, yana aiki da farko don sarrafa wurin siginan allo na fitarwa. A zahiri, tare da 'gotoxy', masu haษaka C na iya tantance inda za a buga fitarwa ta gaba akan allon wasan bidiyo kai tsaye.
Yin amfani da aikin 'gotoxy' a cikin C na iya haษaka ฦa'idodin gani da tsari na abubuwan wasan bidiyo, kuma yana da fa'ida musamman yayin gina shirye-shirye kamar wasanni, inda sanya abu akan allon wasan bidiyo yana taka muhimmiyar rawa.
Fahimtar aikin 'gotoxy' a cikin C
Aikin 'gotoxy' yana ba mu damar sake saita siginan kwamfuta akan allon wasan bidiyo, amma yana buฦatar a lura cewa ana amfani da wannan galibi a cikin yanayin DOS kuma baya samun amfani a dandamali na Windows ko Linux na zamani.
#include <conio.h> void main() { clrscr(); gotoxy(10, 20); printf("Hello, World!"); getch(); }
A cikin wannan snippet lambar, aikin 'gotoxy' yana mayar da siginan kwamfuta zuwa matsayin da (10, 20) ke nunawa akan allon wasan bidiyo. Aikin 'printf' sannan ya buga kirtani "Sannu, Duniya!" farawa daga inda aka saita ta aikin 'gotoxy'.
- Ana amfani da aikin 'clrscr()' don share allon wasan bidiyo kafin mu aiwatar da aikin 'gotoxy'.
- Ana amfani da aikin `getch()` don jira mai amfani ya danna maษalli kafin shirin ya ฦare.
Yin aiki 'gotoxy' daidai a cikin Muhalli na zamani
Kamar yadda muka lura, `gotoxy` yana daure da tsohuwar muhallin DOS kuma maiyuwa baya aiki da kyau a tsarin yanzu. Koyaya, babu buฦatar damuwa saboda muna iya ฦirฦirar aiki daidai don yin aiki iri ษaya a cikin aikin zamani.
#include <stdio.h> void SetCursorPosition(int x, int y) { printf("33[%d;%dH", y, x); } void main() { SetCursorPosition(10, 20); printf("Hello, World!"); }
An gurษata cikin aikin `SetCursorPosition()`, `printf("33[%d;%dH", y, x);' lambar tserewa ce ta ANSI wacce ke da tallafi da yawa kuma tana yin irin wannan aiki ga 'gotoxy' a cikin yanayi na zamani. Lambobin `y` da `x` suna ฦayyadadden haษin kai.
Wannan aikin 'SetCursorPosition', daidai da 'gotoxy', yana ba ku damar sarrafa daidaiton wuri na fitarwa akan allon wasan bidiyo da aka keษe ta ฦimar (x, y). 'Printf' mai zuwa yana buga kirtani "Sannu, Duniya!" dama a waษancan ฦayyadaddun haษin gwiwar.
Amfani da waษannan ayyukan na iya taimakawa ฦirฦirar abubuwan wasan bidiyo masu ban sha'awa na gani da samar da iko kai tsaye akan matsayi ko rubutu. Wannan yana da matukar amfani wajen gina hadaddun ayyukan shirye-shirye.
Tunawa da cewa kowane aikin C da ษakin karatu yana kawo saiti na fa'idodi na musamman ga tebur, haษaka amfani da waษannan kayan aikin na iya haษaka ingantaccen aiki, daidaito, da ฦirฦira a matsayin mai tsara shirye-shirye a C.