html金山打字源码,c#实现简单金山打字小游戏(源码)

 2023-09-05 阅读 119 评论 0

摘要:using GameDemo.Utils;using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace GameDemo{class Program{static void Main(string[] args){int total=0;//计时Console.WriteLine("开始游戏");Console.WriteLine("准备

using GameDemo.Utils;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace GameDemo

{

class Program

{

static void Main(string[] args)

{

int total=0;//计时

Console.WriteLine("开始游戏");

Console.WriteLine("准备好开始游戏吗?y/n?");

if (Console.ReadLine().Equals("n")) {

Console.WriteLine("游戏已退出!");

return;

}

Console.WriteLine("请输入关卡数量");

int gk = Int32.Parse(Console.ReadLine());

Console.WriteLine("请输入每个关卡输入的次数");

int count = Int32.Parse(Console.ReadLine());

Console.WriteLine("请输入闯关输入的字数的个数");

int size = Int32.Parse(Console.ReadLine());

for (int i = 0; i

{

for (int j = 0; j

{

Console.WriteLine("这是第"+(i+1)+"关"+"第"+(j+1)+"次");

//产生随机字母

string str = new RandomUtils().CreateRandomWord(size);

Console.WriteLine("你要输入的内容为:"+str);

//时间计算

DateTime start = DateTime.Now;

//等待用户输入

string userinput=Console.ReadLine();

DateTime end = DateTime.Now;

int t= (int)(end.Ticks - start.Ticks)/10000000;//单次计时

total += t;//总计时

//检查用户输入是否正确

if (userinput.Equals(str))

{

Console.WriteLine("恭喜,你输入对了!用时"+t+"秒");

}

else {

Console.WriteLine("抱歉,你输入错了,游戏结束!");

return;

}

}

if (i == gk-1) {//闯完所有关卡

Console.WriteLine("恭喜你全部过关,总用时为"+total+"秒");

return;

}

Console.WriteLine("准备好进入下一关了吗 y/n");

string comd = Console.ReadLine();

if (comd.Equals("n")) {

Console.WriteLine("游戏已退出!");

return;

}

}

}

}

}

//生产字符串的工具类

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace GameDemo.Utils

{

class RandomUtils

{

///

/// 用来装载字符的数组

///

private char[] chars = new char[50];

///

/// 初始化数组数据

///

public RandomUtils() {

//得到a-z的字符

int idx=0;

for (int i = ‘a‘; i

{

if (i == ‘o‘) {//去掉o字母

continue;

}

chars[idx] += (char)i;

idx++;

}

//得到1-9的字符

int idx2=idx;

for (int j =‘0‘; j

{

chars[idx2++] = (char)j;

}

//重新组装数据

char[] newchars = new char[idx2];

for (int m = 0; m

{

if (chars[m] == ‘l‘) {//将小写的l换成L

chars[m] = ‘L‘;

}

newchars[m] = chars[m];

}

//将重组后的新数组赋值给原来的数组便于给其他方法访问数组数据

chars = newchars;

}

///

/// 随机产生字符串

///

/// 产生的字符串个数

///

public string CreateRandomWord(int size) {

StringBuilder builder = new StringBuilder();

Random r = new Random();

for (int i = 0; i

{

char c = chars[r.Next(chars.Length)];

if (builder.ToString().Contains(c)) {//处理字符串重复出现

i--;

continue;

}

builder.Append(c);

}

return builder.ToString();

}

}

}

原文:http://www.cnblogs.com/zzjbk/p/5188494.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://808629.com/94.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 86后生记录生活 Inc. 保留所有权利。

底部版权信息