猜拳扩展练习,三局两胜

int count1 = 0, count2 = 0;//设定赢的次数,输的次数

for (; ; )

{

//1、提示用户出拳

Console.Write("请出拳(石头0,剪子1,布2):");

int yh = int.Parse(Console.ReadLine());

//2、电脑随机生成

Random r = new Random();

int dn = r.Next(0, 3);

//3、判断输赢

//  用户赢:0-1=-1 1-2=-1 2-0=2

//用户输了:0-2=-2 1-0=1  2-1=1

//平局     0

int jg = yh-dn;

if (yh < 0 || yh > 2)

{

Console.WriteLine("输入有误!");

}

else

{

if (jg == -1 || jg == 2)

{

Console.WriteLine("您赢了!");

count1++;

if (count1 == 2)

{

Console.WriteLine("您最终赢了!"); break;//赢两次结果,跳出循环

}

}

else if (jg == -2 || jg == 1)

{

Console.WriteLine("您输了!");

count2++;

if (count2 == 2)

{

Console.WriteLine("您最终输了!"); break;

}

}

else if (jg == 0)

{

Console.WriteLine("平局!");

}

}

}

Console.ReadLine();

时间: 2024-10-05 21:50:53

猜拳扩展练习,三局两胜的相关文章

猜拳游戏(三局两胜)

//猜拳,剪刀0-1,石头-1, 布-2 int renying = 0; int dnying = 0; for (int i = 1; i <= 3; i++) { Random r = new Random(); int diannao = r.Next(3); Console.Write("请出拳;剪刀0-1,石头-1, 布-2 :"); int ren = int.Parse(Console.ReadLine()); Console.WriteLine("电脑

猜拳游戏三局两胜------java实现代码

package com.javasm.exerices02; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.Scanner; /** * *TODO 石头剪刀布猜拳游戏,三局两胜 * @author caolei 2018年5月2日下午10:51:23 * RockPaperScissors */ public class RockPaperScissors

猜拳(三局两胜)

int renying = 0; int dnying = 0; for (int i = 1; i <= 3; i++) { Random r = new Random();//生成随机数 int diannao = r.Next(3);//生成0-3之间,不包括3的数 Console.Write("请出拳:剪刀-0 石头-1 布-2 :"); int ren = int.Parse(Console.ReadLine());//控制台录入字符串,转换为int类型 Console

猜拳 三局两胜

int ry = 0;//记录人赢的次数 int ny = 0;//记录电脑赢的次数 for (int i = 0; i < 3; i++)//三局两胜 { Random r = new Random(); int ncq = r.Next(3); Console.WriteLine("请输入0,1,2分别代表”剪刀“,”包袱“,”锤“"); int rcq = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(ncq)

猜拳三局两胜

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int rcount = 0; int dncount = 0; for (int i = 0; i <

09.22函数,三局两胜

//猜拳,三局两胜无返回值 //public void caiquan() //{ // int count = 0; // for (int k = 1; k <=3; k++) // {Console.Write("a="); // int i = int.Parse(Console.ReadLine()); // Console.Write("b="); // int j = int.Parse(Console.ReadLine()); // if (i

python 实现剪刀石头布(三局两胜)

1 # -*- coding:utf-8 -*- 2 import random 3 4 # best of three 5 def finger_guess(): 6 rule = {1:'rock', 2:'paper', 3:'scissor'} 7 win_way = [['rock', 'scissor'], ['paper', 'rock'], ['scissor', 'paper']] 8 num_list = [1, 2, 3] 9 count = 0 10 person_sco

剪刀石头布(三局两胜)

(1)通过最简单的选择和循环实现(但代码过长) import random computer_win_count = 0people_win_count = 0 while True:    computer = random.randint(0,2)    people = int(input("请做出选择(0:石头 1:剪刀 2:布):"))    if computer == people == 0:        print("电脑:石头   玩家:石头   结果:平

Python,while循环小例子--猜拳游戏(三局二胜)

1 import random 2 3 all_choice = ['石头', '剪刀', '布'] 4 5 prompt = '''(0)石头 6 (1)剪刀 7 (2)布 8 请选择(0\1\2)''' 9 # 人的计分板 10 pwin = 0 11 # 计算机的计分板 12 cwin = 0 13 # 人和计算机都没有赢够两次则继续 14 while pwin < 2 and cwin < 2: 15 # 人的选择在前,计算机随机选择在后,组成小列表,把所有人赢的情况再放到大列表中 1