欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言實(shí)現(xiàn)騎士飛行棋

 更新時(shí)間:2020年02月05日 14:13:31   作者:Not-Object  
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)騎士飛行棋,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C語言實(shí)現(xiàn)騎士飛行棋的具體代碼,供大家參考,具體內(nèi)容如下

/* 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☆幸運(yùn)輪盤  2◎地雷  3△暫停  4卍時(shí)空隧道
 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 = "☆"; // 幸運(yùn)輪盤
   break;
  case 2:
   res = "◎"; // 地雷 
   break;
  case 3:
   res = "△"; // 暫停 
   break;
  case 4:
   res = "卍"; // 時(shí)空隧道 
   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<<"地圖說明:【☆幸運(yùn)輪盤  卍時(shí)空隧道  ◎地雷  △暫停  <>玩家同處一個(gè)位置】"<<endl; 
 } 
 void gameOver(){ //游戲結(jié)束 
 isGameOver = true;
 winer = gamePlayer;
 playerPos[gamePlayer]=99;
 system("cls");
 drowMap();
 cout<<"***游戲結(jié)束!恭喜["<<player[gamePlayer]<<"]取得勝利!"<<endl;
 system("PAUSE"); 
 }
 void initMap(){ //初始化地圖 
 int luckyTurn[] = {6,23,40,55,69,83};//幸運(yùn)輪盤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};//時(shí)空隧道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<<"玩家名字不能重復(fù),請重新輸入___" <<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]<<"]投擲的骰子數(shù)為:"<<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]<<"]獲得幸運(yùn)轉(zhuǎn)一轉(zhuǎn)的機(jī)會..."<<endl;
   cout<<"***請輸入數(shù)字選擇要進(jìn)行的操作...."<<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<<"輸入非規(guī)定數(shù)字!機(jī)會丟失。"<<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]<<"]穿越時(shí)空隧道..."<<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<<"***開始初始化玩家設(shè)置..."<<endl; 
 joinPlayer();
 initMap();
 drowMap();
 cout<<"***本場游戲開始:["<<player[0]<<"] VS ["<<player[1]<<"]"<<endl;
 gamePlayer = random(2);
 yaoYiYao();
 return 0;
 }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 純c語言優(yōu)雅地實(shí)現(xiàn)矩陣運(yùn)算庫的方法

    純c語言優(yōu)雅地實(shí)現(xiàn)矩陣運(yùn)算庫的方法

    本文主要介紹了純c語言優(yōu)雅地實(shí)現(xiàn)矩陣運(yùn)算庫,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • LeetCode 單調(diào)棧內(nèi)容小結(jié)

    LeetCode 單調(diào)棧內(nèi)容小結(jié)

    這篇文章主要介紹了LeetCode 單調(diào)棧內(nèi)容小結(jié),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • 淺談C語言的字節(jié)對齊 #pragma pack(n)2

    淺談C語言的字節(jié)對齊 #pragma pack(n)2

    下面小編就為大家?guī)硪黄獪\談C語言的字節(jié)對齊 #pragma pack(n)2。小編覺得挺不錯(cuò)的現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01
  • C++實(shí)現(xiàn)浮點(diǎn)數(shù)精確加法

    C++實(shí)現(xiàn)浮點(diǎn)數(shù)精確加法

    這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)浮點(diǎn)數(shù)精確加法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • C語言 共用體(Union)詳解及示例代碼

    C語言 共用體(Union)詳解及示例代碼

    本文主要介紹C語言 共用體,這里整理了相關(guān)資料及示例代碼,幫助大家學(xué)習(xí)理解此部分的知識,有興趣的小伙伴可以參考下
    2016-08-08
  • C++空類詳解

    C++空類詳解

    以下是對C++中的空類進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下
    2013-09-09
  • C++中標(biāo)準(zhǔn)線程庫的基本使用介紹

    C++中標(biāo)準(zhǔn)線程庫的基本使用介紹

    大家好,本篇文章主要講的是C++中標(biāo)準(zhǔn)線程庫的基本使用介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-02-02
  • C++中的常對象與常對象成員詳解

    C++中的常對象與常對象成員詳解

    常成員函數(shù)可以訪問常對象中的數(shù)據(jù)成員,但仍然不允許修改常對象中數(shù)據(jù)成員的值。有時(shí)在編程時(shí)有要求,一定要修改常對象成員中的某個(gè)數(shù)據(jù)成員的值(例如類中有一個(gè)用于計(jì)數(shù)的變量count,其值應(yīng)當(dāng)不能變化)
    2013-10-10
  • C語言實(shí)現(xiàn)2048游戲

    C語言實(shí)現(xiàn)2048游戲

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)2048小游戲,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • c++中用TINYXML解析XML文件

    c++中用TINYXML解析XML文件

    這篇文章主要介紹了c++中如何用TINYXML解析XML文件,文中案例非常詳細(xì),幫助大家更好的了解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06

最新評論