Skip to content

Commit

Permalink
switching out outdated files with new files for conditions lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
Lara3333 committed Nov 4, 2024
1 parent 2b03a03 commit d693619
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {
"vscode": {
"languageId": "html"
Expand Down Expand Up @@ -142,7 +142,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "javascript"
Expand All @@ -151,7 +151,7 @@
"outputs": [
{
"data": {
"application/javascript": "\nclass GameObject {\n constructor() {\n this.velocity = { x: 0, y: 0 };\n this.direction = '';\n this.xVelocity = 1;\n this.yVelocity = 1;\n }\n\n handleKeyDown({ keyCode }) {\n switch (keyCode) {\n case 87: // 'W' key\n this.direction = 'up';\n break;\n case 65: // 'A' key\n this.direction = 'left';\n break;\n case 83: // 'S' key\n this.direction = 'down';\n break;\n case 68: // 'D' key\n this.direction = 'right';\n break;\n }\n }\n}\n\n// Example usage\nconst gameObject = new GameObject();\nconsole.log('Initial State:', gameObject);\n\ngameObject.handleKeyDown({ keyCode: 87 }); // Simulate 'W' key press\nconsole.log('After W Key Press:', gameObject);\n\ngameObject.handleKeyDown({ keyCode: 65 }); // Simulate 'A' key press\nconsole.log('After A Key Press:', gameObject);\n\ngameObject.handleKeyDown({ keyCode: 83 }); // Simulate 'S' key press\nconsole.log('After S Key Press:', gameObject);\n\ngameObject.handleKeyDown({ keyCode: 68 }); // Simulate 'D' key press\nconsole.log('After D Key Press:', gameObject);\n",
"application/javascript": "\nclass GameObject {\n constructor() {\n this.velocity = { x: 0, y: 0 };\n this.direction = '';\n this.xVelocity = 1;\n this.yVelocity = 1;\n }\n\n handleKeyDown({ keyCode }) {\n switch (keyCode) {\n case 87: // 'W' key\n \n this.direction = 'up';\n break;\n case 65: // 'A' key\n \n this.direction = 'left';\n break;\n case 83: // 'S' key\n \n this.direction = 'down';\n break;\n case 68: // 'D' key\n \n this.direction = 'right';\n break;\n }\n }\n}\n\n// Example usage\nconst gameObject = new GameObject();\nconsole.log('Initial State:', gameObject);\n\ngameObject.handleKeyDown({ keyCode: 87 }); // Simulate 'W' key press\nconsole.log('After W Key Press:', gameObject);\n\ngameObject.handleKeyDown({ keyCode: 65 }); // Simulate 'A' key press\nconsole.log('After A Key Press:', gameObject);\n\ngameObject.handleKeyDown({ keyCode: 83 }); // Simulate 'S' key press\nconsole.log('After S Key Press:', gameObject);\n\ngameObject.handleKeyDown({ keyCode: 68 }); // Simulate 'D' key press\nconsole.log('After D Key Press:', gameObject);\n",
"text/plain": [
"<IPython.core.display.Javascript object>"
]
Expand Down Expand Up @@ -223,7 +223,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.12.5"
}
},
"nbformat": 4,
Expand Down
124 changes: 64 additions & 60 deletions _notebooks/CSSE/Lessons/Conditions/2024-11-10-conditinals_hacks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,78 +22,82 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Popcorn Hack 1: Create a Simple Combat System for Your RPG Game"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Develop a basic combat system that allows characters to engage in battles with enemies. This will help you practice using functions, conditionals, and basic game mechanics in JavaScript."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Popcorn Hack Part 1 - 1\n",
"#### <span style=\"color: #ADD8E6; text-shadow: 3px 3px 8px #4682B4; font-weight: bold; font-size: 2em;\">Popcorn Hacks:</span>\n",
"Develop a basic combat system that allows characters to engage in battles with enemies. This will help you practice using functions, conditionals, and basic game mechanics in JavaScript.\n",
"\n",
"Using function `intializeData`\n",
"---\n",
"##### <span style=\"color: #FF6347; text-shadow: 2px 2px 6px #8B0000; font-weight: bold; font-size: 1.5em;\">Popcorn Hack Part 1 - 1: Using <code>initializeData</code> Function</span> \n",
"\n",
"1. Add `speed` to the `function intializeData(data = null)` and give it a default value.\n",
"1. Add `speed` to the <code>initializeData(data = null)</code> function and give it a default value.\n",
"2. Add `seed` to the HTML output.\n",
"3. Add `speed` to JSON data.\n",
"4. Try make call to `initializeData` with `no argument` and using `data` JSON object as argument when call "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "javascript"
}
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Popcorn Hack Part 1 - 2\n",
"3. Add `speed` to the JSON data.\n",
"4. Test calling <code>initializeData</code> with no argument, and then using a `data` JSON object as an argument.\n",
"\n",
"On `handleKeyDown({ keyCode }` switch statement can you add conditions for IJKL keys.\n",
"##### <span style=\"color: #FF6347; text-shadow: 2px 2px 6px #8B0000; font-weight: bold; font-size: 1.5em;\">Popcorn Hack Part 1 - 2: Adding IJKL Key Conditions in <code>handleKeyDown</code></span> \n",
"\n",
"1. Add a `case` statement for each of the IJKL keys\n",
"2. Send key code for IJKL keys to method `gameObject.handleKeyDown` \n",
"3. Output `gameObject` using console.log"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Hack 3"
"1. Add a `case` statement for each of the IJKL keys in the `handleKeyDown({ keyCode })` switch statement.\n",
"2. Send the key code for each IJKL key to the <code>gameObject.handleKeyDown</code> method.\n",
"3. Use <code>console.log()</code> to output `gameObject`.\n",
"\n",
"---\n",
"\n",
"##### <span style=\"color: #FF6347; text-shadow: 2px 2px 6px #8B0000; font-weight: bold; font-size: 1.5em;\">Popcorn Hack 2: Creating a Simple Attack System</span>\n",
"1. Add a <code>boolean</code> variable named <code>canAttack</code>, and set it to <code>false</code>.\n",
"2. Use an <code>if</code> statement to check if the player can attack.\n",
"3. If <code>canAttack</code> is <code>false</code>, output \"Can't attack.\"\n",
"4. Use <code>Math.random()</code> to determine if the player is allowed to attack. (Tip: Use ChatGPT for help with <code>Math.random()</code> if needed!)\n",
"5. This will pick a random number to decide if the attack can happen.\n",
"6. Use <code>console.log()</code> for all outputs.\n",
"\n",
"---\n",
"\n",
"##### <span style=\"color: #FF6347; text-shadow: 2px 2px 6px #8B0000; font-weight: bold; font-size: 1.5em;\">Popcorn Hack 3: Level Requirement Check</span>\n",
"1. Use the <code>ternary operator</code> to create an output if the player meets the level requirements.\n",
"2. If not, output a message telling the player they are under-leveled.\n",
"3. Use <code>console.log()</code> to print your output."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the ternary operator make an output apear if you meet the level requerments otherwise output a message that telss the player that they are under leveled"
"<!-- Homework Section with Enhanced Glowing Title -->\n",
"\n",
"### <span style=\"color: #78C0E0; text-shadow: 0 0 10px #1E3D59, 0 0 20px #1E3D59; font-weight: bold; font-size: 2em;\">Homework:</span>\n",
"\n",
"#### <span style=\"color: #FFA07A; text-shadow: 0 0 8px #3C3C3C, 0 0 15px #3C3C3C; font-weight: bold; font-size: 1.5em;\">Objectives</span>\n",
"\n",
"<span style=\"font-size: 1.2em; color: #E5E5E5; line-height: 1.8;\">\n",
" <br><strong style=\"color: #FFD700;\">Option 1:</strong> <span style=\"color: #C0C0C0;\">Create a simple combat system.</span>\n",
" <ul style=\"color: #D3D3D3; margin-left: 20px; list-style-type: circle;\">\n",
" <li>Allow characters to fight enemies.</li>\n",
" <li>Use basic functions and conditionals in JavaScript.</li>\n",
" <li>Focus on making it easy to understand how battles work.</li>\n",
" </ul>\n",
"\n",
" <br>\n",
" <strong style=\"color: #FFD700;\">Option 2:</strong> <span style=\"color: #C0C0C0;\">Make a dialogue system for your NPC (Non-Player Character).</span>\n",
" <ul style=\"color: #D3D3D3; margin-left: 20px; list-style-type: circle;\">\n",
" <li>Use the <code style=\"color: #7FFFD4;\">prompt()</code> function to ask the player for a response (choose a number from 1 to 4).</li>\n",
" <li>This dialogue should appear when the player gets close to the NPC and presses a button.</li>\n",
" </ul>\n",
"</span>\n",
"\n",
"### <span style=\"color: #FFA07A; text-shadow: 1px 1px 6px #3C3C3C; font-weight: bold;\">Additional Tips:</span>\n",
"- <span style=\"color: #FFD700;\">**For Option 1:**</span>\n",
" <ul style=\"color: #D3D3D3; margin-left: 20px; list-style-type: square;\">\n",
" <li>Start by writing down what the characters and enemies will be. Create simple names and attributes (like health).</li>\n",
" <li>Use <code style=\"color: #7FFFD4;\">console.log()</code> to print out what's happening at each step. This will help you understand the flow of your code.</li>\n",
" <li>Look for example code online to see how others have created combat systems. Don't be afraid to borrow ideas!</li>\n",
" </ul>\n",
"\n",
"- <span style=\"color: #FFD700;\">**For Option 2:**</span>\n",
" <ul style=\"color: #D3D3D3; margin-left: 20px; list-style-type: square;\">\n",
" <li>Plan out the dialogue options before you start coding. Write them down in a list.</li>\n",
" <li>Use comments in your code to remind yourself what each part does. For example, <code style=\"color: #7FFFD4;\">// Ask the player for a response</code>.</li>\n",
" <li>Test your code frequently. After writing a few lines, run it to see if it works before adding more.</li>\n",
" </ul>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "javascript"
}
},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
18 changes: 2 additions & 16 deletions _notebooks/CSSE/Lessons/Conditions/2024-11-10-conditinals_p3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 16,
"metadata": {
"vscode": {
"languageId": "html"
Expand Down Expand Up @@ -214,20 +214,6 @@
"the : represents the else so that section of code with run if the requrments are nor met<br>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# QUIZ :]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### add your hw and hacks below"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -259,7 +245,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit d693619

Please sign in to comment.