-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
290 lines (250 loc) · 9.14 KB
/
Copy pathindex.html
File metadata and controls
290 lines (250 loc) · 9.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="manifest" href="manifest.json">
<title>ChatGem</title>
<style>
body {
background-color: #7B1FA2;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
#header {
text-align: center;
padding: 20px;
background-color: #7B1FA2;
}
canvas {
display: none;
/* Hide the canvas by default */
margin: 20px auto;
background-color: #7B1FA2;
}
#chat-log {
margin-top: 20px;
padding: 10px;
background-color: #7B1FA2;
max-width: 800px;
margin-left: auto;
margin-right: auto;
}
input[type="text"],
button {
width: calc(100% - 20px);
max-width: 300px;
height: 45px;
margin: 0 10px;
box-sizing: border-box;
display: block;
margin: 10px auto;
}
.paddle {
width: 20px;
height: 100px;
/* Changed height of the paddles */
background-color: white;
z-index: 1;
position: absolute;
}
/* Additional styles for the clock */
#clock {
position: absolute;
top: 20px;
right: 20px;
color: black;
font-size: 20px;
cursor: pointer;
/* Change cursor to indicate it's clickable */
}
</style>
</head>
<body>
<h1>ChatGenie</h1>
<div id="chat-log"></div>
<input type="text" id="user-input" placeholder="Type your message here">
<button id="clear-button">Reset Chat</button>
<button onclick="location.href='credits.html'">All Credits</button>
<button onclick="window.location.href='mathgenie.html'">MathGenie</button>
<button onclick="location.href='weathergenie.html'">WeatherGenie</button>
<canvas id="pingPongCanvas" width="800" height="400" style="border: 1px solid black;"></canvas>
<!-- Clock div -->
<div id="clock"></div>
<script>
const chatLog = document.getElementById('chat-log');
const userInput = document.getElementById('user-input');
const clearButton = document.getElementById('clear-button');
const canvas = document.getElementById("pingPongCanvas");
const context = canvas.getContext("2d");
const paddleWidth = 20;
const paddleHeight = 100;
const ballSize = 10;
let leftScore = 0;
let rightScore = 0;
let paddle1Y = (canvas.height - paddleHeight) / 2;
let paddle2Y = (canvas.height - paddleHeight) / 2;
let paddleSpeed = 5;
let ballX = canvas.width / 2;
let ballY = canvas.height / 2;
let ballSpeedX = 5;
let ballSpeedY = 5;
let keys = {};
let canvasClicked = false; // Track whether the canvas is clicked
var prefix = "ChatGenie: "
// Function to update the clock
function updateClock() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // Handle midnight (0 hours)
minutes = minutes < 10 ? '0' + minutes : minutes;
var timeString = hours + ':' + minutes + ' ' + ampm;
document.getElementById('clock').textContent = timeString;
setTimeout(updateClock, 1000); // Update the clock every second
}
// Call the function to initially set up the clock
updateClock();
// Add event listener to the clock for displaying time-specific messages
userInput.addEventListener('keyup', function (event) {
if (!canvasClicked && event.keyCode === 13) {
const userInputValue = userInput.value.toLowerCase();
sendMessage(userInputValue);
if (userInputValue === "pingpong") {
canvas.style.display = "block";
}
userInput.value = ''; // Clear the input after sending the message
}
});
clearButton.addEventListener('click', clearChat);
function displayMessage(message) {
const messageElement = document.createElement('div');
messageElement.textContent = message;
chatLog.appendChild(messageElement);
}
function sendMessage(userMessage) {
displayMessage('You: ' + userMessage);
const sanitizedMessage = userMessage.toLowerCase();
if (sanitizedMessage.includes('whopper') || sanitizedMessage.includes('bk') || sanitizedMessage.includes('whopper song') || sanitizedMessage.includes('bk song')) {
displayMessage("ChatGenie: Whopper Whopper Whopper Whopper Junior, Double, Triple Whopper. Flame grilled taste with perfect toppers I rule this day. Lettuce, mayo, pickle, ketchup, it's okay if I don't want that. Impossible or Bacon Whopper any Whopper my way You rule you're seizin the day at BK have it your way. You rule!");
} else if (sanitizedMessage.includes('hello') || sanitizedMessage.includes('hi') || sanitizedMessage.includes('hey')) {
displayMessage('ChatGenie: Hello, I\'m ChatGenie!');
} else if (sanitizedMessage.includes('type your message here')) {
displayMessage('ChatGenie: Using placeholder text, are we?');
} else if (sanitizedMessage.includes('you are')) {
const words = sanitizedMessage.split(' ');
const index = words.indexOf('are');
if (index !== -1 && index < words.length - 1) {
const adjective = words.slice(index + 1).join(' ');
displayMessage(`ChatGenie: Thank you for the compliment, you are ${adjective} too! 😄`);
} else {
displayMessage('ChatGenie: Thank you 😄');
}
} else if (sanitizedMessage.startsWith('what is') || sanitizedMessage.startsWith('whats')) {
const expression = sanitizedMessage.replace(/[^0-9+\-*\/x^()]/g, ''); // Remove non-numeric, variable, and operator characters
const result = evaluateAlgebraicExpression(expression);
if (result !== null) {
displayMessage('ChatGenie: The result is ' + result);
} else {
displayMessage("ChatGenie: I don't know that yet, I'm dumb.");
}
} else {
displayMessage("ChatGenie: I don't know that yet, I'm dumb.");
}
}
function clearChat() {
chatLog.innerHTML = '';
displayMessage("ChatGenie: Okay, let's start over");
}
function evaluateAlgebraicExpression(expression) {
try {
return eval(expression);
} catch (error) {
return null; // Return null if expression is invalid or cannot be evaluated
}
}
document.addEventListener("keydown", function (event) {
if (!canvasClicked) { // Conditionally handle key events based on whether the canvas is clicked
keys[event.key] = true;
}
});
document.addEventListener("keyup", function (event) {
if (!canvasClicked) { // Conditionally handle key events based on whether the canvas is clicked
keys[event.key] = false;
}
});
canvas.addEventListener("click", function () {
canvasClicked = true; // Update the variable when the canvas is clicked
});
function draw() {
// Clear canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// Draw paddles
context.fillStyle = "#000";
context.fillRect(0, paddle1Y, paddleWidth, paddleHeight);
context.fillRect(canvas.width - paddleWidth, paddle2Y, paddleWidth, paddleHeight);
// Draw ball
context.beginPath();
context.arc(ballX, ballY, ballSize, 0, Math.PI * 2);
context.fillStyle = "#000";
context.fill();
context.closePath();
// Move paddles
movePaddle();
// Move ball
ballX += ballSpeedX;
ballY += ballSpeedY;
// Ball collisions with walls
if (ballY + ballSize > canvas.height || ballY - ballSize < 0) {
ballSpeedY = -ballSpeedY;
}
// Ball collisions with paddles
if (
(ballX - ballSize < paddleWidth && ballY > paddle1Y && ballY < paddle1Y + paddleHeight) ||
(ballX + ballSize > canvas.width - paddleWidth && ballY > paddle2Y && ballY < paddle2Y + paddleHeight)
) {
ballSpeedX = -ballSpeedX;
}
// Game over if the ball goes beyond paddles
if (ballX - ballSize < 0 || ballX + ballSize > canvas.width) {
if (ballX - ballSize < 0) {
rightScore++;
} else {
leftScore++;
}
setTimeout(resetGame, 200);
}
requestAnimationFrame(draw);
}
function movePaddle() {
// Move paddle1 based on "W" and "S" keys
if (keys["w"] && paddle1Y > 0) {
paddle1Y -= paddleSpeed;
}
if (keys["s"] && paddle1Y < canvas.height - paddleHeight) {
paddle1Y += paddleSpeed;
}
// Move paddle2 based on arrow keys
if (keys["ArrowUp"] && paddle2Y > 0) {
paddle2Y -= paddleSpeed;
}
if (keys["ArrowDown"] && paddle2Y < canvas.height - paddleHeight) {
paddle2Y += paddleSpeed;
}
}
function resetGame() {
// Reset ball and paddles
ballX = canvas.width / 2;
ballY = canvas.height / 2;
paddle1Y = (canvas.height - paddleHeight) / 2;
paddle2Y = (canvas.height - paddleHeight) / 2;
ballSpeedX = -ballSpeedX; // Start the ball in the opposite direction
ballSpeedY = -ballSpeedY;
}
draw();
</script>
</body>
</html>