Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <graphics.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <windows.h>
- #include <iostream>
- #include <cmath>
- #include <time.h>
- #define SIZE 40
- DWORD screenWidth = GetSystemMetrics(SM_CXSCREEN);
- DWORD screenHeight = GetSystemMetrics(SM_CYSCREEN);
- const char *sfondo = "Immagini/Sfondo.jpg";
- const char *testa = "Immagini/Testa.bmp";
- const char *locomotiva = "Immagini/Locomotiva.jpg";
- const char *start_btn = "Immagini/Start_btn.jpg";
- using namespace std;
- void isEnd();
- bool controllo(int xMouse, int yMouse, bool check);
- void stampaGriglia(int matrice[SIZE][SIZE]);
- int main()
- {
- srand(time(NULL));
- initwindow(screenWidth, screenHeight, "", -3, -3);
- int xMouse = 0, yMouse = 0, xBuffer = 0, yBuffer = 0, x = 0, y = 0, snake;
- bool check = 0;
- int griglia[SIZE][SIZE] = {0};
- readimagefile(sfondo, 0, 0, 1920, 1080);
- //initializeMatrix(griglia);
- readimagefile(testa, 0, 0, 320, 320);
- while(!check){
- xMouse = mousex();
- yMouse = mousey();
- //cout << xMouse << " " << yMouse << endl;
- check = controllo(xMouse, yMouse, check);
- }
- closegraph();
- initwindow(screenWidth, screenHeight, "Snake", -3, -3);
- rectangle(0, 0, 25, 25);
- int l = 3, posX, posY, tempX, tempY;
- posX = rand() % 20 + 10;
- posY = rand() % 20 + 10;
- griglia[posX][posY] = 2;
- griglia[posX-1][posY] = 1;
- griglia[posX-2][posY] = 1;
- int buffer[25][25];
- int W, A, S, D;
- while(1){ // game loop
- buffer[25][25];
- delay(10);
- stampaGriglia(griglia);
- if(GetKeyState('W') & 0x8000){
- cout << "bananaW ";
- }
- if(GetKeyState('A') & 0x8000){
- tempX = posX;
- tempY = posy;
- posX = griglia[posX - 1][posY];
- if(griglia[posX][posY] == 0){
- griglia[posX][posY] = 1;
- for(int i = l; i > 0; i--){
- griglia[posX + i - l][posY];
- }
- }
- if(griglia[posX][posY] == -1){ // -1 è il cibo
- l++;
- //sposti altri pezzi
- }
- if(posX < 0){
- //pop up hai perso
- }
- }
- if(GetKeyState('S') & 0x8000){
- cout << "bananaS ";
- }
- if(GetKeyState('D') & 0x8000){
- cout << "bananaD ";
- }
- }
- getch();
- return 0;
- }
- void stampaGriglia(int matrice[SIZE][SIZE]){
- int i, j;
- for(i= 0; i < 40; i++){
- for(j = 0; j < 40; j++){
- if(matrice[j][i] == 0){
- cout << '-';
- }else{
- cout << matrice[j][i];
- }
- }
- cout << endl;
- }
- Sleep(1000);
- system("cls");
- }
- void isEnd(){
- exit(0);
- }
- bool controllo(int xMouse, int yMouse, bool check){
- //start
- if(xMouse > 400 && xMouse < 600 && yMouse > 365 && yMouse < 465){
- if(ismouseclick(WM_LBUTTONUP)){
- clearmouseclick(WM_LBUTTONUP);
- check = 1;
- return check;
- }
- }
- // exit
- if(ismouseclick(WM_LBUTTONUP) && ((xMouse > 400 && xMouse < 600) && (yMouse > 665 && yMouse < 765)))
- {
- clearmouseclick(WM_LBUTTONUP);
- isEnd();
- }
- }
- /*
- #include <iostream>
- #include <graphics.h>
- #include <time.h>
- using namespace std;
- int main()
- {
- initwindow(700,700,"snake");
- int cx=400; int cy=200;
- int x1[701][701]={0};
- int rx,ry,sx;
- char ch;
- srand(time(NULL));
- rx=rand()%(500-100+1)+100;
- ry=rand()%(500-100+1)+100;
- x1[rx][ry]=1;
- setfillstyle(1,15);
- circle(rx,ry,2);
- floodfill(rx,ry,15);
- for ( ; ; )
- {
- delay(10);
- setcolor(0);
- setfillstyle(1,0);
- circle(cx-11,cy,10);
- floodfill(cx-11,cy,0);
- x1[cx-11][cy]=0;
- cx++;
- setcolor(15);
- setfillstyle(1,15);
- circle(cx-10,cy,10);
- floodfill(cx-10,cy,15);
- x1[cx-10][cy]=2;
- for (int i=1 ; i<=10 ;i++)
- {
- setcolor(15);
- setfillstyle(1,15);
- circle(cx-i,cy,10);
- floodfill(cx-i,cy,15);
- x1[cx-i][cy]=2;
- }
- if (kbhit())
- {
- for( ; ; )
- {
- if(kbhit())
- {
- ch=getch();
- }
- if (ch=='s')
- {
- cy++;
- sx=1;
- }
- else if (ch=='d')
- {
- cx++;
- sx=2;
- }
- else if (ch=='w')
- {
- cy--;
- sx=3;
- }
- else if (ch=='a')
- {
- cx--;
- sx=4;
- }
- if ( sx==1 )
- {
- delay(10);
- setcolor(0);
- setfillstyle(1,0);
- circle(cx,cy-11,10);
- floodfill(cx,cy-11,0);
- x1[cx][cy-11]=0;
- cy++;
- setcolor(15);
- setfillstyle(1,15);
- circle(cx,cy-10,10);
- floodfill(cx,cy-10,15);
- x1[cx][cy-10]=2;
- for (int i=1 ; i<=10 ;i++)
- {
- setcolor(15);
- setfillstyle(1,15);
- circle(cx,cy-i,10);
- floodfill(cx,cy-i,15);
- x1[cx][cy-i]=2;
- }
- }
- else if ( sx==2 )
- {
- delay(10);
- setcolor(0);
- setfillstyle(1,0);
- circle(cx-11,cy,10);
- floodfill(cx-11,cy,0);
- x1[cx-11][cy]=0;
- cx++;
- setcolor(15);
- setfillstyle(1,15);
- circle(cx-10,cy,10);
- floodfill(cx-10,cy,15);
- x1[cx-10][cy]=2;
- for (int i=1 ; i<=10 ;i++)
- {
- setcolor(15);
- setfillstyle(1,15);
- circle(cx-i,cy,10);
- floodfill(cx-i,cy,15);
- x1[cx-i][cy]=2;
- }
- }
- else if ( sx==3 )
- {
- delay(10);
- setcolor(0);
- setfillstyle(1,0);
- circle(cx,cy+11,10);
- floodfill(cx,cy+11,0);
- x1[cx][cy+11]=0;
- cy--;
- setcolor(15);
- setfillstyle(1,15);
- circle(cx,cy+10,10);
- floodfill(cx,cy+10,15);
- x1[cx][cy+10]=2;
- for (int i=1 ; i<=10 ;i++)
- {
- setcolor(15);
- setfillstyle(1,15);
- circle(cx,cy+i,10);
- floodfill(cx,cy+i,15);
- x1[cx][cy+i]=2;
- }
- }
- else if ( sx==4 )
- {
- delay(10);
- setcolor(0);
- setfillstyle(1,0);
- circle(cx+11,cy,10);
- floodfill(cx+11,cy,0);
- x1[cx+11][cy]=0;
- cx--;
- setcolor(15);
- setfillstyle(1,15);
- circle(cx+10,cy,10);
- floodfill(cx+10,cy,15);
- x1[cx+10][cy]=2;
- for (int i=1 ; i<=10 ;i++)
- {
- setcolor(15);
- setfillstyle(1,15);
- circle(cx+i,cy,10);
- floodfill(cx+i,cy,15);
- x1[cx+i][cy]=2;
- }
- }
- }
- }
- }
- getch();
- return 0;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement