// card.h
#ifndef CARD_H
#define CARD_H
class card
{
protected:
int mCardScore;
int mFace;
int mSuit;
int Ace;
public:
card();
~card(){};
void setCardScore();
int getCardScore() const;
void getCard();
int getFace() const;
int getSuit() const;
int getAce() const;
};
#endifДобавлено (16.07.2012, 00:12)
---------------------------------------------
// card.cpp
#include "stdafx.h"
#include "card.h"
#include <iostream>
#include <cstring>
#include <ctime>
#include <cstdlib>
card::card()
{
mCardScore = 0;
mFace = 0;
mSuit = 0;
Ace = 0;
}
int card::getCardScore() const
{
return mCardScore;
}
int card::getAce() const
{
return Ace;
}
void card::getCard()
{
int kalod[ 4 ][ 13 ] = { 0 };
std::srand( time( 0 ) );
int i = 0;
for( int row = 0; row < 4; ++row )
{
for( int column = 0; column < 13; ++column )
{
kalod[ row ][ column ] = i++;
}
}
bool b = true;
std::srand( time( 0 ) );
while( b ){
int card = std::rand() % 52;
for(int row = 0; row < 4; row++ ){
for( int column = 0; column < 13; column++ )
{
if( kalod[ row ][ column ] == card )
{
mFace = column;
mSuit = row;
column = 100;
row = 100;
b = false;
}
}
}
}
}
int card::getFace() const
{
return mFace;
}
int card::getSuit() const
{
return mSuit;
}
void card::setCardScore()
{
int nkar = getFace();
int mast = getSuit();
switch ( nkar )
{
case 0:
mCardScore += 11;
Ace++;
break;
case 1:
mCardScore += 2;
break;
case 2:
mCardScore += 3;
break;
case 3:
mCardScore += 4;
break;
case 4:
mCardScore += 5;
break;
case 5:
mCardScore += 6;
break;
case 6:
mCardScore += 7;
break;
case 7:
mCardScore += 8;
break;
case 8:
mCardScore += 9;
break;
case 9:
mCardScore += 10;
break;
case 10:
mCardScore += 2;
break;
case 11:
mCardScore += 3;
break;
case 12:
mCardScore += 4;
break;
default:
std::cout << "Senc pti chlner:DDD " << std::endl;
break;
};
}
Добавлено (16.07.2012, 00:12)
---------------------------------------------
// comp.h
#ifndef COMP_H
#define COMP_H
#include "card.h"
class comp : public card
{
protected:
int mCompScore;
int compAce;
public:
comp();
~comp(){};
void compResult();
int getCompScore();
int getCompAce() const;
};
#endif
Добавлено (16.07.2012, 00:12)
---------------------------------------------
// comp.cpp
#include "stdafx.h"
#include "comp.h"
#include <iostream>
#include <string>
#include <windows.h>
comp::comp()
{
mCompScore = 0;
Ace = 0;
}
int comp::getCompScore()
{
return mCompScore;
}
int comp::getCompAce() const
{
return compAce;
}
void comp::compResult()
{
getCard();
setCardScore();
compAce += getAce();
int cardScore = getCardScore();
mCompScore = cardScore;
int nkar = getFace();
int mast = getSuit();
std::string nkarner[ 13 ] = { "Tuz", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "Valet", "Dama", "Karol" };
std::string master[ 4 ] = { "Srti ", "Qyapi ", "Xari ", "Xachi " };
std::cout << master[ mast ] << nkarner[ nkar ]
<< "\t" << "@ndhanur achokner: " << getCompScore() << std::endl;
Sleep(2000);
}
Добавлено (16.07.2012, 00:13)
---------------------------------------------
// player.h
#ifndef PLAYER_H
#define PLAYER_H
#include "card.h"
#include <string>
class player : public card
{
protected:
int mPlayerScore;
std::string mPlayerName;
int playerAce;
public:
player();
~player(){};
void setName( std::string & );
std::string getName() const;
void playerResult();
int getPlayerScore();
int getPlayerAce() const;
};
#endif
Добавлено (16.07.2012, 00:13)
---------------------------------------------
// player.cpp
#include "stdafx.h"
#include "player.h"
#include <iostream>
#include <string>
#include <windows.h>
player::player()
{
mPlayerScore = 0;
mPlayerName = "";
playerAce = 0;
}
void player::setName( std::string & name )
{
mPlayerName = name;
}
std::string player::getName() const
{
return mPlayerName;
}
int player::getPlayerScore()
{
return mPlayerScore;
}
int player::getPlayerAce() const
{
return playerAce;
}
void player::playerResult()
{
getCard();
setCardScore();
playerAce += getAce();
int cardScore = getCardScore();
mPlayerScore = cardScore;
int nkar = getFace();
int mast = getSuit();
std::string nkarner[ 13 ] = { "Tuz", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "Valet", "Dama", "Karol" };
std::string master[ 4 ] = { "Srti ", "Qyapi ", "Xari ", "Xachi " };
std::cout << master[ mast ] << nkarner[ nkar ]
<< "\t" << "@ndhanur achokner: " << getPlayerScore() << std::endl;
Sleep(1000);
}
Добавлено (16.07.2012, 00:14)
---------------------------------------------
// 21.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "card.h"
#include "player.h"
#include "comp.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::string name;
std::cout << "Anun: ";
std::cin >> name;
player player1;
player1.setName( name );
std::cout << "********** XAXUMENQ 21 " << player1.getName()
<< " **********" << std::endl << std::endl;
player1.getCard();
player1.playerResult();
int playerKey = 0;
do
{
playerKey = 0;
std::cout << "\n\n'1' eli kart vercnel, '2' heriqa: ";
std::cin >> playerKey;
if( playerKey == 2 )
{
std::cout << "\nSpasi compin\n\n";
break;
}
if( playerKey == 1 )
{
player1.getCard();
player1.playerResult();
if( player1.getPlayerScore() > 21 )
{
std::cout << "\n\nAncar 21@\nHaxtec comp@! " << std::endl << std::endl;
system("pause");
exit( 1 );
}
if( player1.getPlayerScore() == 21 || ( player1.getPlayerScore() == 22 && player1.getPlayerAce() == 2 ) )
{
std::cout << "\n\n********** " << player1.getName()
<< " du haxtecir!!! **********" << std::endl << std::endl;
system("pause");
exit( 1 );
}
}
} while( true );
comp Comp;
while( Comp.getCompScore() <= player1.getPlayerScore() )
{
Comp.getCard();
Comp.compResult();
if( Comp.getCompScore() == 21 || ( Comp.getCompScore() == 22 && Comp.getCompAce() == 2 ) )
{
std::cout << "\n\nHaxtec comp@" << std::endl << std::endl;
system("pause");
exit( 1 );
}
if( Comp.getCompScore() > 21 )
{
std::cout << "\n\n********** " << player1.getName() << " du haxtecir **********" << std::endl << std::endl;
system("pause");
exit( 1 );
}
if( Comp.getCompScore() >= player1.getPlayerScore() )
{
std::cout << "\n\nHaxtec comp@" << std::endl << std::endl;
system("pause");
exit( 1 );
}
}
std::cout << std::endl;
system("pause");
return 0;
}
Добавлено (16.07.2012, 00:14)
---------------------------------------------
@h@@@@@@@@@@@@N 