-
[Psuedo] Selling thingy
hiho, well I want to create something simple for learning purpose.
So, whats the smartest way to do it?
oh, some info first, it's for a game, and item name is just referring to like uhh "leather armor" or "steel sword" oki, and green djinn, blue djinn, rashid, are NPCs (non person characters) so just people who you sell items to.
[Psuedo] idea 1:
ask for item name
get item name
if item name = item a, item b, c,d,e,f, then say green djinn
else if item name = item y,u,i,o,p then say blue djinn
else if item name = q,w,e,r, then say rashid
else false
---
[Psuedo] idea 2:
ask for item name
get item name
if item = group a then say green djinn
else if item = group b then say blue
else if item = c the say rashid
else false
---
well umm, yeah thats it :p
which is the best way to do it?
-
So just to understand what you are doing: A player want to sell some item that the player has (owns), and you want to find the right buyer (from a list of buyers) for the item?
One way to achieve that is just the same as I would do in that situation: Offer it to all potential buyers, and sell it to the highest bidder.
The way you'd implement that in the game is to let each buyer have a list of items that the buyer is interested in buying, and a price for that item (perhaps combined by a condition factor, meaning that a "well used" Sword is less valuable than a brand new one). You may also add more complicated factors, such as "if buyer A has three steel swords in stock already, offer 20% less, and buyer B offers 10% under the standard bid, so buyer B gets the sale". If the buyer is not interested, bid 0 units of money.
--
Mats
-
Well, uhm... it's for an already made game, called tibia.
You got different npc's, and they all buy different items (you first need to do long quest and stuff :p)
so for example guy 1 (green djinn) buys: "plate armor", "short sword"
guy 2 buys: "fire sword", "knight armor"
guy 3 buys: "paladin armor"
well I was thinking about something like this:
Code:
#include <iostream>
using namespace std;
int main()
{
char item;
cout >> "Item: "; <<endl;
cin << item;
if (item =='item name') "blah blah npcs buys it for blahblah gp.";
else if (item =='item name 2') "blah blah npcs buys it for blahblah gp.";
return 0;
}
just quick code, probably not compiling but just for the idea.
-
It is probably not reasonable to attempt to hardcode the items' and the buyers' names into the logic of if...else. The idea is that the names of the creatures and items should not be set in stone, but you should be able to add and remove items and buyers at runtime any way you like.
Instead you should probably use arrays (or something more advanced like std::vector, std::map) with the names of buyers and items, and use loops to find out who is interested in what you have to offer. (Making a few classes might also help organize things a lot.)
Something like:
Code:
for each buyer:
if is interested in item:
sell
exit loop
-
I've don't really got an 'image' of how I could do that, could you maybe show an example?
(yeah I did see that one xd)