renjiCreate.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { _decorator, Component, Node, Label, Button, Slider, EventTouch, NodeEventType, Sprite, Color } from 'cc';
  2. import ChessRBSel from '../Game/ChessGame/ChessRBSel';
  3. import ChessMng, { ChessType } from '../Game/DiffSel/ChessMng';
  4. import UIDiffSel from '../Game/DiffSel/UIDiffSel';
  5. import ScenceMng from '../gcommon/ScenceMng';
  6. import { UIButton } from '../gcommon/UIButton';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('renjiCreate')
  9. export class renjiCreate extends Component {
  10. @property(Label)
  11. nandu_lab: Label = null; //难度
  12. @property(Label)
  13. guoguanlv_lab: Label = null; // 通关率
  14. @property(Label)
  15. nandu_lv_lab: Label = null; // 难度等级
  16. @property(Node)
  17. btn_hongse: Node = null; //让电脑红色方
  18. @property(Node)
  19. btn_heise: Node = null; // 让电脑黑色放
  20. @property(Slider)
  21. nandu_sd: Slider = null; //
  22. selectSlider:number = 0
  23. old_selectSlider:number = 0
  24. select_index:number = 0;
  25. index:number = 0
  26. color:Color = new Color()
  27. public static lvArr=['小白','普通','中等','困难','大師'];
  28. public static ndArr=['55.6%','31.5%','35.9','40.69%','14.14%'];
  29. start() {
  30. var self = this;
  31. UIButton.BindClick(this.btn_hongse,()=>{
  32. if(ChessRBSel.selIndex!=1){
  33. self.color = self.color.fromHEX("#E70000")
  34. self.btn_hongse.getComponent(Sprite).color = self.color
  35. self.color = self.color.fromHEX("#EDE4D5")
  36. self.btn_heise.getComponent(Sprite).color = self.color
  37. self.color = self.color.fromHEX("#000000")
  38. self.btn_heise.getChildByName("Label").getComponent(Label).color = self.color
  39. self.color = self.color.fromHEX("#FFFFFF")
  40. self.btn_hongse.getChildByName("Label").getComponent(Label).color = self.color
  41. var index = self.btn_hongse.getSiblingIndex()
  42. self.btn_hongse.setSiblingIndex(self.btn_heise.getSiblingIndex())
  43. self.btn_heise.setSiblingIndex(index)
  44. ChessRBSel.selIndex = 1;
  45. }
  46. },this);
  47. UIButton.BindClick(this.btn_heise,()=>{
  48. if(ChessRBSel.selIndex!=0){
  49. self.color = self.color.fromHEX("#EDE4D5")
  50. self.btn_hongse.getComponent(Sprite).color = self.color
  51. self.color = self.color.fromHEX("#4D4C4A")
  52. self.btn_heise.getComponent(Sprite).color = self.color
  53. self.color = self.color.fromHEX("#000000")
  54. self.btn_hongse.getChildByName("Label").getComponent(Label).color = self.color
  55. self.color = self.color.fromHEX("#FFFFFF")
  56. self.btn_heise.getChildByName("Label").getComponent(Label).color = self.color
  57. var index = self.btn_hongse.getSiblingIndex()
  58. self.btn_hongse.setSiblingIndex(self.btn_heise.getSiblingIndex())
  59. self.btn_heise.setSiblingIndex(index)
  60. ChessRBSel.selIndex = 0;
  61. }
  62. },this);
  63. this.updateInfo();
  64. ChessRBSel.selIndex = 0; //默认自己是红色方
  65. }
  66. update(deltaTime: number) {
  67. if(this.selectSlider == this.old_selectSlider){
  68. return;
  69. }
  70. this.old_selectSlider = this.selectSlider;
  71. this.updateInfo();
  72. }
  73. onSlider(event){
  74. this.selectSlider = event._progress;
  75. // console.log("onSlider",event._progress)
  76. }
  77. updateInfo(){
  78. var index = 0
  79. if(this.old_selectSlider<0.2) {
  80. index =0;
  81. this.select_index = 0.2
  82. } else if(this.old_selectSlider>0.2&&this.old_selectSlider<0.4){
  83. index = 1;
  84. this.select_index = 0.4
  85. }else if(this.old_selectSlider>0.4&&this.old_selectSlider<0.6){
  86. index = 2;
  87. this.select_index = 0.6
  88. }else if(this.old_selectSlider>0.6&&this.old_selectSlider<0.8){
  89. index = 3;
  90. this.select_index = 0.8
  91. }else if(this.old_selectSlider>0.8){
  92. index = 4;
  93. this.select_index = 1
  94. }
  95. this.index = index;
  96. this.nandu_lab.string = renjiCreate.lvArr[index];
  97. this.guoguanlv_lab.string = renjiCreate.ndArr[index];
  98. this.nandu_lv_lab.string = index.toString();
  99. }
  100. onCreateRenji(){
  101. UIDiffSel.selectIndex=this.index;
  102. ChessMng.Instance.chesstype=ChessType.renjiboyi;
  103. console.log("UIButton onclick")
  104. ScenceMng.Instance.load('Chess')
  105. }
  106. }