-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
109 lines (80 loc) · 2.43 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <windows.h>
#include <conio.h>
#include <conio2.h>
#include <unistd.h>
int run = 1;
char key;
int direcao, num = 4;
struct Cobra{int x_pos, y_pos; char corpo;} c[100];
struct Fruta{int x_pos, y_pos;} f;
void Teclado(){
printf("%c%d\n", key, direcao);
if(direcao==0){printf("up ^\n");};
if(direcao==1){printf("down v\n");};
if(direcao==2){printf("rigth >\n");};
if(direcao==3){printf("left <\n");};
printf("xpos%d\t yposx%d\n", c[0].x_pos, c[0].y_pos);
};
int Pos_Co(){
for (int i=num;i>0;--i){
c[i].x_pos=c[i-1].x_pos;
c[i].y_pos=c[i-1].y_pos;
};
//limites da tela
if(c[0].x_pos <= 1){c[0].x_pos = 1;};
if(c[0].x_pos >= 80){c[0].x_pos = 80;};
if(c[0].y_pos <= 1){c[0].y_pos = 1;};
if(c[0].y_pos >= 80){c[0].y_pos = 80;};
//direcao
if(direcao==0){c[0].y_pos-=1;};
if(direcao==1){c[0].y_pos+=1;};
if(direcao==2){c[0].x_pos+=1;};
if(direcao==3){c[0].x_pos-=1;};
};
int Draw(){
//desenha a figura
//printf("\033[0;10m %i", c[0]);
//c[0].corpo = 'O';
//c[1].corpo = '0';
//c[2].corpo = '0';
//c[3].corpo = '0';
//c[4].corpo = '0';
COORD coord;
for(int a = 0; a < 10; a ++){
c[a].corpo = '@';
coord.X = c[a].x_pos;
coord.Y = c[a].y_pos;
printf("%c", c[a].corpo);
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
};
};
void SetBackgroundColor(int backcolor){
CONSOLE_SCREEN_BUFFER_INFO csbi;
WORD wColor = ((backcolor & 0x0F) << 4) + (csbi.wAttributes & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
};
int main(){
SetBackgroundColor(3);
//loop
while(run==1){
Draw();
//keyboard detections
int hit = kbhit();
if(hit){
char key = getch();
if(key=='w'){direcao=0;};
if(key=='s'){direcao=1;};
if(key=='d'){direcao=2;};
if(key=='a'){direcao=3;};
if(key=='p'){printf(" :) jogo pausado!\n"); system("pause");};
};
//run+=1;
Pos_Co();
system("cls");
};
system("pause");
}