zoukankan      html  css  js  c++  java
  • 和电脑玩石头剪刀布

    #import <Foundation/Foundation.h>

    #import "Judge.h"

    int main(int argc, const char * argv[]) {

        @autoreleasepool {

            

            Judge * ju=[Judge new];

            [ju caijue];

        }

        return 0;

    }

    #import <Foundation/Foundation.h>

    @interface Person : NSObject

    @property(assign,nonatomic)  int ren;

    /**

     *  带返回值的声明

     *

     *  @return 字符串(剪刀,石头,布)

     */

    -(NSString*)personuse;

    @end

    @implementation Person

    /**

     *  实现

     *

     *  @return NSstring类型

     */

    -(NSString*)personuse

    {

        NSString *st=[[NSString alloc]init];

        switch (self.ren) {

            case 1:

                st=[NSString stringWithFormat:@"石头"];

                break;

            case 2:

                st=[NSString stringWithFormat:@"剪刀"];

                break;

            case 3:

                st=[NSString stringWithFormat:@"布"];

                break;

            default:

                

                break;

        }

        return st;

    }

    @end

    #import <Foundation/Foundation.h>

    @interface Comepute : NSObject

    @property(assign,nonatomic) int ji;  //同人

    -(NSString*)jisuse;//同人

    @end

    #import "Comepute.h"

    @implementation Comepute

    //同人

    -(NSString *)jisuse

    {

        NSString *st=[[NSString alloc]init];

        switch (self.ji) {

            case 1:

                st=[NSString stringWithFormat:@"石头"];

                break;

            case 2:

                st=[NSString stringWithFormat:@"剪刀"];

                break;

            case 3:

                st=[NSString stringWithFormat:@"布"];

                break;

                

            default:

                break;

        }

        

        return st;

    }

    @end

    #import <Foundation/Foundation.h>

    #import "Comepute.h"

    #import "Person.h"

    #import "Methods.h"

    @interface Judge : Methods

    -(void)caijue;

    @end

    #import "Judge.h"

    @implementation Judge

    -(void)caijue

    {

        int a=1 ,i;

        while (a==1||a==2||a==3) {

            NSLog(@"请输入猜拳的方式:1--石头 2--剪刀 3--布");

            scanf("%d",&a);

            if (a==1||a==2||a==3) {

                Person *per=[[Person alloc]init];

                per.ren=a;

                NSLog(@"人出的是:%@",[per personuse]);

                Comepute *com=[Comepute new];

                com.ji=arc4random()%3+1;

                NSLog(@"计算机出的是:%@",[com jisuse]);

                [super personwithperson:per.ren andcomeputerwithcomputer:com.ji];

                i++;

                

            }

            else{

                NSLog(@"输入错误,游戏结束");

            }

        }

        

        NSLog(@"猜拳的次数是:%d 人胜利的次数是:%d 计算机胜利的次数是:%d 平局的次数:%d",i,super.rensheng,super.jisuansheng,i-(super.rensheng+super.jisuansheng));

    }

    @end

    #import <Foundation/Foundation.h>

    #import "Person.h"

    #import "Comepute.h"

    @interface Methods : NSObject

    @property(assign,nonatomic) int rensheng;

    @property(assign,nonatomic) int jisuansheng;

    -(void)personwithperson:(int) a  andcomeputerwithcomputer:(int) b;

    @end

    #import "Methods.h"

    @implementation Methods

    -(void)personwithperson:(int)a andcomeputerwithcomputer:(int)b

    {

        if ((a==1&&b==3)||(a==2&&b==1)||(a==3&&b==2)) {

            NSLog(@"计算机胜利");

            self.jisuansheng++;

        } else  if ((a==1&&b==2)||(a==2&&b==3)||(a==3&&b==1)) {

            NSLog(@"人胜利");

            self.rensheng++;

        } else{

            NSLog(@"平局");

        }

    }

    @end

  • 相关阅读:
    freenas的踩坑记录:群晖CIFS挂载freeNas的smb共享目录
    【ikuai】爱快软路由上手
    Nacos集成Spring Cloud Gateway使用第三章:nacos配置中心
    Nacos集成Spring Cloud Gateway使用第二章:上手demo
    Nacos集成Spring Cloud Gateway使用第一章:理解解释
    函数指针数组
    回调函数
    使用C语言实现strcpy函数和字符串大小写交换
    Qt : Setting应用程序的数据保存和读取
    Qt 文件操作以及字体颜色选择
  • 原文地址:https://www.cnblogs.com/fume/p/5243566.html
Copyright © 2011-2022 走看看