Nhờ nhận xét đoạn code cocos2d-x với ngôn ngữ c++

Em là 1 newbie của cocos2d-x với ngôn ngữ c++, em vừa mới viết 1 đoạn code, nhờ anh chị nhận xét ạ.Em cảm ơn rất nhiều

#include Puzzle.h

USING_NS_CC

Scence” Puzzle::createScene(){
	auto scene = Scene::create();
	auto layer = Game::create();
	scene->addChild(layer);	
}

bool Puzzle::init(){
auto noiDat = Sprite::create(“3x3.png”);
	auto hinhMau = Sprite::create(“ngonnui.jpg”);
	auto phan1 = Sprite::create(“phan1.jpg”);
auto phan2 = Sprite::create(“phan2.jpg”);
auto phan3 = Sprite::create(“phan3.jpg”);
auto phan4 = Sprite::create(“phan4.jpg”);
auto phan5 = Sprite::create(“phan5.jpg”);
auto phan6 = Sprite::create(“phan6.jpg”);
auto phan7 = Sprite::create(“phan7.jpg”);
auto phan8 = Sprite::create(“phan8.jpg”);
auto phan9 = Sprite::create(“phan9.jpg”);
auto ketQua;
auto kiemTra = Sprite::create(“kiemtra.jpg”);
int diemKiemTra = 0;
Vec2 tungdo = 30;
Vec2 hoanhdo = 30;
noiDat->setAnchorPoint(0,0);
hinhMau->AnchorPoint(0,0);
kiemTra->setAnchorPoint(0,0);
noiDat->setPosition(30,30);
hinhMau->setPosition(50,50);
kiemTra->setPosotion(200,0);
addChild(noiDat);
addChild(hinhMau);
addChild(kiemTra);
std::vector<auto> cacphan;
cacphan = {phan1, phan2, phan3, phan4, phan5, phan6, phan7, phan8, phan9};
for(int i =0, i < 9, i++){
	cacphan.at(i)->setAnchorPoint(0,0);
}
phan1->setPosition(Vec2(0,0));
phan2->setPosition(Vec2(0,5));
phan3->setPosition(Vec2(0,20));
phan4->setPosition(Vec2(0,10));
phan5->setPosition(Vec2(5,20));
phan6->setPosition(Vec2(0,25));
phan7->setPosition(Vec2(5,0));
phan8->setPosition(Vec2(5,15));
phan9->setPosition(Vec2(0,15));
for(int i =0, i < 9, i++){
	addChild(cacphan.at(i));
}
auto touchListener = EventListenerTouchOneByOne::create();
auto touchListener1 = EventListenerTouchOneByOne::create();
auto touchListener2= EventListenerTouchOneByOne::create();
auto touchListener3 = EventListenerTouchOneByOne::create();
auto touchListener4 = EventListenerTouchOneByOne::create();
auto touchListener5 = EventListenerTouchOneByOne::create();
auto touchListener6 = EventListenerTouchOneByOne::create();
auto touchListener7 = EventListenerTouchOneByOne::create();
auto touchListener8 = EventListenerTouchOneByOne::create();
auto touchListener9 = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan =  CC_CALLBACK_2(onTouchBegan,kiemTra);
touchListener1->onTouchBegan =  CC_CALLBACK_2(onTouchBegan1,phan1);
touchListener2->onTouchBegan =  CC_CALLBACK_2(onTouchBegan2,phan2);
touchListener3->onTouchBegan =  CC_CALLBACK_2(onTouchBegan3,phan3);
touchListener4->onTouchBegan =  CC_CALLBACK_2(onTouchBegan4,phan4);
touchListener5->onTouchBegan =  CC_CALLBACK_2(onTouchBegan5,phan5);
touchListener6->onTouchBegan =  CC_CALLBACK_2(onTouchBegan6,phan6);
touchListener7->onTouchBegan =  CC_CALLBACK_2(onTouchBegan7,phan7);
touchListener8->onTouchBegan =  CC_CALLBACK_2(onTouchBegan8,phan8);
touchListener9->onTouchBegan =  CC_CALLBACK_2(onTouchBegan9,phan9);
touchListener1->onTouchMoved =  CC_CALLBACK_2(onTouchMoved1,phan1);
touchListener2->onTouchMoved =  CC_CALLBACK_2(onTouchMoved2,phan2);
touchListener3->onTouchMoved =  CC_CALLBACK_2(onTouchMoved3,phan3);
touchListener4->onTouchMoved =  CC_CALLBACK_2(onTouchMoved4,phan4);
touchListener5->onTouchMoved =  CC_CALLBACK_2(onTouchMoved5,phan5);
touchListener6->onTouchMoved =  CC_CALLBACK_2(onTouchMoved6,phan6);
touchListener7->onTouchMoved =  CC_CALLBACK_2(onTouchMoved7,phan7);
touchListener8->onTouchMoved =  CC_CALLBACK_2(onTouchMoved8,phan8);
touchListener9->onTouchMoved =  CC_CALLBACK_2(onTouchMoved9,phan9);
phan1->getEvenDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener,phan1);
Phan2->getEvenDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener,phan2);
Phan3->getEvenDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener,phan3);
Phan4->getEvenDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener,phan4);
Phan5->getEvenDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener,phan5);
Phan6->getEvenDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener,phan6);
Phan7->getEvenDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener,phan7);
Phan8->getEvenDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener,phan8);
Phan9->getEvenDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener,phan9);
kiemTra->getEvenDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener,kiemTra);
onTouchBegan1(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan1->setPosition(touchLocation)
}
onTouchBegan2(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan2->setPosition(touchLocation)
}
onTouchBegan3(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan3->setPosition(touchLocation)
}
onTouchBegan4(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan4->setPosition(touchLocation)
}
onTouchBegan5(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan5->setPosition(touchLocation)
}
onTouchBegan6(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan6->setPosition(touchLocation)
}
onTouchBegan7(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan7->setPosition(touchLocation)
}
onTouchBegan8(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan8->setPosition(touchLocation)
}
onTouchBegan9(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan9->setPosition(touchLocation)
}
onTouchMoved1(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan1->setPosition(touchLocation)
}
onTouchMoved2(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan2->setPosition(touchLocation)
}
onTouchMoved3(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan3->setPosition(touchLocation)
}
onTouchMoved4(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan4->setPosition(touchLocation)
}
onTouchMoved5(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan5->setPosition(touchLocation)
}
onTouchMoved6(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan6->setPosition(touchLocation)
}
onTouchMoved7(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan7->setPosition(touchLocation)
}
onTouchMoved8(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan8->setPosition(touchLocation)
}
onTouchMoved9(Touch*touch, Event* event){
	auto touchLocation = touch->getPosition();
	phan9->setPosition(touchLocation)
}
for(int i = 0; i < 9, i++){
auto hinhKiemtra = Sprite(“hinhbatky”);
hinhKiemtra->getAnchorPoint(0,0);
hinhKiemtra->getPosition(hoanhdo, tungdo)
	if(cacphan.at(i)->getPosition() = hinhKiemtra->getPosition()){
		diemKiemtra++;	
}
if(i  > 2 && i < 6){
	if( i = 3){
		tungdo+=5;
}
hoanhdo-=5;
}elseif(i > 5){
	if(i = 6){
		tungdo+=5;
}
hoanhdo+=5;
}else{
	hoanhdo+=5; 
}
}
if( diemKiemtra = 9){
	ketQua = Sprite::create(“Win.png”);
}else{
	ketQua = Sprite::create(“Lost.png”);
}
onTouchBegan(Touch*touch,Event*event){
	ketQua->setPosition(150,80);
	addChild(ketQua);
}
} 

This post was flagged by the community and is temporarily hidden.

1 Like

This post was flagged by the community and is temporarily hidden.

1 Like

Em cam on anh rat nhieu a!

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?