简单版猜拳游戏
来源:互联网 发布:年轻人大城市买房知乎 编辑:程序博客网 时间:2024/03/29 22:58
界面很简单
//玩家类using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 猜拳游戏{ /// <summary> /// 玩家类 /// </summary> public class Player { //出拳结果 public string FistName { get; set; } public int Play(string fistName) { this.FistName = fistName; int num = 0; switch (fistName) { case "石头": num = 1; break; case "剪刀": num = 2; break; case "布": num = 3; break; } return num; } }}//电脑类using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 猜拳游戏{ /// <summary> /// 电脑类 /// </summary> public class Computer { //出拳结果 public string FistName { get; set; } public int Play() { //随机生成 Random r = new Random(); int num = r.Next(1, 4); switch (num) { case 1: this.FistName = "石头"; break; case 2: this.FistName = "剪刀"; break; case 3: this.FistName = "布"; break; } return num; } }}//裁判类using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 猜拳游戏{ /// <summary> /// 裁判类 /// </summary> public class Judge { public string Win(int playNum, int computerNum) { if (playNum - computerNum == -1 || playNum - computerNum == 2) { return "玩家赢"; } else if (playNum - computerNum == 0) { return "平手"; } else { return "电脑赢"; } } }}//窗体using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace 猜拳游戏{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnStone_Click(object sender, EventArgs e) { Button btn = sender as Button; StartGame(btn.Text); } private void StartGame(string str) { Player player = new Player(); int playerNum = player.Play(str); lbPlay.Text = player.FistName; Computer computer = new Computer(); int computerNum = computer.Play(); lbComputer.Text = computer.FistName; Judge jud = new Judge(); lbRes.Text = jud.Win(playerNum, computerNum); } }}
0 0
- 简单版猜拳游戏
- 简单的猜拳游戏
- JAVA简单猜拳游戏(二)
- JAVA简单猜拳游戏(三)
- Android简单实现猜拳游戏
- JavaSE之简单猜拳游戏
- Cocos2dx实现简单猜拳游戏
- 猜拳游戏BETA版
- 猜拳游戏改良版
- android猜拳游戏简易版
- 猜拳游戏(单击版)
- 猜拳游戏 3.0升级版
- JAVA简单猜拳游戏(一)
- 简单的猜拳游戏的实现
- 一个简单的猜拳游戏的实现
- Android学习-简单的猜拳游戏
- 猜拳游戏
- 猜拳游戏
- 总结
- CSS基础
- Struts2实现文件上传报错(二)
- oracle db打one-off-patch 一例
- 《剑指offer》面试题4 替换空格
- 简单版猜拳游戏
- 正则表达式常用知识点总结
- 有思想的程序员
- Java的JDBC事务详解
- HDOJ-2222 Keywords Search 字典树+AC自动机(三叉树实现字典树)
- LayerMask的使用
- 批处理实例
- hdu1175
- 游戏Entity设计不完全整理(转)