c#游戏 剪刀石头
电脑
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace shitou
{
class diannao
{
public int chuanquan()
{
Random rd = new Random();
int num=rd.Next(1, 4);
return num;
}
}
}
人
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace shitou
{
class ren
{
public int chuquan(string quanfa)
{
switch (quanfa)
{
case "石头":
return 1; case "剪刀":
return 2; case "布":
return 3; default:
return 0; }
}
}
}
裁判
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace shitou
{
enum win
{
ren,diannao,ping
}
class caipan
{
/// <summary>
/// 判断谁赢
/// </summary>
/// <param name="num1"></param>
/// <param name="num2"></param>
/// <param name="num3"></param>
/// <returns></returns>
public win judge(int num1, int num2)
{
//switch (num1 - num2)
//{
// case -1:
// return win.ren;
// break;
// case 2:
// return win.ren;
// break;
//}
if (num1 - num2 == -1 || num1 - num2 == 2)
{
return win.ren;
}
else if (num1 == num2)
{
return win.ping;
}
else {
return win.diannao;
} }
}
}
主代码 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace shitou
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string px = "石头";
play(px); } private void play(string px)
{ ren p = new ren();
int num1 = p.chuquan(px);
diannao d = new diannao();
int num2 = d.chuanquan();
caipan a = new caipan();
win re = a.judge(num1, num2);
this.caipan1.Text = re.ToString();
this.ren1.Text = px;
if (num2 == 1)
{
this.diannao1.Text = "石头";
}
else if (num2 == 2)
{
this.diannao1.Text = "剪刀";
}
else
{
this.diannao1.Text = "布";
}
} }
}
c#游戏 剪刀石头的更多相关文章
- Java自制人机小游戏——————————剪刀、石头、布
package com.hello.test; import java.util.Scanner; public class TestGame { public static void main(St ...
- 自己写的一个小的剪刀——石头——布游戏的GUI程序
很简单的一个程序,建议各位初学Java的同学可以试试写写这个程序: import javax.swing.JOptionPane; public class Game { public static ...
- python小游戏,石头/剪子/布
#从控制台输入石头(1)/剪子(2)/布(3) player=int(input("玩家出拳 石头(1)/剪子(2)/布(3)")) #电脑随机出拳 computer comput ...
- 【BZOJ2973】石头游戏 矩阵乘法
[BZOJ2973]石头游戏 Description 石头游戏的规则是这样的. 石头游戏在一个n行m列的方格阵上进行.每个格子对应了一个编号在0~9之间的操作序列. 操作序列是一个长度不超过6且循环执 ...
- 从零开始学java(小游戏 石头剪刀布)
Game.java package com.java;import java.util.Scanner;public class Game { private Player player ...
- [luogu1327][生活大爆炸石头剪子布]
题目地址 https://www.luogu.org/problemnew/show/P1328 题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负. ...
- Wikioi 3776 生活大爆炸版石头剪子布
题目描述 Description 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8集中出现了一种石头剪刀布的升级版游戏 ...
- java--demo之猜拳游戏
版本1:人机大战 基础随机出 用户键盘录入 package com.hainiu.demo; import java.util.Scanner; /* * 人机大战石头剪刀布 */ publi ...
- 洛谷P1328 生活大爆炸版石头剪刀布——S.B.S.
题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的 ...
随机推荐
- wpf 面试题目
初级工程师 解释什么是依赖属性,它和以前的属性有什么不同?为什么在WPF会使用它?什么是样式什么是模板绑定(Binding )的基础用法解释这几个类的作用及关系: Visual, UIElement, ...
- JAVA-语法-运算符
1.赋值运算符 = (优先级较低) 2.算数运算符 + — * / % 3.字符串连接运算 + (把其他类型转成字符串并和字符串类型进行连接) 4.扩展赋值运算符 += — ...
- 转:MIME(Multipurpose Internet Mail Extensions)类型
MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型.是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器 ...
- Android 优秀UI控件 ---- FlowingDrawer
1,前天在git上看到了一个不错的控件 ,最近两天项目也没有那么赶了,就抽时间来写写代码,锻炼一下手感,先看一下效果吧. 2 整体来看 ,主要是有两块来实现的,①主界面的RecyclerView ,② ...
- BI (商业智能)
BI (商业智能) 编辑 商业智能(BI,Business Intelligence). BI(Business Intelligence)即商务智能,它是一套完整的解决方案,用来将企业中现有的数据进 ...
- YbRapidSolution.MVC项目首页缓存没有起作用
Response.Cache.SetOmitVaryStar(true); 文件方面的内容,增加了这个语句 没有的话缓存没起作用,增加这个语句可提高系统性能. HomeController: usin ...
- 夺命雷公狗---node.js---19之项目的构建在node+express+mongo的博客项目4mongodb在项目中的基本引入
首先我们在命令行下先建立这个库: 然后我们在项目中引入mongodb的模块: var MongoClient = require('mongodb').MongoClient; var DB_STR ...
- PAT乙级 1031. 查验身份证(15) 标志要清零!!!!!!!!!
1031. 查验身份证(15) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 一个合法的身份证号码由17位地区. ...
- PAT乙级 1028. 人口普查(20)
1028. 人口普查(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 某城镇进行人口普查,得到了全体居民的 ...
- [fedora21]给fedora21安装fcitx输入法
如果已经安装了ibus,需要卸载ibus: sudo yum remove ibus; 安装fcitx: sudo yum install fcitx fcitx-pinyin fcitx-con ...