PDA

View Full Version : مبتدی: کمک در برنامه for line up



langroud
شنبه 26 آذر 1390, 16:37 عصر
سلام.این برنامه یه مشکلی دارهٰ هر کاری کردم درست نشد.قطر اصلی مشکل داره ٰ اون قطری که بالاش سمته چپه!
اگه میتونید کمکم کنید.


#include <iostream.h>
#include <conio.h>
char ja[7][7], a1[100], a2[100], ramz[] = {'s','o','f','t','w','a','r','e'}, r[100];
int a[7], number, number1,turn;
// print information
void print()
{
cout << "\t\t********IN THE NAME OF GOD********\n";
cout << "\t\t\t softwar 90\n";
cout << "\t\t\t ostad rostami \n";
}
bool finish()
{
for(int i=0; i<7; i++) if(a[i] < 7) return 0;
return 1;
}
// password check
bool c()
{
int i;
for(int i=0; ramz[i]; i++)
{
if(r[i] == NULL)
return 0;
if(ramz[i] != r[i])
return 1;
}
if(r[i] == NULL) return 1;
return 0;
}
// chape jadval
void chap_jadval()
{
cout <<"\t\t";
for (int i=0 ;i<17 ;i++)
cout <<"-.";
cout << "-\n";
for (int i=6 ;i>=0 ;i--)
{
cout <<"\t\t|";
for (int j=0;j<17;j++) cout << ja[j][i]<<(j<6?"||":"|");
cout << "\n\t\t";
for (int i=0 ;i<17 ;i++) cout <<"-.";
cout << "-\n";
}
cout <<"\t\t";
for(int i=0 ;i<7 ;i++) cout<<i<<" ";
}
// winning check
bool check()
{
//amoodi
for(int i=0; i<7; i++)
{
for(int j=3; j<7; j++)
{
if(ja[i][j] == ja[i][j - 1] && ja[i][j - 2] == ja[i][j] && ja[i][j - 3] == ja[i][j] && (ja[i][j] == 'X' || ja[i][j] == 'O'))
return 0;
}
}
//ofoghi
for(int i=0; i<7; i++)
{
for(int j=0; j<7; j++)
{
if(ja[i][j] == ja[i - 1][j] && ja[i - 2][j] == ja[i][j] && ja[i - 3][j] == ja[i][j] && (ja[i][j] == 'X' || ja[i][j] == 'O'))
return 0;
}
}
//movarab
for(int i=0; i<7; i++)
{
for(int j=0; j<7; j++)
{
if(i + j > 10 || i - 3 < 0 || j - 3 < 0 || i + j < 3) continue;
if(ja[i][j] == ja[i + 1][j - 1] && ja[i + 2][j - 2] == ja[i][j] && ja[i][j] == ja[i + 3][j - 3] && (ja[i][j] == 'O' || ja[i][j] == 'X'))
return 0;
}
}
//movarab /////
for(int i=0; i<7; i++)
{
for(int j=0; j<7; j++)
{
if(i - j >= 5 || j - i >= 5 || i + 3 > 6 || j + 3 > 6) continue;
if(ja[i][j] == ja[i + 1][j + 1] && ja[i + 2][j + 2] == ja[i][j] && ja[i + 3][j + 3] == ja[i][j] &&(ja[i][j] == 'O' || ja[i][j] == 'X'))
return 0;
}
}
return 1;
}
void marhale(int x)
{
cout<< (x==1?a1:a2)<<":";
cin >> number;
while (number>6 || a[number]==7)
{
cout << (number>6 ? "wrong number" : "it is full") << "\nplease enter another number :";
cin >>number;
}
ja[number][a[number]++]=(x==1? 'X':'O');
clrscr();
chap_jadval();
//undo
cout << "if you want to undo press Y else N : ";
char undo;
cin >> undo;
if(undo == 'Y')
{
int number1;
cin >> number1;
while(number1 > 6 || a[number1] == 7)
{
cout << (number1 >6 ? "wrong number": " it is full")<< "\nplease enter another number :";
cin >> number1;
}
ja[number][--a[number]] = ' ';
ja[number1][a[number1]++] = 'O';
clrscr();
chap_jadval();
}
else if(undo != 'N') cout << "please follow the rules\n";
}
int main()
{
print();
cout << "please type your password : ";
cin >> r;
while(c())
{
cout << "please type another password : ";
cin >> r;
}
cout << "player1 name : ";
cin >> a1;
cout << "player2 name : ";
cin >> a2;
for(int i=0; i<7; i++)
for(int j=0; j<7; j++)
ja[i][j] = ' ';
cout<< "\n\n\n\n";
chap_jadval();
while(check())
{
if (turn % 2 == 1) marhale(2);
else marhale (1);
turn++;
if (finish())
{
cout << "\tgame over\n";
getch();
return 0;
}
}
cout << ((turn + 1) % 2 ? a2 : a1) << "\t\t won the game";
cout << ((turn ) % 2 ? a2 : a1) << "\t don't worry next time you will win ";
getch();
return 0;
}

langroud
شنبه 26 آذر 1390, 16:39 عصر
یکی کمکم کنه لطفا