Manual of Puissant Skill at Game Programming
Total Page:16
File Type:pdf, Size:1020Kb
Manual of Puissant Skill at Game Programming Clinton Jeffery ii Manual of Puissant Skill at Game Programming by Clinton Jeffery ii Portions adapted from "Programming with Unicon", http://unicon.org Copyright © 1999-2015 Clinton Jeffery Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back- Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". Dedication This book is dedicated to Curtis and Cary and future programmers everywhere. This is a draft manuscript dated 1/6/2015. Send comments and errata to [email protected]. This document was prepared using LibreOffice 4.2. iii Contents Dedication........................................................................................................................ii Preface................................................................................................................................vi Introduction........................................................................................................................vii Chapter 1: Preliminaries......................................................................................................1 Variables...........................................................................................................................3 Reading from the keyboard..............................................................................................3 Random Thoughts............................................................................................................3 Deciding what to do next.................................................................................................3 Repeating Yourself...........................................................................................................4 Chapter 2: Guessing Games.................................................................................................5 Scrambler.........................................................................................................................5 Hangman..........................................................................................................................7 Thespian's Little Helper.................................................................................................10 Play Files and the Gutenberg Repository.......................................................................11 Reading in a Play...........................................................................................................11 Giving the User their Queues.........................................................................................11 Testing the Responses: How Perfect Must it Be?..........................................................12 Exercises........................................................................................................................15 Chapter 3: Dice Games......................................................................................................17 Scoring...........................................................................................................................18 Complete Program.........................................................................................................20 Graphics.........................................................................................................................23 Exercises........................................................................................................................24 Chapter 4: Tic Tac Toe.......................................................................................................25 The Tic Tac Toe Board...................................................................................................25 Taking Turns..................................................................................................................26 Reading the Player's Move.............................................................................................27 A Complete Two-Player Tic Tac Toe Program...............................................................27 Graphical TTT...............................................................................................................28 Adding a Computer Player.............................................................................................31 Making the Computer Smarter......................................................................................32 Exercises........................................................................................................................34 Chapter 5: Card Games......................................................................................................35 Representing Cards........................................................................................................35 The Deck........................................................................................................................36 Dealing...........................................................................................................................36 Turns in War...................................................................................................................36 Graphics.........................................................................................................................37 Exercises........................................................................................................................38 Chapter 6: Checkers...........................................................................................................39 Drawing the Checkers Board Textually.........................................................................40 Taking Turns..................................................................................................................41 Reading the Player's Move.............................................................................................42 Checkers Graphics.........................................................................................................44 Moving Pieces Around...............................................................................................44 Animation..................................................................................................................45 A Computer Checkers Player.........................................................................................45 The Minimax Algorithm............................................................................................46 Exercises........................................................................................................................54 iv Chapter 7: Text Adventures................................................................................................55 Design............................................................................................................................55 CIA.................................................................................................................................56 The Adventure Shell......................................................................................................72 Chapter 8: Resource Simulation........................................................................................73 Hamurabi.......................................................................................................................73 Taipan.............................................................................................................................80 Chapter 9: Turn-based Role-Playing..................................................................................81 Pirate Duel.....................................................................................................................81 Chapter 10: Paddle Games.................................................................................................87 Ping................................................................................................................................87 Brickout.........................................................................................................................90 Exercises........................................................................................................................96 Chapter 11: Sesrit...............................................................................................................97 The Gameplay of Falling Blocks...................................................................................97 Chapter 12: Blasteroids....................................................................................................112 Creating Graphical User Interfaces with Ivib...............................................................113 The Blasteroid Game Class..........................................................................................115 Exercises......................................................................................................................120 Chapter 13: Network Games and Servers........................................................................122 An Internet Scorecard Server.......................................................................................122