C 언어 는 기사 비행 기 를 실현 한다.

7285 단어 C 언어비행 기
본 논문 의 사례 는 C 언어 가 기사 비행 기 를 실현 하 는 구체 적 인 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.

/* Author Mr.Long
 * Date  2015 12 2 17:33:17 
 */
#include<iostream>
#include<string>
#include<windows.h>
#include<stdlib.h>
#include<time.h>
#define random(x) (rand()%x)
 
using namespace std;
 
string player[2]={"  A","  B"};
int map[100];
int playerPos[2]={0,0};
int gamePlayer = 0;
bool isGameOver = false;
int winer = -1;
int pausePlayer = -1; 
//0□   1☆      2◎    3△    4d    
 string getLogo(int pos){ 
 
 string res = "□";
 if((playerPos[0] == pos) && (playerPos[1] == pos)){
 res = "<>";  
 }else if(playerPos[0]==pos){
  res = "A";
 }else if(playerPos[1]==pos){
  res = "B";
 }else{
  switch(map[pos]){
  case 1:
   res = "☆"; //     
   break;
  case 2:
   res = "◎"; //    
   break;
  case 3:
   res = "△"; //    
   break;
  case 4:
   res = "d"; //      
   break;
  } 
 }
 return res;
 }
 void drowMap(){ //     
 
 for(int i = 0;i<=29;++i){
  cout<<getLogo(i);
 }
 cout<<endl;
 for(int i = 30;i<=34;++i){
 for(int j = 0;j<=28;j++){
  cout<<" ";
 }
  cout<<getLogo(i)<<endl;;
 }
 for(int i =64;i>=35;i--){
 cout<<getLogo(i);
 }
 cout<<endl;
 for(int i = 65;i<=69;++i){
 cout<<getLogo(i)<<endl;
 }
 for(int i = 70;i<=99;i++){
  cout<<getLogo(i);
 }
 cout<<endl;
 cout<<"    :【☆      d      ◎    △    <>        】"<<endl; 
 } 
 void gameOver(){ //     
 isGameOver = true;
 winer = gamePlayer;
 playerPos[gamePlayer]=99;
 system("cls");
 drowMap();
 cout<<"***    !  ["<<player[gamePlayer]<<"]    !"<<endl;
 system("PAUSE"); 
 }
 void initMap(){ //      
 int luckyTurn[] = {6,23,40,55,69,83};//    1 
 int landMine[] = {5,13,17,33,38,50,64,80,94};//  2 
 int pause[] = {9,27,60,93};//  3 
 int timeTunnel[] = {20,25,45,63,72,88,90};//    4 
 int i;
 for(i =0;i<6;++i){
  int pos = luckyTurn[i];
  map[pos] = 1; 
 }
 for(i =0;i<9;++i){
  int pos = landMine[i];
  map[pos] = 2; 
 }
 for(i =0;i<4;++i){
  int pos = pause[i];
  map[pos] = 3; 
 }
 for(i =0;i<7;++i){
  int pos = timeTunnel[i];
  map[pos] = 4; 
 }
 }
 void initUI(){ //      
 
 cout<<"*******************   *****************"<<endl;
 cout<<"*                    *"<<endl;
 cout<<"*                    *"<<endl;
 cout<<"*                    *"<<endl;
 cout<<"****************@     ***************"<<endl;
 }
 void joinPlayer(){ //     
 
 string tmpStr = "";
 cout<<"     A   ___" <<endl;
 cin>>tmpStr;
 while(tmpStr==""){
 cout<<"             ___" <<endl; 
 cin>>tmpStr;
 }
 player[0] = "A" + tmpStr;
 
 cout<<"     B   ___" <<endl;
 cin>>tmpStr;
 while(tmpStr==""){
 cout<<"             ___" <<endl; 
 cin>>tmpStr;
 }
 while(tmpStr == player[0]){
 cout<<"        ,     ___" <<endl; 
 cin>>tmpStr;
 }
 player[1] = "B" + tmpStr;
 system("cls");
 cout<<"***      ..."<<endl;
 cout<<"***   [A]    ["<<player[0]<<"]   ..."<<endl;
 cout<<"***   [B]    ["<<player[1]<<"]   ..."<<endl;
 } 
 void yaoYiYao(){ //     
 
 short number = 0;
 while(!isGameOver){
  char a;
  cout<<"*** ["<<player[gamePlayer]<<"]  g    ..."<<endl;
 cin>>a;
  if(a=='g'){
  system("cls");
  number = random(6)+1;
  cout<<"***  ["<<player[gamePlayer]<<"]       :"<<number<<endl; 
  playerPos[gamePlayer] += number;
  int pos = playerPos[gamePlayer];
  if(pos >=99){
  gameOver();
  }else{
  switch(map[pos]){
  case 0:
   if(pausePlayer = -1){
   gamePlayer = !gamePlayer;
   }else if(pausePlayer = 0){
   pausePlayer++;
   }else if(pausePlayer = 1){
   pausePlayer = -1;
   }
   break;
  case 1:
   int cnumber;
   cout<<"***  !  ["<<player[gamePlayer]<<"]          ..."<<endl;
   cout<<"***             ...."<<endl;
   cout<<"1--       "<<endl<<"2--    "<<endl; 
   cin>>cnumber;
   if(cnumber == 1){
    int t = 0;
    t = playerPos[gamePlayer];
    playerPos[gamePlayer] = playerPos[!gamePlayer];
    playerPos[!gamePlayer] = t;
   }else if(cnumber == 2){
    playerPos[!gamePlayer] -=6 ;
   }else{
    cout<<"       !    。"<<endl; 
   }
   gamePlayer = !gamePlayer;
   break;
  case 2:
   cout<<"***  !  ["<<player[gamePlayer]<<"]     ,  6 ..."<<endl;
   playerPos[gamePlayer] -= 6;
   gamePlayer = !gamePlayer;
   break;
  case 3:
   cout<<"***   !  ["<<player[gamePlayer]<<"]      ..."<<endl;
   pausePlayer = 0;
   gamePlayer = !gamePlayer;
   break;
  case 4:
   cout<<"***  !  ["<<player[gamePlayer]<<"]      ..."<<endl;
   playerPos[gamePlayer] += 10;
   if(playerPos[gamePlayer]>=99){
   gameOver();
   }
   gamePlayer = !gamePlayer;
   break;
  }
  } 
 }else if(a == 'a'){
  winer = 0;
  gameOver();
 }else if(a == 'b'){
  winer = 1;
  gameOver();
 }
 for(int i=0;i<=1;i++){
  if(playerPos[i]<0)
  playerPos[i] = 0; 
 }
 if(!isGameOver){
  drowMap();
 } 
 }
 }
 
 int main(){
 srand((unsigned)time(NULL));
 
 initUI();
 cout<<"***         ..."<<endl; 
 joinPlayer();
 initMap();
 drowMap();
 cout<<"***      :["<<player[0]<<"] VS ["<<player[1]<<"]"<<endl;
 gamePlayer = random(2);
 yaoYiYao();
 return 0;
 }
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기