标签:
第一步先在数据库中建表(code,name,blood,attack,defence,mingzhong,shanbi,dengji)
三大类:
数据连接:
实体类
namespace ConsoleApplication1
{
public class youxi
{
private int code;
public int Code
{
get { return code; }
set { code = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int blood;
public int Blood
{
get { return blood; }
set { blood = value; }
}
private int attack;
public int Attack
{
get { return attack; }
set { attack = value; }
}
private int defence;
public int Defence
{
get { return defence; }
set { defence = value; }
}
private int mingzhong;
public int Mingzhong
{
get { return mingzhong; }
set { mingzhong = value; }
}
private int shanbi;
public int Shanbi
{
get { return shanbi; }
set { shanbi = value; }
}
private int dengji;
public int Dengji
{
get { return dengji; }
set { dengji = value; }
}
}
数据访问类
在Program里添加
class Program1
{
static void Main1(string[] args)
{
while (true)
{
Console.WriteLine("请输入代号:");
int code = int.Parse(Console.ReadLine());
Console.WriteLine("请输入姓名:");
string name = Console.ReadLine();
youxiDA da = new youxiDA();
if (da.add(code, name))
{
List<youxi> list = da.Select(code);
foreach (youxi data in list)
{
Console.WriteLine("代号是:" + data.Code + "--" + "姓名是:" + data.Name + "--" +
"等级是:" + data.Dengji + "--" + "血量是:" + data.Blood + "--" + "攻击是:" + data.Attack + "--" +
"防御是:" +data.Defence+ "--" + "命中是:" + data.Mingzhong + "--" + "闪避是:" + data.Shanbi);
}
}
else
{
Console.WriteLine("添加失败!");
}
Console.WriteLine("还要添加吗?Y or N");
string s = Console.ReadLine();
if (s == "Y")
{
}
else
{
Console.WriteLine("输入完成!");
break;
}
}
Console.ReadLine();
开始设定对打:
//pk结束
Console.WriteLine("------战斗结束------");
Console.WriteLine();
if (p1[0].Blood <= 0 && p2[0].Blood > 0)
{
Console.WriteLine(p2[0].Code+"赢了!恭喜晋级一级!");
Console.WriteLine("提升为:");
if (da.update(code_2))
{
List<youxi> List = da.Select(code_2);
foreach (youxi data in List)
{
Console.WriteLine("代号是:" + data.Code + "\t" + "名字是:" + data.Name + "\t" + "血量剩:" + data.Blood + "\t" + "攻击力:" + data.Attack + "\t" +
"防御率:" + data.Defence + "\t" + "命中率:" + data.Mingzhong + "\t" + "闪避力:" + data.Shanbi + "\t" + "等级为:" + data.Dengji + "\t");
}
}
else
{
Console.WriteLine("输入错误!");
}
}
else if (p2[0].Blood <= 0 && p1[0].Blood > 0)
{
Console.WriteLine(p1[0].Code+"赢了!恭喜晋级一级!");
Console.WriteLine("提升为:");
if(da.update(code_1))
{
List<youxi> List = da.Select(code_1);
foreach (youxi data in List)
{
Console.WriteLine("代号是:" + data.Code + "\t" + "名字是:" + data.Name + "\t" + "血量剩:" + data.Blood + "\t" + "攻击力:" + data.Attack + "\t" +
"防御率:" + data.Defence + "\t" + "命中率:" + data.Mingzhong + "\t" + "闪避力:" + data.Shanbi + "\t" + "等级为:" + data.Dengji + "\t");
}
}
else
{
Console.WriteLine("输入错误!");
}
}
else if (p1[0].Blood <= 0 && p2[0].Blood <= 0)
{
Console.WriteLine("同归于尽了!");
}
Console.ReadLine();
结果:
标签:
原文地址:http://www.cnblogs.com/yp11/p/5789051.html