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 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的 ...
随机推荐
- Android Push Notification实现信息推送使用
本贴在http://www.cnblogs.com/hanyonglu/archive/2012/03/16/2399655.html下略为改动. Apndroid Push Notification ...
- 比较Date时间先后
if ([firstDetailSelect compare:secondDetailSelect] == NSOrderedDescending) { [MBProgressHUD showErro ...
- PostgreSQL wiki
https://wiki.postgresql.org/wiki/Main_Page https://wiki.postgresql.org/wiki/Converting_from_other_Da ...
- 为benchmarksql的PostgreSQL java驱动进行升级
为benchmarksql的PostgreSQL java驱动进行升级[root@minion1 benchmarksql-4.1.0]# wget https://jdbc.postgresql.o ...
- Centos7 安装 Nginx
Nginx有很多版本的,下面我给个链接http://nginx.org/packages/mainline/centos/7/x86_64/RPMS/ 下载对应当前系统版本的nginx包(packag ...
- 变形--缩放 scale()
缩放 scale()函数 让元素根据中心原点对对象进行缩放. 缩放 scale 具有三种情况: 1. scale(X,Y)使元素水平方向和垂直方向同时缩放(也就是X轴和Y轴同时缩放) 例如: div: ...
- paper 19 :机器学习算法(简介)
本来看了一天的分类器方面的代码,乱乱的,索性再把最基础的概念拿过来,现总结一下机器学习的算法吧! 1.机器学习算法简述 按照不同的分类标准,可以把机器学习的算法做不同的分类. 1.1 从机器学习问题角 ...
- paper 7:支持向量机系列四:Outliers —— 介绍支持向量机使用松弛变量处理 outliers 方法。
在最开始讨论支持向量机的时候,我们就假定,数据是线性可分的,亦即我们可以找到一个可行的超平面将数据完全分开.后来为了处理非线性数据,使用 Kernel 方法对原来的线性 SVM 进行了推广,使得非线性 ...
- LDA-math-文本建模
http://cos.name/2013/03/lda-math-text-modeling/ 4. 文本建模 我们日常生活中总是产生大量的文本,如果每一个文本存储为一篇文档,那每篇文档从人的观察来说 ...
- [Ubuntu] Install teamviewer9 on Ubuntu14.04_x64
The article copied from http://ubuntuhandbook.org/index.php/2013/12/install-teamviewer-ubuntu-1404/ ...