Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 3 [4] 5 6

Author Topic: Astronaut text based game (Python)  (Read 8549 times)

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #45 on: January 17, 2011, 12:36:44 pm »

Spoiler (click to show/hide)

This will do for today, I'm well on my way now.
   
   
Changes:
Found and error in the date change. qt should be reset to 0 not 1. Fixed.
« Last Edit: January 17, 2011, 12:39:31 pm by Deadmeat1471 »
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Astronaut text based game (Python)
« Reply #46 on: January 17, 2011, 04:11:36 pm »

You're encoding a lot of information in your program via numbers, for example the different actions taken or if the player is still alive. The problem with this is that if you're going to return to your code after a leave of some weeks, you're going to be scratching your head about what all numbers mean. To combat this, the best way is to either define several variables holding those numbers (with sensible names of course) and refer to the variables instead of the numbers, or you define an object for each different kind of number you can have, like this:
Code: [Select]
class MenuOptions
    rest = 1
    practice = 2
And make a new MenuOptions object, for example Menu. Then the numbers will be stored in Menu.rest, Menu.practice et cetera. (The numbers are automatically set to the values you supplied in the class description). Advantage to this method is that you can change the values if needed (don't do that unless you're dead-sure you want to), but it takes a little more work.
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #47 on: January 18, 2011, 02:23:37 am »

At first I didnt like how id have to rewrite some into functions, but I think i'll do this suggestion first, as it would be helpful in the long run. Though, i'll keep rewrites to a minimum. This is the first program i am certain I can finish with the knowledge I already have. I want to get it done! even if I do massive rewrites later.
« Last Edit: January 18, 2011, 02:29:59 am by Deadmeat1471 »
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #48 on: January 18, 2011, 06:18:57 am »

Did a testrun on the OIB calculation and bugfix of my errors. This will be the basis of every stage of every mission, they will follow the same format for the most part. This is probably all I'll get done today as i'm busy. But its some good progress.

http://snipt.org/wkooj

I'm going to think about making a class to streamline mission calculation. Something along the lines of:
Code: [Select]
class stage(oib, tli, etc):
               

Maybe even turning the mission resolution into a function instead of a 'while' loop.

Changelog:
Spoiler (click to show/hide)

(This format thinking may be obvious to you guys, but i'm learning as I go here, and the process is going well  :D)



what I get is...

Code: [Select]
Performing orbital insertion burn
.
.
.
Orbital insertion burn successful
#this is end of the mission stage#
Splashdown! mission complete.
#this is completion of all stages#

Once this is ironed out, ill be adding seperate descriptions of failures. Instead of simply 'launch failure', it would be either something like, rocket ignition failed to fire, targeting computer malfunctioned, burned up in the atmosphere etc.
Thinking of this I will definitely put the stages inside a function, I will be using it multiple(many many) times.
« Last Edit: January 18, 2011, 06:50:23 am by Deadmeat1471 »
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #49 on: January 18, 2011, 07:08:07 am »

Just wanted to celebrate, added my first sound to programming yay! intro music from BARIS as a test.


Onto the first sound problem!
If anyone knows, how do I get this to stop? it basicly plays just the sound but doesnt run the program! Just wanted to see if I could get some sound in for future reference.

Spoiler (click to show/hide)

What I wanted was intro music, which could be skipped by pressing any key etc.
« Last Edit: January 18, 2011, 07:38:21 am by Deadmeat1471 »
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #50 on: January 19, 2011, 07:49:22 am »

Am working on the astronaut selection now.

I am trying to make the program pick from the list of cosmonauts the highest skilled.

Code: [Select]
Gagarin = ['Gagarin', 3, 1, 1, 1, 1]
Titov = ['Titov', 2, 1, 1, 1, 1]
Nikolayev = ['Nikolayev', 2, 1, 1, 1, 3]
Popovich = ['Popovich', 2, 1, 1, 2, 3]
Bykovsky = ['Bykovsky', 2, 2, 2, 2, 3]
Tereshkova = ['Tereskova', 0, 1, 1, 0, 1]
Player = ['Player', 1, 1, 1, 1, 1]

Cosmonaut = [Gagarin, Titov, Nikolayev, Popovich, Bykovsky, Tereshkova, Player]

I know a long way to do this - I could make it look over each cosmonaut one at a time comparing it to all the others and choosing the one whom is greater/equal to all the rest.

im trying to think of a loop like code around the lines of...

Code: [Select]
while Cosmonaut[>1] ##I dont know how to make it count the number of 'listsoflists' if thats even possible##
        crewsel = '-1'
        if cosmonaut[crewsel + 1][1] > cosmonaut[1][1]
        del cosmonaut[1]

Anyone know how to do this?
« Last Edit: January 19, 2011, 07:51:54 am by Deadmeat1471 »
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #51 on: January 19, 2011, 08:31:56 am »

Current selection system so far:


Code: [Select]
##Vostok crew##
Gagarin = ['Gagarin', 3, 1, 1, 1, 1]
Titov = ['Titov', 2, 1, 1, 1, 1]
Nikolayev = ['Nikolayev', 2, 1, 1, 1, 3]
Popovich = ['Popovich', 2, 1, 1, 2, 3]
Bykovsky = ['Bykovsky', 2, 2, 2, 2, 3]
Tereshkova = ['Tereskova', 0, 1, 1, 0, 1]
Player = ['Player', 3, 1, 1, 1, 1]

Cosmonaut = [Gagarin, Titov, Nikolayev, Popovich, Bykovsky, Tereshkova, Player]



crewchosen = ''
check = 'checking'
while check == 'checking':
    one = Cosmonaut[0][1]
    two = Cosmonaut[1][1]
    three = Cosmonaut[2][1]
    four = Cosmonaut[3][1]
    five = Cosmonaut[4][1]
    six = Cosmonaut[5][1]
    seven = Cosmonaut[6][1]


    if one >= two:
        check = 'finished'
        if one >= three:
            if one >= four:
                if one >= five:
                    if one >= six:
                        if one >= seven:
                            crewchosen = Cosmonaut[0][0]

    if two >= one:
        if two >= three:
            if two >= four:
                if two >= five:
                    if two >= six:
                        if two >= seven:
                            crewchosen = Cosmonaut[1][0]

    if three >= one:
        if three >= two:
            if three >= four:
                if three >= five:
                    if three >= six:
                        if three >= seven:
                            crewchosen = Cosmonaut[2][0]

    if four >= one:
        if four >= two:
            if four >= three:
                if four >= five:
                    if four >= six:
                        if four >= seven:
                            crewchosen = Cosmonaut[3][0]

    if five >= one:
        if five >= two:
            if five >= three:
                if five >= four:
                    if five >= six:
                        if five >= seven:
                            crewchosen = Cosmonaut[4][0]

    if six >= one:
        if six >= two:
            if six >= three:
                if six >= four:
                    if six >= five:
                        if six >= seven:
                            crewchosen = Cosmonaut[5][0]

    if seven >= one:
        if seven >= two:
            if seven >= three:
                if seven >= four:
                    if seven >= five:
                        if seven >= six:
                            crewchosen = Cosmonaut[6][0]

   


    print crewchosen
« Last Edit: January 19, 2011, 08:55:38 am by Deadmeat1471 »
Logged

Frajic

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #52 on: January 19, 2011, 09:05:54 am »

Code: [Select]
best = 0
for cosmonaut in Cosmonaut:
    if cosmonaut[1] > best:
        best = cosmonaut
A "for" loop goes through each of the entries in a tuple/list/dictionary. And please, using objects is much more practical than lists, just for the fact you can refer directly to their names.
Logged
EoS company name: Vikings Inc.

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #53 on: January 19, 2011, 09:09:09 am »

hm ill have to look into that further, until then I have a crude workaround with partially works. (It will pick the last best, one in the list)

Spoiler (click to show/hide)
   
   
The latest code. Added the astronaut selection + some minor changes.

*note to self. Add crewcheck end.
« Last Edit: January 19, 2011, 09:19:41 am by Deadmeat1471 »
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #54 on: January 19, 2011, 09:16:35 am »

Code: [Select]
best = 0
for cosmonaut in Cosmonaut:
    if cosmonaut[1] > best:
        best = cosmonaut
A "for" loop goes through each of the entries in a tuple/list/dictionary. And please, using objects is much more practical than lists, just for the fact you can refer directly to their names.

I fiddled with objects, but wasnt quickly able to turn that into something more useful than a list with the selection process. (Amaturism :D)
Logged

Frajic

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #55 on: January 19, 2011, 09:42:45 am »

Fiddled around with your code a bit. It's slightly less clunky; fixed a bug(you put the end-turn stuff in the practice choice), some typos, and removed unnecessary loops(especially the skill-find one). Of course, I did this only for fun. You're free to use whatever code you want to.
Spoiler (click to show/hide)
Logged
EoS company name: Vikings Inc.

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Astronaut text based game (Python)
« Reply #56 on: January 19, 2011, 09:54:10 am »

Quote
Code: [Select]
if choice == '4':
            print 'Your skills are\n'
            [...]
##rest##
        elif choice == '1':
/fixed

Gonna read it more thoroughly, but that one was pretty obvious right now. Everything else seems ok so far.

Quote
Code: [Select]
while True:
    time.sleep(2)
Uh, isn't True always, well, true?

Quote
Code: [Select]
##BEGINNING OF ROSTERS##

##mercury 7##
Shirra = [2, 1 , 1, 1, 1, 100]
Glenn = [1, 1, 1, 0, 1, 100]
Grissom = [3, 1, 1, 1, 1, 100]
Cooper = [2, 1, 1, 1, 3, 100]
Shepard = [1, 1 ,1 ,1 ,2 , 100]
Slayton = [4, 1, 1, 0, 1, 100]
Carpenter = [1, 0, 1, 0, 2, 100]
Player = ['Player', 3, 1, 1, 1, 1]

Astronauts = [Shirra, Glenn, Grissom, Cooper, Shepard, Slayton, Carpenter, Player] + [name]

##Vostok crew##
Gagarin = ['Gagarin', 3, 1, 1, 1, 1]
Titov = ['Titov', 2, 1, 1, 1, 1]
Nikolayev = ['Nikolayev', 2, 1, 1, 1, 3]
Popovich = ['Popovich', 2, 1, 1, 2, 3]
Bykovsky = ['Bykovsky', 2, 2, 2, 2, 3]
Tereshkova = ['Tereskova', 0, 1, 1, 0, 1]
Player = ['Player', 3, 1, 1, 1, 1]

Cosmonaut = [Gagarin, Titov, Nikolayev, Popovich, Bykovsky, Tereshkova, Player]
Question, why are these rosters so different?
« Last Edit: January 19, 2011, 09:59:46 am by Darvi »
Logged

Frajic

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #57 on: January 19, 2011, 10:02:36 am »

Quote
Code: [Select]
while True:
    time.sleep(2)
Uh, isn't True always, well, true?
See this part?
Code: [Select]
    if nationchoice == 'Cosmonaut' or nationchoice == "cosmonaut":
        break
    elif nationchoice == 'Astronaut' or nationchoice == "astronaut":
        break
"break" is a function that breaks the current loop. That way, you can end it without editing the loop conditional. If you have several loops in one loop(bad wording but w/e), it's the latest loop that gets broken.
« Last Edit: January 19, 2011, 10:08:49 am by Dwarf Midget »
Logged
EoS company name: Vikings Inc.

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Astronaut text based game (Python)
« Reply #58 on: January 19, 2011, 10:05:20 am »

Quote
Code: [Select]
while True:
    time.sleep(2)
Uh, isn't True always, well, true?
See this part?
Code: [Select]
    if nationchoice == 'Cosmonaut' or nationchoice == "cosmonaut":
        break
    elif nationchoice == 'Astronaut' or nationchoice == "astronaut":
        break
"break" is a function that breaks the current loop. That way, you can end it without editing the loop conditional. If you have several loops in one loop, it's the latest loop that gets broken.
'k, thanks. *makes mental note. then misplaces it*
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Astronaut text based game (Python)
« Reply #59 on: January 19, 2011, 10:23:38 am »

Quote
Code: [Select]
##BEGINNING OF ROSTERS##

##mercury 7##
Shirra = [2, 1 , 1, 1, 1, 100]
Glenn = [1, 1, 1, 0, 1, 100]
Grissom = [3, 1, 1, 1, 1, 100]
Cooper = [2, 1, 1, 1, 3, 100]
Shepard = [1, 1 ,1 ,1 ,2 , 100]
Slayton = [4, 1, 1, 0, 1, 100]
Carpenter = [1, 0, 1, 0, 2, 100]
Player = ['Player', 3, 1, 1, 1, 1]

Astronauts = [Shirra, Glenn, Grissom, Cooper, Shepard, Slayton, Carpenter, Player] + [name]

##Vostok crew##
Gagarin = ['Gagarin', 3, 1, 1, 1, 1]
Titov = ['Titov', 2, 1, 1, 1, 1]
Nikolayev = ['Nikolayev', 2, 1, 1, 1, 3]
Popovich = ['Popovich', 2, 1, 1, 2, 3]
Bykovsky = ['Bykovsky', 2, 2, 2, 2, 3]
Tereshkova = ['Tereskova', 0, 1, 1, 0, 1]
Player = ['Player', 3, 1, 1, 1, 1]

Cosmonaut = [Gagarin, Titov, Nikolayev, Popovich, Bykovsky, Tereshkova, Player]
Question, why are these rosters so different?
[/quote]

Gah, I did the cosmonauts in a seperate pad while I was testing, forgot to add the 'moral' statistic! Thanks for the spot!

@Dwarf Thanks for the edits! I'm going to read through them carefully and compare to what I did, so I dont do the same in the future. I need to look at that selection code, I just cant get my head around it ;)

Code: [Select]
                   vostok1crew = Cosmonaut[0][1]
                   
            for cosmonaut in Cosmonaut:
                if cosmonaut[1] > vostok1crew:
                    vostok1crew = cosmonaut[1]

for ?cosmonaut?? in Cosmonaut:
     if ??cosmonaut?? ??number 1?? > vostok1crew:
              vostok crew being ??cosmonaut number 1??
« Last Edit: January 19, 2011, 10:38:25 am by Deadmeat1471 »
Logged
Pages: 1 2 3 [4] 5 6