Close
Faqja 0 prej 2 FillimFillim 12 FunditFundit
Duke shfaqur rezultatin -9 deri 0 prej 20
  1. #1
    ...gjenķ... Maska e mad
    Anėtarėsuar
    18-03-2004
    Vendndodhja
    Prage [EU]
    Postime
    1,321

    Exclamation Java - Nje "Loje fjalesh"

    Pershendetje forumistave te informatikes, perseri!

    Eshte kesaj rradhe pak si abstrakte kjo kerkese. do mundohem ta shpjegoj sa me mire, sepse eshte pak e cuditshme!
    Kerkohet te behet nje loje ne Java, e cila ka disa nivele, ose dhoma, ne te cilat mund te kalohet nepermjet disa fjaleve kyce! dmth, e vetmja paraqitje grafike eshte shkrimi! nuk ka figura, vetem disa situata te cilat paraqiten me ane te fjalive, dhe nga te cilat duhet te dalesh po me ane te shkrimit te nje informacionit te caktuar!
    une kam bere attach nje loje te tille, ku useri, ndodhet ne fillim te lojes ne oborrin e Campusit te nje shkolle, dhe te vetmet komanda qe mund te perdore jane "go", "quit" dhe "help"! me ane te "go" dhe nje fjale te dyte e cila eshte emertimi i nivelit(apo dhomes) tjeter, mund te levize! mund ta provoni! dhe ju lutem me beni pyetje nqs keni probleme!
    loja ka dicka: qe nuk ka fund! une do ju lutesha ti jepnit nje fund kesaj loje, ose me mire te them te me jepni nje ndihme per pjesen e sourcecode-it, qe duhet te perdor per ti dhene fund programit!
    problemi im eshte se deri simestrin e kaluar, ne shkolle perdoreshin java editore te thjeshte te cilet tregonin kodin, dhe e kompilonin ate, ndersa tani, e kane vene te detyruar perdorimin e JBlue, i cili eshte pak si me ndryshe! nuk e kam hapur akoma te gjithe sourcecode-in njeheresh sepse me JBlue shihen klasat vec e vec!
    nejse, ju falemnderit per vemendjen e kushtuar keto 2min! dhe shpresoj te lexoj sa me shume dhe sa me shpejt nga ju!


    {^_^}
    Skedarėt e Bashkėngjitur Skedarėt e Bashkėngjitur
    ::|maDes!gn © 2009|::

  2. #2
    Programues Softueresh Maska e edspace
    Anėtarėsuar
    04-04-2002
    Vendndodhja
    Filadelfia, SHBA
    Postime
    2,565
    Po e perdor kodin qe ke bashkengjitur apo e hodhe ate sa per shembull?
    Kodi qe kishe bashkengjitur nuk ka funksion main, prandaj nuk te del edhe ne JBlue. Mbase ke harruar ta hedhesh.

    Nqs kodin qe kishe hedhur me lart e hodhe sa per shembull, atehere hidh kodin tend qe te japim nje pergjigje te sakte.

    Kur thua qe do ti japesh lojes fund, cilat jane kushtet qe duhet te plotesoje personi qe te dale nga loja? Mund ti jap fund lojes nga cdo dhome apo duhet te kthehet ne dhomen fillestare qe te dale?

    Cfare duhet te beje programi kur perdoruesi jep komanden quit? Duhet te gjej menyren si te dale nga dhoma (si labirint) apo thjesht duhet te mbylle programin?

    Nqs kompjuteri duhet te gjeje vete daljen, atehere puna veshtiresohet pak por nqs komanda (quit) vetem mbyll programin, atehere eshte e lehte dhe mjafton te dalesh nga loop qe do jete ne main.

    Ja nje menyre se si i jepet fund lojes:

    Kodi:
    do_te_luaj = true;
    Per aq kohe sa personi do_te_luaj {
            nxirr dhomen qe eshte tani
            nxirr daljet (dyert) e mundshme nga mund te dale
            merr komanden
            analizo komanden 
                   Nqs komanda eshte 'quit' 
                           do_te_luaj = false
    }
    
    nxirr ne ekran: Mirupafshim
    Edi

  3. #3
    ...gjenķ... Maska e mad
    Anėtarėsuar
    18-03-2004
    Vendndodhja
    Prage [EU]
    Postime
    1,321
    Edi, me komanden quit, perdoruesi del fare nga programi. ose te pakten nga aplication-i.
    te pakten ne kete loje. kurse per te dale jashte perdoren komanda si psh:
    go outside, dhe kthehesh ne room = outside! komanda quit duhet te jete njelloj si "Alt+F4"!

    dmth levizja behet me ane te komandes "go" + nje fjale tjeter, e cila eshte emertimi i nje dhome te caktuar! nuk eshte e detyrueshme te perdoren komanda si go up, down, east north, ecc!

    ne cdo dhome mund te ndodhen objekte te ndryshme, dhe grumbullimi i disa prej ketyre objekteve te caktuara, ben te mundur perfundimin e lojes!
    psh. ne njeren nga dhomat mund te takoje ndonje personazh te caktuar, ku di une, nje xhuxh, nje fallxhor, dicka, dhe vetem nqs i jep nje nga ato sendet e gjetura, te le te kalosh me tej! e kshu me rradhe!

    tani, ketu akoma se kam vendosur se c'kushte i duhen userit te plotesoje ne menyre qe te mbaroje lojen.

    ai kodi qe kam attach-ur, eshte basic code per permiresimin ose zhvillimin e programit ne nje stad pak me te larte. me duhet edhe ti fus te gjithe keto class-et, ne nje .jar te vetem!
    me JBlue, eshte e mundur te luhet, mjafton ti japesh komanda vizuale!

    une po mundohem te fus te gjitha komentet ne anglisht, dhe do mundohem te vazhdoj ti jap nje ide me konkrete vazhdimesise se saj!

    rrofsh Edi!

    p.s: nqs ke ndonje koment shtese, apo edhe pyetje tjeter, je i lutur te shkruash!

    {^_^}
    ::|maDes!gn © 2009|::

  4. #4
    Programues Softueresh Maska e edspace
    Anėtarėsuar
    04-04-2002
    Vendndodhja
    Filadelfia, SHBA
    Postime
    2,565
    Une mendoja se ti kerkove ndihme per kodin e komandes quit por shoh qe ai kod eshte ne skedaret e bashkengjitur.

    Kodi PHP:
    public void play() {            

      
    printWelcome();

      
    // Enter the main command loop.  Here we repeatedly read commands and
      // execute them until the game is over.
                     
      
    boolean finished false;

      while (! 
    finished) {
           
    Command command parser.getCommand();
           
    finished processCommand(command);
      }

      
    System.out.println("Thank you for playing.  Good bye.");


    Nga mesazhi tend i fundit mu duke sikur ti kerkon mendim se si te mbarosh lojen ne kuptimin se cfare duhet te beje lojtari per te dale fitimtar, apo jo?

    Kjo pyetje duhet pergjigjur njeherese si dizajn dhe pastaj te mendosh per shkruajtjen e kodit.

    Dhomat mund te jene pjese e nje keshtjelle dhe lojtari si fillim mund te jete jashte dhe qellimi i tij eshte qe te ngjitet ne dhomen e mbretit (per ta vrare) ose akoma me mire ne dhomen e princesesh (per ti marre doren). Sigurisht qe do i duhet ndihma e xhuxhave, shtriges, ndonje magjistari, si dhe shpata, shtiza, dhe mos harro ndonje gjerdan te bukur per princeshen.

    Kodi i dhomave dhe levizja nga nje dhome ne tjetren eshte programuar ne skedaret qe bashkengjite me lart. Per te shtuar sendet ne nje dhome, mund te shtosh nje hashmap tjeter (si ajo e daljeve) ne klasen "room" dhe gjate deklarimit te dhomave mund te shtosh te gjitha objektet qe gjenden ne ate dhome me funksionin add_object(string "emri"). Per lojtarin mendoj se duhet krijuar nje klase me vete qe permban emrin e tij (string), nje torbe (hashmap ose list) te sendeve qe ka marre nga dhomat e ndryshme, emrin e dhomes ku ai gjendet (room ose string), piket qe ka fituar, parate qe ka (integer) nqs do i duhet te bleje gje. Parate mund te trajtohen edhe si send ne hashmap ("para", "150"). Klasa e lojtarit do kete edhe funksionet e duhura per te shtuar/hequr nje send te ri ne torbe, per te shtuar pike, per te ndryshuar emrin (ose ne konstruktor), si dhe per te ndryshuar vendodhjen (emrin e dhomes).

    Ne klasen game, krijo nje lojtar te ri duke pyetur personin per emrin e tij, caktoji dhomen e fillimit (jashte), shuma e parave (psh 100), sende te tjera qe mund te kete, dhe piket (0).

    Perseri ne klasen game, ndrysho funksionin create_rooms qe te shtosh edhe sendet e ndryshme qe gjenden ne cdo dhome; e ngjashme me setExits.

    Gjithcka qe ty te duhet per te pare nqs ka mbaruar loja do jete ne klasen lojtari (player) dhe pas cdo komande mund te shikosh nqs lojtari.getLocation()="dhoma e princeshes" ose nqs do bazohesh mbi piket, mund te shikosh nqs lojtari.getScore()>10000 duke menduar se po arriti me shume se 10000 pike, lojtari ka fituar.

    Pra ne funksionin Game::Play() pervec kushteve qe mbarojne lojen me komanden quit, do shtosh edhe kushtet qe permenda me lart (lojtari ka arritur qellimin e lojes ose ka fituar piket e mundshme per te mbaruar lojen). Per cdo dhome mund te krijosh nje funksion me vete qe kontrollon ngjarjen ne ate dhome dhe pas cdo levizjen qe ben lojtari nga nje dhome ne tjetren, ti thirr funksionin e asaj dhome.
    Kodi:
    ...
    
    if player.getLocation()=="jashte"
       jashte();
    if player.getLocation()=="burg"
       burg();
    if player.getLocation()=="dhoma princeshes"
       princesha();
       mbaro_lojen();
       finished = true;
    ...
    Keto ishin mendimet e mia duke zgjeruar mbi ato sa shkruajte. Nuk e di sa ke bere deri tani dhe duhet te shikoj kodin qe te te pergjigjem edhe une me kod. Nuk kam shume njohuri per sintaksen e Java por mund te shkruaj dicka ne C++ qe ti ta kthesh pastaj ne Java.
    Edi

  5. #5
    ...gjenķ... Maska e mad
    Anėtarėsuar
    18-03-2004
    Vendndodhja
    Prage [EU]
    Postime
    1,321

    Post

    Edi, pershendetje!
    pak a shume i kam dhene nje skeme ecurise se lojes:

    dhomat deklarohen ne class Game,
    Kodi:
    private Parser parser;
        private Room currentRoom;
    
        /**
         *  Creates rooms and calls parser.
         */
        public Game() {
            createRooms();
            parser = new Parser();
        }
    
    
        /**
         *  Creates single rooms and equips them with the exit help.
         */
        private void createRooms() {
            Room bridge;
            Room courtyard;
            Room stable;
            Room mainhall;
            Room kitchen;
            Room stair1;
            Room lounge;
            Room shortcut;
            Room stair2;
            Room tower;
            Room cell;
            
    
            // single rooms being created
            bridge = new Room("bridge","the middle of the bridge. Cross it over, and go towards the castle!");
            courtyard = new Room("courtyard","the yard of the castle");
            stable = new Room("stable","stable. The horseman might have something interesting for you!");
            mainhall = new Room("mainhall", "the entrance of the castle, which takes you inside!");
            kitchen = new Room("kitchen","the kitchen, where the servants used to work (better check in there!)");
            stair1 = new Room("stair1","the stairway that takes you to the 2nd floor!");
            lounge = new Room("lounge","the place where the treasuries of the Dark Warlord are kept(look in!)");
            shortcut = new Room("shortcut","for the hidden and shorter way to win the game!");
            stair2 = new Room("stair2"," the stairway that takes you to the highest floor of the castle!");
            tower = new Room("tower","highest level of the castle!");
            cell = new Room("cell","the place where the princess is locked!");
    dhe lidhjet midis dhomave:
    Kodi:
     // sets the exits (with connecting rooms)
            bridge.setExit(courtyard);
            courtyard.setExit(bridge);
            courtyard.setExit(stable);
            courtyard.setExit(mainhall);
            stable.setExit(courtyard);
            mainhall.setExit(courtyard);
            mainhall.setExit(kitchen);
            mainhall.setExit(stair1);
            kitchen.setExit(mainhall);
            stair1.setExit(mainhall);
            stair1.setExit(lounge);
            stair1.setExit(stair2);
            lounge.setExit(shortcut);
            shortcut.setExit(lounge);
            shortcut.setExit(cell);
            stair2.setExit(stair1);
            stair2.setExit(tower);
            tower.setExit(stair2);
            tower.setExit(cell);
            cell.setExit(tower);
            
            
            currentRoom = bridge;  // loja fillon ne dhomen "bridge"
    dhe kjo eshte pjesa tjeter e class Game:

    Kodi:
        /**
         *  The main method of the game. Cycles until the end of the game (as long 
         *  as the processCommand method returns true value)
         */
        public void play() {
            printWelcome();
    
            // the first cycle of the program - repeatedly the commands are read
            //and then they are erased in the end of the game.
    
            boolean finished = false;
            while (!finished) {
                Command command = parser.getCommand();
                finished = processCommand(command);
            }
            System.out.println("Thank you for playing. See you soon. Good bye.");
            System.out.println();
        }
    
    
        /**
         *  Writes beggining phrases for the player.
         */
        private void printWelcome() {
            System.out.println();
            System.out.println("Welcome to Koon!");
            System.out.println("Koon is a new, incredibly boring adventure game.");
            System.out.println("Type 'help' if you need help.");
            System.out.println();
            System.out.println(currentRoom.longDescription());
        }
    
    
        /**
         *  The method works with the command like a parameter, and gives the 
         *  answering method. If it's the end of the game, the method returns 
         *  the true value, otherwise returns false.
         *
         *@param  command  the command, which has to be valuated 
         *@return          returns true value, if it's the end of the game,
         *                 else false.
         */
        private boolean processCommand(Command command) {
            if (command.isUnknown()) {
                System.out.println("I don't know what you mean...");
                return false;
            }
    
            String commandWord = command.getCommandWord();
            if (commandWord.equals("help")) {
                printHelp();
                System.out.println();
            }
            else if (commandWord.equals("go")) {
                goRoom(command);
            }
            else if (commandWord.equals("quit")) {
                if (command.hasSecondWord()) {
                    System.out.println("Quit what?");
                }
                else {
                    return true;
                }
            }
            return false;
        }
    
    
        // follows the implementation of single commands
    
        /**
         *  Writes the first info after giving the help command. There is written 
         *  the list of used commands.
         */
        private void printHelp() {
            System.out.println("You are on a wandering, in the wild Fanghorn Forest.");
            System.out.println("You are looking for a castle, The Dark Warlord's Castle.");
            System.out.println("Your mission is to get to the highest room, in the highest");
            System.out.println("tower, so u can save the Princess of Noland");
            System.out.println();
            System.out.println("You find your way out of the Forest, look for a bridge");
            System.out.println("Your command words are:");
            parser.showCommands();
        }
    
    
        /**
         *  The "go" command. Tries to move towards the selected direction.
         *  If that direction is right, enters in a new area(room). If the command
         *  is not assigned, writes error message.
         *
         *@param  command  command - like the second parameter specifies a 
         *                 direction, which you can go.
         */
        private void goRoom(Command command) {
            if (!command.hasSecondWord()){
                // if the second word is missing, then...
                System.out.println("Go where?");
                return;
            }
    
            String direction = command.getSecondWord();
    
            // try to go into the next room
            Room nextRoom = currentRoom.nextRoom(direction);
    
            if (nextRoom == null) {
                System.out.println("I can't go this way!");
            }
            else {
                currentRoom = nextRoom;
                System.out.println(currentRoom.longDescription());
            }
        }
    }
    une do ti postoj te gjithe class-et qe permban loja. doja pak ndihme per vendosjen, marrjen dhe perdorimin e sendeve nga dhomat e ndryshme.

    -psh. lojtari, gjendet ne fillim mbi ure, pastaj me te njejten menyre komandash > go "dhoma", leviz drejt keshtjelles, ne oborrin e saj(courtyard), i cili ka lidhje me 2 dhoma te tjera, stallen(stable) dhe hyrjen ne keshtjelle(mainhall). ne stalle mendova te jete nje kalores(horseman) dhe objektet(items) kali dhe shpata.
    -futet ne keshtjelle. nga [mainhall] und te shkohet ne [kitchen] ose [ne stair1]. ne [kitchen] jane objektet "meat" dhe "pan".
    -me ane te shkalleve hipen ne katin e dyte, i cili ka lidhje me [lounge] dhe [stair2]. ne lounge, nuk lejohet te hysh nqs nuk gjen menyren per te shmangur nje "hellhound",menyre e cila eshte ti japesh mishin e gjetur ne [kitchen]. vete [lounge] ka lidhje me [shortcut], i cili te shpie te qelia ku eshte kycyr princesha.
    nqs nuk ben kete, por vazhdon me ane te [stair2] per ne nivelin me te larte te keshtjelles [tower], takon "Dark Warlord", te cilit duhet ti tregosh "shpaten" e gjetur ne [stable] per ta mposhtur. pas mposhtjes ai le nje objekt po ne kete dhome, [key]. me ane te ketij objekti behet e mundur hyrja per ne dhomen qe vijon [cell].
    kjo eshte me pak fjale ecuria e lojes Edi. do te doja te te pergjigjesha per cfaredo lloj paqartesie ose pyetje qe mund te kesh.

    edhe dicka tjeter; e kam provuar qe me krijimin e ketyre objekteve, pasi i merr nga dhoma X, dhe vazhdon me tej per ne dhomen Y, por te mbushet mendja te kthehesh perseri te dhoma X, me dhenien e komandes "go dhomaX", te shfaqet perseri edhe ai objekti te cilin e ke marre nje here brenda lojes. do ishte mire qe objekti te merrej vetem nje here.

    ....>>>>
    ::|maDes!gn © 2009|::

  6. #6
    ...gjenķ... Maska e mad
    Anėtarėsuar
    18-03-2004
    Vendndodhja
    Prage [EU]
    Postime
    1,321
    gjithashtu krijova nje class te ri.
    Kodi:
    public class Koon {
        public static void main (String [] args) {
           	Game start = new Game();
    	start.play();
        }
    }
    meqenese e bera nepermjet JBlue, nuk e di si e kam lidhur. por mendoj dhe besoj se kjo mjafton per te filluar lojen edhe pasi e gjithe loja do te dorezohet si .jar archive.

    {^_^}
    ::|maDes!gn © 2009|::

  7. #7
    ...gjenķ... Maska e mad
    Anėtarėsuar
    18-03-2004
    Vendndodhja
    Prage [EU]
    Postime
    1,321
    Si te behen objektet?

    --si duhet ti kete perparesite
    - emri <--(string name)
    - nese mund te merret <--(boolean take)
    - nese eshte i dukshem?
    --si duket ti kete veprimet?
    - konstruktor <--( Item(String name, boolean take) )
    - marrja e emrave <--( public String getName() )
    - nqs mund te merret <--( public boolean isTake() )

    dhe kodi per kete pjese:
    Kodi:
    public class Item {
    
    	private String name; //emri i objektit
    	private boolean take; //bartesia, nqs mund te merret
    
    	public Item(String name, boolean take) {
    		this.name = name;
    		this.carry = take;
    	}
    	public String getName () {
    		return name;
    	}
    	public boolean isTake() {
    		return take;
    	}
    }

    {^_^}
    ::|maDes!gn © 2009|::

  8. #8
    ...gjenķ... Maska e mad
    Anėtarėsuar
    18-03-2004
    Vendndodhja
    Prage [EU]
    Postime
    1,321
    -- Lista e objekteve ne nje dhome! --
    [class Room]
    -atributet e objekteve
    - array <--( Item [] listItems = new Item [10]; )
    - collection <--( Collection listItems = new ArrayList(); )
    - map <--( Map listItems = new HashMap(); )
    - veprimet e objekteve (metodat)
    - ruajtja e objekteve <--( void saveItem(Item smth) )
    - selektimi i objekteve <--( Item selectItem(String name) )
    - njohja e objekteve <--( String getListItems() )

    [class Room]
    Kodi:
    public void saveItem (Item smth) {
         lisItems.add(smth);
    }
    Kodi:
    public String getListItems () {
         String list = "";
         Iterator iter = listItems.iterator();
         while (iter.hasNext()) {
    	Item smth = (Item)it.next();
    	list = list+smth.getName()+" ";
         }
         return list;
    }
    Kodi:
    public Item selectItem (String name) {
         Item notfound = null;
         Iterator iter = listItems.iterator();
         while (iter.hasNext()) {
    	Item smth = (Item)iter.next();
    	if (smth.getName().equals(name)) {
    	    found = smth;
    	    listItems.remove(smth);  // heq objektin e zgjedhur nga koleksioni
    	    break;
    	}
          }
          return notfound;
    }
    ::|maDes!gn © 2009|::

  9. #9
    Programues Softueresh Maska e edspace
    Anėtarėsuar
    04-04-2002
    Vendndodhja
    Filadelfia, SHBA
    Postime
    2,565
    E shoh qe je ne forum.
    Une do pergjigjem tani me gjeresisht por nderkohe hidh nje ZIP me te gjithe kodin qe ke shkruar deri tani. Mundesisht dicka qe mund te kompliohet qe te testoj ndryshimet qe do bej une.
    Edi

  10. #10
    ...gjenķ... Maska e mad
    Anėtarėsuar
    18-03-2004
    Vendndodhja
    Prage [EU]
    Postime
    1,321
    kurse per vendosjen e sendeve ne nje dhome:

    [class Game]

    Kodi:
    // krijimi i nje dhome, shembull
    stable = new Room("stable","the stable of the castle!");
    
    // vendosja e daljeve
    stable.setExit(courtyard);
    
    // krijimi i objekteve, sendeve
    stable.saveItem(new Item(“horse”, false));
    stable.saveItem(new Item(“sword”, true));
    [class Game]

    ndersa, marrja e ketyre objekteve (sipas menyres me komanden "go")

    Kodi:
    private void take(Command command) 
        {
            if(!command.hasSecondWord()) {
    	 System.out.println(„Take what?");
                return;
            }
            String nameItem = command.getSecondWord();
            Item selectedItem = currentRoom.selectItem(nameItem);
            if (selectedItem == null) {
    	System.out.println(“This item isn't here!”);
            }
            else {
    	if (selectedItem.isTake()) {
    	     // objektet e futura ne cante, psh. bag.saveItem(selectedItem);
    	     // ose saveInBag(selectedItem) – varet nga implementimi i cantes
    	}
    	else {
    		System.out.println(“You cannot take this very object!”);
    		currentRoom.saveItem(selectedItem);
    	}
        }

    {^_^}
    ::|maDes!gn © 2009|::

Faqja 0 prej 2 FillimFillim 12 FunditFundit

Regullat e Postimit

  • Ju nuk mund tė hapni tema tė reja.
  • Ju nuk mund tė postoni nė tema.
  • Ju nuk mund tė bashkėngjitni skedarė.
  • Ju nuk mund tė ndryshoni postimet tuaja.
  •