我正在建造俄罗斯方块,我很困惑如何制作一块硬件.
我尝试向hardDrop()Board类添加一个方法,该方法将从底行迭代并检查开放空间...
董事会类:
public int hardDrop() {
int hardDropRow = 0;
for(int row = totalRows-1; row > 0; row--) {
for(int col = 0; col < grid[row].length; col++) {
if (grid[row][col] != null) {
hardDropRow = row;
return hardDropRow;
}
}
}
return hardDropRow;
}
Run Code Online (Sandbox Code Playgroud)
件类:
然后在这里,我将每件作品添加dropRow到getRow():
//Hard drop
if (keycode == KeyEvent.VK_UP) {
//get next valid coordinates nearest to bottom
//hard drop needs to which row the piece needs to drop to
int …Run Code Online (Sandbox Code Playgroud) 我想每次撞到墙壁时都会改变球的弹跳角度.
它将根据它击中墙壁中间的距离而发生变化......
现在,当我遇到表面时,我很难对X和Y的变化进行编码......我的目标是从当前的X和Y获得度数,对度数应用一个变化(现在我随机添加一个数字到度),然后计算X和Y的新增量值.我知道如何获得newX和newY,但不知道如何获得增量值.
绿色是开始x y的(5,5)......蓝色是下一帧(4,4).

45基于此的度数.currX(5) - wallX(0)= distX(5)
currY(5) - wallY(0)= distY(5)
取我的角度的余弦+随机增量,我们会说55度,*distX
cos(55 degrees) = .5735... .5735 x distX (5) = 2.86
和我的角度的罪恶*distiy
sin(55 degrees) = .8191... .8191 x distY (5) = 4.09
newX = cos result (2.86) + originX (5) = 7.86
newY = sin result (4.09) + originY (5) = 9.09
newX, newY = (7.86, …
如果它们匹配wordList中的单词,我需要隐藏span元素.
HTML:
<span class="wordBank_Words">
<span word="hello"></span>
<span word="you"></span>
<span word="hi"></span>
</span>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
wordList = ['hello', 'how', 'are', 'you'];
$('.wordBank_Words span').each(function (index, val) {
if ($(this).attr('word').match(wordList)) {
$(this).hide();
}
});
Run Code Online (Sandbox Code Playgroud)
所以,如果做得正确,它应该隐藏'你好'和'你',但不是'你好'
如果我这样做match('hello'),这正确地隐藏了HTML元素列表中的'hello'范围.
但我需要循环遍历每个span元素wordBank_Words,并将它们与wordList中的每个单词进行比较,并且只有在匹配时才隐藏.无论顺序如何,都需要进行比较.
如何才能做到这一点?
我想为MongoDB中的所有文档对象分别设置几年和几个月的时间。
例如,如果文档有日期:
返回所有文档的唯一月份和年份,例如:
模式片段:
var myObjSchema = mongoose.Schema({
date: Date,
request: {
...
Run Code Online (Sandbox Code Playgroud)
我尝试distinct对模式字段使用date:
db.mycollection.distinct('date',{},{})
但这给出了重复的日期。输出代码段:
ISODate("2015-08-11T20:03:42.122Z"),
ISODate("2015-08-11T20:53:31.135Z"),
ISODate("2015-08-11T21:31:32.972Z"),
ISODate("2015-08-11T22:16:27.497Z"),
ISODate("2015-08-11T22:41:58.587Z"),
ISODate("2015-08-11T23:28:17.526Z"),
ISODate("2015-08-11T23:38:45.778Z"),
ISODate("2015-08-12T06:21:53.898Z"),
ISODate("2015-08-12T13:25:33.627Z"),
ISODate("2015-08-12T14:46:59.763Z")
Run Code Online (Sandbox Code Playgroud)
所以问题是:
distinct('date.month'...)吗?编辑:我发现您可以通过以下查询获得这些日期,例如,但是结果并不明显:
db.mycollection.aggregate(
[
{
$project : {
month : {
$month: "$date"
},
year : {
$year: "$date"
},
day: {
$dayOfMonth: "$date"
}
}
}
]
);
Run Code Online (Sandbox Code Playgroud)
输出:重复
{ "_id" : "", "month" …Run Code Online (Sandbox Code Playgroud) 我正在尝试Java硬币找零问题,以枚举将给n的所有可能的找零集。
我的逻辑如下:
while n >= denom m {
array[]+= denom m
n-= denom m
}
list.add[array[]]
return coinChanger(++denom)
Run Code Online (Sandbox Code Playgroud)
我的代码:
public List<Integer> makeChange(int change) {
int[] denominations;
denominations = new int[]{1, 5, 10, 25};
return changeMaker(change, denominations, 0);
}
public List<Integer> changeMaker(int change, int[] denominations, int index) {
List<Integer> resultsList = new ArrayList<Integer>();
int[] resultDenom;
resultDenom = new int[4];
if (change <= 1) {
return resultsList;
}
while (change >= denominations[index]) {
resultDenom[index] += denominations[index];
System.out.println("ResultsDenom: " + resultDenom[index]);
change -= …Run Code Online (Sandbox Code Playgroud) 我注意到如果我使用jquery更改元素的css,它会删除已经为元素指定的一些css规则.
例如,
.className, .className2, etc... {
background-color: black;
color : silver;
}
.className:hover, .className2:hover, etc... {
background-color: gray;
color : white;
}
Run Code Online (Sandbox Code Playgroud)
现在,如果用户单击此元素,我希望它永久更改背景以显示它已被单击,如果已单击另一个兄弟元素,它将丢失其jQuery-set css规则并返回到原始css-指定的规则(也就是说,它将丢失其rgba背景,并且将添加"悬停"规则)
highlightClicked : function (el) {
el.css({
"background-color" : "rgba(70, 70, 70, 0.7)",
"color" : "white"
});
$('#parentElement > span').each(function () {
$($(this)).not(el).css({
"background-color" : "rgba(70, 70, 70, 0.0)",
"color" : "gray"
});
});
},
Run Code Online (Sandbox Code Playgroud)
但是jquery .css似乎删除了那些原始规则.
怎么能保存它们?
我问了以下问题,为什么类在典型的无类原型继承语言(如 js)中使用: 类在基于原型继承的语言中使用
似乎它们是“语法糖”,因为大众喜欢类……而且它们只是背景中的常规 js 对象。
现在我想知道js假“类”和经典类之间的区别是什么?
鉴于href如下:
HTTP://本地主机:8888 /#/路/ someValue中/ needthis
如何获取路径字符串中的最后一个值(又名:"needthis")?
我尝试使用window.location.pathname,它给出了"/".
我也尝试过使用Angular $location,它没有提供最后一个值.
如何构造MongooseJS / MongoDB查询以获取特定字段值的重复项/出现项总数?又名:总用文件custID的some value所有custIDs
我可以在命令行中手动执行此操作:
db.tapwiser.find({"custID" : "12345"}, {}, {}).count();
输出:1
db.tapwiser.find({"custID" : "6789"}, {}, {}).count();
输出:4
我找到了这个资源:
但这要求我指定要累加的唯一字段。
在这种情况下,我要遍历所有文档,并对每个文档的出现求和。