#include "Card_Layer.h"
#include "Hero.h"
#include "Page0.h"
using namespace cocos2d;
bool Card_Layer::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
_hero=Hero::getHero();
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCSprite*ybg=CCSprite::create("UI/ybg.png");
ybg->setAnchorPoint(ccp(0.5,0.5));
ybg->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
this->addChild(ybg);
CCSprite*cardsp=CCSprite::create("layer/card_splayer.png");
cardsp->setPosition(ccp(visibleSize.width/2,visibleSize.height/2+10));
this->addChild(cardsp);
CCMenuItemImage *buy = CCMenuItemImage::create(
"anniu/buy.png",
"anniu/buy1.png",
this,
menu_selector(Card_Layer::BuyCallBack));
buy->setPosition(ccp(200,30));
CCMenuItemImage *sale = CCMenuItemImage::create(
"anniu/sale.png",
"anniu/sale1.png",
this,
menu_selector(Card_Layer::SaleCallBack));
sale->setPosition(ccp(600,30));
//退出
CCMenuItemImage *exit = CCMenuItemImage::create(
"anniu/card_back.png",
"anniu/card_back1.png",
this,
menu_selector(Card_Layer::CallBack));
exit->setPosition(ccp(700,460));
//点数-----------------------------------测试---------------------------------------------------
char *string = new char();
sprintf(string, "%d",_hero->dianshu);
dianshu = CCLabelTTF::create(string, "HanWangShinSuMedium", 24);
dianshu->setPosition(ccp(400, 30));
dianshu->setColor(ccc3(241,124,9));
this->addChild(dianshu);
//描述
CCDictionary *strings = CCDictionary::createWithContentsOfFile("ch.xml");
const char *charchinese = ((CCString*)strings->objectForKey("introduction1"))->m_sString.c_str();
font = CCLabelTTF::create(charchinese, "
", 30);
font->setPosition(ccp(550,280));
font->setColor(ccc3(235,139,26));
this->addChild(font);
//对应卡牌购买点数====================
const char *dianshu_sp = ((CCString*)strings->objectForKey("dianshu_sp"))->m_sString.c_str();
CCLabelTTF *font_dianshu = CCLabelTTF::create(dianshu_sp, "HanWangShinSuMedium", 24);
font_dianshu->setPosition(ccp(350,200));
this->addChild(font_dianshu);
//卡牌点数
card_dianshu = CCLabelTTF::create("50", "HanWangShinSuMedium", 24);
card_dianshu->setPosition(ccp(420, 200));
card_dianshu->setColor(ccc3(241,124,9));
this->addChild(card_dianshu);
//=======================
//添加卡牌
//为了方便 决定全部添加卡牌
card1 = CCMenuItemImage::create(
"card/card_1.png",
"card/1.png",
this,
menu_selector(Card_Layer::ChooseBack1));
card1->setPosition(ccp(140,360));
card2 = CCMenuItemImage::create(
"card/card_2.png",
"card/2.png",
this,
menu_selector(Card_Layer::ChooseBack2));
card2->setPosition(ccp(190,360));
card3 = CCMenuItemImage::create(
"card/card_3.png",
"card/3.png",
this,
menu_selector(Card_Layer::ChooseBack3));
card3->setPosition(ccp(240,360));
card4 = CCMenuItemImage::create(
"card/card_4.png",
"card/4.png",
this,
menu_selector(Card_Layer::ChooseBack4));
card4->setPosition(ccp(290,360));
card5 = CCMenuItemImage::create(
"card/card_5.png",
"card/5.png",
this,
menu_selector(Card_Layer::ChooseBack5));
card5->setPosition(ccp(340,360));
card6 = CCMenuItemImage::create(
"card/card_6.png",
"card/6.png",
this,
menu_selector(Card_Layer::ChooseBack6));
card6->setPosition(ccp(390,360));
card7 = CCMenuItemImage::create(
"card/card_7.png",
"card/7.png",
this,
menu_selector(Card_Layer::ChooseBack7));
card7->setPosition(ccp(440,360));
card8 = CCMenuItemImage::create(
"card/card_8.png",
"card/8.png",
this,
menu_selector(Card_Layer::ChooseBack8));
card8->setPosition(ccp(140,280));
card9 = CCMenuItemImage::create(
"card/card_9.png",
"card/9.png",
this,
menu_selector(Card_Layer::ChooseBack9));
card9->setPosition(ccp(190,280));
card10 = CCMenuItemImage::create(
"card/card_10.png",
"card/10.png",
this,
menu_selector(Card_Layer::ChooseBack10));
card10->setPosition(ccp(240,280));
card11 = CCMenuItemImage::create(
"card/card_11.png",
"card/11.png",
this,
menu_selector(Card_Layer::ChooseBack11));
card11->setPosition(ccp(290,280));
card12 = CCMenuItemImage::create(
"card/card_12.png",
"card/12.png",
this,
menu_selector(Card_Layer::ChooseBack12));
card12->setPosition(ccp(340,280));
card13 = CCMenuItemImage::create(
"card/card_13.png",
"card/13.png",
this,
menu_selector(Card_Layer::ChooseBack13));
card13->setPosition(ccp(390,280));
//添加闪烁
//初始化
spriteBlink = CCSprite::create("card/choose.png");
spriteBlink->setPosition(ccp(140, 360));
this->addChild(spriteBlink, 1);
CCActionInterval *blinkAction = CCBlink::create(10, 10);
spriteBlink->runAction(blinkAction);
choose_num=1;
isupdating=false;
isSaling=false;
isBuying=false;
m_pMenu = CCMenu::create(buy,sale,exit,card1,card2,card3,card4,card5,card6,card7,card8,card9,card10,card11,card12,card13,NULL);
m_pMenu->setPosition(CCPointZero);
this->addChild(m_pMenu,1);
//玩家已有卡牌的添加
for(int i=0;i<_hero->hero_card.top;i++)// i 值 为0,1,2
{
int No=_hero->hero_card.card_mk[i];
CCLOG("No : %d",No);
char *string = new char();
char *string1 = new char();
sprintf(string, "card/card_%d.png",No);
sprintf(string1, "card/%d.png",No);
if(i==0){
card_my1 = CCMenuItemImage::create(
string,
string1,
this,
menu_selector(Card_Layer::ChooseBack_my1));
card_my1->setPosition(ccp(150+i*60,108));
m_pMenu->addChild(card_my1);
}
if(i==1){
card_my2 = CCMenuItemImage::create(