Difference between revisions of "Intermediate C++ Game Programming Tutorial 17"

From Chilipedia
Jump to: navigation, search
(Created page with "In the video we take a look at a couple of bangers from <code><algorithm></code>, and we learn what lambda functions are and how to use them. == Topics Covered == * Algorithm...")
 
Line 2: Line 2:
  
 
== Topics Covered ==
 
== Topics Covered ==
* Algorithms <code>std::sort</code> and <code>std::remove_if</code>
+
* Mutable modifier for member data
* Concepts (as in, type concepts like Comparable)
+
* <code><functional></code> functors as predicates
+
* Lambda functions
+
  
 
== Video Timestamp Index ==
 
== Video Timestamp Index ==
 
[https://youtu.be/3J1Pz30IE4Q Tutorial 16]
 
[https://youtu.be/3J1Pz30IE4Q Tutorial 16]
 +
 +
== Part 2 Class Specification ==
 +
All of the meme entities of the system will have the following shared functionality:
 +
* Member data for name (string), hp, speed, and power (int)
 +
* Getters for name, initiative (speed + 2d6), and alive state
 +
* Punch function that takes a different meme entity and applies damage (str + 2d6) to it
 +
* Tick function where the entity recovers 1d6 hp
 +
 +
Functions should narrate actions / effects when it makes sense. Tests should be made to check whether a character is alive before an action is performed (dead characters can't punch, recover, etc.)
 +
 +
There are two concrete entites: MemeFrog and MemeStoner
 +
MemeFrog:
 +
* Has 69 hp, 7 speed, and 14 power
 +
* Has a SpecialMove function that takes an entity and has a 1/3 chance of dealing 3d6 + 20 damage
 +
* Takes 1d6 of damage every turn
 +
 +
MemeStoner:
 +
* Has 80 hp, 4 speed, and 10 power
 +
* Has a SpecialMove function that takes no parameters and has a 1/2 chance of adding 3 speed, increasing power by 69/42, adding 10 hp, and adding to the entity's name
  
 
== Homework ==
 
== Homework ==
Solve the problems in Source.cpp attached below using the <algorithm> library and other parts of the standard library as extensively as possible. As a bonus problem, implement the sprite drawing effect shown at the end of the video using a lambda function.
+
=== Part 1 ===
 +
Predict the output generated when the function shown at the end of Part 1 is executed.
  
* [http://www.planetchili.net/downloads/I16-HW.zip Source.cpp (homework file)]
 
* [https://github.com/planetchili/sprite Sprite Repo (for bonus problem)]
 
  
 
== Links ==
 
== Links ==

Revision as of 19:10, 16 November 2017

In the video we take a look at a couple of bangers from <algorithm>, and we learn what lambda functions are and how to use them.

Topics Covered

  • Mutable modifier for member data

Video Timestamp Index

Tutorial 16

Part 2 Class Specification

All of the meme entities of the system will have the following shared functionality:

  • Member data for name (string), hp, speed, and power (int)
  • Getters for name, initiative (speed + 2d6), and alive state
  • Punch function that takes a different meme entity and applies damage (str + 2d6) to it
  • Tick function where the entity recovers 1d6 hp

Functions should narrate actions / effects when it makes sense. Tests should be made to check whether a character is alive before an action is performed (dead characters can't punch, recover, etc.)

There are two concrete entites: MemeFrog and MemeStoner MemeFrog:

  • Has 69 hp, 7 speed, and 14 power
  • Has a SpecialMove function that takes an entity and has a 1/3 chance of dealing 3d6 + 20 damage
  • Takes 1d6 of damage every turn

MemeStoner:

  • Has 80 hp, 4 speed, and 10 power
  • Has a SpecialMove function that takes no parameters and has a 1/2 chance of adding 3 speed, increasing power by 69/42, adding 10 hp, and adding to the entity's name

Homework

Part 1

Predict the output generated when the function shown at the end of Part 1 is executed.


Links

Algorithms Library

See also