我们怎样才能从它们的文件夹中显示一堆图像? (一副牌)

时间:2022-08-11 00:32:23

So in our class we have a project to make a game and we are making a card game.

所以在我们班上我们有一个制作游戏的项目,我们正在制作纸牌游戏。

We have a folder called cards that has a .jpg of all the cards in a deck as well as the backs

我们有一个名为卡片的文件夹,其中包含甲板上所有卡片的.jpg以及背面

i can get image per image manually but thats lag and no one wants that

我可以手动获取每个图像的图像,但这是滞后的,没有人想要这样

how could we call the images(each with a file name of the card value and suit)?

我们怎样才能调用图像(每个图像都带有卡片值和套装的文件名)?

3 个解决方案

#1


Get all the images on loading of the game and store them in variables. Then when you need them, you call the variable programmatically without having to re-read the image in -- minimal lag. If this is a Swing GUI (you don't say), you could store them as ImageIcons and display the icons in JLabels.

在加载游戏时获取所有图像并将其存储在变量中。然后,当您需要它们时,您可以以编程方式调用变量,而无需重新读取图像 - 最小滞后。如果这是一个Swing GUI(您没有说),您可以将它们存储为ImageIcons并在JLabel中显示图标。

The fine details of the solution will depend on the fine details of your problem, your file structure and your current code base.

解决方案的细节取决于问题的详细信息,文件结构和当前代码库。

#2


Establish some pattern for the filenames (e.g. card_{{SUIT}}{{VALUE}}.jpg). Then when you load, you'd have something along the lines of:

为文件名建立一些模式(例如,卡_ {{SUIT}} {{VALUE}}。jpg)。然后当你加载时,你会有以下几点:

for each suit
    for each value
        load "card_" + suit + value + ".jpg"

#3


This is a learning exercise, I'd recommend just doing your best to find a solution that works.

这是一个学习练习,我建议你尽力找到有效的解决方案。

However, if you want to go the extra mile, you can store the images as static in your card or deck class file so there's only one version of each image in memory. In terms of the best practice for categorizing the cards, I'd recommend giving the card class some enumerators. Here's the oracle enumerators tutorial

但是,如果您想加倍努力,可以将图像作为静态存储在卡片或卡片类文件中,这样每个图像在内存中只有一个版本。就分类卡的最佳实践而言,我建议给卡类一些枚举器。这是oracle枚举器教程

#1


Get all the images on loading of the game and store them in variables. Then when you need them, you call the variable programmatically without having to re-read the image in -- minimal lag. If this is a Swing GUI (you don't say), you could store them as ImageIcons and display the icons in JLabels.

在加载游戏时获取所有图像并将其存储在变量中。然后,当您需要它们时,您可以以编程方式调用变量,而无需重新读取图像 - 最小滞后。如果这是一个Swing GUI(您没有说),您可以将它们存储为ImageIcons并在JLabel中显示图标。

The fine details of the solution will depend on the fine details of your problem, your file structure and your current code base.

解决方案的细节取决于问题的详细信息,文件结构和当前代码库。

#2


Establish some pattern for the filenames (e.g. card_{{SUIT}}{{VALUE}}.jpg). Then when you load, you'd have something along the lines of:

为文件名建立一些模式(例如,卡_ {{SUIT}} {{VALUE}}。jpg)。然后当你加载时,你会有以下几点:

for each suit
    for each value
        load "card_" + suit + value + ".jpg"

#3


This is a learning exercise, I'd recommend just doing your best to find a solution that works.

这是一个学习练习,我建议你尽力找到有效的解决方案。

However, if you want to go the extra mile, you can store the images as static in your card or deck class file so there's only one version of each image in memory. In terms of the best practice for categorizing the cards, I'd recommend giving the card class some enumerators. Here's the oracle enumerators tutorial

但是,如果您想加倍努力,可以将图像作为静态存储在卡片或卡片类文件中,这样每个图像在内存中只有一个版本。就分类卡的最佳实践而言,我建议给卡类一些枚举器。这是oracle枚举器教程