众所周知呢,c#是微软推出的一门面向对象的语言,学习他的人非常的多,有多少呢?很多很多,哈哈哈
学习呢,当然要有一个目标,或者觉得有趣才会去主动的,心甘情愿的去学,哈哈哈
这里呢,给大家分享一个以前学习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
106using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { /// <summary> /// 程序入口 /// </summary> class Program//只包含ABCDE五个字符,遇到三个相同的自动消除,当字符等于null时游戏结束 { static void Main(string[] args) { int index = 0; //插入的序号 string c_insert = ""; //插入的字符 string game_str = "ABDCBBDDAEECBDC"; Console.WriteLine("****************************************************n" + "* 游戏开始 *n" + "****************************************************"); while (!end(game_str)) { Console.WriteLine("需要插入的字符串:" + game_str); Console.WriteLine("输入要插入的序号(0~" + game_str.Length + ")和插入的字符"); if (in_error(ref index, ref c_insert, game_str)) { Console.WriteLine("输入有误,下一轮"); } else { game_str = game_str.Insert(index, c_insert); if (game_str.Length > 2) { check(ref game_str); } } } Console.WriteLine("游戏结束"); } #region 检查是否消除,可以则消除 /// <summary> /// 检查是否消除,可以则消除 /// </summary> /// <param name="game_str"></param> public static void check(ref string game_str) { for (int i = 0; i < game_str.Length - 2; i++) { if (game_str[i].Equals(game_str[i + 1]) && game_str[i].Equals(game_str[i + 2])) { for (int j = 0; j < 3; j++) { game_str = game_str.Remove(i, 1); } if(game_str.Length > 2) { check(ref game_str); } } } } #endregion 检查是否消除,可以则消除 #region 判断是否结束游戏 /// <summary> /// 判断是否结束游戏 /// </summary> /// <returns></returns> private static bool end(string game_str) { if (game_str.Equals("")) return true; else return false; } #endregion 判断是否结束游戏 #region 判断输入是否错误 /// <summary> /// 判断输入是否错误 /// </summary> /// <param name="index">插入的序号</param> /// <param name="c_insert">插入的字符</param> /// <param name="game_str">被插入的字符串</param> /// <returns></returns> private static bool in_error(ref int index, ref string c_insert, string game_str) { try { index = Convert.ToInt32(Console.ReadLine()); } catch(Exception e) { return true; } c_insert = Console.ReadLine(); if (index > game_str.Length || index < 0 || c_insert[0] < 'A' || c_insert[0] > 'E' || c_insert.Length != 1) { return true; } return false; } #endregion 判断输入是否错误 } }
重点提示一下!!!!
字符串类型变量是不可变的!
大家要自己研究下这句话哦~
大家直接创建一个项目,复制代码运训即可,学习娱乐两不误~
什么??!你不想新建项目,不想复制粘贴?
好吧,你赢了,在这直接下载项目把。。。
c#字符祖玛游戏-C#代码类资源-CSDN下载
祝大家学习愉快,心想事成~
最后
以上就是顺心招牌最近收集整理的关于c#字符串学习之祖玛游戏~的全部内容,更多相关c#字符串学习之祖玛游戏~内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复