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 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的 ...
随机推荐
- duplicate命令创建physical standby数据库报RMAN-03015 ORA-17628
The following error is reported trying to create a Physical Standby database using "duplicate f ...
- 源码安装nginx以及平滑升级
源码安装nginx以及平滑升级 ...
- 树形DP+二分(Information Disturbing HDU3586)
题意:给出一颗数,1结点代表司令部,叶子节点代表前线,边全值代表花费,然后需要在某些边放置一些炸弹,炸弹的能量不能小于该边的费用,且炸掉的总费用不能超过m问炸弹能力最小多少, 分析dfs+二分,二分枚 ...
- C++动态内存分配
C++动态内存分配1.堆内存分配 :C/C++定义了4个内存区间:代码区,全局变量与静态变量区,局部变量区即栈区,动态存储区,即堆(heap)区或自由存储区(free store). 堆的概念:通常定 ...
- XML节点名称中有小数点处理(deal with dot)导致使用xpath时报错解决方法
<?xml version="1.0"?> <ModifyFiles> <_Layout.cshtml>123456</_Layout.c ...
- [转]JAVA程序员一定知道的优秀第三方库(2016版)
原文地址:http://blog.csdn.net/zxc123e/article/details/51418163 几乎每个程序员都知道要“避免重复发明轮子”的道理——尽可能使用那些优秀的第三方框架 ...
- paper 72 :高动态范围(HDR)图像 HDR (High Dynamic Range)
In standard rendering, the red, green and blue values for a pixel are each represented by a fraction ...
- paper 47 :Latex中文显示(转)
中文支持需要cjk-latex,总得来说中文可以使用GB和GBK两种字体,GBK需要从windows下copy *.ttc或*.ttf, GB字体则在linux下就用. 先说支持GB的中文显示,安装以 ...
- Perl中的匹配(六)
在Perl中,匹配的定界符如果是双斜线//,可以直接使用双斜线完成匹配操作. 如果特定条件下需要改变定界符,如改为{},[]等.需要加入m,m{},m[]等. m%^http://% 默认的模式匹配对 ...
- 【sublime】解决汉字输入的办法——InputHelper;在sublime中输入汉字==》InputHelper方法
手工安装办法: cd ~/.config/sublime-text-2/Packages #如果是sublime3就改一下 git clone https://github.com/xgenvn/I ...