java飞行棋实现思路

2025-05-29 0 37

本文实例为大家分享了java飞行棋的注释版,供大家参考,具体内容如下

可以直接用:

?

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

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281
import java.util.Scanner;

public class Fly3 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner sc = new Scanner(System.in);

int all1 = 0;// 记录A的步数

int all2 = 0;// 记录B的步数

int flag1 = 1;// 对于A的暂停情况进行判断

int flag2 = 1;// 对于B的暂停情况进行判断

int first1 = 0;// 进行初始化判断

int first2 = 0;

System.out.print("|||||||||✈|||||||||||||||||||||||" + "\\n||||✈||||||飞行棋Beta版||||||||||||\\n"

+ "|||||||||||||||||||||||||||✈|||||\\n"+ "||||||||✈||||||||||||||||||||||||");// 标题显示

System.out.println();

System.out.println();

System.out.println();

System.out.println("\\t}}}}图形展示{{{{");

System.out.println("✈为传送门,一次10格" + "\\n为炸弹,一次退回6格" + "\\n⚡为被雷劈,一次直接返回原点 " + "\\n为幸运轮盘,踩上去可选择相关"

+ "\\n为暂停,踩上后下一次行动无法进行" + "\\n注:玩家与玩家的位置相同时,后一个玩家将会将上一个玩家挤退2格");

System.out.println();

System.out.println();

String A = "玩家A";// 用户选择角色

A = login(A);

String B = "玩家B";

B = login(B);

if (A.equals(B)) {

B = B + "2号";

}

maps(icon(all1, all2));

for (int i = 0;; i++) {

// A玩家视角

System.out.println(A + "开始投骰子");

int random1 = (int) (Math.random() * 6 + 1);

String msg = sc.nextLine();

System.out.println("少女祈祷中。。。");

System.out.println(A + "走" + random1 + "步");

all1 += random1;

if (first1 > 0) {// 判断是否为第一次运行地图(由于数组坐标重复的原因)

if (flag1 % 2 != 0) {// 判断为第几次踩到了暂停格子

all1 = all1 - random1;// 如果是第二次则将前面走的随机步数减回去

System.out.println("但是" + A + "不能走!因为");

}

}

first1++;

all2 = samepoint(all1, all2, B, A);// 判断二者坐标相同时(当A挤到B的位置时B怎么办(一种为后退四个格子一种为回到原点))

all1 = walk(A, all1);// 得到A所在数组下标位置,接下来对A的位置进行一次是否暂停的判定

flag1 = check(all1, flag1);

/*

* if (all1 == 15 || all1 == 28 || all1 == 85 || all1 == 90)

* {//(在输出地图之后对A当前所在的位置进行判定,如果满足则让flag自加1)

* flag1++;}此时flag在暂停判定模块中满足条件,进入判定,当第二次结束后flag则不会满足上面暂停模块的判定条件 else { flag1 =

* 0; }//正常情况时flag被赋值为0;则不会走到上面的暂停判定模块

*

*/

if (all1 == 55 || all1 == 22 || all1 == 10) {// 对幸运转盘进行操作判定

System.out.println("请选择" + A + "要执行的操作!\\n1.和" + B + "换个位置\\n2.让" + B + "退后个4格子");

int choice = sc.nextInt();

if (choice == 1) {

int temp = all1;

all1 = all2;

all2 = temp;

System.out.println(A + "和" + B + "的位置交换了!");

} else {

if (all2 < 4) {

all2 = 0;

System.out.println("直接把" + B + "送回原点了!");

} else {

all2 -= 4;

}

}

}

maps(icon(all1, all2));// 判断A是否符合条件获胜

System.out.println(A+"的位置是"+all1+"\\n"+B+"的位置是"+all2+"\\n");

if (all1 >= 100) {

System.out.println(A + "赢啦");

return;

}

// 到此为止,对A的一轮判定结束

// B玩家地图视角

System.out.println(B + "开始投骰子");

int random2 = (int) (Math.random() * 6 + 1);

String msg2 = sc.nextLine();

System.out.println("少女祈祷中。。。");

System.out.println(B + "走" + random2 + "步");

all2 += random2;

if (first2 > 0) {// 判断是否初始化

if (flag2 % 2 != 0) {// 判断第几次踩到了暂停格子

all2 = all2 - random2;

System.out.println("但是" + B + "不能走!因为");

}

}

first2++;

all1 = samepoint(all2, all1, A, B);// 判断二者坐标相同时(当B挤到A的位置时A怎么办(一种为后退四个格子一种为回到原点))

all2 = walk(B, all2);

flag2 = check(all2, flag2);

if (all2 == 55 || all2 == 22 || all2 == 10) {

System.out.println("请选择" + B + "要执行的操作!\\n1.和" + A + "换个位置\\n2.让" + A + "退后个4格子");

int choice = sc.nextInt();

if (choice == 1) {

int temp = all2;

all2 = all1;

all1 = temp;

System.out.println(B + "和" + A + "的位置交换了!");

} else {

if (all1 < 4) {

all1 = 0;

System.out.println("直接把" + A + "送回原点了!");

} else {

all1 -= 4;

}

}

}

maps(icon(all1, all2));

System.out.println(A+"的位置是"+all1+"\\n"+B+"的位置是"+all2+"\\n");

if (all2 >= 100) {// 判断B是否符合条件获胜

System.out.println(B + "赢啦");

return;

}

// 到此位置,对B的一轮判定结束

}

}

public static void maps(String[] a) {// 加空格是为了美观

for (int i = 0; i < 32; i++) {

System.out.print(a[i] + " ");

}

System.out.println();// 第一排地图图形输出

for (int i = 0; i < 32; i++) {

System.out.print(" ");

}

System.out.println(" " + a[32]);// 第二排地图图形输出

for (int i = 0; i < 32; i++) {

System.out.print(" ");

}

System.out.println(" " + a[33]);// 第三排地图图形输出

for (int i = 65; i > 33; i--) {

System.out.print(a[i] + " ");// 第四排地图图形输出

}

System.out.println();

System.out.println(a[66]);

System.out.println(a[67]);// 第五第六排地图输出

for (int i = 68; i < 100; i++) {

System.out.print(a[i] + " ");// 第七排地图图形输出

}

for (int i = 100; i < 105; i++) {// 结尾小旗子图像输出

System.out.print(a[i]);

}

System.out.println();

}

public static String[] icon(int a, int b) {

String[] map = new String[105];

for (int i = 0; i < 105; i++) {

if (i == 32 || i == 33 || i == 66 || i == 67) {

map[i] = "||";// 竖向输出道路

} else if (i == 3 || i == 9 || i == 23 || i == 40) {

map[i] = "✈";// 传送门logo

} else if (i == 75 || i == 62 || i == 48 || i == 37 || i == 98) {

map[i] = "";// 炸弹logo

} else if (i == 15 || i == 28 || i == 85 || i == 90) {

map[i] = "";// 暂停logo

} else if (i == 55 || i == 22 || i == 10) {

map[i] = "";// 幸运转盘logo

} else if (i == 100 || i == 101 || i == 102 || i == 103 || i == 104) {

map[i] = "";// 结尾处旗帜logo

} else if (i == 99) {

map[i] = "⚡";// 结尾处闪电logo

} else {

map[i] = "=";// 其余为横向的道路

}

}

map[b] = "B";

map[a] = "A";

return map;

}

public static int walk(String player, int a) {// 对当前角色应该走到的数组下标进行判断

int num = a;

switch (a) {

case 3:

case 9:

case 23:

case 40:

System.out.println(player + "进入传送门,传送10格!");

num = a + 10;

break;

case 75:

case 62:

case 48:

case 37:

case 98:

System.out.println(player + "危!!\\n踩到炸弹了,退6格!");

num = a - 6;

return num;

case 15:

case 28:

case 85:

case 90:

num = a;

System.out.println(player + "踩到了暂停格子!");

break;

case 55:

case 22:

case 10:

num = a;

System.out.println(player + "踩到了幸运转盘!!!!");

break;

case 99:

num = 0;

System.out.println(player + "危!!!\\n被雷劈了,直接送回原点");

break;

default:

num = a;

break;

}

return num;

}

public static int check(int a, int b) {// a为位置,b为状态判断

if (a == 15 || a == 28 || a == 85 || a == 90) {

b++;

} else {

b = 0;

}

return b;

}

public static String login(String a) {

String[] names = { "劳拉", "不知火舞", "春丽" };

Scanner sc = new Scanner(System.in);

System.out.println("可选角色:1.劳拉\\t2.不知火舞\\t3.春丽");

System.out.println("请" + a + "选择你的角色");// 角色选择

int aplayer = sc.nextInt();

String player = names[aplayer - 1];

return player;

}

public static int samepoint(int a, int b, String A, String B) {// 输入的A为受害者,B为幸运玩家

if (a == b && a >= 2 && a != 0) {

b = b - 2;

System.out.println(A + "玩家被" + B + "玩家挤回去了2格!");

return b;

} else if (a == b && a < 2 && a > 0) {

b = 0;

System.out.println(A + "玩家被" + B + "玩家挤回去了原点!");

}

return b;

}

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

原文链接:https://blog.csdn.net/Sisto/article/details/108665637

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 java飞行棋实现思路 https://www.kuaiidc.com/117003.html

相关文章

发表评论
暂无评论