Card* Card::createCard(Vec2 pos, Node *parent) { auto card = new Card(); if (card && card->initCard(pos, parent)) { card->autorelease(); return card; } CC_SAFE_DELETE(card); return nullptr; }
SdErrorCode directoryReset() { reset(); SdErrorCode rsp = initCard(); if (rsp != SD_SUCCESS && rsp != SD_ERR_CARD_LOCKED) { return rsp; } fat_reset_dir(dd); return SD_SUCCESS; }
PokerCard::PokerCard(int number,PokerColor color,int size){ Sprite::init(); m_Number = number; m_Color = color; m_Value = 0; m_Size = size; m_CardSize.width = 0; m_CardSize.height = 0; initCard(); setAnchorPoint(Vec2(0, 0)); }
SdErrorCode startRead(char const* filename) { reset(); SdErrorCode result = initCard(); /* for playback it's ok if the card is locked */ if (result != SD_SUCCESS && result != SD_ERR_CARD_LOCKED) { return result; } file = 0; if (!openFile(filename, &file) || file == 0) { return SD_ERR_FILE_NOT_FOUND; } playing = true; fetchNextByte(); return SD_SUCCESS; }
bool GameScene::init() { if (!Layer::init()) { return false; } initGameData(); initBG(); initTopMenuLabel(); initCard(); return true; }
// 初期化 bool GatyaTenDrawScene::init() { if (!Layer::init()) { return false; } // シングルタップイベントの取得 auto touchListener = EventListenerTouchOneByOne::create(); touchListener->setSwallowTouches(_swallowsTouches); touchListener->onTouchBegan = CC_CALLBACK_2(GatyaTenDrawScene::onTouchBegan, this); touchListener->onTouchMoved = CC_CALLBACK_2(GatyaTenDrawScene::onTouchMoved, this); touchListener->onTouchEnded = CC_CALLBACK_2(GatyaTenDrawScene::onTouchEnded, this); touchListener->onTouchCancelled = CC_CALLBACK_2(GatyaTenDrawScene::onTouchCancelled, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); initCard(); return true; }
int main () { int** newCard; int index; Player Harry; //This is how you make a player. Player Bob for(index=0; index<10; index++)//generate bingoCards for every player connected { newCard = createCard(); initCard(newCard); } /*Heres a little demo on how you would access elements inside the struct*/ strncpy(Harry.playerName,"Harrison",20); //copy Name into the structs playerName field. Harry.playerBingoCard = newCard; //give Harry his bingo card so he can beat old women at bingo printf("Player Name: %s\n", Harry.playerName); //access Player's name printCard(Harry.playerBingoCard); //access Player's bingo card return 0; }
StoryCardScene::StoryCardScene(QObject *parent) : QGraphicsScene(0,0,298,210,parent) { initDefaultLayout(0,0,298,210); initCard(0,0,298,210); }
StoryCardScene::StoryCardScene(qreal x, qreal y, qreal width, qreal height, QObject *parent) : QGraphicsScene(x,y,width,height) { initDefaultLayout(0,0,298,210); initCard(x,y,width,height); }
StoryCardScene::StoryCardScene(const QRectF &sceneRect, QObject *parent) : QGraphicsScene(QRectF(0,0,298,210), parent) { initDefaultLayout(0,0,298,210); initCard(0,0,298,210); }
void *connection_handler(void *socket_desc) { //Get the socket descriptor int sock = *(int*)socket_desc; int read_size; char *message , client_message[2000]; /*close(0); close(1); close(2); */ dup2( sock, STDOUT_FILENO ); /* duplicate socket on stdout */ dup2( sock, STDERR_FILENO ); /* duplicate socket on stderr too */ dup2( sock, STDIN_FILENO ); int** newCard; int index; int numbCalledArray[1000] = {0}; int *ptrCalledArrayTail; ptrCalledArrayTail = numbCalledArray; Player Harry; //This is how you make a player. newCard = createCard(); initCard(newCard); /*Heres a little demo on how you would access elements inside the struct*/ strncpy(Harry.playerName,"Harrison",20); //copy Name into the structs playerName field. Harry.playerBingoCard = newCard; //give Harry his bingo card so he can beat old women at bingo printf("Player Name: %s\n", Harry.playerName); //access Player's name printCard(Harry.playerBingoCard); //access Player's bingo card /*Heres a demo on how you would draw a number ptrCalledArrayTail = drawNumber(ptrCalledArrayTail, numCalledArray); printf("The final number drawn is %d", *ptrCalledArrayTail--); */ //Send some messages to the client //message = "Greetings! I am your connection handler\n"; //write(sock , message , strlen(message)); drawStuff(Harry.playerBingoCard); //write(sock , drawStuff(Harry.playerBingoCard) , strlen(message)); //Receive a message from client /*while( (read_size = recv(sock , client_message , 2000 , 0)) > 0 ) { //Send the message back to client write(sock , client_message , strlen(client_message)); bzero(client_message, 2000); } if(read_size == 0) { puts("Client disconnected"); fflush(stdout); } else if(read_size == -1) { perror("recv failed"); } */ //Free the socket pointer free(socket_desc); return 0; }
int main (int argc, char *argv[]) { int numClients = argc - 1; fd_set readfds, activefds, tempfds; char buffer[BUFFSIZE]; struct hand *myHand = NULL; struct hand *temp; struct client clients[numClients]; struct timeval timeout; int clientsPlaying = 0; int numRead; int i; resetDeck(); //have the dealer get its first 2 cards myHand = initCard(); myHand->next = initCard(); //have the clients get their first 2 cards for (i = 0; i < numClients; i++) { clients[i].hand = initCard(); clients[i].hand->next = initCard(); } //initialize the active client list FD_ZERO (&activefds); FD_ZERO (&tempfds); for (i = 1; i < argc; i++) { int socket = atoi(argv[i]); FD_SET (socket, &activefds); clients[clientsPlaying].socket = socket; clients[clientsPlaying].countdown = 10; clients[clientsPlaying].finished = 0; //send the initial cards to the client temp = clients[clientsPlaying].hand; strcpy(buffer, temp->card); strcat(buffer, temp->next->card); strcat(buffer, myHand->card); if (write(socket, buffer, sizeof(buffer)) < 0) { fprintf(stderr, "ERROR contacting client.\n"); FD_CLR(socket, &activefds); } clientsPlaying++; } while (clientsPlaying > 0) { fflush(stderr); //disconnect any clients who have timed out for (i = 0; i < numClients; i++) { if ((clients[i].countdown < 1) && (clients[i].finished == 0)) { fprintf(stderr, "A client has timed out.\n"); FD_CLR(clients[i].socket, &activefds); close(clients[i].socket); clients[i].finished = 1; clientsPlaying--; } } readfds = activefds; timeout.tv_sec = 1; timeout.tv_usec = 0; numRead = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout); if (numRead < 0) { fprintf(stderr, "ERROR with select %d\n", errno); continue; } //keep track of the inactivity for each client if (numRead == 0) { fprintf(stderr, "."); for (i = 0; i < numClients; i++) if (clients[i].finished == 0) clients[i].countdown--; continue; } //check for the client input for (i = 0; i < numClients; i++) { if (FD_ISSET (clients[i].socket, &readfds) && (clients[i].finished == 0)) { if (read(clients[i].socket, buffer, sizeof(buffer)) < 0) { fprintf(stderr, "ERROR reading the client's message.\n"); continue; } //give the player another card if (strcasecmp(buffer, "HIT") == 0) { clients[i].countdown = 10; struct hand *last = clients[i].hand; while (last->next != NULL) last = last->next; last->next = initCard(); write(clients[i].socket, last->next->card, sizeof(last->next->card)); //check to see if the client bust if (handValue(clients[i].hand) > 21) { fprintf(stderr, "A client has bust.\n"); FD_CLR(clients[i].socket, &activefds); close(clients[i].socket); clients[i].finished = 1; clientsPlaying--; } } else if (strcasecmp(buffer, "STAND") == 0) { //remove the client from ongoing gameplay fprintf(stderr, "A client has chosen to stand.\n"); clients[i].finished = 1; FD_CLR(clients[i].socket, &activefds); FD_SET(clients[i].socket, &tempfds); clientsPlaying--; } } } } activefds = tempfds; //calculate the rest of the dealer's hand, first check for soft 17 if ((getValue(myHand->card) == 1 || getValue(myHand->next->card) == 1) && dealerValue(myHand) == 17) myHand->next->next = initCard(); //keep hitting until 17 or higher while (dealerValue(myHand) < 17) { struct hand *last = myHand; while (last->next != NULL) last = last->next; last->next = initCard(); } //output the rest of the dealers hand to the buffer temp = myHand->next; strcpy(buffer, temp->card); temp = temp->next; while (temp != NULL) { strcat(buffer, temp->card); temp = temp->next; } //send the rest of the dealers hand to the clients for (i = 0; i < numClients; i++) { if (FD_ISSET (clients[i].socket, &activefds)) { write(clients[i].socket, buffer, sizeof(buffer)); close(clients[i].socket); } } return EXIT_SUCCESS; }