Deutsch

DOS игра 16.03.2025

16.03.25 17:14
Re: DOS игра 16.03.2025
 
uscheswoi_82 патриот

Улучшил код:

#include <stdio.h>
#include <conio.h>
#include <bios.h>
#define WIDTH  79
#define HEIGHT 23 
#define ESC    283
#define LEFT   19200
#define RIGHT  19712
#define UP     18432
#define DOWN   20480

int key, x, y, score;

void draw() {
  textattr(BLACK*0x10+LIGHTGRAY);
  gotoxy(1, 25);
  printf("У вас очков:d", score);
  gotoxy(x, y);
  printf("o");
  gotoxy(x, y);
}

void init() {
  key = 0;
  score = 0;
  x = 1;
  y = 1;
  draw();
}

int main(void) {
  clrscr();
  init();
  while(key != ESC) {
    key = bioskey(0);
    switch(key) {
      case LEFT:
        if(x > 1) x--;
      break;
      case RIGHT:
        if(x <= WIDTH) x++;
      break;
      case UP:
        if(y > 1) y--;
      break;
      case DOWN:
        if(y <= HEIGHT) y++;
      break;
    }
    clrscr();
    draw();
  }
  return 0;
}


Вуаля! Результат работы кода/игры:




Если я кому-то отвечаю, это не значит что я ему симпатизирую, каждый остаётся при своём мнение
 

Перейти на