要使用 Json,我想安装 Aeson 包。
在package.yaml我添加- aeson到该dependencies:部分的文件中,我收到了一大堆错误,我在网上找不到这些错误,例如:“但是这个 GHC 启动包已被修剪”。
我试图理解错误,但我不理解其中任何一个。例如对于第一个:如果我stack ls dependencies得到text 1.2.4.0,它符合匹配,那么为什么它不起作用?
有没有办法让 Stack 为我安装东西,而不必编辑 yaml 文件然后遇到问题?(stack install似乎没有做任何事情)
完整的错误:
PS D:\Documents\Programming\Unity\Poging8_(catan)\HaskellServer> stack build
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for aeson-1.4.7.1:
text must match >=1.2.3.0 && <1.3, but this GHC boot package has been pruned (issue #4510); you need to add the
package explicitly to extra-deps (latest matching version is …Run Code Online (Sandbox Code Playgroud) 
检查我生成的图像,但我想要做的是生成带边框的矩形,并将背景颜色设置为另一个.我怎样才能做到这一点?
glRectf(top_left_x, top_left_y, bottom_right_x, bottom_right_y)?
if loop==0:
ratio = 0.10
glBegin(GL_QUADS)
while ratio <= 1.0:
width = window_width/2
height = window_height
long_length = width * ratio
short_length = height* (1.0 - ratio)
top_left_x = (width - long_length) / 2.0
top_left_y = (height - window_height * (1.0-ratio)) /2
bottom_right_x = top_left_x + long_length
bottom_right_y = top_left_y + short_length
glColor(1.0,1.0,1.0,0.5)
glVertex3f(top_left_x, top_left_y, 0.0)
glVertex3f(top_left_x + long_length, top_left_y, 0.0)
glVertex3f(bottom_right_x,bottom_right_y, 0.0)
glVertex3f(bottom_right_x-long_length,bottom_right_y, 0.0)
ratio += 0.05
glEnd()
Run Code Online (Sandbox Code Playgroud) 我试图通过创造一个从侧面反弹并减速的球来重建一些物理.球在x方向上停止移动,但它在y方向上仅向上和向下振动1个像素.它也会在底部边框上方稍微做一点.
还有,我的代码可读/良好实践吗?
Bouncy.java
package Bouncy;
import javax.swing.*;
public class Bouncy {
private static void createAndShowGui() {
JFrame frame = new JFrame("Bouncy Balls");
Board board = new Board();
frame.getContentPane().add(board);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setLocation(2000, 50);
board.requestFocusInWindow();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> createAndShowGui());
}
}
Run Code Online (Sandbox Code Playgroud)
Board.java
package Bouncy;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Board extends JPanel implements ActionListener {
public static final int BOARDWIDTH = 800;
public static final int BOARDHEIGHT = 800; …Run Code Online (Sandbox Code Playgroud) 所以我想为我的Asteroids游戏/作业定义多个数据类:
data One = One {oneVelocity :: Velocity, onePosition :: Position, (((other properties unique to One)))}
data Two = Two {twoVelocity :: Velocity, twoPosition :: Position, (((other properties unique to Two)))}
data Three = Three {threeVelocity :: Velocity, threePosition :: Position, (((other properties unique to Three)))}
Run Code Online (Sandbox Code Playgroud)
如您所见,我有多个具有重叠属性(速度,位置)的数据类.这也意味着我必须为每个数据类赋予不同的名称("oneVelocity","twoVelocity",......).
有没有办法让这些类型的数据扩展?我想过使用一个带有多个构造函数的数据类型,但是这些当前数据类中的一些是非常不同的,我不应该将它们存放在一个具有多个构造函数的数据类中.
当我从Square实例创建Board实例时,我尝试将窗口的大小分配给整数x和y.我没有这样做,因为它似乎在开始时大小为0.在Board.java的构造函数中,x和y不应该像-50一样现在最终结束.
Square.java:
package Square;
import javax.swing.*;
public class Square extends JFrame {
public Square(){
add(new Board());
setSize(800, 800);
setVisible(true);
}
public static void main(String[] args){
new Square();
}
}
Run Code Online (Sandbox Code Playgroud)
Board.java
package Square;
import javax.swing.*;
import java.awt.*;
public class Board extends JPanel{
int x,y;
public Board(){
x = width-50;
y = height-50;
}
public int width = (int) getSize().getWidth();
public int height = (int) getSize().getHeight();
public void paintComponent(Graphics g){
super.paintComponent(g);
g.fillRect(x,y, 100, 100);
}
}
Run Code Online (Sandbox Code Playgroud)
完整代码澄清:Square.java
package Square;
import javax.swing.*;
public …Run Code Online (Sandbox Code Playgroud) 我尝试重新创建四子棋,并且成功了。但我想通过时不时地切换颜色来让玩家知道获胜的四张棋子在哪里。我对编程中的线程和时间概念很陌生。
我也成功地向用户提供了此指示,但在关闭应用程序后,控制台仍然给出输出,当我使用 setOnCloseRequest 时也是如此。
其他一些问题:
1:对于我使用 html 名称的颜色,使用十六进制三元组更好还是没有偏好。
2:为了阻止网格和其他元素紧贴屏幕左侧,我添加了一个与背景颜色相同的边框,有更好的方法吗?
3:我没有创建将键码转换为整数的方法,而是在 init 函数中创建。我这样做是因为我不知道如何传递关键事件。这个怎么做?
这是代码:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class FourInARow extends Application {
GridPane boardGrid = new GridPane();
Label[][] labels = new Label[7][7];
Label statusLabel = new Label();
int[][] cell = new int[7][6];
int player = 0;
int won = 0;
String baseStyle = "-fx-background-radius: 40; -fx-min-width: …Run Code Online (Sandbox Code Playgroud) 你好
我尝试设置添加:after,color: ;覆盖但text-decoration: ;不起作用的内容.
code.html
<html>
<head>
<style>
.separate-hyphen *:not(:last-child):after {
content: " -\00a0";
text-decoration: none;
color: red;
}
</style>
</head>
<body>
<div class="separate-hyphen">
<a href="link1.extension">Link 1</a>
<a href="link2.extension">Link 2</a>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
结果 (这是一张图片)