Das deutsche QBasic- und FreeBASIC-Forum Foren-Übersicht Das deutsche QBasic- und FreeBASIC-Forum
Für euch erreichbar unter qb-forum.de, fb-forum.de und freebasic-forum.de!
 
FAQFAQ   SuchenSuchen   MitgliederlisteMitgliederliste   BenutzergruppenBenutzergruppen  RegistrierenRegistrieren
ProfilProfil   Einloggen, um private Nachrichten zu lesenEinloggen, um private Nachrichten zu lesen   LoginLogin
Zur Begleitseite des Forums / Chat / Impressum
Aktueller Forenpartner:

Rollenspielengine mit Items, Inventaren, Charakteren

 
Neues Thema eröffnen   Neue Antwort erstellen    Das deutsche QBasic- und FreeBASIC-Forum Foren-Übersicht -> Projektvorstellungen
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen  
Autor Nachricht
Andt2018



Anmeldungsdatum: 22.12.2017
Beiträge: 7

BeitragVerfasst am: 12.10.2018, 17:55    Titel: Rollenspielengine mit Items, Inventaren, Charakteren Antworten mit Zitat

Dies ist die Rollespielengine für mein ersters großes Projekt - Frei zur freien verwendung inkl. einfaches Kampfsystem.. zwinkern
Code:
type Item
    Itemname as string
    ItemType as string
    ItemID as Integer
    Amount as Integer
    Cost as Integer
    Damage as Integer
end type 

type charakter
    Username as String
    Inventory(any) as Item
    HP as integer
    Damage as integer
end type

'find an item in an itemtable
function find_item(ItemName as string,ItemTable() as Item) as integer
    for i as integer = lbound(ItemTable) to ubound(ItemTable)
        If ItemTable(i).Itemname = ItemName then
            return i
        end if
    next
    return -1
end function


'add an item to the itemtable
sub add_item_to_table (ItemName as String,ItemTable() as Item)
    if find_item(ItemName,ItemTable()) = -1 then
        redim preserve ItemTable(ubound(ItemTable)+1)
        with ItemTable(ubound(ItemTable))
            .ItemName = ItemName
            .Amount = 0
            .ItemId = ubound(ItemTable)
            .ItemType = "None"
        end with
        print "Item '";ItemName;"' Registered to ID :";Ubound(ItemTable)
    else
        print "Registration failed"
    end if
end sub

'add an item to the charactere inventory like a player or a seller
sub add_item_to_character (ItemName as String,ItemTable() as Item,character as charakter)
    dim as integer item_id = find_item(ItemName,ItemTable())
    dim as integer id = find_item(ItemName,character.inventory())
    if id > -1 then print "Item already added" : EXIT SUB
    if item_id = -1 then print "E Item not found" : exit sub
    redim preserve character.inventory(ubound(character.inventory)+1)
    id = ubound(character.inventory)
    character.inventory(id)=ItemTable(item_id)
end sub

'set the amount of the item to a charactere
sub set_amount (ItemName as String,amount as integer,char as charakter)
    dim as integer id = find_item(ItemName,char.inventory())
    if id = -1 then print "A Item not found" : exit sub
    char.inventory(id).amount = amount
end sub

'get the amount of the item from a charactere
function get_amount (ItemName as String,char as charakter) as uinteger
    dim as integer id = find_item(ItemName,char.inventory())
    if id = -1 then print "B Item not found" : exit function
    return char.inventory(id).amount
end function

'set the cost of an item to the itemtable
sub set_cost (ItemName as String,cost as uinteger,ItemTable() as Item)
   
    dim as integer id = find_item(ItemName,ItemTable())
    if id =-1 then print "C Item not found" : exit sub
    ItemTable(id).cost = cost
    Print "Item ";Itemname;" has now Cost :";cost
end sub

'get the cost of an item from the itemtable
function get_cost (ItemName as String,ItemTable() as Item) as integer
    dim as integer id = find_Item(ItemName,ItemTable())
    if id = -1 then print "F Item not found" : exit function
    Return ItemTable(id).cost
end function

'lists all inventorys from charactere
sub list_inventory(char as charakter)
    Print "Charakter '";char.username;"' has this items:"
    print "Amount","ItemName","ItemType","Damage"
    for i as integer = lbound(char.inventory) to ubound(char.inventory)
        with char.inventory(i)
            Print .amount,.Itemname,.ItemType,.Damage
        end with
       
    next
end sub

sub set_damage(Itemname as string,damage as integer,ItemTable() as Item)
    dim as integer id = find_Item(ItemName,ItemTable())
    if id = -1 then print "G Item not found"
    ItemTable(id).damage = damage
    Print "Item ";Itemname;" has now Damage :";damage
end sub

function get_damage (ItemName as String,ItemTable() as Item) as integer
    dim as integer id = find_item(ItemName,ItemTable())
    if id = -1 then print "H Item not found"
    return ItemTable(id).damage
end function

sub set_itemtype(ItemName as String,Itemtype as string,ItemTable() as Item)
    dim as integer id = find_item(ItemName,ItemTable())
    if id = -1 then print "I Item not found"
    ItemTable(id).ItemType = ItemType
end sub

sub list_player_stats(p as charakter)
    with p
        print "Username : ";.Username
        list_inventory(p)
        PRINT "HP :";.hp
        Print "Damage :";.damage
    end with
end sub

sub set_waepon_damage_from_charakter (char as charakter)
    with char
        for i as integer = lbound(char.inventory) to ubound(char.inventory)
            .damage += char.inventory(i).damage * char.inventory(i).amount
        next
    end with
end sub

   

sub buy_item(buy_from as charakter,buy_to as charakter, buywith as string,buywhat as string,buy_amount as integer,ItemTable() as Item)
    dim as integer buy_from_object = find_item(buywhat, buy_from.inventory())
    dim as integer buy_to_object   = find_item(buywhat, buy_to.inventory())
    dim as integer from_money_id  = find_item(buywith, buy_from.inventory())
    dim as integer to_money_id  = find_item(buywith, buy_to.inventory())
    dim as integer ItemID          = find_item(buywhat, ItemTable())
    if buy_from_object = -1 then print "D Item not found"
    If ItemTable(ItemID).Cost * buy_amount <= buy_to.inventory(to_money_id).amount then
        if buy_to_object = -1 then
            add_item_to_character(buywhat,ItemTable(),buy_to)
            buy_to_object = ubound(buy_to.inventory)           
        end if
        if get_amount(buywhat,buy_from) >= buy_amount then
           
            buy_to.inventory(to_money_id).amount -= get_cost(BuyWith,ItemTable()) * ItemTable(ItemID).Cost * buy_amount
            buy_from.inventory(from_money_id).amount += get_cost(BuyWith,ItemTable()) *ItemTable(ItemID).Cost*buy_amount
            buy_to.inventory(buy_to_object).amount += buy_amount
            buy_from.inventory(buy_from_object).amount -= buy_amount
            Select case ItemTable(ItemId).ItemType
            case "Waepon"
                set_waepon_damage_from_charakter buy_to
            end select
           
               
        else
            print "Buy Failed - ";buywhat; " sold out."
        end if
    else
        print "Buy Failed - Not engouh money"
       
    end if
   
end sub

sub fight (byref Player as charakter,byref Enemy1 as charakter,Items() as Item)
cls
locate ,,0
do
   
   locate 1
   Print "Lets fight!"
   
   color 15
   PRINT "**PLAYER STATS**"
   color 11
   list_player_stats(Player)
   color 12
   list_player_stats(Enemy1)
   color 7

    select case inkey
    case " "
        beep
        cls
        Enemy1.HP - = Player.Damage
       
        Player.HP - = Enemy1.Damage
        if Enemy1.HP <= 0 then Enemy1.HP = 0
        If Player.HP <= 0 then Player.HP = 0 : Print "You lose! :O" : Exit do
        If Enemy1.HP <= 0 then
            locate 1
            Print "Let's Fight"
            color 15
            PRINT "**PLAYER STATS**"
            color 11
            list_player_stats(Player)
            color 12
            list_player_stats(Enemy1)
            color 15
            print "You won this fight!"
            for i as integer = lbound(Enemy1.Inventory) to ubound(Enemy1.Inventory)
                Print "You became " & Enemy1.Inventory(i).amount ;" ";Enemy1.Inventory(i).Itemname ;
                if Enemy1.Inventory(i).ItemType = "Waepon" then
                    print " with Damage ";Enemy1.Inventory(i).Damage & "."
                else
                    print ""
                end if
               
                add_item_to_character(Enemy1.Inventory(i).Itemname,Items(),Player)
                set_amount(Enemy1.Inventory(i).Itemname,Enemy1.Inventory(i).amount,Player)
                set_amount(Enemy1.Inventory(i).Itemname,0,Enemy1)
                if Enemy1.Inventory(i).ItemType = "Waepon" then
                    Player.Damage + = Enemy1.Inventory(i).Damage * Enemy1.Inventory(i).Amount : print Enemy1.Inventory(i).Damage * Enemy1.Inventory(i).Amount
                    Enemy1.Damage - = Enemy1.Inventory(i).Damage
                    Print "Congratulations your damage is now :";Player.Damage
                end if
               
            next
            exit do
        end if
               
    case chr(27)
        exit do
    end select
loop
end sub


'example

'configuration
dim Items(any) as Item
dim as charakter Player,Seller,Enemy1
add_item_to_table "Gold",Items()
add_item_to_table "Sword",Items()
add_item_to_table "Sting",Items()
add_item_to_character ("Gold",Items(),Seller)
add_item_to_character ("Gold",Items(),Player)
add_item_to_character ("Sword",Items(),Seller)
set_amount("Gold",10000,Seller)
set_amount("Gold",5000,Player)
set_itemtype("Sword","Waepon",Items())
set_amount("Sword",15,Seller)

set_cost("Sword",2500,Items()) ' here - a sword cost 2500
set_cost("Gold",1,Items())
set_damage("Sting",4,Items())
set_damage("Sword",7,Items())

set_itemtype("Sting","Waepon",Items())
add_item_to_character ("Sting",Items(),Enemy1)
set_amount("Sting",1,Enemy1)
set_waepon_damage_from_charakter Enemy1
Player.Username ="Player"
Player.HP = 25
Seller.Username ="Seller"
Enemy1.Username ="MrBee"
Enemy1.HP = 80
list_inventory(Player)
list_inventory(Seller)
color 15 : PRINT "NOW WE BUY TWO SWORDS FOR " & get_cost ("Sword",Items()) * 2: color 7


buy_item (Seller,Player,"Gold","Sword",2,Items())
print "New Player stats:"
list_inventory(Player)
list_inventory(Seller)
PRINT "DONE."
color 15

'example fight
Print "An Enemy is standing in the top of you hit him with [SPACE] :)"
Print "Enemy stats: "
list_player_stats(Enemy1)
print "Press a key to do this!"
sleep
fight (Player,Enemy1,Items())
print "Your Stats:"
list_player_stats(Player)

Nach oben
Benutzer-Profile anzeigen Private Nachricht senden
Beiträge der letzten Zeit anzeigen:   
Neues Thema eröffnen   Neue Antwort erstellen    Das deutsche QBasic- und FreeBASIC-Forum Foren-Übersicht -> Projektvorstellungen Alle Zeiten sind GMT + 1 Stunde
Seite 1 von 1

 
Gehe zu:  
Du kannst keine Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum nicht antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.

 Impressum :: Datenschutz