作者热门文章
- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章C语言实现骑士飞行棋由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了C语言实现骑士飞行棋的具体代码,供大家参考,具体内容如下 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/* 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△暂停 4卍时空隧道
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 =
"卍"
;
// 时空隧道
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<<
"地图说明:【☆幸运轮盘 卍时空隧道 ◎地雷 △暂停 <>玩家同处一个位置】"
<<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;
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:https://blog.csdn.net/zxlong7749/article/details/50156267 。
最后此篇关于C语言实现骑士飞行棋的文章就讲到这里了,如果你想了解更多关于C语言实现骑士飞行棋的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我是一名优秀的程序员,十分优秀!