void CNewGameSession::CmdEditName (void) // CmdEditName // // Handles the edit name button { const CVisualPalette &VI = m_HI.GetVisuals(); if (m_bEditingName) { IAnimatron *pEdit; if (m_pRoot->FindElement(ID_PLAYER_NAME_FIELD, &pEdit)) { m_Settings.sPlayerName = CUniverse::ValidatePlayerName(pEdit->GetPropertyString(PROP_TEXT)); m_Settings.bDefaultPlayerName = false; DeleteElement(ID_PLAYER_NAME_FIELD); } SetPlayerName(m_Settings.sPlayerName, m_xPlayerName, m_yPlayerName, m_cxPlayerName); m_bEditingName = false; } // If we're not editing, then start editing else { DeleteElement(ID_PLAYER_NAME); // Create edit control IAnimatron *pEdit; VI.CreateEditControl(NULL, ID_PLAYER_NAME_FIELD, m_xPlayerName + SMALL_BUTTON_WIDTH + MAJOR_PADDING_HORZ, m_yPlayerName, NAME_FIELD_WIDTH, 0, NULL_STR, &pEdit, NULL); pEdit->SetPropertyString(PROP_TEXT, m_Settings.sPlayerName); m_pRoot->AddLine(pEdit); SetInputFocus(ID_PLAYER_NAME_FIELD); m_bEditingName = true; } }
void CNewGameSession::SetShipClassDesc (const CString &sDesc, int x, int y, int cxWidth) // SetShipClassDesc // // Sets the current ship class description { const CVisualPalette &VI = m_HI.GetVisuals(); const CG16bitFont &MediumFont = VI.GetFont(fontMedium); const CG16bitFont &MediumBoldFont = VI.GetFont(fontMediumBold); const CG16bitFont &SubTitleFont = VI.GetFont(fontSubTitle); // Delete the previous one DeleteElement(ID_SHIP_CLASS_DESC); int xCenter = x + (cxWidth / 2); int cxDesc = 2 * SHIP_IMAGE_WIDTH; // Ship class IAnimatron *pDesc = new CAniText; pDesc->SetID(ID_SHIP_CLASS_DESC); pDesc->SetPropertyVector(PROP_POSITION, CVector(xCenter - cxDesc / 2, y + SMALL_BUTTON_HEIGHT + SMALL_SPACING_VERT + MediumBoldFont.GetHeight() + SubTitleFont.GetHeight())); pDesc->SetPropertyVector(PROP_SCALE, CVector(cxDesc, 100.0)); pDesc->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogLabel)); pDesc->SetPropertyFont(PROP_FONT, &MediumFont); pDesc->SetPropertyString(PROP_TEXT, sDesc); pDesc->SetPropertyString(PROP_TEXT_ALIGN_HORZ, ALIGN_CENTER); m_pRoot->AddLine(pDesc); }
list search_and_destroy(element e, list l) { list r = l; if (l == NULL) return NULL; if (detect(e, l) == false) return l; list tmp = l; if (IsEqual(head(l), e) == true) { l = DelFirst(l); return l; } while (llenght(l) != 1) { if (IsEqual(head(tail(l)), e) == true) { DeleteElement(l->next->value); tmp = l->next; l->next = l->next->next; free(tmp); return r; } l = tail(l); } return NULL; }
void CNewGameSession::SetPlayerName (const CString &sName, int x, int y, int cxWidth) // SetPlayerName // // Sets the current player name { const CVisualPalette &VI = m_HI.GetVisuals(); const CG16bitFont &MediumBoldFont = VI.GetFont(fontMediumBold); const CG16bitFont &SubTitleFont = VI.GetFont(fontSubTitle); // Delete the previous one DeleteElement(ID_PLAYER_NAME); // Player name IAnimatron *pName = new CAniText; pName->SetID(ID_PLAYER_NAME); pName->SetPropertyVector(PROP_POSITION, CVector(x + SMALL_BUTTON_WIDTH + MAJOR_PADDING_HORZ, y + MediumBoldFont.GetHeight())); pName->SetPropertyVector(PROP_SCALE, CVector(cxWidth, 100.0)); pName->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogLabel)); pName->SetPropertyFont(PROP_FONT, &SubTitleFont); pName->SetPropertyString(PROP_TEXT, sName); m_pRoot->AddLine(pName); }
void CElementPropPage::OnDelbutton() { int index = m_lbElementList.GetCurSel (); int count = m_lbElementList.GetCount(); DeleteElement(index); m_lbElementList.DeleteString(index); if(index==0) { if(count==1) { m_lbElementList.AddString(L"Element-0"); m_lbElementList.SetCurSel (index); SetPropText(L"Element",index); } else if (count>1) { m_lbElementList.SetCurSel (index); SetPropText(L"Element", index); } } else { index--; m_lbElementList.SetCurSel (index); SetPropText(L"Element", index); } UpdateControls(); }
void CNewGameSession::SetShipClassName (const CString &sName, int x, int y, int cxWidth) // SetShipClassName // // Sets the current ship class anem { const CVisualPalette &VI = m_HI.GetVisuals(); const CG16bitFont &MediumBoldFont = VI.GetFont(fontMediumBold); const CG16bitFont &SubTitleFont = VI.GetFont(fontSubTitle); // Delete the previous one DeleteElement(ID_SHIP_CLASS_NAME); // Ship class IAnimatron *pName = new CAniText; pName->SetID(ID_SHIP_CLASS_NAME); pName->SetPropertyVector(PROP_POSITION, CVector(x, y + SMALL_BUTTON_HEIGHT + SMALL_SPACING_VERT + MediumBoldFont.GetHeight())); pName->SetPropertyVector(PROP_SCALE, CVector(cxWidth, 100.0)); pName->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogLabel)); pName->SetPropertyFont(PROP_FONT, &SubTitleFont); pName->SetPropertyString(PROP_TEXT, sName); pName->SetPropertyString(PROP_TEXT_ALIGN_HORZ, ALIGN_CENTER); m_pRoot->AddLine(pName); }
int CALL RadUtiDel(int* n, int Elem) { DeleteElement(Elem); *n = ioBuffer.OutInt(); return ioBuffer.OutErrorStatus(); }
BOOL KDicomDS::DeleteElement(unsigned short group, unsigned short element, KDicomElement * pParent) { KDicomElement * pDE = GetElement(group, element, pParent); if(pDE == NULL) return FALSE; DeleteElement(pDE, pParent); return TRUE; }
int DeleteTileRowElement (ElementList **list, int counter, unsigned short *buff) { int i; for (i=0;i < windowwidth; i++) { counter -= DeleteElement (list, (unsigned int) buff[i]); } return counter; }
void WindowManager::close() { if (root == current) root = root->child; FoldChildren( windows, current ); DeleteElement( windows, current ); if (!windows.size()) Scene::Exit(); current = *(windows.begin()); root->setSize(0,0,Scene::w, Scene::h); }
int DeleteTileColElement (ElementList **list, int counter, unsigned short *buff) { int i; for (i=0;i < windowheight; i++) { counter -= DeleteElement (list, (unsigned int) *buff); buff += datawidth; } return counter; }
list DelFirst(list l) { list next = tail(l); DeleteElement(head(l)); free(l); SetRoot(next, next); return next; }
int main (int argc, char* argv[]) { int dataInt[] = {1, 2, 3, 4, 5}; CSinglyListNode* head = CreateTestList(dataInt, 5); PrintList(head); CSinglyListNode* deleteMe = NULL; // Test 1 deleteMe = Find(head, 2); if (deleteMe) { if (!DeleteElement(&head, deleteMe)) std::cout << "Can't delete : " << deleteMe->iData << std::endl; } PrintList(head); // Test 2 deleteMe = Find(head, 7); if (!deleteMe) { std::cout << "This element 7 doesn't exist" << std::endl; } // Test 3 deleteMe = Find(head, 5); if (deleteMe) { if (!DeleteElement(&head, deleteMe)) std::cout << "Can't delete : " << deleteMe->iData << std::endl; } PrintList(head); // Test 3 std::cout << "DeleteList..." << std::endl; DeleteList(&head); std::cout << "head now : " << head << std::endl; PrintList(head); std::cout << "bye" << std::endl; return 0; }
static void * ReplaceKeyData(PQueue *h, PQueueElement *x, intptr_t key, void *data) { void *odata; int okey; PQueueElement *y; int r; odata = x->Data; okey = x->Key; /* * we can increase a key by deleting and reinserting, that * requires O(lgn) time. */ if ((r = comparedata(h, key, data, x)) > 0) { /* XXX - bad code! */ abort(); DeleteElement(h, x); if (data) memcpy(x->Data , data,h->ElementSize); x->Key = key; insertel(h, x); return odata; } if (data) memcpy(x->Data , data, h->ElementSize); x->Key = key; /* because they are equal, we don't have to do anything */ if (r == 0) return odata; y = x->Parent; if (okey == key) return odata; if (y != NULL && compare(h, x, y) <= 0) { Cut(h, x, y); CascadingCut(h, y); } /* * the = is so that the call from delete will delete the proper * element. */ if (compare(h, x, h->Minimum) <= 0) h->Minimum = x; return odata; }
// TODO: optimize adding/deleting void Vanish_CleanUp() { Element* el; while(delCount > 0) { delCount--; el = delList[delCount]; DeleteElement(el, false, false); } }
void CNewGameSession::CmdEditNameCancel (void) // CmdEditNameCancel // // Cancel editing name { if (m_bEditingName) { DeleteElement(ID_PLAYER_NAME_FIELD); SetPlayerName(m_Settings.sPlayerName, m_xPlayerName, m_yPlayerName, m_cxPlayerName); m_bEditingName = false; } }
int main() { FILE *p; p=fopen("input.dat","r"); o=fopen("output.dat","w"); char a[100],*c,*d; while(fgets(a,100,p)) { c=strtok(a," \n"); d=strtok(NULL," \n"); if(strcmp(c,"AF") == 0) { AddFirst(atoi(d), &Works); } else if (strcmp(c,"AL") == 0) { AddLast(atoi(d), &Works); } else if(strcmp(c,"DF")==0) { DeleteFirst(&Works); } else if(strcmp(c,"DL")==0) { DeleteLast(&Works); } else if(strcmp(c,"DE")==0) { DeleteElement(atoi(d), &Works); } else if(strcmp(c,"PRINT_ALL")==0) { print(&Works); } else if(strcmp(c,"PRINT_F")==0) { PrintNrOfElements(atoi(d), &Works); } else if(strcmp(c,"PRINT_L")==0) { PrintNrOfElementsLast(atoi(d), &Works); } else if(strcmp(c,"DOOM_THE_LIST")==0) { Doom(&Works); } } return 0; }
int main () { SeqList List; SeqList *Li = &List; scanf("%d", &List.listLength); for (int i = 0; i < List.listLength; i++ ) { scanf("%d", &List.data[i]); } printf("输入完毕 %d\n", List.listLength); DeleteElement(Li, 66); for (int i = 0; i < List.listLength; i++) { printf("%d ", List.data[i]); } printf("length: %d", List.listLength); //printf("%d\n", FindElement(Li, 3)); return 0; }
void CNewGameSession::SetPlayerGenome (GenomeTypes iGenome, int x, int y, int cxWidth) // SetPlayerGenome // // Sets the current player genome { const CVisualPalette &VI = m_HI.GetVisuals(); const CG16bitFont &MediumBoldFont = VI.GetFont(fontMediumBold); const CG16bitFont &SubTitleFont = VI.GetFont(fontSubTitle); // Delete the previous one DeleteElement(ID_PLAYER_GENOME); // Player genome IAnimatron *pGenome = new CAniText; pGenome->SetID(ID_PLAYER_GENOME); pGenome->SetPropertyVector(PROP_POSITION, CVector(x, y + MediumBoldFont.GetHeight())); pGenome->SetPropertyVector(PROP_SCALE, CVector(cxWidth - SMALL_BUTTON_WIDTH - MAJOR_PADDING_HORZ, 100.0)); pGenome->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogLabel)); pGenome->SetPropertyFont(PROP_FONT, &SubTitleFont); pGenome->SetPropertyString(PROP_TEXT, strTitleCapitalize(GetGenomeName(iGenome))); pGenome->SetPropertyString(PROP_TEXT_ALIGN_HORZ, ALIGN_RIGHT); m_pRoot->AddLine(pGenome); // Change the button image IAnimatron *pButton; if (m_pRoot->FindElement(CMD_CHANGE_GENOME, &pButton)) { const CG16bitImage *pImage; if (iGenome == genomeHumanMale) pImage = &VI.GetImage(imageSmallHumanMale); else pImage = &VI.GetImage(imageSmallHumanFemale); IAnimatron *pStyle = pButton->GetStyle(STYLE_IMAGE); pStyle->SetFillMethod(new CAniImageFill(pImage, false)); } }
list Del(list l, item *ToDelete) { list r = l; size_t list_size = llenght(r); if (l == ToDelete) DelFirst(l); for (size_t i = 0; i < list_size; ++i) { if (tail(r) == ToDelete) { r->next = ToDelete->next; break; } r = tail(r); } DeleteElement(head(ToDelete)); free(ToDelete); return r; }
void AddWithDeleteElement_test() { pListHeader headerA; InitListHeader(&headerA, 'A'); int StartIndex = 10; int EndIndex = 20; int Length = EndIndex - StartIndex; pElementType pArr[Length]; int k = 0; for(int i = StartIndex; i < EndIndex; i++, k++) { pElementType tmp; tmp = malloc(sizeof(ElementType)); if(tmp == NULL) { printf("malloc failed in Practice_3_2!\n"); break; } tmp->data = i; pArr[k] = tmp; AddElement(k,tmp,headerA); if(i%5 == 0) { DeleteElement(k, headerA); k--; } } { for(int i = 0; i < k; i++) { printf("%p\t%p\n", pArr[i], headerA->pltArr[i]); if(pArr[i] != headerA->pltArr[i]) printf("WRONG:\n\t%d %p\t%p\n", i, pArr[i], headerA->pltArr[i]); } } FreeList(headerA); }
void DeleteTrack() { Element* elem = firstElem; Element* elemnext; while(elem != NULL) { elemnext = elem->next; if(elem->patt == field_pattern) { if(elem->trknum == C.trknum) { elemnext = NextElementToDelete(elem); DeleteElement(elem, true, true); } else if(elem->trknum > C.trknum) { elem->Move(0, -1); } } elem = elemnext; } Trk* trk = C.trk; if(trk->buncho == true) { if(trk->next->bunchito == true) { Remove_Bunch(trk->trkbunch, field_pattern); } else { trk->next->buncho = true; trk->next->bunched = false; trk->trkbunch->start_track = trk->next->trknum; trk->trkbunch->trk_start = trk->next; } } else if(trk->bunchito == true) { trk->prev->bunchito = true; trk->prev->trkbunch = trk->trkbunch; trk->trkbunch->end_track--; trk->trkbunch->trk_end = trk->prev; trk->trkbunch->endpix -= lineHeight; } trk->start_line = last_trkdata->start_line; trk->vol->active = trk->pan->active = trk->mute->active = trk->solo->active = false; trk->end_line = trk->start_line; trk->trk_start_line = trk->start_line; trk->trk_end_line = trk->start_line; trk->buncho = false; trk->bunched = false; trk->bunchito = false; trk->trkbunch = NULL; trk->vol_lane.visible = false; trk->vol_lane.height = 3; trk->pan_lane.visible = false; trk->pan_lane.height = 3; trk->params->Reset(); trk->vol->drawarea->UnChange(); trk->pan->drawarea->UnChange(); trk->UpdateLaneBases(); trk->trknum = 999; trk = last_trkdata; while(trk != C.trk) { trk->trknum--; trk->start_line--; trk->end_line--; trk->trk_start_line--; trk->trk_end_line--; if(trk->trkbunch != NULL) { if(trk->buncho == true) { trk->trkbunch->start_track--; trk->trkbunch->startpix -= lineHeight; } if(trk->bunchito == true) { trk->trkbunch->end_track--; trk->trkbunch->endpix -= lineHeight; } } trk->UpdateLaneBases(); trk = trk->prev; } C.trk = trk->next; trk->prev->next = trk->next; trk->next->prev = trk->prev; last_trkdata->next->prev = trk; trk->next = last_trkdata->next; last_trkdata->next = trk; trk->prev = last_trkdata; last_trkdata = trk; if(trk == first_trkdata) { first_trkdata = C.trk; } field_pattern->first_trkdata = first_trkdata; field_pattern->last_trkdata = last_trkdata; UpdateAllElements(field_pattern); }
void InsertTrack() { Element* elem = firstElem; Element* elemnext; while(elem != NULL) { elemnext = elem->next; if(elem->patt == field_pattern) { if(elem->trknum == 999) { elemnext = NextElementToDelete(elem); DeleteElement(elem, true, true); } else if(elem->trknum >= C.trknum && elem->patt == field_pattern) { elem->Move(0, 1); } } elem = elemnext; } Trk* trk = last_trkdata; if(trk->bunchito == true) { trk->bunchito = false; trk->prev->bunchito = true; trk->trkbunch->end_track = trk->prev->trknum; trk->trkbunch->trk_end = trk->prev; } if(trk->prev->buncho == true) { Remove_Bunch(trk->trkbunch, field_pattern); } trk->trknum = C.trknum; trk->start_line = C.trk->start_line; trk->end_line = trk->start_line; trk->trk_start_line = trk->start_line; trk->trk_end_line = trk->start_line; trk->buncho = false; trk->bunched = C.trk->bunched; trk->trkbunch = C.trk->trkbunch; trk->vol_lane.visible = false; trk->vol_lane.height = 3; trk->pan_lane.visible = false; trk->pan_lane.height = 3; trk->params->vol->SetNormalValue(1); trk->params->pan->SetNormalValue(0); trk->UpdateLaneBases(); trk = C.trk; while(trk != last_trkdata) { trk->trknum++; trk->start_line++; trk->end_line++; trk->trk_start_line++; trk->trk_end_line++; if(trk->trkbunch != NULL) { if(trk->buncho == true) { trk->trkbunch->start_track++; trk->trkbunch->startpix += lineHeight; } if(trk->bunchito == true) { trk->trkbunch->end_track++; trk->trkbunch->endpix += lineHeight; } } trk->UpdateLaneBases(); trk = trk->next; } trk->prev->next = trk->next; trk->next->prev = trk->prev; last_trkdata = trk->prev; C.trk->prev->next = trk; trk->prev = C.trk->prev; trk->next = C.trk; C.trk->prev = trk; if(C.trk == first_trkdata) { first_trkdata = trk; } C.trk = trk; field_pattern->first_trkdata = first_trkdata; field_pattern->last_trkdata = last_trkdata; UpdateAllElements(field_pattern); }
void CNewGameSession::SetShipClass (CShipClass *pClass, int x, int y, int cxWidth) // SetShipClass // // Sets the ship class { int i; const CPlayerSettings *pPlayerSettings = pClass->GetPlayerSettings(); const CVisualPalette &VI = m_HI.GetVisuals(); const CG16bitFont &MediumBoldFont = VI.GetFont(fontMediumBold); const CG16bitFont &SubTitleFont = VI.GetFont(fontSubTitle); // Ship class name SetShipClassName(pClass->GetName(), x, y, cxWidth); SetShipClassDesc(pPlayerSettings->GetDesc(), x, y, cxWidth); // Offset int yOffset = SMALL_BUTTON_HEIGHT + SMALL_SPACING_VERT + MediumBoldFont.GetHeight() + 2 * SubTitleFont.GetHeight(); // Ship class image SetShipClassImage(pClass, x, y + yOffset, cxWidth); // Delete previous info DeleteElement(ID_SHIP_CLASS_INFO); // Create a sequencer for all class info components CAniSequencer *pClassInfo; CAniSequencer::Create(CVector(x, y + yOffset + SubTitleFont.GetHeight()), &pClassInfo); pClassInfo->SetID(ID_SHIP_CLASS_INFO); // Generate default devices for the ship class CDeviceDescList Devices; pClass->GenerateDevices(1, Devices); // Generate list of all weapons, sorted by level and name TSortMap<CString, CItem> RightSide; for (i = 0; i < Devices.GetCount(); i++) { CDeviceClass *pDevice = Devices.GetDeviceClass(i); if (pDevice->GetCategory() == itemcatWeapon || pDevice->GetCategory() == itemcatLauncher) RightSide.Insert(strPatternSubst(CONSTLIT("%02d_%02d_%s"), 1, pDevice->GetLevel(), pDevice->GetName()), CItem(pDevice->GetItemType(), 1)); } // Add shields TSortMap<CString, CItem> LeftSide; CDeviceClass *pShields = Devices.GetNamedDevice(devShields); if (pShields) RightSide.Insert(strPatternSubst(CONSTLIT("%02d_%02d_%s"), 2, pShields->GetLevel(), pShields->GetName()), CItem(pShields->GetItemType(), 1)); // Add armor RightSide.Insert(CONSTLIT("03"), CItem(g_pUniverse->GetItemType(0), SPECIAL_ARMOR)); // Add reactor LeftSide.Insert(CONSTLIT("01"), CItem(g_pUniverse->GetItemType(0), SPECIAL_REACTOR)); // Add engines LeftSide.Insert(CONSTLIT("02"), CItem(g_pUniverse->GetItemType(0), SPECIAL_DRIVE)); // Add cargo LeftSide.Insert(CONSTLIT("03"), CItem(g_pUniverse->GetItemType(0), SPECIAL_CARGO)); // Add misc devices for (i = 0; i < Devices.GetCount(); i++) { CDeviceClass *pDevice = Devices.GetDeviceClass(i); if (pDevice->GetCategory() == itemcatMiscDevice) LeftSide.Insert(strPatternSubst(CONSTLIT("%02d_%02d_%s"), 4, pDevice->GetLevel(), pDevice->GetName()), CItem(pDevice->GetItemType(), 1)); } // Add device slots LeftSide.Insert(CONSTLIT("05"), CItem(g_pUniverse->GetItemType(0), SPECIAL_DEVICE_SLOTS)); // Set the ship class info. All weapons go to the right of the ship image int xPos = (cxWidth / 2) + (SHIP_IMAGE_RECT_WIDTH / 2); int yPos = 0; int cxInfo = (cxWidth - xPos); for (i = 0; i < RightSide.GetCount(); i++) { int cyInfo; IAnimatron *pInfo; AddClassInfo(pClass, Devices, RightSide[i], xPos, yPos, cxInfo, 0, &cyInfo, &pInfo); pClassInfo->AddTrack(pInfo, 0); yPos += cyInfo + ITEM_INFO_PADDING_VERT; } // Misc devices go on the left xPos = (cxWidth / 2) - (SHIP_IMAGE_RECT_WIDTH / 2); yPos = 0; cxInfo = xPos; for (i = 0; i < LeftSide.GetCount(); i++) { int cyInfo; IAnimatron *pInfo; AddClassInfo(pClass, Devices, LeftSide[i], xPos, yPos, cxInfo, CUIHelper::OPTION_ITEM_RIGHT_ALIGN, &cyInfo, &pInfo); pClassInfo->AddTrack(pInfo, 0); yPos += cyInfo + ITEM_INFO_PADDING_VERT; } m_pRoot->AddLine(pClassInfo); }
void CNewGameSession::SetShipClassImage (CShipClass *pClass, int x, int y, int cxWidth) // SetShipClassImage // // Sets the current ship class image { const CPlayerSettings *pPlayerSettings = pClass->GetPlayerSettings(); const CG16bitImage *pImage = g_pUniverse->GetLibraryBitmap(pPlayerSettings->GetLargeImage()); // Delete the previous one DeleteElement(ID_SHIP_CLASS_IMAGE); // Add the new one, if we've got one. const CG16bitImage *pImageToUse = NULL; bool bFree = false; if (pImage && !pImage->IsEmpty()) { // If this image is not the right size, then create a resized version // that is. if (pImage->GetWidth() != SHIP_IMAGE_WIDTH || pImage->GetHeight() != SHIP_IMAGE_HEIGHT) { int cxNewWidth = SHIP_IMAGE_WIDTH; int cyNewHeight = cxNewWidth * pImage->GetHeight() / pImage->GetWidth(); if (cyNewHeight > SHIP_IMAGE_HEIGHT) { cyNewHeight = SHIP_IMAGE_HEIGHT; cxNewWidth = cyNewHeight * pImage->GetWidth() / pImage->GetHeight(); } CG16bitImage *pNewImage = new CG16bitImage; pNewImage->CreateFromImageTransformed(*pImage, 0, 0, pImage->GetWidth(), pImage->GetHeight(), (Metric)cxNewWidth / pImage->GetWidth(), (Metric)cyNewHeight / pImage->GetHeight(), 0.0); pImageToUse = pNewImage; bFree = true; } else { pImageToUse = pImage; bFree = false; } } // If we don't have an image then ask the class to paint it else { CG16bitImage *pNewImage = new CG16bitImage; pNewImage->CreateBlank(SHIP_IMAGE_WIDTH, SHIP_IMAGE_HEIGHT, false); ViewportTransform Trans; pClass->Paint(*pNewImage, SHIP_IMAGE_WIDTH / 2, SHIP_IMAGE_HEIGHT / 2, Trans, 0, 0, false, false ); pImageToUse = pNewImage; bFree = true; } // Position int xImage = x + (cxWidth - pImageToUse->GetWidth()) / 2; int yImage = y + (SHIP_IMAGE_HEIGHT - pImageToUse->GetHeight()) / 2; // New image frame IAnimatron *pImageFrame = new CAniRect; pImageFrame->SetID(ID_SHIP_CLASS_IMAGE); pImageFrame->SetPropertyVector(PROP_POSITION, CVector(xImage, yImage)); pImageFrame->SetPropertyVector(PROP_SCALE, CVector(pImageToUse->GetWidth(), pImageToUse->GetHeight())); pImageFrame->SetFillMethod(new CAniImageFill(pImageToUse, bFree)); m_pRoot->AddLine(pImageFrame); }
void CList::DeleteElement(list_element* toDelete){ if(toDelete->next) DeleteElement(toDelete->next); delete toDelete; }
CList::~CList(){if(head!=NULL){DeleteElement(head);head=NULL;}};
void Delete (int i) { DeleteElement (i+1); }
void CMethod::SplitCards()//拆牌 { temp_rocket.clear(); temp_bosb.clear(); temp_three.clear(); temp_plane.clear(); temp_link.clear(); temp_doubleLink.clear(); temp_double.clear(); temp_single.clear(); m_handNum.clear(); if (m_intArray[13]==1&&m_intArray[14]==1)//火箭 { tempStyle.max=15; temp.min =15; tempStyle.m_value =8; tempStyle.m_ISprimary =true; m_intArray[13]=m_intArray[14]=0; temp_rocket.push_back(tempStyle); } for (int i=0;i<13;i++) { switch (m_intArray[i]) { case 4://炸弹 tempStyle.max=i; tempStyle.min =i; tempStyle.m_value = 7; tempStyle.m_ISprimary =true; m_intArray[i]=0; temp_bosb.push_back(tempStyle); break; case 3://3条 tempStyle.max =i; tempStyle.min =i; tempStyle.m_value =3; tempStyle.m_ISprimary =true; m_intArray[i]=0; temp_three.push_back(tempStyle); break; case 2://对子 tempStyle.max=i; tempStyle.min =i; tempStyle.m_value =2; tempStyle.m_ISprimary =true; m_intArray[i]=0; temp_double.push_back(tempStyle); break; } } JudeFly(temp_three,temp_plane,true);//判断飞机 JudeDoubleLink(temp_double,temp_doubleLink,true);//判断连队 //删除对子中的连队 DeleteElement(temp_double,temp_doubleLink); //删除3条中的飞机 DeleteElement(temp_three,temp_plane); int tempbosb,tempplane,tempLinkdouble,tempthree,tempdouble; if (temp_bosb.empty())tempbosb =0;else tempbosb =1; if(temp_plane.empty())tempplane=0;else tempplane =1; if(temp_doubleLink.empty())tempLinkdouble=0;else tempLinkdouble=1; if (temp_three.empty())tempthree=0;else tempthree =1; if(temp_double.empty())tempdouble =0;else tempdouble =1; for (int i=0;i<=tempbosb;i++)//炸弹 { for (int j=0;j<=tempplane;j++)//飞机 { for (int k=0;k<=tempLinkdouble;k++)//连队 { for (int f=0;f<=tempthree;f++)//3条 { for (int h=0;h<=tempdouble;h++)//对子 { ErgodicCard(i,j,k,f,h); } } } } } int tempQuanzhi=0,tempShoushu=0,tempShoushu1=0,tempQuanzhi1=0; for (int i=0;i<m_handNum.size()-1;) { tempShoushu=m_handNum[i].s_bosb.size()+m_handNum[i].s_double.size()+m_handNum[i].s_doubleLink.size()+ m_handNum[i].s_link.size()+m_handNum[i].s_plane.size()+m_handNum[i].s_rocket.size()+ m_handNum[i].s_single.size()+m_handNum[i].s_three.size(); if(m_handNum[i].s_three.size()==m_handNum[i].s_single.size()|| m_handNum[i].s_three.size()==m_handNum[i].s_double.size() )tempShoushu-=m_handNum[i].s_three.size(); tempShoushu1=m_handNum[i+1].s_bosb.size()+m_handNum[i+1].s_double.size()+m_handNum[i+1].s_doubleLink.size()+ m_handNum[i+1].s_link.size()+m_handNum[i+1].s_plane.size()+m_handNum[i+1].s_rocket.size()+ m_handNum[i+1].s_single.size()+m_handNum[i+1].s_three.size(); if(m_handNum[i+1].s_three.size()==m_handNum[i+1].s_single.size()|| m_handNum[i+1].s_three.size()==m_handNum[i+1].s_double.size() )tempShoushu1-=m_handNum[i+1].s_three.size(); tempQuanzhi =returnValue(m_handNum[i].s_bosb)+returnValue(m_handNum[i].s_double)+returnValue(m_handNum[i].s_doubleLink) +returnValue(m_handNum[i].s_link)+returnValue(m_handNum[i].s_plane) +returnValue(m_handNum[i].s_rocket)+returnValue(m_handNum[i].s_single)+returnValue(m_handNum[i].s_three); tempQuanzhi1 =returnValue(m_handNum[i+1].s_bosb)+returnValue(m_handNum[i+1].s_double)+returnValue(m_handNum[i+1].s_doubleLink) +returnValue(m_handNum[i+1].s_link)+returnValue(m_handNum[i+1].s_plane) +returnValue(m_handNum[i+1].s_rocket)+returnValue(m_handNum[i+1].s_single)+returnValue(m_handNum[i+1].s_three); vector<ZONGCARDS>::iterator iterTemp; if (tempShoushu>tempShoushu1) { iterTemp= m_handNum.begin()+i; i=0; }else if(tempShoushu<tempShoushu1) { iterTemp= m_handNum.begin()+i+1; i=0; }else { if (tempQuanzhi>tempQuanzhi1) { iterTemp= m_handNum.begin()+i+1; i=0; }else { iterTemp= m_handNum.begin()+i; i=0; } } m_handNum.erase(iterTemp); } insert(m_rocket,m_handNum[0].s_rocket); insert(m_bomb,m_handNum[0].s_bosb); insert(m_three,m_handNum[0].s_three); insert(m_plane,m_handNum[0].s_plane); insert(m_link,m_handNum[0].s_link); insert(m_doubleLink,m_handNum[0].s_doubleLink); insert(m_double,m_handNum[0].s_double); insert(m_single,m_handNum[0].s_single); }
//拆牌,说有能组成的牌型添加进行遍历 //炸弹,飞机,连对,3条,对子 void CMethod::ErgodicCard(bool bosb,bool plane,bool linDouble,bool three,bool Double) { RegainCard();//恢复原始牌 zong.s_bosb.clear(); zong.s_double.clear(); zong.s_doubleLink.clear(); zong.s_link.clear(); zong.s_plane.clear(); zong.s_rocket.clear(); zong.s_single.clear(); zong.s_three.clear(); //炸弹 if (bosb) { for (int i=0;i<temp_bosb.size();i++) { zong.s_bosb.push_back(temp_bosb[i]); m_intArray[temp_bosb[i].max] =0; } } //飞机 if (plane) { for (int i=0;i<temp_plane.size();i++) { zong.s_plane.push_back(temp_plane[i]); for (int j=zong.s_plane[i].min;j<=zong.s_plane[i].max;j++) { m_intArray[j] =0; } } } //连队 if (linDouble) { for (int i=0;i<temp_doubleLink.size();i++) { zong.s_doubleLink.push_back(temp_doubleLink[i]); for (int j=zong.s_doubleLink[i].min;j<=zong.s_doubleLink[i].max;j++) { m_intArray[j] =0; } } } //3条 if (three) { for (int i=0;i<temp_three.size();i++) { zong.s_three.push_back(temp_three[i]); m_intArray[temp_three[i].max] =0; } } //对子 if (Double) { for (int i=0;i<temp_double.size();i++) { zong.s_double.push_back(temp_double[i]); m_intArray[temp_double[i].max] =0; } } //在剩余的牌中提出连牌 int index=0; for (int i=0;i<12;i++) { if (m_intArray[i]>0) { index++; if (index==5) { tempStyle.max = i; tempStyle.min= tempStyle.max-4; tempStyle.m_value = 4; tempStyle.m_ISprimary =true; zong.s_link.push_back(tempStyle); for(int j=tempStyle.min;j<=tempStyle.max;j++) { m_intArray[j]-=1; } index=0; i=-1; } }else { index=0; } } //合并连牌 if(zong.s_link.size()!=0) { //单张合并 for (int i=0;i<12;i++) { for(int j=0;j<zong.s_link.size();j++) { if (m_intArray[i]>0) { if (zong.s_link[j].max+1==i) { zong.s_link[j].max =i; m_intArray[i]-=1; } } } } //2连牌直接合并 for (int i=0;i<zong.s_link.size()-1;i++) { if (zong.s_link[i].max+1==zong.s_link[i+1].min) { zong.s_link[i+1].min = zong.s_link[i].min; vector<CARDSTYLE>::iterator iter = zong.s_link.begin()+i; zong.s_link.erase(iter); } } //将连牌加入手数数组 } //加入对子 int a=0; for (int i=0;i<15 ;i++) { switch(m_intArray[i]) { case 4: tempStyle.max =i; tempStyle.min =i; tempStyle.m_value =7; tempStyle.m_ISprimary =true; zong.s_bosb.push_back(tempStyle); break; case 3: tempStyle.max =i; tempStyle.min =i; tempStyle.m_value =3; tempStyle.m_ISprimary =true; zong.s_three.push_back(tempStyle); break; case 2: tempStyle.max =i; tempStyle.min =i; tempStyle.m_value =2; tempStyle.m_ISprimary =true; zong.s_double.push_back(tempStyle); break; case 1: tempStyle.max =i; tempStyle.min =i; tempStyle.m_value =1; tempStyle.m_ISprimary =true; zong.s_single.push_back(tempStyle); break; } } JudeFly(zong.s_three,zong.s_plane,true);//判断飞机 JudeDoubleLink(zong.s_double,zong.s_doubleLink,true);//判断连队 //删除对子中的连队 DeleteElement(zong.s_double,zong.s_doubleLink); //删除3条中的飞机 DeleteElement(zong.s_three,zong.s_plane); m_handNum.push_back(zong); }