C#小游戏-----猜数字

solarsoft 2001-10-09 11:38:20
朋友们,刚编写完这个小游戏,已经11点多了.休息一下,欣赏一下.学习任何的语言,都是在不断的编写中提高了.勿以简小而不为.using System;
public class Game
{
private string number;
private static int x,y;
private int count=0;
//char q,b,s,g;
public void init()
{
do{
Console.WriteLine("Please input number:");
number=(string)Console.ReadLine();
}while(number.Length!=4);
}
public void play()
{
string ready="1234";
//这里ready的值是要随机变化的.否则,没人玩你的游戏了.
//做的方法:char[] r=new char[]{'0',.......'9'};
// 用循环和随机函数将其顺序打乱.在取其前4个元素,给ready就可以了.
do{
x=0;
y=0;
init();
for(int i=0;i<=3;i++)
{
for(int j=0;j<=3;j++)
{
if(number[i]==ready[j])
{
if (i==j)
++x;
else
++y;
}
}
}
++count;
Console.WriteLine("{0}A{1}B",x.ToString(),y.ToString());
if(count>=8)
{
Console.WriteLine("-------------------");
Console.WriteLine("You already lossed");
Console.WriteLine("-------------------");
return;
}
}while(number!=ready);
Console.WriteLine("----------------------------");
Console.WriteLine("OK! You are very cleverness!");
Console.WriteLine("----------------------------");

}
}
public class MyGame
{
public static void Main()
{
Game g=new Game();
g.play();
}
}
已经编译通过.
...全文
76 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
javanow 2001-10-10
  • 打赏
  • 举报
回复

永远的 1234!!

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧