A Gamer's Introduction to Programming in C#: Welcome Brave Adventurer!

A Gamer's Introduction to Programming in C#: Welcome Brave Adventurer!

A Gamer's Introduction to Programming in C#: Welcome Brave Adventurer!

Автор: Aaron Langille
Дата выхода: 2025
Издательство: CRC Press is an imprint of Taylor & Francis Group, LLC
Количество страниц: 343
Размер файла: 13,8 МБ
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

Acknowledgements............................................................................................xiii
1. Cutscene 1: Backstory...................................................................................1
Press Start to Begin........................................................................................1
Why These Books?.........................................................................................1
Visual Studio, the Console, and MonoGame............................................3
Books That Are Like Games.........................................................................5
How to Use These Books (for Instructors and Everyone Else)..............6
What Is Not Covered in These Books........................................................8
What About AI That Writes Code?.............................................................8
Introducing Your Coding Journey Companions......................................9
A Brief Pep Talk...........................................................................................12
2. Level 1: Prepare for Adventure................................................................13
Games Are Software That Use Hardware...................................13
Software vs. Hardware................................................................................14
Common Computer Hardware Components..........................................14
Software Tools for Our Adventure...........................................................17
How We Program – Write-Compile-Run (and Debug).........................19
Side Quests....................................................................................................25
3. Code Quest 1: Hello, World!.....................................................................27
Main Quest: Hello, World!..........................................................................27
Creating a New Console Project in Visual Studio.................................28
Compiling and Running a Console Project in Visual Studio...............31
Your Own Hello!..........................................................................................33
Side Quests....................................................................................................34
4. Level 2: Adventure Begins.........................................................................35
Video Games Show Us Things..................................................................35
Displaying to the Console...........................................................................36
Built-In Data Types......................................................................................39
Frequently Used C# Built-in Data Types (and Some Special Case Ones).................40
Data Literals...................................................................................................42
Revisiting Output – Now with Concatenation!......................................44
Revisiting “Hello, World!” – Basic Console Program Structure..........47
Revisiting Top-Level Statements...............................................................49
Side Quests....................................................................................................50
5. Code Quest 2: Great Game Quotes.........................................................53
Main Quest – Great Game Quotes............................................................53
Side Quests....................................................................................................54
6. Level 3: A Variable Inventory of Items..................................................55
Video Games Use Dynamic Data and Information...............................55
The What and Why of Variables?.............................................................56
Declaring Variables......................................................................................58
Assigning and Accessing Variables..........................................................60
Reassigning Variables..................................................................................64
Common Assignment and Reassignment Errors....................................65
Initialization = Declaration + Assignment...............................................67
Naming Your Variables...............................................................................69
Side Quests....................................................................................................70
7. Code Quest 3: Character Builder (Part 1)...............................................72
Main Quest – Character Builder (Part 1).................................................72
Side Quests....................................................................................................73
8. Level 4: Some Friendly Input...................................................................74
Video Games Use Input..............................................................................74
Getting Console Input from Our Player..................................................75
Steps to Collect User Input.........................................................................76
Inputting Numbers and Other Fun Things.............................................78
Parsing Can Be Tricky.................................................................................80
Don’t Know, Don’t Care – The True Power of Variables + Input......81
Comments (They Matter)............................................................................82
Side Quests....................................................................................................86
Code Reward – The Player Introduction.................................................86
9. Code Quest 4: Character Builder (Part 2)...............................................90
Main Quest – Character Builder (Part 2).................................................90
Side Quests....................................................................................................92
10. Cutscene 2: Recipes for Success...............................................................93
Video Games Are Made of Algorithms...................................................93
Algorithms Are Recipes for Code.............................................................94
The Properties of Algorithms.....................................................................96
Algorithmic Problem Solving.....................................................................97
Side Quests....................................................................................................98
11. Level 5: Divide and Conquer....................................................................99
Video Games Use Math...............................................................................99
Common Built-in Math Operators..........................................................100
Order of Operations and ().......................................................................104
Unary Negation..........................................................................................106
Updating Variables.....................................................................................107
Compound Assignment Operators.........................................................109
Increment and Decrement (++ and −−)..................................................110
Revisiting Concatenation, Addition, and Automatic Conversion.....112
Math Functions...........................................................................................114
Side Quests..................................................................................................115
Code Reward – The Amazingly Silly Score Calculator.......................116
12. Code Quest 5: Tiny Tournament Stats.................................................119
Main Quest – Tiny Tournament Stats....................................................119
Side Quests..................................................................................................121
13. Level 6: A Random Opportunity............................................................122
Video Games Use Random Numbers.....................................................122
Setting Up a Random Number Generator.............................................123
Generating Random Integers....................................................................124
Simulating Dice...........................................................................................127
Generating Random Decimals and Casting...........................................128
Side Quests..................................................................................................131
Code Reward – The Higher Roll.............................................................132
14. Code Quest 6: A Random Encounter (Part 1)......................................134
Main Quest – A Random Encounter (Part 1)........................................134
Side Quests..................................................................................................136
15. Level 7: A Fork in the Road....................................................................137
Video Games Use Simple Decisions.......................................................137
Conditional Execution...............................................................................138
Simple Ifs (or Nothing but the Truth)....................................................141
Else Handles the False Case.....................................................................144
Comparison Operators..............................................................................147
Comparing Strings and Characters.........................................................148
Introducing Logic Errors...........................................................................150
A Few Last Words on Simple Ifs............................................................152
Side Quests..................................................................................................154
Code Reward – A Simple Encounter......................................................155
16. Code Quest 7: A Random Encounter (Part 2)......................................159
Main Quest – A Random Encounter (Part 2)........................................159
Side Quests..................................................................................................161
17. Level 8: Decisions, Decisions..................................................................162
Video Games Use “Complex” Decisions................................................162
If-Else-If (More than Two Paths).............................................................163
Things to Think About with If-Else-If....................................................168
Nested Ifs.....................................................................................................169
Strict Decisions with && (and)................................................................171
Relaxed Decisions with || (or)................................................................175
Multiple Decisions with && and || (Together)...................................180
The Not Operator (!)..................................................................................181
Side Quests..................................................................................................182
Code Reward – A Professional Choice...................................................183
18. Code Quest 8: My First Loot Box (Part 1)............................................186
Main Quest – My First Loot Box (Part 1)..............................................187
Side Quests..................................................................................................188
19. Level 9: Here We Go Again, and Again...............................................189
Video Games Do the Same Things Over and Over.............................189
While Loops Are Ifs That Repeat............................................................190
Some While Loops Count.........................................................................192
Some While Loops Don’t Count..............................................................195
Boolean Flags Can Help with Some While Loops...............................196
&& (and) and || (or) Work for Loops..................................................198
For Loops Are Compact Counting Loops..............................................199
Before, During, and After Loops.............................................................202
Nested Loops...............................................................................................203
Infinite Loops..............................................................................................205
Loops That Never Run..............................................................................205
Side Quests..................................................................................................206
Code Reward – A More Possible Guessing Game...............................207
20. Code Quest 9: My First Loot Box (Part 2)............................................210
Main Quest – My First Loot Box (Part 2)..............................................211
Side Quests..................................................................................................213
21. Cutscene 3: Yikes, Gremlins!..................................................................214
Video Games Have Errors........................................................................214
Bugs, Glitches, and Gremlins. Oh My!...................................................214
Kinds of Errors............................................................................................215
Reduce Code................................................................................................216
Test, Then Test Again................................................................................218
Tracer (or Debug) Code.............................................................................220
A Bit of Style Goes a Long Way..............................................................223
Stay Calm, Errors Happen........................................................................224
Side Quests..................................................................................................226
22. Level 10: Crafting Custom Objects........................................................228
Games Are Made of Objects (Part 1)......................................................228
Why Object-Oriented Programming?.....................................................229
A Change in Thinking – Object-Oriented Programming....................230
My Approach to Teaching and Learning OOP.....................................232
Creating a New Object Class for Our Project.......................................233
Attributes – The Heart of Our Objects...................................................236
Constructors – Setting the Default Attribute Values...........................240
Getter/Accessor Methods – Retrieving Attribute Values...................245
Setter/Mutator Methods – Changing Attribute Values......................248
Object Helper Methods..............................................................................251
Full-Object Classes from This Level........................................................252
Side Quests..................................................................................................254
Code Reward – An Objectively Better Loot Box..................................255
23. Code Quest 10: A Companion for Our Hero (Part 1)........................259
Main Quest – A Companion for Our Hero (Part 1)............................259
Side Quests..................................................................................................260
24. Level 11: A Factory for Our Objects....................................................262
Games Are Made of Objects (Part 2)......................................................262
An Object Class Isn’t an Object...............................................................263
The Lifecycle of Objects.............................................................................264
Don’t Panic – You’ve Done This Before.................................................265
Back to Our Regular Program.cs.............................................................266
Creating Objects with Constructors........................................................267
Accessing or Getting Object Properties by Calling..............................273
Mutating or Setting Object Properties....................................................275
Side Quests..................................................................................................278
Code Reward – An Epic Battle................................................................278
25. Code Quest 11: A Companion for Our Hero (Part 2)........................284
Main Quest – A Companion for Our Hero (Part 2)............................284
Side Quests..................................................................................................286
26. Cutscene 4: The Adventure Ends … Or Does It?...............................287
Game Over!..................................................................................................287
Actually, the Adventure Is Just Beginning?..........................................288
What’s Left in This Book?.........................................................................288
A Fond Farewell.........................................................................................289
27. Bonus Code Quest: Cornflower Blue! (MonoGame Sneak Peek).....................290
Main Quest: Cornflower Blue! (MonoGame Sneak Peek)...................290
Creating a New MonoGame Project in Visual Studio.........................290
Compiling and Running a MonoGame Project in Visual Studio......292
A More Fiery Start......................................................................................293
Side Quests..................................................................................................293
28. Bonus Level 1: A Bit about Binary.......................................................294
Storing Data in Bits....................................................................................294
Different Bits for Different Data Types..................................................296
Bits & Bytes (and Kilos, Megas, Gigas …).............................................297
29. Bonus Level 2: A Slight Miscalculation..............................................299
Overflow.......................................................................................................299
Decimal Errors............................................................................................300
Integer Division and Integer Remainder................................................302
Casting Revisited – Converting from One Type to Another.............304
30. Bonus Level 3: Input Made (A Little Bit) Friendlier.......................308
TryParse() – Dealing with Unparsable Input........................................308
TryParse() and Input Validation..............................................................310
31. Bonus Level 4: The Return of Decisions, Decisions........................314
The Bare Truth............................................................................................314
Switching Things Up with Switch Statements......................................316
32. Bonus Level 5: A Matter of Scope........................................................319
Curly Braces { } Define Variable Scope..................................................319
33. Bonus Level 6: Let’s Take This Online................................................323
WelcomeBraveAdventurer.ca...................................................................323
Example Code and Visual Studio Projects............................................323
Index..................................................................................................325

 Turn your love of video games into a new love of programming by learning the ins and outs of writing code while also learning how to keep track of high scores, what video game heroes and loot boxes are made of, how the dreaded RNG (random number generation) works, and much, much more. This book is the first in an ongoing series designed to take readers from no coding knowledge to writing their own video games and interactive digital experiences using industry standard languages and tools.

 But coding books are technical, boring, and scary, aren’t they? Not this one. Within these pages, readers will find a fun and approachable adventure that will introduce them to the essential programming fundamentals like variables, computer-based math operations, RNG, logic structures, including if-statements and loops, and even some object-oriented programming. Using Visual Studio and C#, readers will write simple but fun console programs and text-based games that will build coding skills and confidence.

 Packed with practical examples and plain-language explanations, this book is structured like a video game, complete with levels to progress through, bonus levels for extra practice, cutscenes that offer info-packed coding breaks, and end-of-level code rewards to illustrate how everything fits together. Gain even more experience by exploring the resources and bonus materials at the companion website: https://welcomebraveadventurer.ca. Engaging and concise, this book is appealing to both a general readership as well as course convenors and students of programming.

 Put on your cap of +5 courage and level up by joining the coding adventure that awaits you inside!


Похожее:

Список отзывов:

Нет отзывов к книге.