1 / 19

Programming games

Programming games. Reprise on dice game and alternative dice game Homework: [Catch up.]. Finish dice game. Staged implementation. Throw 1 die Throw 2 dice Throw 2 dice and get sum Show sum Do rules of craps NOTE: you will be adding code into the dthrow function (inside the brackets).

preston
Télécharger la présentation

Programming games

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming games Reprise on dice game and alternative dice game Homework: [Catch up.]. Finish dice game.

  2. Staged implementation Throw 1 die Throw 2 dice Throw 2 dice and get sum Show sum Do rules of craps NOTE: you will be adding code into the dthrow function (inside the brackets)

  3. Incremental development Do practice writing outlines as just shown. Get small parts of project working Follow suggestions in the tutorials and Follow this practice for your own projects. You may divide tasks differently.

  4. Faces examples First example, faces is a list of character strings representing names of image files. Second example, faces is a list of image elements. To get the name of the image file, the code needs to bedocument.dicea.src = faces[choice].src; TWO EXAMPLES IN TUTORIAL ARE DIFFERENT…. TO SHOW YOU DIFFERENT WAYS OF DOING THINGS….

  5. Testing • You test the program to see if it works correctly! • This means you as the player win and lose! • Because of the pseudo-random feature (aka stochastic processing), testing takes time…many cases.

  6. Work session Catch up and show us: sites, coin toss, biased coin, drawings, alternative coin toss Work on dice game If you have completed dice game, do alternative dice game OR add feature(s) Add (more) graphics Display different message depending on situation Keep score and show it using an alert statement or form variable (May take knowledge/research): add field for entering value of bet.

  7. Extra credit posting opportunity What are the chances of winning on a first move? What are the chances of losing? What are the chances of needing followup moves? For each possible point value, what are the chances of winning, losing, needing to continue?

  8. Recap: Dice game Game logic implemented using if statement and switch statements Game rules require global variables to hold state information: information persisting between throws Arrays: sequences of things (names of files or img elements) Indexing starts at 0

  9. Reflection on dice game Logic: switch statements in clauses of if/else statements Global variables holding state of the game first move or follow-up point value (only has significance if follow-up) Display using graphics and text Implement in stages!!!! Need to test all possibilities not test until you win….

  10. Reflect and Continue • Storage of standard things (e.g., numbers) solved but representation of information for specific problems is / will be new challenge • Now on to representation of formulas and logic. • Closed form – mathematical formula – easy to represent in code • Algorithm, logic, may require use of conditionals, more… • Models: build computer model = representation of something, some phenomenon. NOT simple (closed form) formula, but involving programs…

  11. Alternative dice game • Remove the need for image files by drawing the die faces. • http://faculty.purchase.edu/jeanine.meyer/html5/craps.html • examine code

  12. Calling pattern • throwdice function sets up dx and dy for each die and calls • drawface(n) • uses a switch statement to determine what to do, namely single or combination from a set of functions.

  13. switch(n) { case 1: draw1();break; case 2: draw2();break; case 3: draw2();draw1();break; case 4: draw4();break; case 5: draw4();draw1();break; case 6: draw4();draw2mid();break; }

  14. draw2 function draw2() { var dotx; var doty; ctx.beginPath(); dotx = dx + 3*dotrad; doty = dy + 3*dotrad; ctx.arc(dotx,doty,dotrad,0,Math.PI*2,true); dotx = dx+dicewidth-3*dotrad; doty = dy+diceheight-3*dotrad; ctx.arc(dotx,doty,dotrad,0,Math.PI*2,true); ctx.closePath(); ctx.fill();}

  15. Exercise • Take one of the choices for the switch statement and be able to explain how it works. • Choose different colors and make it do what you want!

  16. How many files…. • original coin toss • alternative coin toss • original dice game • new dice game (draw the faces)

  17. Comparison of two dice games? • Using image files means…you can use fancy image files. • Not using image files means that this application is just the one html file. • Speed? Downloading of image files versus drawing. The downloading time is not repeated. • ?

  18. Enhancements • Adding other images. • Adding a bankroll feature. • start with a certain amount, say 100 and • at each game (first throw), decrease this by 10. • at each win, increase by 20. • Display this amount in a new input field in the form. • Comment: this is appropriate method of scoring for this type of game! How to score varies and can be subjective.

  19. Homework • [catch up] • Complete dice game. • You can do html5 drawing on canvas version for extra credit. • You can enhance the game • Keep up with uploading applications and updating your index file. • Choose / invent appealing names

More Related