返回顶部

收藏

21点游戏的c++实现

更多
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main ()
{
 int loopx;
 loopx = 1;
 while(loopx == 1){
  int computer;
  int player;
  int addon;
  srand ( time(NULL) );
  computer = rand() % 23 + 4;
   player = rand() % 21 + 4;
    addon = rand() % 11 + 1;
     int loop = 1;
  while (loop == 1){
     cout << "New round... your cards: " << player;
  string response;
   cin >> response;
   if(response == "done"){
               cout << "ok then...";
               loop = 0;
               }
   if(response == "hitme"){
              cout << "ok then...";
           player = player + addon;
           cout << "your new cards are equal to " << player;
               }
               if(player>computer){
                    if(player<22){
                                  cout << "you won! Computer's cards:" << computer;
                                  loop = 0;
                                  }
                    if (player>21){
                                   cout << "you lose! Computer's cards:" << computer;
                                   loop = 0;
                                   }
                    }
                if(computer>player){
                                    if(computer<22){
                                                  cout << "You lose! Computer's cards:" << computer;  
                                                    }
                                    if(computer>21){
                                         cout << "You won! Computer's cards:" << computer;
                                         }
                                    }  
               }
               }
system ("pause>nul");
return 0;
}

标签:c++,blackjack

收藏

0人收藏

支持

0

反对

0

发表评论