int main() { FOOD food; PSNAKE p_snake = init(&food); int input = 1; while (input) { menu(); scanf("%d", &input); switch (input) { case START: play(p_snake, &food); input = 0; print(p_snake); printf("\tGame Over!\n"); break; case EXIT: input = 0; break; } } distroy(p_snake); system("pause"); return 0; }
void test_reverse_lists() { list_t *list = create_list(); insert_at_end(list, 10); insert_at_end(list, 20); insert_at_end(list, 30); insert_at_end(list, 40); result_t reverse_result = reverse_list(list); assert(reverse_result == SUCCESS && is_at_begining(list, 40) && insert_before_data(list, 40, 30) && is_after(list, 10, 20) && is_at_end(list, 10)); distroy(&list); }
void Dog::display() { //body body = Sprite::create("DrDog1.png"); Animation* bodyAni = Animation::create(); bodyAni->addSpriteFrameWithFile("DrDog1.png"); bodyAni->addSpriteFrameWithFile("DrDog2.png"); bodyAni->setLoops(-1); bodyAni->setDelayPerUnit(0.2f); bodyAct = Animate::create(bodyAni); bodyAct->retain(); addChild(body); //explode explode = Sprite::create("boom1.png"); addChild(explode); Animation* explodeAnimation = Animation::create(); char name[20]; for (int i = 1; i <= 5; i++) { sprintf(name, "boom%d.png", i); explodeAnimation->addSpriteFrameWithFile(name); } explodeAnimation->setDelayPerUnit(0.2f); Animate* explodeAni = Animate::create(explodeAnimation); CallFunc* callFunc = CallFunc::create([&]()->void {distroy(); }); actions = Sequence::create(explodeAni, callFunc, NULL); actions->retain(); hitRect = body->getBoundingBox(); /*DrawNode* draw = DrawNode::create(); this->addChild(draw); Vec2 point1[4]; point1[0] = Point(hitRect.getMinX(), hitRect.getMaxY()); point1[1] = Point(hitRect.getMaxX(), hitRect.getMaxY()); point1[2] = Point(hitRect.getMaxX(), hitRect.getMinY()); point1[3] = Point(hitRect.getMinX(), hitRect.getMinY()); draw->drawPolygon(point1, 4, Color4F(1,0,0,0), 1, Color4F(1,0,0,1));*/ born(); }
void test_merge_lists() { list_t *list_1 = create_list(); list_t *list_2 = create_list(); insert_at_end(list_1, 100); insert_at_end(list_1, 54); insert_at_end(list_1, 65); insert_at_end(list_2, 87); insert_at_end(list_2, 120); insert_at_end(list_2, 45); list_t *merged_list = merge(list_1, list_2); assert(merged_list != NULL && is_at_begining(merged_list, 45) && is_at_end(merged_list, 120)); distroy(&merged_list); }
void test_concat_lists() { list_t *list_1 = create_list(); list_t *list_2 = create_list(); insert_at_end(list_1, 10); insert_at_end(list_1, 20); insert_at_end(list_1, 30); insert_at_end(list_2, 40); insert_at_end(list_2, 50); insert_at_end(list_2, 60); list_t *new_list = concat(list_1, list_2); assert(is_at_begining(new_list, 10) && is_at_end(new_list, 60)); distroy(&new_list); }
void Cat::display() { //body body = Sprite::create("catBody1.png"); Animation* animation = Animation::create(); animation->addSpriteFrameWithFile("catBody1.png"); animation->addSpriteFrameWithFile("catBody2-4.png"); animation->addSpriteFrameWithFile("catBody3.png"); animation->setDelayPerUnit(0.1f); animation->setLoops(-1); bodyAct = Animate::create(animation); bodyAct->retain(); addChild(body); //tail tail = Sprite::create("catTail.png"); tail->setAnchorPoint(Point(0.5, 1)); tail->setScale(0.3f); tail->setPosition(0,-30); /*RotateBy* rotateBy = RotateBy::create(0.5f, 30); RepeatForever* rotateForever = RepeatForever::create(rotateBy);*/ tailAct = RepeatForever::create(Sequence::create(RotateBy::create(0.5f, 40), RotateBy::create(0.5f, -40), nullptr)); tailAct->retain(); addChild(tail); //left hand leftHand = Sprite::create("catHand1.png"); leftHand->setAnchorPoint(Point(1, 0.5)); leftHand->setPosition(-18, -20); addChild(leftHand); //right hand rightHand = Sprite::create("catHand2.png"); rightHand->setAnchorPoint(Point(0, 0.5)); rightHand->setPosition(18, -20); addChild(rightHand); //explode explode = Sprite::create("boom1.png"); addChild(explode); Animation* explodeAnimation = Animation::create(); char name[20]; for (int i = 1; i <= 5; i++) { sprintf(name, "boom%d.png", i); explodeAnimation->addSpriteFrameWithFile(name); } explodeAnimation->setDelayPerUnit(0.2f); Animate* explodeAni = Animate::create(explodeAnimation); CallFunc* callFunc = CallFunc::create([&]()->void {distroy(); }); actions = Sequence::create(explodeAni, callFunc, NULL); actions->retain(); hitRect = body->getBoundingBox(); EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create(); //注意绑定的用法,要传入this指针作为第一个参数 //这个可以实现完美的事件机制!!! listener->onTouchBegan = CC_CALLBACK_2(Cat::onTouchBegan, this);//std::bind(&Cat::onTouchBegan,this, _1, _2); listener->onTouchMoved = CC_CALLBACK_2(Cat::onTouchMove, this); listener->onTouchEnded = CC_CALLBACK_2(Cat::onTouchEnd, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, body); }
void test_distroy(list_t** list) { distroy(list); assert(length(*list) == 0 && *list == NULL); }