Thread: [Psuedo] Selling thingy

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    3

    [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
    which is the best way to do it?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    3
    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 )


    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.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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 might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    3
    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)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. selling my old computers
    By Xterria in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 07-01-2004, 07:16 PM
  2. looking for advice on selling golf balls
    By lambs4 in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 05-30-2004, 04:03 PM
  3. I"m selling a book...
    By St0rmTroop3er in forum Game Programming
    Replies: 2
    Last Post: 12-13-2003, 01:55 PM
  4. selling your programs
    By lambs4 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 01-27-2003, 01:28 AM