Creative Commons License Foxbond's Repo

/** (c) 2012 Michał (Foxbond) Chraniuk */
#include <iostream>
#include <conio.h>
#include <time.h>
#include <windows.h>

#define BLUE 1
#define GREEN 2
#define RED 4
#define PURPLE 5
#define GOLD 6
#define LIGHTBLUE 9
#define WHITE 15


using namespace std;

int ch=0;
int mapMatrix[11][21] = {
		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
		{1,2,2,2,2,1,2,2,2,2,2,2,2,2,2,1,2,2,2,2,1},
		{1,2,1,1,2,1,2,1,1,1,1,1,1,1,2,1,2,1,1,2,1},
		{1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,1},
		{1,2,1,2,1,1,2,1,1,1,2,1,1,1,2,1,1,2,1,2,1},
		{1,2,2,2,2,2,2,1,2,2,2,2,2,1,2,2,2,2,2,2,1},
		{1,2,1,2,1,1,2,1,1,1,1,1,1,1,2,1,1,2,1,2,1},
		{1,2,1,2,2,2,2,2,2,2,3,2,2,2,2,2,2,2,1,2,1},
		{1,2,1,1,2,1,2,1,1,1,1,1,1,1,2,1,2,1,1,2,1},
		{1,2,2,2,2,1,2,2,2,2,2,2,2,2,2,1,2,2,2,2,1},
		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
		};
	
int i,ii;
int score=0;
int x=10;
int y=7;

void changeColor (int color){
	 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}

void cls () { system("cls"); }

void drawField (void){
	for (i=0;i<11;i++){
		for (ii=0;ii<21;ii++){
			if (mapMatrix[i][ii] == 0){
				cout << " "; 
			} else if (mapMatrix[i][ii] == 1){
   			    changeColor(PURPLE);
			  	cout << "#";
			  	changeColor(WHITE);
   			} else if (mapMatrix[i][ii] == 2){
			  	cout << ".";
			  	//•
   			} else if (mapMatrix[i][ii] == 3){
			  	cout << "e";
			  	//
   			}	  
		}
		cout << endl;	  
   }
}

void init (void){
	 
	SetConsoleTitle("SHIT-PAC");
	cout << "SHIT-PAC\nPoruszasz sie wsad\nW czasie gry nacisnij esc, aby zamknac\n\n";
	system("pause");
	 
	 
}

bool move (int yC, int xC){
	 
	 if (mapMatrix[(y+yC)][(x+xC)] == 1){
  	 	return false;
	 }else if (mapMatrix[(y+yC)][(x+xC)] == 2){
	 	score++;
     }
	 
	 mapMatrix[y][x] = 0;
	 y=y+yC;
	 x=x+xC;
	 mapMatrix[y][x] = 3;
	 return true;
	 
}

int main () {
	
	
	
	init();
	
	while (ch != 27){
 		  cls();
 		  drawField();
 		  cout << "Aktualny wynik: "<<score<<endl;
 		  
 		  
 		  ch = getch();
 		  _sleep(100);
 		  if (ch == 'w'){
		  	 move(-1,0);
 		  }else if (ch == 's'){
		  	 move(1,0);
		  }else if (ch == 'a'){
		  	 move(0,-1);
		  }else if (ch == 'd'){
		  	 move(0,1);
		  }
 		  
 		  
 		  if (score==109){
			  ch=27;
			  cls();
			  cout << "Zebrales wszystkie kupy!\n";
			  system("pause");
		  }
 		  
 		  
 		  
 		  
	}
	
	return 0;
}

> Back