所以我是HTML5的新手,并决定开始编写乒乓球游戏.我想用键盘顺利移动我的角色,左边的W和S键以及右边的向上和向下箭头.我似乎无法让它发挥作用.这可能很容易,但我是我的菜鸟,我需要一些帮助.提前致谢!
<!DOCTYPE html>
<html>
<head>
<title>Pingedy Pong</title>
</head>
<body style="font-family:Arial;">
<canvas id="ctx" width="699" height="400" style="background-color:black;border:2px solid black;background-image: url('background.jpg');"></canvas>
<script>
// STARTING SCRIPT
var ctx = document.getElementById("ctx").getContext("2d");
ctx.fillStyle="white";
ctx.font = '30px Arial';
// VARIABLES
var keys1 = [];
var keys2 = [];
var width = 699;
var height = 400;
var ball = {
width:20,
height:20,
spdX:2.9,
spdY:2.9,
x:340,
y:190,
};
var char1 = {
w:15,
h:90,
spdX:3,
spdY:3,
x:10,
y:155,
};
var char2 = {
w:15,
h:90,
spdX:3,
spdY:3,
x:674, …Run Code Online (Sandbox Code Playgroud)我正在尝试完成这个PHP挑战,我目前有这个代码:
<?php
/*
Challenge 2: Implement AnswerInterface and get Question to echo "4".
*/
class Question
{
public function __construct(AnswerInterface $answer)
{
echo "What is 2 + 2?\n";
$answer = $answer->get()->the()->answer();
if ($answer instanceof AnswerInterface) {
echo $answer . PHP_EOL;
}
}
}
interface AnswerInterface
{
public function get();
public function the();
public function answer();
}
class Answer implements AnswerInterface
{
public function get()
{
return new Answer();
}
public function the()
{
return new Answer();
}
public …Run Code Online (Sandbox Code Playgroud)