Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Creating Hunt the Wumpus....need help in a variety of areas. :S
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Talion




PostPosted: Thu Oct 25, 2007 9:00 am   Post subject: Creating Hunt the Wumpus....need help in a variety of areas. :S

Ok, so in my class we're being asked to make a really simple game. Hunt the Wumpus. I don't know how many people have ever heard of or played this game. Honestly, until this assignment i'd never heard of it, but apparently a lot of older programmers got into the field because of it. O.o;

Anyways if you've never played the game http://www.taylor.org/~patrick/wumpus/. That's it, real simple eh? My problem is I don't know how to keep track of everything. The game has no visuals, and i'm not sure how to make it work. :S I understand having a variable for the users position and one for the wumpus. In the version I have to make thankfully there are no bats or holes, but the wumpus does randomly move. I know how to do that.

I'm thinking that for shooting arrows (to kill the wumpus) I know what i'm doing. the user ends the command s+the direction key and the arrow shoots three spaces in that direction. Should I return a message saying you can't shoot in that direction if they're on the edge of the grid? I mean, that isn't an issue in the original since you only ever have three directions to go, so you never have that fourth possibility. :S Anyways here's my first problem now that i think about it.

The arrow moves three spaces, so how to keep track of whether the wumpus was in each room? Perhaps have the arrow move one room at a time? like you choose command sN. So the arrow moves one room north of you, checks to see is the value of arrow = wumpus. If it does declare the wumpus is dead. If the two don't equal move on to the next room, and likewise onto the next? I could use a counter to keep track of the rooms maybe? :S pardon my probably wrong coding buy i'm just thinking atm not coding...so yeah, here's my little mental attempt at this arrow issue. I forget how if statements work >_>;;; which is bad...but yeah.

code:

if(arrowX = wumpusX and arrowY = wumpusY)
{
System.out.println ("You hear the wumpus scream out horribly and collapse onto the ground");
}
else
{
arrow(Y or X) (++ or --)
}

Would that kind of work? :S An issue I see with that is that i'd have to remake it for each direction and that'd take up a lot of space...plus should that be placed in a while loop or something? I mean, repeating that three times seems inefficient but I haven't coded in a while to be honest and i'm struggling to remember how it'd work. a while loop that counts to three? with simply that code in it per direction? Or would it only repeat twice >_>;; blah! I need to review this.

I also just realised that in the original you can hit yourself. I.e. you shoot and if you go off the screen, it's comes out the other side...like how it is with the pipes in pacman. Do you think I should make the code like that? It'd be a bit harder then simply negating the move...but yeah.

Let's see what else I have to do...displaying the amount of arrows is simple, display directions, statements saying what you're doing....hm. When you're within one square of the wumpus, two and three you get a specific message. So, to do that I'd presume you check wumpus(x or y) +1, +2, +3 etc. Looking at this problem it's the same as the arrow thing almost right?

code:

if (wumpusX= playerX and wumpusY = playerY and turn = 0 and living=false //living is true when the wumpus is alive and false when the wumpus is dead
    {
        System.out.println ("The carcass of the Wumpus lies on the ground.")
     }
if (wumpusX= playerX and wumpusY = playerY and turn = 0) // turn 0 is the players movement
    {
        System.out.println ("The Wumpus catches you and dismembers you!")
     }
if (wumpusX= playerX and wumpusY = playerY and turn = 1) // turn 1 is the wumpus' movement
    {
        System.out.println ("The Wumpus eats you!")
     }
if (wumpusX+1= playerX or wumpusx-1 = playerX)
    {
        System.out.println ("You can smell the putrid breath of the Wumpus!")
     }
if (wumpusY-1= playerY or wumpusY-1 = playerY)
     {
       System.out.println ("You can smell the putrid breath of the Wumpus!")
     }
if (wumpusX+2= playerX or wumpusx-2 = playerX)
     {
          System.out.println ("You can hear the Wumpus slouching nearby!")
      }
if (wumpusY-2= playerY or wumpusY-2 = playerY)
     {
         System.out.println ("You can hear the Wumpus slouching nearby!")
      }
if (wumpusX+3= playerX or wumpusx-3 = playerX)
     {
        System.out.println ("You can sense the Wumpus lurking nearby!")
     }
if (wumpusY-3= playerY or wumpusY-3 = playerY)
    {
       System.out.println ("You can sense the Wumpus lurking nearby!")
     }
else
    {
       //left blank this would imply nothing happens right?Right (I hope).
     }


Hm? I mean, it's big and clunky, but i'm not sure how else to do it. It's a different message based on how far away you are, and I don't want to do anything overly complicated here. It's a basic project so it should be kept relatively basic Razz

Erm...and I think that's all I have to say. I know it's a lot but i've been thinking things through as i type, and surprisingly there is A LOT of issues I had that I haven't posted here because writing them out, trying to explain and give potential idea like this, as though talking to another person helped me think up new solutions. Very Happy Erm I think actually I have one more issue! Yes it's a lot I'm asking here, but I need to work on this asap Razz so i get get it all done and worked out sooner rather then later.

My last issue is less related to the game details so much as over all. The game continues to play until either the player find the gold in the maze (which is randomly placed, and once player values = gold values some variable will be set to true) and the player returns to the starting point and the game ends, the wumpus kills you, or you quit. How would I go about doing that? Razz I kind of left my largest problem for last. I mean, it's great if I can make the game, but I need to figure out how to have it continually repeat. So if the player enters q to quit, or dies, or wins it'll ask them if they want to play again, and they enter y or n. then either the game ends, or it repeats. I'm not sure how to do that anymore. I remember in turing I would of had a loop, with the instructions etc, and once they wanted to play it'd take them into the 'game' loop. Then when they die or win it'd exit the game loop, and ask them if they want to play again or not. If they want to it loops to the top, and if they want to stop playing it'd exit that loop as well.

:S Is it the same in java? If so what kind of loops am I using? :S while's? and what would the exit command be? :S

That is officially all I have to say on this topic! I have nothing left to ask or toss at you for comments / opinions. Whether I get replies to this or not, and whether they're positive or negative doesn't matter. I'd really like positive comments >.>; but just taking the time to write everything out and really truly think everything through cleared up a lot of things, and hopefully the issues i still have can be fixed with your help! Razz Sorry for the MASSIVE post >.>;;;;; if any of you actually read the entire thing I thank you and will bake you a fresh batch of cookies! >>; course unless you're in toronto you'd never get them...but still!

Edit: Oh and yes i know you can't use the word 'and' >> you can use || instead though. ^^; just thought i'd mention I know that O.o;;; now that i'm writing it up I know it
Sponsor
Sponsor
Sponsor
sponsor
Aziz




PostPosted: Sun Oct 28, 2007 12:36 pm   Post subject: RE:Creating Hunt the Wumpus....need help in a variety of areas. :S

Didn't read the whole post since I don't have time, but try viewing the source of that page you posted. It's got the javascript code, which can help you out.

Also, || is or, and && is and, while ! is not
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: