McGill Mini Assignment #7 COMP 206Vybihal School of Computer Science Page 1 of 7CGI and Basic Web InterfacingDue: December 3, 2019 on myCourses at 23:55Lab J will provide some background help for this mini assignment.Week 10, slides 28 to 44 will help you with CGI development.YOU CAN WORK IN A TEAM OF TWO, if you want, for this assignment. Both teammates will hand in the same files.QUESTION: Web GameWe will build a simple multi user web dungeon crawler-like game.You or your team must build it cooperatively with your classmates.You can only use HTML, CGI and C. No CSS. No JS, etc.The goal of the game will be to get 100 gold pieces.You start the game with 10 gold pieces.Each dungeon room you enter results in a win of 10 gold pieces or a loss of 5 gold pieces.You will gain or lose gold by engaging in a Q/A activity. Each room will have either asingle COMP206 question or a single Zelda question. If the player answers correctlythey get 10 gold pieces. If they answer incorrectly, they lose 5 gold pieces. When youcannot pay, you die. When you get 100 gold pieces, you win.This is an equal opportunity dungeon, so you can start from any room. Simply type theURL of anyone’s room to start the game. Your room does not need to be pretty. It onlyneeds to be functional. If you want to make it pretty, then please go ahead, but stick toHTML, CGI and C. Have fun with this.Each room is responsible to (1) show a question, (2) a picture, (3) be able to process theuser’s response to the question, (4) award 10 gold or (5) remove 5 gold, (6) display howmuch gold the user has, (7) display a DIE and (8) WIN message.Each room will have a textbox input field and a submit button. In that textbox the usercan either answer the question posed by the room to win 10 gold pieces or lose 5 goldpieces, or they can input a command. Valid commands are: NORTH, SOUTH, EAST,WEST, or GOLD. Each of the directions is connected to another classmate’s room. Thismeans that your room must connect to four other rooms. If we do this right, a player willbe able to travel to all 250-500 rooms. You only need to make sure that your roomconnects to four other rooms.Once the user has 100 gold they win. When a user presses submit with 0 gold a losemessage is automatically displayed. If the user has some gold, even 1 gold piece, thegame validates the attempt. If the person got it correct, then they get 10 more gold pieces,otherwise they lose 5 gold pieces. If they do not have enough gold pieces to pay for theloss, then they automatically die.McGill Mini Assignment #7 COMP 206Vybihal School of Computer Science Page 2 of 7This is what you need to do:STEP 0 – The public_html directoryLab J shows you how to create the public_html directory. Please do this.You will need to create four files: index.html, answers.c, addgold.c and a picture.The index.html file will be your dungeon room. The rest of the files are describedbelow.STEP 1 – Build the room using HTML and CGIYour dungeon room must look like this:You can center your NAME OF ROOM with the tag .To make the game more fun you must add at least one picture to your page. Usethe command:McGill Mini Assignment #7 COMP 206Vybihal School of Computer Science Page 3 of 7The tag displays a .gif or .jpg or .png file stored in your public_htmldirectory. Write the filename in the src=”filename” attribute and specify how bigyou want the picture to be using the height and width attributes.Then write the question. Possible tags you might want to use are: bold,underline.Then write the instruction: “Please type NORTH, SOUTH, EAST, WEST, GOLD,or answer the question.”All the initial interaction with the room will be through the textbox and submitbutton. The player will need to enter one of the five commands NORTH, SOUTH,EAST, WEST, or GOLD, or provide the answer to the question in the textbox andthen press the submit button. Pressing the submit button will call the programanswer (from gcc -o answer answer.c) to process the player’s request.The commands NORTH, SOUTH, EAST, and WEST are movement commands.These commands cause the player to exit the room and enter another room. Youwill need to talk to four other teams in our class to get their room URL.The command GOLD will display the number of gold pieces the player currentlypossesses.The player will input their command in the textbox and then press the submitbutton. The submit button will call the program answer. This will beimplemented using the tag as covered in class. You may use either thePOST or GET method to communicate with the C program.Your web page can look basic and you will receive full marks.If you want to take the time to make it fun looking, then please do so.STEP 2 – The Submit button calls a C program called ./answerCreate a C program called answer.c and compile it to the executable answerusing gcc -o answer answer.c. This program receives two possiblestrings from your webpage. The first string is one of the five commands“NORTH”, “SOUTH”, “EAST”, “WEST”, or “GOLD” in all caps. The secondstring is the answer to the question. You will extract this string from the shellmemory if the form used GET or from STDIN if the form used POST (see lecturenotes). It is easiest to check for the command first. If the string is not a command,then it must be an attempted answer to the question.If the player input the word NORTH, SOUTH, EAST, or WEST, the program willprogrammatically generate a webpage that hyperlinks to another room. Reviewfrom the lecture notes how to printf() to the browser. You will need to dosomething like this:printf(“Press HERE to go North”);The above printf() will display on the browser a hyperlink. The player will simplyclick on the word Press HERE to go North with their mouse to cause the browser McGill Mini Assignment #7 COMP 206Vybihal School of Computer Science Page 4 of 7to change to another webpage. The HTML tag to link to another webpage is:TEXT TO CLICK. You will need to do this for eachdirection: NORTH, SOUTH, EAST and WEST.If the player input the word GOLD, the program will programmatically generate awebpage that displays the amount of gold pieces the player currently owns and ahyperlink to return the player bac代做COMP 206、代写C/C++程序语言、c++代做、代k to the current room.If the number of gold pieces is 0 or 100 the program must programmaticallygenerate a webpage that displays “YOU WIN” or “YOU LOSE” without ahyperlink to another webpage. The game is now over. This message can be basiclooking, or you can make it fun looking.STEP 3 – The URL and Gold PiecesProcessing the gold pieces is the hardest part of this assignment. It is probably agood idea to leave this to the end. Get steps 1 and 2 working without gold pieces.Once that works, then add the gold pieces.We need a special HTML tag to handle the gold pieces. Use:The input type “hidden” is an invisible input field. The user cannot see it. Theuser cannot interact with it. But you can programmatically manipulate it.Your index.html page should not have the hidden field at the beginning. Do notwrite it in your index.html file. When a user enters the game for the first time,they will do this by inputting a room URL into their browser to start the game.Your game will assume that a missing hidden field means that the user is startingthe game and will assume the player has only 10 gold pieces. So, your index.htmlfile should not contain a hidden field. This will be added later through theanswer.c program.When the user presses the submit button the CGI payload will look somethinglike this:http://URL/answer?command=NORTHorhttp://URL/answer?command=NORTH&gold=50The payload format will depend on the presence of the hidden field. In the firstcase the hidden field was not present, so we do not see a gold argument. In thesecond case the hidden field was present.When your program attempts to extract the gold argument from the payload anddoes not find it, the program will assume 10 gold pieces.When you hyperlink NORTH, SOUTH, EAST, WEST, or back to the currentpage, you will need to programmatically insert the hidden field with the correctamount of gold into the destination page. Unfortunately, you are not permitted to McGill Mini Assignment #7 COMP 206Vybihal School of Computer Science Page 5 of 7edit someone else’s webpage because it has been chmod read/execute only. Theway to get around this is for the owner of the room to provide a service program.Let us call this service program gcc -o addgold addgold.c. Instead ofthe hyperlinks from STEP 2 directing the player to the index.html page of the nextroom, the hyperlink will direct the player to the addgold program of the nextroom. The addgold program will display the webpage and insert the hidden fieldinto the webpage.The URL to the addgold program works like this:1. Assume my game webpage is at http://www.cs.mcgill.ca/~usernameThe player would type that URL at the browser to start the game.2. When the player presses the submit button (when they want to input acommand or answer the question) the form calls the following URL (let usassume the player wanted to go north):http://www.cs.mcgill.ca/~username/cgi-bin/answer?command=NORTH&gold=50(Note: all executable programs must be in subdirectory cgi-bin)3. The answer program will programmatically display a webpage with ahyperlink to the northern webpage using this URL:http://www.cs.mcgill.ca/~otherpage/cgi-bin/addgold?gold=504. The addgold program will display the room owner’s index.html page with thehidden field. We are now at step 2 and we can input a command on their page,which leads us to step 3, etc. until WIN or DIE.The addgold program does its magic in the following way:- It will fopen(“index.html”,”rt”) and fgets() each line and printf() each line ofthe file to the player’s browser.- When the printing comes to the tag, it inserts an extra printf() thatadds the gold. As in:printf(“value=\”%d\””, goldpieces);Note the following:o \” prints out the double quote. This is unfortunate but necessary in C.o I am assuming goldpieces is an integer and I am adding it into theoutput with the %d, but there are other ways to do this (maybe the goldwas still a string).- After the inserted line, it continues to read and write the index.html file untilthe entire file has been printed to the player’s browser. The addgold programterminates.- The player now sees the new webpage with the hidden gold tag. You havenow successfully passed a value from your website to the other website.That is it.The rest should be straight forward.McGill Mini Assignment #7 COMP 206Vybihal School of Computer Science Page 6 of 7Ask the prof or the TA for help.IMPORTANTYou must use mimi.cs.mcgill.ca to create the solutions to this assignment. You cannotuse your Mac command-line, Windows command-line, nor a Linux distro installedlocally on your laptop. You can ssh or putty from your laptop to mimi, or you can goto the third floor of Trottier and use any of those labs, to complete this assignment.WHAT TO HAND INEverything must be submitted to My Courses before the due date. Remember that youcan hand in your assignment up to two days late but there will be a penalty of 5% eachday. After that, your assignment will not be accepted. Please hand in the following:• A readme.txt file with the names and student ID numbers of your team• A game.html page with a so the TA can quickly go toyour game page.• The C files: answer.c and addgold.c• Do not hand in the executable• Zip only the C files.• Make sure to add comments to your C program.• Add your name and student ID number as a comment.HOW IT WILL BE GRADEDThe TA will click on the hyperlink from game.html to go quickly to your home page.POINTS AWARDEDThe assignment is worth a total of 20 points.o Question• 2 points – follow instructions• 5 points – STEP 1• 5 points – STEP 2• 5 points – STEP 3• 3 points – WIN and LOSE conditionMcGill Mini Assignment #7 COMP 206Vybihal School of Computer Science Page 7 of 7GRADING RULESThe following rules are followed by the TA when grading assignments:• A program must run in order to get a grade (even if it does not run well). If itdoes not run (does not compile) it will receive a zero. (Make sure to run yourprograms from mimi.cs.mcgill.ca).• The TA will grade using the mimi.cs.mcgill.ca server.• All questions are graded proportionally. This means that if 40% of the question iscorrect, you will receive 40% of the grade.转自:http://www.6daixie.com/contents/13/4482.html