SlideServe
Menu
Préférences
© SlideServe · v2026

GBK Programming 2 2009-10

aradia avatar
15 diapositives · 331 Views · Jul 18, 2014

GBK Programming 2 2009-10. Jordan Johnson. Today’s plan. Greeting Networking and the Sea Battle game Clean-up. Multi-player sea battle: Networking. player 2. server. player 1. Requirements: Player program ( client ) “Game master” program ( server ) Protocol to govern communications.

GBK Programming 2 2009-10 - slide 1
01 / 15GBK Programming 2 2009-10
1 / 17

Télécharger la présentation

GBK Programming 2 2009-10
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. GBK Programming 22009-10 Jordan Johnson

  2. Today’s plan Greeting Networking and the Sea Battle game Clean-up

  3. Multi-player sea battle:Networking player 2 server player 1 • Requirements: • Player program (client) • “Game master” program (server) • Protocol to govern communications

  4. Multi-player sea battle: Example Protocol “Give me a ship of length 5.” player 2 (place 5) server player 1 • Placing ships: • Server requests a ship • Player places a ship • Repeat until all ships are placed.

  5. Multi-player sea battle: Example Protocol player 2 ((1 1) (2 1) (3 1) (4 1) (5 1)) server player 1 “Here it is: (1,1), (2,1), ...” • Placing ships: • Server requests a ship • Player places a ship • Repeat until all ships are placed.

  6. Multi-player sea battle:Example Protocol “Give me a ship of length 4.” player 2 (place 4) server player 1 ...and so on... • Placing ships: • Server requests a ship • Player places a ship • Repeat until all ships are placed.

  7. Battle Protocol: Placing Ships • Summary of messages required: • Server  Client: (place N), where N  {2,3,4,5} • Client  Server: listof[coord-pair] • where a coord-pair is a list of two coords, • and a coord is a nat[<20]. • Server  Client: • All ships are placed? ‘your-turn OR ‘enemy-turn • Player’s ships are all placed? ‘ok • Player sent a bogus ship? (try-again N) • Ships left to place? Back to...(place N) • The players are mostly independent.

  8. Battle protocol: Shooting Represents the cell a player is shooting at Responses to shots (if a ship was sunk, length was its length) coord = nat[<20] length = int[2..5] “win” messages mean the player’s last shot won the game.

  9. Implementing the Universe(Server-side data) • Data required for the placement phase:

  10. Implementing the Universe (Server-side data) • Data required for the battle phase:

  11. Data Definitions A pre-battle is a (make-pre-battle iworldiworld listof[len] listof[len] board board) (define-struct pre-battle (p1 p2 len1* len2* bd1 bd2)) representing the phase of the game where p1 and p2 are connected, have placed the ships on their boards bd1 & bd2, and have yet to place ships of the lengths specified in len1* and len2*. • Data definitions for the universe (server): A universe is either • empty, or • an iworld, or • a pre-battle, or • a battle.

  12. Data Definitions ; A battle is a ; (make-battle iworldiworld; board board ; status) (define-struct pre-battle (p1 p2 bd1 bd2 status)) ; where status is either ; ‘p1-turn or ‘p2-turn or ; ‘game-over. ; This represents a state in the ; turn-based portion of the ; game: bd1 and bd2 store the ; current state of the ships; ; status tells whose turn it is ; (or whether the game’s ended). • Data definitions for the universe (server): A universe is either • empty, or • an iworld, or • a pre-battle, or • a battle.

  13. To-do List (for the universe): • on-new handler: • hookup : universe world  bundle • on-disconnect handler: • hangup : universe world  bundle • on-msg handler: • receive : universe world  bundle • Add helper functions as needed.

  14. Reminders Write out your templates. In the handlers, decide what kind of universe you have, and call a helper function for the appropriate kind. Use helper functions to process lists. Write test cases before functions.

  15. Clean-up • Before you leave, please . . . • Log out. • Push in your chair. • Make sure you’ve got everything. • Make sure all trash ends up in the trash can.