本帖最后由 凤凰涅槃 于 2013-11-7 21:16 编辑
- /// <summary>
- /// 用户玩家类
- /// </summary>
- class Player
- {
- /// <summary>
- /// 用户玩家姓名
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// 用户玩家出拳
- /// </summary>
- /// <param name="fist"></param>
- /// <returns></returns>
- public string ShowFist(string fist)
- {
- return fist;
- }
- }
复制代码- /// <summary>
- /// 电脑玩家类
- /// </summary>
- class PC
- {
- /// <summary>
- /// 电脑玩家出拳
- /// </summary>
- /// <returns></returns>
- public string ShowFist()
- {
- string fist = "";
- Random ran = new Random();
- int fistNum = ran.Next(1,4);
- switch (fistNum)
- {
- case 1:
- fist = "石头";
- break;
- case 2:
- fist = "剪刀";
- break;
- case 3:
- fist = "布";
- break;
- default:
- fist = "未知拳法!";
- break;
- }
- return fist;
- }
复制代码- /// <summary>
- /// 判断输赢类
- /// </summary>
- class IsWin
- {
- //用户出拳值
- public string PlayerFist { get; set; }
- //电脑出拳值
- public string PCFist { get; set; }
- /// <summary>
- /// 判断输赢
- /// </summary>
- /// <returns></returns>
- public string GetWin()
- {
- if ((PlayerFist == "石头" && PCFist == "剪刀")
- || (PlayerFist == "剪刀" && PCFist == "布")
- || (PlayerFist == "布" && PCFist == "石头"))
- {
- return new Player().Name + "赢"; //这里取不到Player的Name属性值
- }
- else if ((PCFist == "石头" && PlayerFist == "剪刀")
- || (PCFist == "剪刀" && PlayerFist == "布")
- || (PCFist == "布" && PlayerFist == "石头"))
- {
- return "电脑赢";
- }
- else
- {
- return "平局";
- }
- }
复制代码- ///单击"石头"、"剪刀"、"布"三个按钮的公共处理程序(方法)
复制代码
求大侠帮忙看看 有点麻烦 这里先谢谢了 。。。。。。。。。。
判断输赢部分: return new Player().Name + "赢"; //这里取不到Player的Name属性值 我真不晓得是哪儿出错了
调一下午了 , 这里先谢谢各位大侠了 。。。。。。。。。。。。
|