‘老虎,鸡 虫子 棒子 ‘

import { promptAction } from '@kit.ArkUI';


@Entry
@Component
struct HjcbPage {
  @State message: string = '老虎,鸡 虫子 棒子 ';
  @State userCz: string = '' //用户出招
  @State comCz: string = '' //电脑
  @State res: string = '' //结果
  @State uY: number = 0 //用户赢多少次
  @State cY: number = 0 //电脑赢多少次
  @State pY: number = 0 //平局多少次
  @State isj: boolean = false //选中状态
  @State iss: boolean = false //选中状态
  @State isb: boolean = false //选中状态
  @State isz: boolean = false //选中状态

  build() {
    Column() {
      Text(this.message).fontSize(30).fontColor(Color.Red)
      Row() {
        Radio({ value: '老虎', group: 'gm' })
          .onChange((isChecked: boolean) => {
            promptAction.showToast({ message: `选中状态:${isChecked}` })
            this.userCz = '老虎'
            this.isj = isChecked

          })
          .checked(this.isj)

        Text('老虎').fontSize(30)
        Radio({ value: '鸡', group: 'gm' })
          .onChange((isChecked: boolean) => {
            promptAction.showToast({ message: `选中状态:${isChecked}` })
            this.userCz = '鸡'
            this.iss = isChecked


          })
          .checked(this.iss)

        Text('鸡').fontSize(30)
        Radio({ value: '虫子', group: 'gm' })
          .onChange((isChecked: boolean) => {
            promptAction.showToast({ message: `选中状态:${isChecked}` })
            this.userCz = '虫子'
            this.isb = isChecked

          })
          .checked(this.isb)

        Text('虫子').fontSize(30)
        Radio({ value: '棒子', group: 'gm' })
          .onChange((isChecked: boolean) => {
            promptAction.showToast({ message: `选中状态:${isChecked}` })
            this.userCz = '棒子'
            this.isz = isChecked

          })
          .checked(this.isz)

        Text('棒子').fontSize(30)


      }
      .justifyContent(FlexAlign.SpaceAround)
      .height(90)

      Text(`电脑:${this.comCz}`).width('100%').backgroundColor(Color.Blue).fontSize(30)

      Text(`胜利者${this.res}`).fontSize(30).fontColor('red')
      Row() {
        Button('重新开始')
          .onClick(() => {
            //清零
            this.userCz = ''
            this.comCz = ''
            this.res = ''
            this.uY = 0
            this.cY = 0
            this.pY = 0
            //初始化选项
            this.isj = false
            this.iss = false
            this.isb = false
            this.isz= false
          })
        Button('电脑出招')
          .onClick(() => {
            if (this.userCz !== '') {
              let num: number = parseInt(`${Math.random() * 4}`)
              switch (num) {
                case 0:
                  this.comCz = '老虎'
                  break
                case 1:
                  this.comCz = '鸡'
                  break
                case 3:
                  this.comCz = '虫子'
                  break
                case 4:
                  this.comCz = '棒子'
                  break
              }

              //1,电脑赢

              if (
                (this.comCz == '老虎' && this.userCz == '鸡') ||
                  (this.comCz == '鸡' && this.userCz == '虫子') ||
                  (this.comCz == '虫子' && this.userCz == '棒子')||
                  (this.comCz == '棒子' && this.userCz == '老虎')
              ) {
                this.res = '电脑'
                this.cY++
              } else if (
                (this.comCz == '棒子' && this.userCz == '虫子') ||
                  (this.comCz == '鸡' && this.userCz == '老虎') ||
                  (this.comCz == '虫子' && this.userCz == '鸡')||
                  (this.comCz == '老虎' && this.userCz == '棒子')
              ) {
                //2,用户赢
                this.res = '用户'
                this.uY++

              } else {
                //3  平
                this.res = '不吃'
                this.pY++

              }

            }else {
              promptAction.showToast({ message: '请用户先出招' })
            }
          })
      }
      .width('80%').justifyContent(FlexAlign.SpaceAround)
      Text(`赢:${this.uY}`).fontSize(30).backgroundColor('red')
      Text(`败:${this.cY}`).fontSize(30).backgroundColor('red')
      Text(`没人吃:${this.pY}`).fontSize(30).backgroundColor('red')
      Text(`总:${this.uY + this.cY + this.pY}`).fontSize(30).backgroundColor('red')
      Text(`胜率:${this.uY}/${this.uY + this.cY + this.pY}`).fontSize(30).backgroundColor('red')

    }
    .height('100%')
    .width('100%')
  }
}
  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值