【猜拳游戏 基于Objective-C语言】

前言

这是一个猜拳游戏,玩家选择想要出的拳头:1 剪刀 2 石头 3 布,
机器人随机出拳头,
裁判宣布比赛结果,并为胜利者加1分。

一、玩家类Player.h和Player.m两个文件

Player.h文件:

#import <Foundation/Foundation.h>
#import “FistType.h”
NS_ASSUME_NONNULL_BEGIN

@interface Player : NSObject
@property NSString *name;
@property FistType fistType;
@property int score;

  • (void)showFist;
  • (NSString *)fistTypeWithNumber:(int)number;
    @end

NS_ASSUME_NONNULL_END

Player.m文件:

#import “Player.h”

@implementation Player

  • (void)showFist
    {
    NSLog(@“亲爱的玩家【%@】,请输入你要出的拳头,1 剪刀 2 石头 3 布:”,self.name);
    int userSelected = 0;
    rewind(stdin);
    scanf(“%d”,&userSelected);
    NSString *fistType = [self fistTypeWithNumber:userSel

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
很抱歉,根据提供的引用内容,没有找到关于C语言实现猜拳游戏的具体示例代码或详细介绍。但是,我可以为您提供一个简单的C语言猜拳游戏的示例代码,供您参考: ```c #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int playerChoice, computerChoice; int playerScore = 0, computerScore = 0; int round = 1; srand(time(0)); // 设置随机数种子 printf("欢迎来到猜拳游戏!\n"); while (round <= 3) { printf("\n第 %d 轮\n", round); printf("请选择:\n"); printf("1. 石头\n"); printf("2. 剪刀\n"); printf("3. 布\n"); printf("请输入您的选择(1-3):"); scanf("%d", &playerChoice); if (playerChoice < 1 || playerChoice > 3) { printf("无效的选择,请重新选择!\n"); continue; } computerChoice = rand() % 3 + 1; printf("您选择了:"); switch (playerChoice) { case 1: printf("石头\n"); break; case 2: printf("剪刀\n"); break; case 3: printf("布\n"); break; } printf("电脑选择了:"); switch (computerChoice) { case 1: printf("石头\n"); break; case 2: printf("剪刀\n"); break; case 3: printf("布\n"); break; } if (playerChoice == computerChoice) { printf("本轮平局!\n"); } else if ((playerChoice == 1 && computerChoice == 2) || (playerChoice == 2 && computerChoice == 3) || (playerChoice == 3 && computerChoice == 1)) { printf("您赢了本轮!\n"); playerScore++; } else { printf("电脑赢了本轮!\n"); computerScore++; } round++; } printf("\n游戏结束!\n"); printf("您的得分:%d\n", playerScore); printf("电脑的得分:%d\n", computerScore); if (playerScore > computerScore) { printf("恭喜您获胜!\n"); } else if (playerScore < computerScore) { printf("很遗憾,电脑获胜!\n"); } else { printf("本局平局!\n"); } return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清风清晨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值