朋友们,刚编写完这个小游戏,已经11点多了.休息一下,欣赏一下.学习任何的语言,都是在不断的编写中提高了.勿以简小而不为.using system;
public class game
{
private string number;
private static int x,y;
private int count=0;
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();
}
}
已经编译通过.
