-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyGame.cpp
73 lines (69 loc) · 2 KB
/
MyGame.cpp
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int player1_score = 0; // 1 ci oyuncu icin xarici deyiseni teyin edirik
int player2_score = 0; // 2 ci oyuncu icin xarici deyiseni teyin edirik
int player1_endscore = 0;
int player2_endscore = 0;
void rollDice(int& score)
{
int dice1 = rand() % 6 + 1;
int dice2 = rand() % 6 + 1;
score = dice1 + dice2;
}
void playGame()
{
int turns = 3;
for(int i = 0; i < turns; i++)
{
cout << "round " << i+1 << endl;
cout << "1-ci oyuncu zeri atir..." << endl;
rollDice(player1_score);
cout << "2-ci oyuncu zeri atir..." << endl;
rollDice(player2_score);
cout << "round neticeleri: " << endl;
cout << "1-ci oyuncu: " << player1_score << endl;
cout << "2-ci oyuncu: " << player2_score << endl;
if(player1_score > player2_score)
{
cout << "1-ci oyuncu round qalibidir!" << endl;
player1_score++;
player1_endscore++;
}
else if(player1_score < player2_score)
{
cout << "2-ci oyuncu round qalibidir!" << endl;
player2_score++;
player2_endscore++;
}
else
{
cout << "berabere" << endl;
}
cout << endl;
}
}
int main()
{
srand(time(NULL)); // random reqem generatorunun inisializasiyasi
cout << "Zer atma oyunu!" << endl;
cout << "qanunlar: her bir oyuncu zer atir, kimin umumi xall sayisi daha coxdusa o qalib gelir" << endl;
cout << endl;
playGame(); // oyun basdiyir
cout << "Oyunun sonu!" << endl;
cout << "1-ci oyuncunun hesabi: " << player1_endscore << endl;
cout << "2-ci oyuncunun hesabi: " << player2_endscore << endl;
if(player1_endscore > player2_endscore)
{
cout << "1-ci oyuncu qalib geldi!" << endl;
}
else if(player1_endscore < player2_endscore)
{
cout << "2-ci oyuncu qalib geldi!" << endl;
}
else
{
cout << "berabere";
}
}