Friday, 24 August 2012

Who wants to be a Millionaire

This is a funny game, I have never won yet. I made it in Rebol and a get the questions database from internet:

Here the source code:
Rebol [
    title: "Who wants to be a Millionaire"
    Author: "Massimiliano Vessi"
    Email: maxint@tiscali.it
    Date: 24-Aug-2012
    version: 1.0.2
    file: %millionaire.r
]
random/seed now
if not exists? %millionair_files/ [make-dir   %millionair_files/ ]
cd %millionair_files/
if not exists? %highscores.txt [save %highscores.txt   [] ]
hscores: load %highscores.txt
requestedfiles: [%questions.csv   %logo.jpg ]
foreach item requestedfiles [
    if not exists? item [      
        request-download/to rejoin [http://www.maxvessi.net/rebsite/millionaire/ to-url item]   item
        ]
    ]
csv-import: func [
    "Import a CSV file transforming it in a series."
    file [file!] "CSV file"
    /local temp temp2 temp3 temp4
    ] [
    temp: read/lines file
    temp2: copy []
    foreach item temp [
    temp3: copy []  
    parse item   [{"} copy temp4 to {","} (append temp3 temp4) some [ thru {","} copy temp4 to {","} (append temp3 temp4)] thru {","} copy temp4 to {"} (append temp3 temp4)   ]
    append/only temp2 temp3
    ]  
    return temp2    
    ]
   
questions: csv-import %questions.csv
;editor questions
;question CSV is organized this way:
;"questionID","body","a","b","c","d","correct","level"
;now I organize question fo level
;creating quetion1, quetion2, ..., question15 blocks
for i 1 15 1 [
    set (to-word join "question" i ) copy []        
    foreach item questions [
        if (last item) = (to-string i) [   ;it's the level requested
            append/only (get to-word join "question" i ) item
            ]
        ]
   
    ]
;print question1

;starting level
level: 1
;extraction function
q_extr: func [/local tmp] [
    ; mix and extract a question for the current level
    q: copy random get to-word join "question" level
    ;let create the question and the set of answers
    bodyq: q/1/2
   
    qq: reduce [q/1/3 q/1/4 q/1/5 q/1/6   ]
    ;let's find the correct answer
    tmp: (to-integer q/1/7) + 2 ; the first answer is in position 3 in the block
    correct:   q/1/:tmp  
    qq: copy random qq  
    ]
q_extr
higscoreslay: layout [
    title "HIGH SCORES"
    table-hs: text-list data hscores
    btn-cancel [unview]
    ]
view layout [
    style buttona button [      
        either face/text = correct [
            temp:   get to-word join "a" level
            temp/color: green
            ++ level    
            either   level > 15 [
                Alert "You win € 1'000'000. You are a millionaire!"
                name: request-text/title "Please insert your name"
                append/only hscores reduce [ (level - 1) " " name ]
                sort hscores
                reverse hscores
                save %highscores.txt hscores                
                view/new higscoreslay
                level: 1
                q_extr
                the_q/text: bodyq
                aa/text: qq/1
                bb/text: qq/2
                cc/text: qq/3
                dd/text: qq/4
                a1/color:   a2/color:   a3/color:   a4/color:   a5/color:   a6/color:   a7/color:   a8/color:   a9/color:   a10/color:   a11/color:   a12/color:   a13/color:   a14/color:   a15/color:   167.173.201
                show [the_q aa bb cc dd   a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15]                
                ] [
                    q_extr
                    the_q/text: bodyq
                    aa/text: qq/1
                    bb/text: qq/2
                    cc/text: qq/3
                    dd/text: qq/4                      
                    show [the_q aa bb cc dd temp]
                    ]
            ] [
                alert "You lost"  
                ;put high score
                name: request-text/title "Please insert your name"
                append/only hscores reduce [ (level - 1) " " name ]
                sort hscores
                reverse hscores
                save %highscores.txt hscores                
                view/new higscoreslay
                level: 1
                q_extr
                the_q/text: bodyq
                aa/text: qq/1
                bb/text: qq/2
                cc/text: qq/3
                dd/text: qq/4
                a1/color:   a2/color:   a3/color:   a4/color:   a5/color:   a6/color:   a7/color:   a8/color:   a9/color:   a10/color:   a11/color:   a12/color:   a13/color:   a14/color:   a15/color:   167.173.201
                show [the_q aa bb cc dd   a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15]
                ]
        ]
          across
    title   "Who wants to be a Millionaire"
    return
    panel [
        across
        image   150x90 (load-image %logo.jpg)
        panel [
            buttona "Restart"
            button "High scores" [view/new higscoreslay ]
            button "Help" [notify   {Push the button with the solution to the given question. Try to solve all 15 questions.
                If you need to contact me, my email is maxint@tiscali.it}
]
            ]
        return
        h3 red 300 center   "Question:"
        return
        the_q: text center middle   300x100 bodyq
        return
        bar navy 310
        return
        aa: buttona 150x70   qq/1
        bb: buttona 150x70   qq/2
        return
        cc: buttona 150x70   qq/3
        dd: buttona 150x70   qq/4
        ]
    panel 167.173.201 [
       
        a15: text "€ 1'000'000"
        a14: text "€ 300'000"
        a13: text "€ 150'000"
        a12: text "€ 70'000"
        a11: text "€ 35'000"
        a10: text "€ 16'000"
        a9: text "€ 8'000"
        a8: text "€ 4'000"
        a7: text "€ 2'000"
        a6: text "€ 1'000"
        a5: text "€ 500"
        a4: text "€ 300"
        a3: text "€ 200"
        a2: text "€ 100"
        a1: text "€ 50"    
        ] edge [size: 2x2 color: navy]  
    ]

6 comments:

  1. ++ level -> level: level + 1

    ReplyDelete
  2. I DON’T WANT YOU GUYS TO MADE THE SAME MISTAKE I MADE, THAT IS WHY I AM SHARING THIS TO ALL MY FRIENDS OUT THERE: YOU MUST BE CAREFUL HERE OF SCAM, MOST OF THE COMMENT ABOUT JOINING ILLUMINATI ARE FAKE, I WAS RECENTLY SCAM BY 3 PEOPLE CLAIMING TO BE ILLUMINATI AGENT. I LOST OVER $3800 UNTIL A FRIEND DIRECTED ME TO A REAL AGENT PLEASE, I WAS GIVEN $ MONEY PAD ($50,000 EVERY 3 DAYS) IF YOU WANT TO BE A MEMBER OF ILLUMINATI QUICKLY, Contact Prof. Theo the illuminati communications centre at: Whatsapp: +2348147017594, or call: +2348034453159. EMAIL: illuminatiworldwideuk@gmail.com or illuminaticommunicationcentre@gmail.com or
    Kindly visit: http://newyork.chaosads.com/item/422684/ or illuminatiworldwideuk.wordpress.com you can contact our new head office in USA because our head office is no longer in UK, we are now located In USA for confirmations email our HEAD OFFICE on: nationwidepriest@gmail.com

    ReplyDelete

  3. JOIN THE GREAT ILLUMINATI BROTHER HOOD TODAY AND LIVE A BETTER AND HAPPY LIFE. WELCOME TO THE GREAT TEMPLE OF RICHES AND FAME. Are you a business, Man, politician, musical, student and you. want to be rich, powerful and be famous in life. You can achieve your dreams by being a member of the Great illuminati brother hood. With this all your dreams and heart desire can be fully accomplish, if you really want to be a member of the great illuminati brother hood, contact the Lord illuminati now, Note: newly recruited members are entitled with 3million US Dollars , A Golden Ring, that will protect and guild you from enemies, and a free visa to United State Of America . Please will do not share blood. Do not miss this opportunity. Call and be rich Now or whatsApp. ¡¡¡ Lordmarshall : +2349033537093 Or email me now on: illuminatibrother71@gmail.com or WhatsApp us for fast via: +2349033537093

    ReplyDelete
  4. I am giving a testimony of how i become rich and famous today, i was deeply strangled up by poverty and i had no body to help me, and also i search for help from different corners but to no avail… i see people around me getting rich but to me i was so ashamed of my self so i met a man on my way he was very rich and he was a doctor so he told me something, that if i would like to join the illuminati brotherhood, and i think over it though out the day so the next day i looked up and i keep repeating what he said to me, and i make up my mind to join the illuminati, today i am so proud of myself, because i am a great man today, well know in the world, rich, famous so if you are also interested to join the illuminati, you are free to join, if you live in America it is free to join the illuminati brotherhood temple, you have to email: churchofdevilinitiationcenter@gmail.com call or text +15084434778 join the illuminati today and enjoy good life with you and your generation.

    ReplyDelete
  5. I am giving testimony, on how i become successful in life, I want to say a big thanks to the illuminati brotherhood, that make me what i am today, hails to the illuminati brother, i was deeply strangled up by poverty, because i have know one to help me achieve my goal in life, i have worked so hard to make it in life, i have done so many things in life, just to make it and live a happy life with my family, and also i search for help from different corners but to no available, i was so ashamed of myself because i see things getting bad everyday, i do not know what to do next i was just thinking about my life, i see people around me getting rich but to me, i get poor everyday of my life, i start to think of what to do next just to get rich and live a good life, one day i think of going for research in google, and i say how many people giving testimony on how church of devil illuminati helped then to get rich and famous, so i think of joining the church of devil illuminati so that i can also get rich and be famous in life, because i was tired of been poor people around me see me as nobody, no one do respect me because i was poor, so i make up my mind and decide to join the church of devil illuminati, to my own believe i see my life changed for good, i am so proud of myself, i am a great man today, well know in the world, rich, famous, i want to tell the whole world today that the illuminati brotherhood can also change your life, if you have the same problem i was having in life, so if you are also interested to join the illuminati, you are free to join, if you live in America it is free to join the illuminati brotherhood, you have to email: churchofdevilinitiationcentre@gmail.com call or text +12545227022 join the illuminati brotherhood and enjoy good life with your family.

    ReplyDelete