Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <windows.h>
- #include <time.h>
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fstream>
- using namespace std;
- int szerokosc=25, wysokosc=25;
- int ruchX, ruchY, pktX, pktY, punkt;
- char c;
- void wspolrzedne(int x,int y)
- {
- COORD coord;
- coord.X=x;
- coord.Y=y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- void rysowanie_mapy()
- {
- wspolrzedne(5,3);
- cout<<char(201);
- for(int a=3;a<=szerokosc;a++) cout<<char(205)<<char(205);
- cout<<char(187);
- for(int b=2;b<=wysokosc;b++){
- wspolrzedne(5,4);
- cout<<char(186);
- for(int c=3;c<=szerokosc;c++) cout<<" ";
- cout<<char(186)<<endl;
- }
- wspolrzedne(5,5);
- cout<<char(204);
- for(int a=3;a<=szerokosc;a++) cout<<char(205)<<char(205);
- cout<<char(185)<<endl;
- for(int b=2;b<=wysokosc;b++){
- wspolrzedne(5,4+b);
- cout<<char(186);
- for(int c=3;c<=szerokosc;c++) cout<<" ";
- cout<<char(186)<<endl;
- }
- wspolrzedne(5,wysokosc+5);
- cout<<char(200);
- for(int a=3;a<=szerokosc;a++) cout<<char(205)<<char(205);
- cout<<char(188)<<endl;
- }
- void pierwszy_punkt()
- {
- pktX=szerokosc+4;
- pktY=wysokosc/2+5;
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
- wspolrzedne(pktX,pktY);
- cout<<char(158);
- }
- void punkty()
- {
- if((ruchX == pktX) && (ruchY == pktY)){
- punkt++;
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
- srand(time(NULL));
- pktX=rand()%(szerokosc*2-4) + 6;
- pktY=rand()%(wysokosc-1) + 6;
- wspolrzedne(pktX,pktY);
- cout<<char(158);
- }
- }
- void ruch()
- {
- if(c == 'w'){
- if(ruchY>6) ruchY--;
- }
- else if(c == 's'){
- if(ruchY<(wysokosc - 1 + 5)) ruchY++;
- }
- else if(c == 'a'){
- if(ruchX>6) ruchX--;
- }
- else if(c == 'd'){
- if(ruchX<(szerokosc*2 - 4 + 5)) ruchX++;
- }
- else{
- cout;
- }
- }
- void gra()
- {
- srand(time(NULL));
- ruchX=rand()%(szerokosc*2-4) + 6;
- ruchY=rand()%(wysokosc-1) + 6;
- system("cls");
- rysowanie_mapy();
- pierwszy_punkt();
- while(c != char(13)){
- punkty();
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
- wspolrzedne(ruchX,ruchY);
- cout<<char(254);
- wspolrzedne(7, 4);
- cout<<"Ilosc zebranych punktow: "<<punkt;
- wspolrzedne(szerokosc*2-12,4);
- cout<<"Wyjdz = ENTER";
- c=getch();
- wspolrzedne(ruchX,ruchY);
- cout<<" ";
- ruch();
- }
- system("cls");
- }
- void ustawienia()
- {
- string ustawienia_wybor;
- int wybor_szerokosci, wybor_wysokosci;
- system("cls");
- cout<<"USTAWIENIA"<<endl;
- cout<<"1. Zmien rozmiar mapy"<<endl;
- cout<<"2. Wyjdz do menu"<<endl;
- cout<<"> ";
- cin>>ustawienia_wybor;
- if(ustawienia_wybor == "1"){
- ustawienia_wybor = "";
- system("cls");
- cout<<"(Zakres 15-30) Zmien szerokosc z '"<<szerokosc<<"' na: ";
- cin>>wybor_szerokosci;
- cout<<"(Zakres 15-30) Zmien wysokosc z '"<<wysokosc<<"' na: ";
- cin>>wybor_wysokosci;
- if((wybor_szerokosci>30 || wybor_szerokosci<15) || (wybor_wysokosci>30 || wybor_wysokosci<15)){
- cout<<endl<<"Zla wartosc!"<<endl;
- Sleep(500);
- system("cls");
- ustawienia();
- }
- else{
- szerokosc=wybor_szerokosci;
- wysokosc=wybor_wysokosci;
- }
- cout<<endl<<"Pomyslnie zmieniono rozmiar mapy!"<<endl;
- Sleep(500);
- ustawienia();
- }
- if(ustawienia_wybor == "2"){
- system("cls");
- }
- else{
- ustawienia_wybor = "";
- cout<<endl<<"Nie ma takiej opcji!"<<endl;
- Sleep(500);
- system("cls");
- ustawienia();
- }
- }
- int menu()
- {
- for(;;){
- string menu_wybor;
- c = char(178);
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),3);
- cout<<"Witaj graczu!"<<endl;
- cout<<"1. Gra"<<endl;
- cout<<"2. Ustawienia"<<endl;
- cout<<"3. Wyjdz"<<endl;
- cout<<"> ";
- cin>>menu_wybor;
- if(menu_wybor == "1") gra();
- else if(menu_wybor == "2") ustawienia();
- else if(menu_wybor == "3"){
- system("cls");
- return 0;
- }
- else{
- cout<<endl<<"Nie ma takiej opcji!"<<endl;
- Sleep(500);
- system("cls");
- menu();
- }
- }
- }
- int main()
- {
- menu();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement