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 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的 ...
随机推荐
- 异常信息:由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults
有方法说找到web.config 文件修改如下(蓝色部分) <behaviors> <serviceBehaviors> <behavior> ...
- ImportError: No module named setuptools
Python第三方模块中一般会自带setup.py文件,在Windows环境下,我们只需要使用命令 cd c:\Temp\foo python setup.py install 两个命令就可以完成第三 ...
- C++Primer 第十三章
//1.当定义一个类时,我们显示地或隐式地指出在此类型的对象(注意这里是此类型的对象,而不包括此类型的指针)拷贝,移动,赋值,销毁时做什么.一个类通过定义五种特殊的成员函数来控制这些操作:拷贝构造函数 ...
- pg_rewind 介绍
pg_rewind—使一个PostgreSQL数据目录与另一个数据目录(该目录从第一个PostgreSQL数据目录创建而来)一致. 描述 pg_rewind是一个在集群的时间线参数偏离之后,用于使一个 ...
- Java基础(8):方法重载的4个依据与例子
判断方法重载的依据: 1. 必须是在同一个类中 2. 方法名相同 3. 方法参数的个数.顺序或类型不同 4. 与方法的修饰符或返回值没有关系 运行结果:
- C#:IO
1. File和Directory类 这两个类属于静态类,经常用到的比如File.Exists(string path), Directory.Exists(string path), Directo ...
- Server.Transfer,Response.Redirect用法点睛
Server.Transfer,Response.Redirect的区别 如果你读过很多行业杂志和 ASP.NET 示例,你会发现,大多数人使用 Response.Redirect 将用户引导到另一个 ...
- 数据库中is null(is not null)与=null(!=null)的区别
在标准SQL语言(ANIS SQL)SQL-92规定的Null值的比较取值结果都为False,既Null=Null取值也是False.NULL在这里是一种未知值,千变万化的变量,不是“空”这一个定值! ...
- git批量删除分支
要删除本地,首先要考虑以下三点 列出所有本地分支 搜索目标分支如:所有含有'dev'的分支 将搜索出的结果传给删除函数 所以我们可以得到: git br |grep 'dev' |xargs git ...
- react tab
<!DOCTYPE html> <html> <head> <script src="js/react.js"></scrip ...