|
@@ -26,6 +26,7 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
private play_move:string[] = [];
|
|
|
private ai_move:string[] = [];
|
|
|
private legalActions:any[] = [];
|
|
|
+ private is_look_answer = false;
|
|
|
@property(Prefab) item_prefab:Prefab;
|
|
|
@property(Node) play_hand_cards_layer:Node;
|
|
|
@property(Node) play_out_cards_layer:Node;
|
|
@@ -40,6 +41,7 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
@property(Node) ai_out_ani:Node;
|
|
|
protected initUI(): void {
|
|
|
this.btn_chu_pai.on(Node.EventType.TOUCH_END,()=>{
|
|
|
+ gameManager.playBtnSound()
|
|
|
if(this.checkCardCanOut()){
|
|
|
this.hideBtns()
|
|
|
if(this.outCards()){
|
|
@@ -52,16 +54,20 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
}
|
|
|
})
|
|
|
this.btn_bu_chu.on(Node.EventType.TOUCH_END,()=>{
|
|
|
+ gameManager.playBtnSound()
|
|
|
this.play_move = []
|
|
|
this.play_out_cards_layer.removeAllChildren()
|
|
|
this.ai_out_cards_layer.removeAllChildren()
|
|
|
this.play_out_ani.getComponent(out_ani).showPass()
|
|
|
+ this.hideBtns()
|
|
|
this.Aithink()
|
|
|
})
|
|
|
this.btn_yao_bu_qi.on(Node.EventType.TOUCH_END,()=>{
|
|
|
+ gameManager.playBtnSound()
|
|
|
this.play_move = []
|
|
|
this.play_out_cards_layer.removeAllChildren()
|
|
|
this.ai_out_cards_layer.removeAllChildren()
|
|
|
+ this.hideBtns()
|
|
|
this.Aithink()
|
|
|
this.play_out_ani.getComponent(out_ani).showyaoBuQi()
|
|
|
this.backOut()
|
|
@@ -74,7 +80,7 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
this.btn_chu_pai.active = false;
|
|
|
this.btn_bu_chu.active = false;
|
|
|
this.btn_yao_bu_qi.active = false;
|
|
|
-
|
|
|
+ this.is_look_answer = false;
|
|
|
this.isShowWin = false;
|
|
|
this.touch_status = false;
|
|
|
this.is_start_move = false;
|
|
@@ -104,12 +110,14 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
this.play_out_cards_layer.removeAllChildren();
|
|
|
this.ai_hand_cards_layer.removeAllChildren();
|
|
|
this.ai_out_cards_layer.removeAllChildren();
|
|
|
- for (let index = 0; index < this.m_play_hand_cards.length; index++) {
|
|
|
+ for (let index = this.m_play_hand_cards.length-1; index >= 0; index--) {
|
|
|
const card = this.m_play_hand_cards[index];
|
|
|
let item:Node = instantiate(this.item_prefab)
|
|
|
item.parent = this.play_hand_cards_layer;
|
|
|
+ item.active = false;
|
|
|
item.getComponent(ddz_card).initView(card,this.getCardType(card),index)
|
|
|
}
|
|
|
+ this.start_play_hand_card_action()
|
|
|
this.play_hand_cards_layer.off(Node.EventType.TOUCH_START)
|
|
|
this.play_hand_cards_layer.on(Node.EventType.TOUCH_START,(event:EventTouch)=>{
|
|
|
this.touch_pos = event.getUILocation()
|
|
@@ -121,20 +129,47 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
this.play_hand_cards_layer.on(Node.EventType.TOUCH_MOVE,this.handCardTouchBegin.bind(this),this)
|
|
|
this.play_hand_cards_layer.on(Node.EventType.TOUCH_END,this.handCardTouchEnd.bind(this),this)
|
|
|
this.play_hand_cards_layer.on(Node.EventType.TOUCH_CANCEL,this.handCardTouchEnd.bind(this),this)
|
|
|
- for (let index = 0; index < this.m_computer_hand_cards.length; index++) {
|
|
|
+ for (let index = this.m_computer_hand_cards.length-1; index >=0; index--) {
|
|
|
const card = this.m_computer_hand_cards[index];
|
|
|
let item:Node = instantiate(this.item_prefab)
|
|
|
item.parent = this.ai_hand_cards_layer;
|
|
|
+ item.active = false;
|
|
|
item.getComponent(ddz_card).initView(card,this.getCardType(card),index)
|
|
|
}
|
|
|
-
|
|
|
+ this.start_ai_hand_card_action()
|
|
|
this.showChuPaiStatus()
|
|
|
this.predict();
|
|
|
+ gameManager.loadPlayMusicByCategoryId(this.categoryid,()=>{
|
|
|
+ gameManager.playGamePlayMusicByCategoryId(this.categoryid,true);
|
|
|
+ })
|
|
|
+ }
|
|
|
+ start_play_hand_card_action(){
|
|
|
+ this.scheduleOnce(()=>{
|
|
|
+ for (let index = 0; index < this.play_hand_cards_layer.children.length; index++) {
|
|
|
+ const item = this.play_hand_cards_layer.children[index];
|
|
|
+ let time = index*50
|
|
|
+ setTimeout(() => {
|
|
|
+ item.active = true;
|
|
|
+ }, time);
|
|
|
+ }
|
|
|
+ },0.2)
|
|
|
+ }
|
|
|
+ start_ai_hand_card_action(){
|
|
|
+ this.scheduleOnce(()=>{
|
|
|
+ for (let index = 0; index < this.ai_hand_cards_layer.children.length; index++) {
|
|
|
+ const item = this.ai_hand_cards_layer.children[index];
|
|
|
+ let time = index*50
|
|
|
+ setTimeout(() => {
|
|
|
+ item.active = true;
|
|
|
+ }, time);
|
|
|
+ }
|
|
|
+ },0.2)
|
|
|
+
|
|
|
}
|
|
|
predict(call_back=null){
|
|
|
this.legalActions = []
|
|
|
this.legalActions = ddz_ai.instance._get_legal_card_play_actions(this.m_play_hand_cards,this.ai_move);
|
|
|
- console.log("this.legalActions",this.legalActions)
|
|
|
+ // console.log("this.legalActions",this.legalActions)
|
|
|
if(call_back!=null){
|
|
|
call_back()
|
|
|
}
|
|
@@ -152,17 +187,25 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
if(tools.isEqualArray(this.play_move,actions)){
|
|
|
return true;
|
|
|
}
|
|
|
- for (let i = 0; i < actions.length; i++) {
|
|
|
- let cards:any = actions[i];
|
|
|
- if(!Array.isArray(cards)){
|
|
|
- cards = [cards]
|
|
|
- }
|
|
|
- if(tools.isEqualArray(this.play_move,cards)){
|
|
|
+ if(!Array.isArray(actions[0])){
|
|
|
+ if(tools.isEqualArray(this.play_move,actions)){
|
|
|
isCanOut = true;
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+ }else{
|
|
|
+ for (let i = 0; i < actions.length; i++) {
|
|
|
+ let cards:any = actions[i];
|
|
|
+ if(!Array.isArray(cards)){
|
|
|
+ cards = [cards]
|
|
|
+ }
|
|
|
+ if(tools.isEqualArray(this.play_move,cards)){
|
|
|
+ isCanOut = true;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
return isCanOut;
|
|
@@ -192,7 +235,6 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
outCards(){
|
|
|
let list = [];
|
|
|
let ai_continue = true;
|
|
|
- console.log("outCards")
|
|
|
for (let index = 0; index < this.play_hand_cards_layer.children.length; index++) {
|
|
|
const element = this.play_hand_cards_layer.children[index];
|
|
|
if(element.getComponent(ddz_card).IsOutCard()){
|
|
@@ -200,6 +242,7 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
}
|
|
|
}
|
|
|
if(list.length>0){
|
|
|
+ this.ai_out_cards_layer.removeAllChildren()
|
|
|
this.play_out_cards_layer.removeAllChildren()
|
|
|
for (let index = 0; index < list.length; index++) {
|
|
|
const element:Node = list[index];
|
|
@@ -209,7 +252,6 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
item.parent = this.play_out_cards_layer;
|
|
|
item.getComponent(ddz_card).initView(card,type,index)
|
|
|
element.removeFromParent()
|
|
|
- console.log("outCards",card)
|
|
|
}
|
|
|
this.updatePlayHandCards()
|
|
|
list=[]
|
|
@@ -226,17 +268,23 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
}
|
|
|
updateAiHandCards(){
|
|
|
this.m_computer_hand_cards = []
|
|
|
+ let temp = []
|
|
|
for (let index = 0; index < this.ai_hand_cards_layer.children.length; index++) {
|
|
|
const element = this.ai_hand_cards_layer.children[index];
|
|
|
- this.m_computer_hand_cards.push(element.getComponent(ddz_card).getCard())
|
|
|
+ temp.push(element.getComponent(ddz_card).getCard())
|
|
|
}
|
|
|
+ temp.sort((a,b)=>{return parseInt(a)-parseInt(b)})
|
|
|
+ this.m_computer_hand_cards = temp;
|
|
|
}
|
|
|
updatePlayHandCards(){
|
|
|
this.m_play_hand_cards = []
|
|
|
+ let temp = []
|
|
|
for (let index = 0; index < this.play_hand_cards_layer.children.length; index++) {
|
|
|
const element = this.play_hand_cards_layer.children[index];
|
|
|
- this.m_play_hand_cards.push(element.getComponent(ddz_card).getCard())
|
|
|
+ temp.push(element.getComponent(ddz_card).getCard())
|
|
|
}
|
|
|
+ temp.sort((a,b)=>{return parseInt(a)-parseInt(b)})
|
|
|
+ this.m_play_hand_cards = temp;
|
|
|
}
|
|
|
|
|
|
onEventTouch(event:EventTouch){
|
|
@@ -272,14 +320,14 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
let width = element.getComponent(UITransform).contentSize.width
|
|
|
if(isLeft){
|
|
|
let offset = this.touch_pos.y - this.first_left_pos.y;
|
|
|
- if((this.first_left_pos.y+offset)<=start_pos.y&&start_pos.y<=this.first_left_pos.y){
|
|
|
+ if((this.first_left_pos.y+offset-width/2)<=start_pos.y&&start_pos.y<=this.first_left_pos.y){
|
|
|
element.getComponent(ddz_card).onSelect()
|
|
|
}else{
|
|
|
element.getComponent(ddz_card).unSelect()
|
|
|
}
|
|
|
}else{
|
|
|
let offset = this.touch_pos.y - this.first_right_pos.y;
|
|
|
- if((this.first_right_pos.y+offset-width/2)>=start_pos.y&&start_pos.y+width>=this.first_right_pos.y){
|
|
|
+ if((this.first_right_pos.y+offset+width/2)>=start_pos.y&&start_pos.y+width>=this.first_right_pos.y){
|
|
|
element.getComponent(ddz_card).onSelect()
|
|
|
}else{
|
|
|
element.getComponent(ddz_card).unSelect()
|
|
@@ -307,7 +355,7 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
}
|
|
|
}
|
|
|
tempArray = tempArray.sort((a, b) => {
|
|
|
- return b.getIndex() - a.getIndex();
|
|
|
+ return a.getIndex()-b.getIndex();
|
|
|
});
|
|
|
return tempArray.length<=0?null:tempArray[0];
|
|
|
}
|
|
@@ -387,6 +435,7 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
});
|
|
|
}else{
|
|
|
let str_act:any = actions
|
|
|
+ this.play_out_cards_layer.removeAllChildren()
|
|
|
console.log("str_act==",str_act)
|
|
|
if(!Array.isArray(str_act)){
|
|
|
str_act = [str_act]
|
|
@@ -528,7 +577,26 @@ export class game_play_dou_di_zhu extends base_view {
|
|
|
}
|
|
|
|
|
|
protected onTipBtnClick(): void {
|
|
|
- this.tip_layer.active = true;
|
|
|
+ if(gameManager.isTestUser()){
|
|
|
+ this.tip_layer.active = true;
|
|
|
+ }else{
|
|
|
+ if(!this.is_look_answer){
|
|
|
+ SdkUtil.showVideoAd(config.rewardVideoAdUnitId.Resume_AdUnitId,(res)=>{
|
|
|
+ if(res.isEnded){
|
|
|
+ this.is_look_answer = true;
|
|
|
+ this.tip_layer.active = true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ this.tip_layer.active = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected onFailQuitClick(fail_view: fail): void {
|
|
|
+ fail_view.close()
|
|
|
+ this.close()
|
|
|
}
|
|
|
}
|
|
|
|