-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdartScore.cpp
127 lines (115 loc) · 3.74 KB
/
dartScore.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
fstream file;
string firstPName = "Guest1", secondPName= "Guest2", matchTitle= "Dart Mutch";
int
firstPScore=501, //first player score
secondPScore=501, //second player score
someOfDarts=0, //some of darts of every player 3 shot
ruleFirstTo=5, //rule first to (max of legs)
playFirstLeg=0, //who play first
playFirst=0,
leg=1, //number of leg (first leg, second leg...)
firstPLegWin=0, //legs wins by first player
secondPLegWin=0; //legs wins by second player
void newLeg(string& pNameFirstGameOn) {
firstPScore = 501;
secondPScore = 501;
cout << "----------Leg " << leg << "-----------\n";
cout << "Leg " << leg << " " << pNameFirstGameOn << " is first game on.\n";
cout << firstPName << " score is " << firstPScore << endl;
cout << secondPName << " score is " << secondPScore << endl;
}
void PSome(string& pName, int& pScore, int& pLegWin)
{
cout << "some of darts of " << pName << " is: ";
cin >> someOfDarts;
cin.ignore(1000,'\n');
if((pScore-someOfDarts) > 0 && (pScore-someOfDarts) != 1)
{
pScore -= someOfDarts;
cout << pName << " score is " << pScore << endl;
}
else if ((pScore-someOfDarts) == 1 || (pScore-someOfDarts) < 0)
{
cout << " No score " << endl;
cout << pName << " score is " << pScore << endl;
}
else if ((pScore-someOfDarts) == 0)
{
pLegWin += 1;
cout << "Game shot " <<"Leg " << leg << " " << pName << ".\n";
leg += 1;
if (playFirstLeg == 1)
{
if (leg &1) {playFirst = 1; newLeg(firstPName);}
else {playFirst = 2; newLeg(secondPName);}
}
else if (playFirstLeg == 2)
{
if (leg &1) {playFirst = 2; newLeg(secondPName);}
else {playFirst = 2; newLeg(firstPName);}
}
}
}
void startPlay()
{
playFirst = playFirstLeg;
while (ruleFirstTo != firstPLegWin && ruleFirstTo != secondPLegWin)
{
if(playFirst==1)
{
playFirst=2;
PSome(firstPName, firstPScore, firstPLegWin);
}
else if (playFirst==2)
{
playFirst=1;
PSome(secondPName, secondPScore, secondPLegWin);
}
else
{
cout << "you write wrong play first!";
}
}
if(ruleFirstTo == firstPLegWin) cout << "Game shot and match " << firstPName << "\n";
if(ruleFirstTo == secondPLegWin) cout << "Game shot and match " << secondPName << "\n";
}
int main(int argc, char const *argv[])
{
string fName, sName;
file.open("dartmutch.txt",ios::app);
file << "if you found me in a file.txt so you win \n";
if(!file) { cout<<"Error in creating file!!!"; return 0;}
file.close();
cout << "Please enter the mutch title: ";
getline(cin, matchTitle);
cout << "\n";
file.open("dartmutch.txt",ios::app);
file << "--------- " << matchTitle << " ---------\n";
if(!file) { cout<<"Error in creating file!!!"; return 0;}
file.close();
cout << "Please enter the Rule First to: ";
cin >> ruleFirstTo;
cin.ignore(1000, '\n');
cout << "\n";
cout << "please enter first player name: \n";
getline(cin, fName);
if(fName != "") firstPName = fName;
cout << "\n";
cout << "please enter second player name: \n";
getline(cin, secondPName);
if(sName != "") secondPName = sName;
cout << "\n";
cout << "Who plays first? \n";
cout << "If " << firstPName << " will play first please type 1:\n";
cout << "If " << secondPName << " will play first please type 2:\n";
cin >> playFirstLeg;
cin.ignore(1000, '\n');
cout << "\n";
startPlay();
return 0;
}