//--------------------------------------------------------------------------- void __fastcall TfKnapsack::btAddItemsClick(TObject *Sender) { //如果已存在陣列 wrItems 將之清除 if (wrItems) { delete[] wrItems; wrItems = NULL; } //讀取使用者輸入 iItemNum = StrToInt(edItemNum->Text); iWeightRange = StrToInt(edWeightRange->Text); iProfitRange = StrToInt(edProfitRange->Text); //亂數產生 Items 的重量以及價值 //並加入 itmRoot AddItems(); //產生新的 wrItems 陣列 iTotalNum += iItemNum; //用來計算現在總共有多少資料 wrItems = new Wrap [iTotalNum]; //用中序走訪樹並將結果存到 wrItems InorderTraversal(itmRoot, wrItems, 0); //顯示所有資料,由 CP 值高到低顯示 if (cbPrintItems->Checked) PrintItems(); memSolution->Lines->Add(edItemNum->Text + " 筆亂數資料新增完成"); }
//--------------------------------------------------------------------------- void __fastcall TfKnapsack::btAddItemClick(TObject *Sender) { //如果已存在陣列 wrItems 將之清除 if (wrItems) { delete[] wrItems; wrItems = NULL; } //讀取使用者輸入 int iItemWeight = StrToInt(edItemWeight->Text); int iItemProfit = StrToInt(edItemProfit->Text); itmRoot = AddItem(itmRoot, iItemWeight, iItemProfit); //產生新的 wrItems 陣列 iTotalNum += 1; //用來計算現在總共有多少資料 wrItems = new Wrap [iTotalNum]; //用中序走訪樹並將結果存到 wrItems InorderTraversal(itmRoot, wrItems, 0); //顯示所有資料,由 CP 值高到低顯示 if (cbPrintItems->Checked) PrintItems(); memSolution->Lines->Add("1 筆資料新增完成"); }
//--------------------------------------------------------------------------- void __fastcall TfKnapsack::btClearAllClick(TObject *Sender) { //如果有資料就刪除 if (itmRoot) { delete[] wrItems; wrItems = NULL; itmRoot = ClearAll(itmRoot); } PrintItems(); memSolution->Lines->Add("資料已清空"); }
bool Player::ParseInstruction() { const Room* t = nullptr; if (m_CurrentInstruction == "north") { t = Dungeon::Instance().GetRoomInDirection(m_Position, NORTH); } else if (m_CurrentInstruction == "south") { t = Dungeon::Instance().GetRoomInDirection(m_Position, SOUTH); } else if (m_CurrentInstruction == "east") { t = Dungeon::Instance().GetRoomInDirection(m_Position, EAST); } else if (m_CurrentInstruction == "west") { t = Dungeon::Instance().GetRoomInDirection(m_Position, WEST); } else if (m_CurrentInstruction == "quit") { Dungeon::Instance().SetDungeonFinished(true); return true; } else if (m_CurrentInstruction == "print items" || m_CurrentInstruction == "print") { PrintItems(); return true; } if (t != nullptr) { m_Position = t->GetID(); } else { return false; } return true; }