我正在查看游戏中的一些代码,我遇到了一些我以前没见过的东西,我真的不知道最近发生了什么.
public abstract class Entity
{
public Entity(World world)
{
// irrelevent code
entityInit();
}
protected abstract void entityInit();
}
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?它呼吁时会发生什么entityInit()
?
确切的错误:
$ ./script.pl file.txt
Can't open file.txt: No such file or directory at ./script.pl line 17.
Use of uninitialized value in chomp at ./script.pl line 17.
Username: Password:
Run Code Online (Sandbox Code Playgroud)
我正在编写一个脚本,从命令行获取文件名,然后将其输出写入它:
#!/usr/bin/perl
use warnings;
use strict;
use Term::ReadKey;
my @array;
my $user;
my $pass;
# get login info
print "Username: ";
chomp($user = <>); # line 17
print "Password: ";
ReadMode 2;
chomp($pass = <>);
ReadMode 0;
print " \n";
# ...
# connect to database, and save the info in "@array" …
Run Code Online (Sandbox Code Playgroud) 我有一个2D数组,作为国际象棋游戏的板.我希望用户输入在Smith Notation中.设置数组的方式是,如果用户说他们想要一块移动到第8行(从用户的角度来看最上面一行),它们就会row[0]
在数组中进行交互.因此,为了解决这个问题,我编写了一个函数,将用户的输入转换为数组的正确行.然而,它似乎有点笨重,我想知道如何有更多经验的程序员将解决这个问题.
int convertToCorrectRow(int row)
{
int newRow;
switch (row) {
case 1:
newRow = 7;
break;
case 2:
newRow = 6;
break;
case 3:
newRow = 5;
break;
case 4:
newRow = 4;
break;
case 5:
newRow = 3;
break;
case 6:
newRow = 2;
break;
case 7:
newRow = 1;
break;
case 8:
newRow = 0;
break;
default:
assert(false);
break;
}
return newRow;
}
Run Code Online (Sandbox Code Playgroud)
我确实想过翻转数组并将其反向显示给用户,这样当用户与第8行交互时,它们实际上row[7]
在数组中进行交互,这将消除对此功能的需求.但是,我仍然想知道解决这个问题的其他方法.在此先感谢您的回复.
I made a fancy shape with OpenGL and I draw that shape this function:
drawShape(const Point & center, char radius, int points, int rotation)
Run Code Online (Sandbox Code Playgroud)
Inside the function I have code that tells OpenGL where the vertexes are:
glBegin(GL_LINE_LOOP);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(center.getX() + 0.0, center.getY() + 1.0);
// more vertices
glEnd();
Run Code Online (Sandbox Code Playgroud)
现在,当我添加 时glRotatef(rotation, 0.0, 0.0, 1.0)
,我只希望我绘制的这个形状在屏幕上旋转。但是,如果我将它添加到它上面,glBegin()
它会旋转窗口中的所有内容。如果我在对象之间包含所有代码glPushMatrix()
并glPopMatrix()
旋转对象,但围绕窗口中心旋转。如何仅旋转我绘制的对象?
我有两个数组,@names
并且@employees
填充了表示名称的字符串. @names
是二维的,持有对匿名数组的引用,但我们关心的数据的位置是@names[i][0]
.我想循环@names
查找哪些名称不在@employees
.
起初我认为@names
向后循环,比较它@employees
并删除任何匹配@names
将起作用,但我遇到了一些错误.这就是我所拥有的:
for my $i (reverse(0 .. $#names)) {
foreach my $employee (@employees) {
if ($names[$i][0] eq $employee) { # line 67
splice(@names, $i, 1);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到这个错误:
在script.pl第67行第2行的字符串eq中使用未初始化的值.
字符串都在数组中定义.所以我猜这是由于我在循环中删除数组中的元素而引起的,但我认为向后循环数组会阻止这样的问题发生.
那我在循环中哪里出错了?此外,我一直在努力解决这个循环,这暗示我的整个思考过程出了问题.有没有更好的方法来做到这一点?
我使用Swing和JTable创建了一个UI.我实现了一个ListSelectionListener
通过它,我可以根据表中选定的行获取记录.选择后我无法取消选择该行.
所以基本上我应该能够通过一次单击选择一行,然后我应该可以通过再次单击取消选择该行.
我尝试过使用tableName.getSelectionModel.clearSelection
,但我不知道如何查看是否选择了某行.什么会告诉我这个?
我尝试的另一个解决方案是使用鼠标单击侦听器.同样,我无法编写条件来检查鼠标单击是否发生在先前选定的行上.有没有办法让我选择上一行?
我正在使用DefaultTableModel
.
我试图将其fofam(h1)
置于页面的中心。但由于nav
和logo
,我遇到了麻烦。帮助?我已经尝试修复它有一段时间了,但我似乎无法让它发挥作用。我尝试过内联等。
<style>
header {
height:300px;
margin:0 auto;
background:#21628c;
font-family:arial;
text-transform:uppercase;
}
div.logo svg{
float:left;
padding:10px 30px;
display:inline-block;
}
nav{
float:right;
color:#000000;
display:inline-block;
padding: 20px 20px;
}
nav a{
margin-left:30px;
color:black;
}
nav a:hover{
color:white;
font-size:20px;
}
h1{
color:white;
font-size:72px;
text-align:center;
display:inline-block;
position:relative;
}
h1 span{
border:10px solid white;
padding: .2em .5em;
}
p.descripton{
text-align:center;
color:white;
}
</style>
<header>
<title>Mikhaila</title>
<div class="logo"><svg...</svg></div>
<nav>
<a href="">Mission</a>
<a href="">Events</a>
<a href="">Contact Us</a>
</nav>
<h1><span>FOFAM</span></h1>
<p class="descripton">Friends of …
Run Code Online (Sandbox Code Playgroud) 我的函数中有一些参数接收并传递相同的值.我应该将所有参数变量命名为相同吗?
例:
// assume numMonth = 12
// assume numYear = 2000
int promptMonth(); // returns numMonth
int promptYear(); // returns numYear
int daysInMonth(int numMonth, int numYear); // numMonth and numYear will always
int daysInYear(int numYear); // be sent to these.
bool isLeapYear(int numYear); // daysInYear() and daysInMonth() call
// this function and send it numYear
// (which would be 2000 in this case).
Run Code Online (Sandbox Code Playgroud)
是否所有这些参数都被命名为相同,因为相同的值被传递给它们?
我正在使用gcc编译程序,当我运行时,a.out
我收到此错误:
分段错误:11
我认为这与它有关Board::display
,但我没有看到它有什么问题..
#include <iostream>
using namespace std;
const bool WHITE = 0;
const bool BLACK = 1;
//-----------------------------
class Piece
{
public:
// constructors
Piece();
Piece(bool color);
// functions
char getColor() const {return color; }
bool getSymbol() const {return symbol;}
protected:
bool color;
char symbol;
};
ostream& operator << (ostream& out, const Piece & piece)
{
out << piece.getSymbol();
return out;
}
Piece::Piece() { }
Piece::Piece(bool color)
{
this->color = color;
}
//-----------------------------
class King …
Run Code Online (Sandbox Code Playgroud) 我对Perl不是很熟悉,但我正在使用它来编写一个简单的脚本.此脚本将与Qualys连接,因此在查找有关Qualys API的信息时,我在查看示例代码时发现了此语句.我把它放在Pastebin.com(这里),所以你不必下载它来查看它.如果由于某种原因你想自己下载它,这里有一个指向我想要能够下载源代码的页面的链接(它是"获取地图").
无论如何,这是声明(第261行),让我有点困惑:
$request = new HTTP::Request GET => $url;
Run Code Online (Sandbox Code Playgroud)
我感到困惑的new
和GET => $url
语句的部分.
new
声明的部分是怎么回事,但是如果有人能够解释如何HTTP::Request
创建一个LWP::UserAgent
有助于澄清这一行的新工作(我在CPAN上看了LWP :: UserAgent,但是"KEY/DEFAULT" "他们在new
子程序解释下的表对我来说没什么意义".GET => $url
声明中发生了什么.我的猜测是它正在分配一个值HTTP::Request
或者LWP::UserAgent
我找不到任何信息来支持这个想法.以此程序为例:
class Piece
{
public:
Piece(bool color);
protected:
bool color;
};
Piece::Piece(bool color)
{
this->color = color;
}
//-----------------------------
class King : public Piece
{
public:
King(bool color);
};
King::King(bool color) : Piece(color)
{
// empty
}
//-----------------------------
class Tile
{
public:
// constructors/destructors
Tile(Piece * ppiece, int rrow, int ccol);
~Tile();
private:
Piece * piece;
int row, col;
};
Tile::Tile(Piece * ppiece, int rrow, int ccol)
{
this->ppiece = piece;
this->row = rrow;
this->col = ccol;
}
//---------------------------
int …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Django-Money将MoneyField添加到我的 Django 应用程序中。
根据要求,我需要安装py-moneyed v0.4或更高版本。
我检查了py-moneyed但它没有提到如何安装 py-moneyed?
有人可以帮助我在我的环境中安装py-moneyed和Django-Money吗?有没有一个pip
或easy_install
包可以做到这一点?