问题描述
我正在用C ++编写此游戏程序,用于两个玩家的oxo游戏...我正处于检查玩家1输入的阶段...有人可以帮助我吗?
#include< iostream>
#include< math.h>
#include< stdlib.h>
使用名称空间std;
char arr1 [8] [8] = {};
void display();
void player1();
void main()
{
显示();
player1();
system("cls");
显示();
}
无效显示()
{
字符字母=``A'';
cout<< ("1 | 2 | 3 | 4 | 5 | 6 | 7 | 8")<< endl;
cout<< ("------------------------------------------------ -----------------)<< endl;
for(int y = 0; y< 8; y ++)
{
cout<<字母;
for(int x = 0; x< 8; x ++)
{
cout<< "|"<< arr1 [y] [x];
}
字母++;
cout<< endl;
cout<< "------------------------------------------------- ----------------<< endl;
cout<< endl;
}
}
void player1()
{
char p1move [30] = {''0''};
char p1sign [30] = {''0''};
布尔输入=假;
cout<< 请输入您的坐标移动..."<< endl;
做
{
cin>> p1move;
if(((p1move [0]>''0'')&&(p1move [0]<''9''))&&(((p1move [1]> ")&&(p1move [1]< I))||((p1move [1]<''))&&(p1move [1]<' 'i'')))))
{inputing = true;}
否则{cout<< (您的举动无效,请输入其他举动")<<恩德尔输入=假;}
}
while(输入== false);
输入=假;
cout<< 请输入您的标志..."<< endl;
做
{
cin>> p1sign;
if((p1sign [0] ==''x'')||(p1sign [0] ==''o''))
{inputing = true;}
否则{cout<< (您的举动无效,请输入其他符号")<<恩德尔输入=假;}
}
while(输入== false);
cout<< "ok";
int get,get1;
if(p1move [0] ==``1'')get = 0;
if(p1move [0] ==``2'')get = 1;
if(p1move [0] ==``3'')get = 2;
if(p1move [0] ==``4'')get = 3;
if(p1move [0] ==``5'')get = 4;
if(p1move [0] ==``6'')get = 5;
if(p1move [0] ==``7'')get = 6;
if(p1move [0] ==``8'')get = 7;
if(((p1move [1] ==``a''))||(p1move [1] ==``A''))get1 = 0;
if((p1move [1] ==``b'')||(p1move [1] ==``B''))get1 = 1;
if(((p1move [1] ==``c''))||(p1move [1] ==``C''))get1 = 2;
if((p1move [1] ==``d'')||(p1move [1] ==``D''))get1 = 3;
if(((p1move [1] ==``e''))||(p1move [1] ==``e''))get1 = 4;
if((p1move [1] ==``f'')||(p1move [1] ==``F''))get1 = 5;
if((p1move [1] ==``g'')||(p1move [1] ==``G''))get1 = 6;
if((p1move [1] ==``h'')||(p1move [1] ==``H''))get1 = 7;
arr1 [get1] [get] = p1sign [0];
}
I am writing this game program in c++ for a two player oxo game ...i am in the phase of checking the player 1 input...can someone help me ?
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
char arr1 [8][8] = {};
void display();
void player1();
void main ()
{
display ();
player1 ();
system("cls");
display ();
}
void display ()
{
char letter = ''A'';
cout << (" 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8") <<endl;
cout << ("-----------------------------------------------------------------") <<endl;
for (int y =0; y<8; y++)
{
cout << letter;
for (int x =0; x<8; x++)
{
cout << " | "<<arr1 [y][x];
}
letter++;
cout << endl;
cout << "-----------------------------------------------------------------"<<endl;
cout << endl;
}
}
void player1()
{
char p1move [30]= {''0''};
char p1sign [30]= {''0''};
bool inputing = false;
cout << "please enter your co-ordinates Move..." <<endl;
do
{
cin >> p1move;
if ((( p1move[0] >''0'') && ( p1move[0] <''9'') ) && ( ( (p1move[1]> ''@'') && (p1move[1]<''I'') ) || ( (p1move[1]> ''<'') && (p1move[1]<''i'') ) ))
{inputing = true;}
else {cout << ("Your move is invalid, Please enter an other move")<< endl; inputing = false;}
}
while (inputing == false);
inputing = false;
cout << "please enter your sign..." <<endl;
do
{
cin >> p1sign;
if ( (p1sign[0] ==''x'') || (p1sign[0] ==''o'') )
{inputing = true;}
else {cout << ("Your move is invalid, Please enter another sign")<< endl; inputing = false;}
}
while (inputing == false);
cout << "ok";
int get, get1;
if (p1move[0] == ''1'') get = 0 ;
if (p1move[0] == ''2'') get = 1 ;
if (p1move[0] == ''3'') get = 2 ;
if (p1move[0] == ''4'') get = 3 ;
if (p1move[0] == ''5'') get = 4 ;
if (p1move[0] == ''6'') get = 5 ;
if (p1move[0] == ''7'') get = 6 ;
if (p1move[0] == ''8'') get = 7 ;
if ((p1move[1] == ''a'') || (p1move[1] == ''A'')) get1 = 0 ;
if ((p1move[1] == ''b'') || (p1move[1] == ''B'')) get1 = 1 ;
if ((p1move[1] == ''c'') || (p1move[1] == ''C'')) get1 = 2 ;
if ((p1move[1] == ''d'') || (p1move[1] == ''D'')) get1 = 3 ;
if ((p1move[1] == ''e'') || (p1move[1] == ''E'')) get1 = 4 ;
if ((p1move[1] == ''f'') || (p1move[1] == ''F'')) get1 = 5 ;
if ((p1move[1] == ''g'') || (p1move[1] == ''G'')) get1 = 6 ;
if ((p1move[1] == ''h'') || (p1move[1] == ''H'')) get1 = 7 ;
arr1 [get1][get]=p1sign[0];
}
推荐答案
这篇关于Oxo游戏问题继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!