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 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的 ...
随机推荐
- TNS-01201: Listener cannot find executablen
有哥们说,他的数据库监听无法启动,报如下错误: 让其查看一下环境变量是否设置,说设置没问题,但是还是报同样的错误.只好让其截图了: 1.监听文件 2.profile文件 从上面的截图中,可以看出,pr ...
- js 多选题选项内容显示在标题下
<body><div class="page-container"> <div class="view-container"> ...
- 在自定义的UINavigationController中设置背景图片
//这个方法中设置 + (void)initialize { UINavigationBar *bar = [UINavigationBar appearance]; [bar setBackgrou ...
- tableview隐藏多余分割线
- (void)setExtraCellLineHidden: (UITableView *)tableView{ UIView *view =[ [UIView alloc]init]; view. ...
- Leetcode: Longest Absolute File Path
Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...
- SLF4J环境变量配置
因部分程序需要,需要把SLF4J加入到环境变量中. 添加位置:CLASSPATH 添加信息如下: C:\slf4j-1.7.19\slf4j-nop-1.7.19.jar;
- 转:python webdriver API 之cookie 处理
有时候我们需要验证浏览器中是否存在某个 cookie,因为基于真实的 cookie 的测试是无法通过白盒和集成测试完成的.webdriver 可以读取.添加和删除 cookie 信息.webdrive ...
- Python学习总结2:raw_input() 与 input()
参考http://www.cnblogs.com/way_testlife/archive/2011/03/29/1999283.html 1. 输入数据要求 raw_input() 直接读取控制台的 ...
- 使用Eclipse构建Maven项目 (转)
Maven这个个项目管理和构建自动化工具,越来越多的开发人员使用它来管理项目中的jar包.本文仅对Eclipse中如何安装.配置和使用Maven进行了介绍.完全step by step. 如果觉得本文 ...
- mysql linux 备份脚本
#!/bin/sh # mysql data backup script # # use mysqldump --help,get more detail. # BakDir=/root/back/m ...