Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <stdlib.h>
- #include <Windows.h>
- using namespace std;
- bool pataikei;
- int const eilutes = 10;
- int const stulpeliai = 10;
- char lenteleZm[11][11];
- char lenteleCpu[11][11];
- char NujaLentCpu[11][11];
- int laivaicpu = 20;
- int laivaizm = 20;
- int xpoz=11, ypoz=11;
- void pradzia()
- {
- for(int i=0; i<stulpeliai; i++)
- {
- for(int j=0; j<eilutes; j++)
- {
- lenteleZm[j][i]='O';
- }
- }
- for(int i=0; i<stulpeliai; i++)
- {
- for(int j=0; j<eilutes; j++)
- {
- lenteleCpu[j][i]='O';
- NujaLentCpu[j][i]='O';
- }
- }
- }
- void spam()
- {
- srand(time(NULL));
- for(int i=0; i<20; i++)
- {
- int x = rand() %9+0;
- int y = rand() %9+0;
- if(lenteleZm[x][y]=='1')
- {
- while(lenteleZm[x][y]=='1')
- {
- x = rand() %9+0;
- y = rand() %9+0;
- }
- lenteleZm[x][y]='1';
- }
- else
- lenteleZm[x][y]='1';
- }
- for(int i=0; i<20; i++)
- {
- int x = rand() %9+0;
- int y = rand() %9+0;
- if(lenteleCpu[x][y]=='1')
- {
- while(lenteleCpu[x][y]=='1')
- {
- x = rand() %9+0;
- y = rand() %9+0;
- }
- lenteleCpu[x][y]='1';
- }
- else
- lenteleCpu[x][y]='1';
- }
- }
- void saudymas()
- {
- cout << " " << endl;
- cout << "Iveskite x ir y pozicijas:" << endl;
- cin >> xpoz >> ypoz;
- while (cin.fail())
- {
- cin.clear();
- cin.ignore();
- cout << "Blogas ivedimas, iveskite skaicius ";
- cin >> xpoz >> ypoz;
- }
- if (xpoz > eilutes || xpoz < 1)
- {
- while (true)
- {
- cout << "Bloga koordinate x, bandykite dar karta: ";
- cin >> xpoz;
- if (xpoz <= eilutes && xpoz >= 1)
- {
- break;
- }
- }
- }
- if (ypoz > eilutes || ypoz < 1)
- {
- while (true)
- {
- cout << "Bloga koordinate y, bandykite dar karta: ";
- cin >> ypoz;
- if (ypoz <= eilutes && ypoz >= 1)
- {
- break;
- }
- }
- }
- bool vienodi=true;
- if(lenteleCpu[xpoz][ypoz]!='X' && lenteleCpu[xpoz][ypoz]!='N')
- {
- if(lenteleCpu[xpoz][ypoz]=='1')
- {
- lenteleCpu[xpoz][ypoz]='X';
- NujaLentCpu[xpoz][ypoz]='X';
- laivaicpu--;
- }
- else
- {
- lenteleCpu[xpoz][ypoz]='N';
- NujaLentCpu[xpoz][ypoz]='N';
- }
- }
- else
- while(vienodi)
- {
- cout << "Cia jau sovei" << endl;
- cout << "Iveskite x ir y pozicijas:" << endl;
- cin >> xpoz >> ypoz;
- if(lenteleCpu[xpoz][ypoz]!='X' && lenteleCpu[xpoz][ypoz]!='N')
- {
- vienodi=false;
- if(lenteleCpu[xpoz][ypoz]=='1')
- {
- lenteleCpu[xpoz][ypoz]='X';
- NujaLentCpu[xpoz][ypoz]='X';
- laivaicpu--;
- }
- else
- lenteleCpu[xpoz][ypoz]='N';
- NujaLentCpu[xpoz][ypoz]='N';
- }
- }
- system("CLS");
- }
- void saudymascpu()
- {
- srand(time(NULL));
- bool vienodi=true;
- int xp = rand() %9+0;
- int yp = rand() %9+0;
- if(lenteleZm[xp][yp]!='X' && lenteleZm[xp][yp]!='N')
- {
- if(lenteleZm[xp][yp]=='1')
- {
- lenteleZm[xp][yp]='X';
- laivaizm--;
- }
- else
- lenteleZm[xp][yp]='N';
- }
- else
- while(vienodi)
- {
- xp = rand() %9+0;
- yp = rand() %9+0;
- if(lenteleZm[xp][yp]!='X' && lenteleZm[xp][yp]!='N')
- {
- vienodi=false;
- if(lenteleZm[xp][yp]=='1')
- {
- lenteleZm[xp][yp]='X';
- laivaizm--;
- }
- else
- lenteleZm[xp][yp]='N';
- }
- }
- system("CLS");
- }
- void spausdinti()
- {
- cout << " Tavo lenta" << endl;
- cout << " Turi laivu " << laivaizm << endl;
- cout << " 0 1 2 3 4 5 6 7 8 9" << endl;
- cout << " --------------------" << endl;
- for(int i=0; i<stulpeliai; i++)
- {
- cout << i << "| ";
- for(int j=0; j<eilutes; j++)
- {
- cout <<lenteleZm[j][i] << " ";
- }
- cout << endl;
- }
- cout << " " << endl;
- cout << " CPU lenta" << endl;
- cout << " Cpu laivai " << laivaicpu << endl;
- cout << " 0 1 2 3 4 5 6 7 8 9" << endl;
- cout << " --------------------" << endl;
- for(int i=0; i<stulpeliai; i++)
- {
- cout << i << "| ";
- for(int j=0; j<eilutes; j++)
- {
- cout <<NujaLentCpu[j][i] << " ";
- }
- cout << endl;
- }
- }
- int main()
- {
- pradzia();
- spam();
- bool pabaiga=true;
- while(pabaiga)
- {
- spausdinti();
- saudymas();
- saudymascpu();
- if(laivaicpu==0 || laivaizm==0)
- pabaiga=false;
- }
- if(laivaicpu==0)
- {
- cout << "Laimejo cpu" << endl;
- }
- else
- cout << "Laimejai!" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement