和電腦玩石頭剪刀布

來源:互聯網
上載者:User

標籤:

 

 

#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

 

和電腦玩石頭剪刀布

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.