0% found this document useful (0 votes)
3 views

AP CS Program Code

The document contains JavaScript code for a game that tracks a player's score and allows them to make choices that affect the game's outcome. It includes functions for updating the score, resetting the game, and handling user interactions through event listeners. The game features various screens and actions, such as fighting, running away, and searching for a spouse, with corresponding score adjustments based on player decisions.

Uploaded by

Tap.Water
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

AP CS Program Code

The document contains JavaScript code for a game that tracks a player's score and allows them to make choices that affect the game's outcome. It includes functions for updating the score, resetting the game, and handling user interactions through event listeners. The game features various screens and actions, such as fighting, running away, and searching for a spouse, with corresponding score adjustments based on player decisions.

Uploaded by

Tap.Water
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

4/30/2018 https://bakerfranke.github.

io/codePrint/

1 var score = 0;
2 var spouseFound = 0;
3 function updateScore() {
4 setText("scoreFight", score);
5 setText("scoreBaccwards", score);
6 setText("scoreDead", score);
7 setText("scoreStart", score);
8 setText("scoreNext", score);
9 setText("scoreOnwards", score);
10 setText("scoreVictory", score);
11 setText("scoreStartWest", score);
12 setText("scoreWest", score);
13 setText("scoreWin", score);
14 setText("scoreTreeDead", score);
15 setText("scoreKinda", score);
16 setText("scoreWinHollow", score);
17 }
18 function reset() {
19 hideElement("image6");
20 hideElement("spouseText1");
21 hideElement("spouseText2");
22 hideElement("ice");
23 hideElement("defeatText");
24 hideElement("fightDefeat");
25 showElement("text_area2");
26 showElement("fightDropdown");
27 hideElement("fire");
28 hideElement("victoryText");
29 hideElement("spellButton2");
30 hideElement("spellButton1");
31 showElement("actButtonFight");
32 hideElement("fightOnwards");
33 hideElement("label4");
34 hideElement("label43");
35 hideElement("label44");
36 hideElement("label56");
37 hideElement("label59");
38 hideElement("label60");
39 hideElement("label64");
40 setScreen("startScreen");
41 spouseFound = 0;

42 score = 0;
43 }
https://bakerfranke.github.io/codePrint/ 1/5
4/30/2018 https://bakerfranke.github.io/codePrint/
}
44 onEvent("actButtonStart", "click", function(event) {
45 console.log("actButtonStart clicked");
46 if (getText("dropdownStart") == "Onwards") {
47 setScreen("onwardsScreen");
48 console.log("Onwards selected");
49 } else if ((getText("dropdownStart") == "Baccwards")) {
50 setScreen("baccwardsScreen");
51 console.log("Baccwards selected");
52 } else if ((getText("dropdownStart") == "West")) {
53 setScreen("startScreenWest");
54 console.log("West selected");
55 }
56 });
57 onEvent("actButtonOnwards", "click", function(event) {
58 console.log("actButtonOnwards clicked");
59 if (getText("dropdownOnwards") == "Fight") {
60 setScreen("fightScreen");
61 console.log("Fight selected");
62 score = score + 2 ;
63 showElement("label43");
64 updateScore();
65 } else if ((getText("dropdownOnwards") == "Run Away")) {
66 setScreen("StartScreenVictory");
67 console.log("Run Away selected");
68 score = score - 2 ;
69 showElement("label4");
70 updateScore();
71 }
72 });
73 onEvent("actButtonFight", "click", function(event) {
74 console.log("actButtonFight clicked");
75 hideElement("label43");
76 if (getText("fightDropdown") == "Magic") {
77 hideElement("fightNo");
78 showElement("spellButton1");
79 showElement("spellButton2");
80 hideElement("fightDropdown");
81 hideElement("actButtonFight");
82 console.log("Magic selected");
83 } else if ((getText("fightDropdown") == "Attack")) {
84 showElement("fightNo");
85 console.log("Attack selected, declined");
86 }
87 });
88 onEvent("spellButton1", "click", function(){
89 showElement("fire");
https://bakerfranke.github.io/codePrint/ 2/5
4/30/2018 https://bakerfranke.github.io/codePrint/
( );
90 showElement("victoryText");
91 showElement("fightOnwards");
92 hideElement("spellButton2");
93 showElement("label43");
94 score = score + 2 ;
95 updateScore();
96 console.log("Fire selected, battle won");
97 });
98 onEvent("spellButton2", "click", function(){
99 showElement("ice");
100 showElement("defeatText");
101 showElement("fightDefeat");
102 hideElement("spellButton1");
103 showElement("label56");
104 score = score - 2 ;
105 updateScore();
106 console.log("Ice selected, battle lost");
107 });
108 onEvent("fightDefeat", "click", function(){
109 setScreen("deadScreen");
110 console.log("Dead - Lost fight");
111 });
112 onEvent("fightOnwards", "click", function(){
113 setScreen("nextScreen");
114 console.log("Moved onwards from fight");
115 });
116 onEvent("retryButton", "click", function(){
117 setScreen("startScreen");
118 console.log("Retry'd");
119 });
120 onEvent("button6", "click", function(){
121 console.log("button6 clicked");
122 if (getText("nextDropdown") == "Search") {
123 showElement("image6");
124 hideElement("text_area2");
125 showElement("spouseText1");
126 showElement("spouseText2");
127 console.log("Area searched");
128 showElement("label44");
129 score = score + 4 ;
130 spouseFound = 1 ;
131 updateScore();
132 } else if ((getText("nextDropdown") == "Baccwards")) {
133 setScreen("StartScreenVictory");
134 console.log("Went back to Start Screen via victory");
135 }
https://bakerfranke.github.io/codePrint/ 3/5
4/30/2018 https://bakerfranke.github.io/codePrint/
}
136 });
137 onEvent("actButtonVictory", "click", function(){
138 console.log("actButtonVictory (Located on startScreenVictory) clicked");
139 if (getText("victoryDropdown") == "Baccwards") {
140 setScreen("baccwardsScreen");
141 console.log("victory Baccwards selected");
142 } else if ((getText("victoryDropdown") == "West")) {
143 setScreen("startScreenWest");
144 console.log("victory West selected");
145 }
146 });
147 onEvent("button2", "click", function(){
148 console.log("button2 clicked");
149 if (getText("baccwardsDropdown") == "Rush it!") {
150 setScreen("deadScreenTree");
151 showElement("label59");
152 score = score - 4 ;
153 updateScore();
154 console.log("Died to a bunch of trees");
155 } else if ((getText("baccwardsDropdown") == "Run Away!")) {
156 setScreen("westScreen");
157 console.log("Found way out of forest to Bitcoin!");
158 }
159 });
160 onEvent("acceptFate", "click", function(){
161 setScreen("deadScreen");
162 console.log("Accepted fate, now dead");
163 });
164 onEvent("retryButton", "click", function(){
165 reset();
166 score = 0
167 updateScore();
168 console.log("Retry button clicked");
169 });
170 onEvent("actButtonLeft1", "click", function(event) {
171 console.log("actButtonLeft1 clicked");
172 if ((getText("dropdownLeft1") == "Baccwards")) {
173 setScreen("baccwardsScreen");
174 console.log("Baccwards from Left");
175 } else {
176 if ((getText("dropdownLeft1") == "Onwards")) {
177 setScreen("onwardsScreen");
178 }
179 }
180 });
181 onEvent("actButtonLeft", "click", function(event) {
https://bakerfranke.github.io/codePrint/ 4/5
4/30/2018 https://bakerfranke.github.io/codePrint/
( , , ( ) {
182 console.log("actButtonLeft clicked");
183 if (getText("dropdownLeft") == "Search" && score >= 8 && spouseFound == 1) {
184 setScreen("youWin");
185 console.log("Bitcoin found");
186 showElement("label60");
187 score = score + 12 ;
188 updateScore();
189 } else if (getText("dropdownLeft") == "Search" && score >= 4) {
190 setScreen("youWinHollow");
191 showElement("label13");
192 score = score - 2 ;
193 updateScore();
194 } else {
195 setScreen("youWinKinda");
196 showElement("label64");
197 score = score - 4 ;
198 updateScore();
199 }
200 });
201 onEvent("retryButtonWin", "click", function(){
202 reset();
203 updateScore();
204 console.log("retryButtonWin clicked");
205 });
206 onEvent("retryButtonKinda", "click", function(){
207 reset();
208 updateScore();
209 console.log("retryButtonKinda clicked");
210 });
211 onEvent("retryButtonHollow", "click", function(){
212 reset();
213 updateScore();
214 console.log("retryButtonHollow clicked");
215 });

PDF document made with CodePrint using Prism

https://bakerfranke.github.io/codePrint/ 5/5

You might also like