今个闲着无聊 编了个21点的小程序 望大家多多指点啊!
#include <iostream>
#include <stdlib.h>
using namespace std;
class point21
{public:
void Sru();
void Cli();
void display();
private:
int a;
int b;
};
void point21::Sru()
{int i=1; char c;
b=0;a=0;
while(i==1)
{
cout<<"是否要牌(是<y/Y>,否<n/N>): "<<endl;
cin>>c;
if(c=='y'||c=='Y')
{a+=rand()%21;cout<<"您的luck num是:"<<a<<endl;}
if(rand()%2==1)
{b+=rand()%21;}
if(c=='n'||c=='N')
i=0;
void clear();
}
}
void point21::Cli()
{cout<<"您的luck num是:"<<a<<" "<<"电脑的luck num是:"<<b<<endl;
if(a>21&&b>21)a=b;
else if(a<=21&&b>21)a=21;
else if(a>21&&b<=21)b=21;
a=abs(21-a);
b=abs(21-b);
}
void point21::display()
{if(a<b){cout<<"您胜利"<<endl;}
else if(a>b){cout<<"您输了"<<endl;}
else {cout<<"平局"<<endl;}
}
int main()
{point21 D;int i=0;
cout<<"欢迎您来到21点游戏世界"<<endl;
do
{
D.Sru();
D.Cli();
D.display();
cout<<"您要继续吗? 继续请按1,退出请按0。"<<endl;
cin>>i;
}
while(i==1);
cout<<"欢迎再来"<<endl;
return 0;
}
我这个程序算不算是面向对象了啊?