I'm creating a computerised version of the card game "spit" using pygame for a project I'm working on. In Spit, the player has 5 hand piles, storing up to 5 cards, with the top card face up and the rest face down. When a card is removed from a card pile and place on a game pile, I want the remaining values of the hand pile to "move up" so that the second value in the list is now the first one.
For this, I planned on using a queue, but there is a problem with that.
In the game, when a hand pile is empty, you can take a face down card from another hand pile, flip it, and place it in the empty hand pile so that there are no more empty hand piles. This is called stockpiling.
And here's my problem, that is not possible in a queue. Is there a work around this? Or another form stack in which I can use to replace this?
Thank you for your time and I look forward to your answers.
It seems like lists could do the job here. You can represent each hand stack by a list with the index 0 being the downmost card. You can then use the list.pop() method to get and remove the last card (visible one) of the list when it's played on the board.
For the stockpiling, if I understand correctly, you can get any card in any stack (except the topmost one, which is visible), take it out and put it on top of the empty stack (which will be an empty list). You can do that with:
firstList[0] = chosenCard #Get the chosen card from the first pile
del firstList[0] #Delete the downmost card. The new list will have element
#firstList[0] equal to the old firstList[1], like a stack
secondList.append(chosenCard) #Add the card to the end of the list (top of the stack)
Related
I have a lazy-column with a pager to show items using paging-compose 1 alpha 16 (latest).
I have some issues around.
1-> Every time an item is off the screen and back again it comes with a leak on the view like it was loading the entire data.
2-> When an item is updated on DB it changes its position on the list (as expected) but it is not show in the new data.
3-> The new data is only displaying correctly when the item goes out and get back to the screen.
I follow this tutorial to achieve the actual behavior https://medium.com/simform-engineering/list-view-with-pagination-using-jetpack-compose-e131174eac8e
My paging Size is of 50 items and i have leaks even with only 15. The views are simple. They have an image and 2 texts. And i tested without the image as well and still remains the problems.
The problem with the second point was that my text where custom AndroidViews and i was missing the update state parameter. For the other problems i still waiting for help
I decided to give SwiftUI a go but I seem to be having a bit of a blonde moment here.
All I did was create a Form to which I added few Text objects. Due to the limit of 10 per parent view, I added the objects to Groups.
When adding new Groups inside the same Form, I noticed that the first object of the Group gets added behind all the objects in the Group above as well. Seems like a weird feature, but it's entirely possible that I'm just being thick here.
I can get rid of the overlapping by adding a Spacer, an empty string or changing the Group to a Section for example. But what would be the solution if I want it to be one long list without any separators?
Group is not a container, imaging it as a transparent thing, which just inserts its content at the top of the available space. So you have two consequent groups, so from layout perspective the top starts for them all at the beginning of Form. That's why group content views overlap, and that's why they are not if you insert some separator between groups - top of each group proposed by Form is different.
In your use-case I would recommend to use VStack instead of Group.
I want the first node to stay on top and should not be affected during scroll. The first node will be like a column header(stays on top even scrolling). How can I do that?
This kind of behavior is something you can currently find in spreasheets:
Lock first column (Header.Columns[0].Options → coFixed)
Lock first row (?)
I'm trying to insert a picture for more explanation but I don't have 10 reputations. Sorry about that. Thanks in advance.
You can't as VirtualTree doesn't support such a behaviour. Besides, VT already has header support (include hoVisible to Header.Options to show it) why don't you use that? You can custom paint it (see OnHeaderDraw events) if you want it to look like ordinary node.
I have this tool tip that is created every so often. What is the appropriate actionscript etiquite?
A. To Create and remove the tooltip moveclip when needed?
or
B. To hide and show the tooltip movieclip when needed?
With these A and B, the answer is B, because creating and then removing an object a lot of times creates a lot of garbage in the memory, which eventually leads to garbage collector calls, that slow your SWF's performance. You can easily go with a single tooltip MC, just fill it with information that corresponds to the new mouse coordinates before you show it.
There is another question, not so straightforward as yours, about how to hide and show a movie clip, either via visible property or via addChild() and removeChild() (AS3 only). If you are using AS2 or AS1, use visible property to hide and show your tooltip.
There are three ways to hide something in Actionscript : Alpha, visible and remove child.
Apha: If you turn the alpha zero the renderer always comes to this displayObject and renders it at alpha zero. So the object is always rendered you just cannot see it.
Visible == false In this case the object still exists in your displaylist. So the renderer comes to the object. Sees it's property is false and leaves it but it still exists in the display list.
removeChild This means that you're removing the object from the display list. This means that the renderer never had to even check for it. Which makes it the fastest option.
addChild doesn't take that much computing power as visible check. I'm sure you can find benchmarks on this.
If you don't have a lot of objects on yours screen and the tooltip is there every second I'd go with visible is false. In all other cases go with the third option.
On a side note, I've found it always easier to manage them with a toolTipManager. A class that makes sure that you have one tooltip on the screen because usually users only use one tooltip. So that makes things easier for me. I just always create the necessary tooltips and add them to the displaylist when required and remove them. (Not recreate them) At the same time have only one tooltip on stage.
Is it possible to add gui components to blackberry screen beginning from the bottom instead of the top ?
Thanks
A quick response would be no but let me explain why and suggest afew work arounds;
Screens don't actually handle the laying out of fields onto themselves, to do this they delcare a delegate manager which can be any type of manager, vertical, horizontal etc. The problem is all managers begin painting themselves from the top left. For a manager to paint fields starting from the bottom it would have to know exaclty where the bottom is located and add components up rather than down which goes against all the low level code inside the manager class. You can read more on managers in the BlackBerry API documentation.
You could still achieve an effect similar to this though by tweaking how you add fields and playing with field styles. For example consider this code:
add(new LabelField("field 1"));
add(new LabelField("field 2"));
This would give us the results;
field 1
field 2
because field 1 is drawn then field 2 below it. However if we were always to insert fields at the begining of our manager e.g. position 0 like so:
insert(new LabelField("field 1", FIELD_BOTTOM), 0);
insert(new LabelField("field 2", FIELD_BOTTOM), 0);
We would get the results;
field 2
field 1
Which is the results you'd expect from a screen described in your question.
I'm not really sure how you'd get the fields to paint to the bottom of a screen though, you could try researching the "position relative bottom" styles but I'm honestly unsure.
You are probably using a VerticalFieldManager, and the documentation on that says:
A vertical field manager lays out
fields top to bottom in a single
column.
So if you
manager.add(field1);
manager.add(field2);
manager.add(field3);
The order of the fields on the screen will be just that.
But you could do something like this:
Vector v = new Vector();
v.add(field1);
v.add(field2);
v.add(field3);
for(int i=v.size()-1;i>=0;i--) {
manager.add((Field)v.elementAt(i));
}
Sort of. You can use the Manager#insert(Field, int) method and always insert at the zero index. If you do this with a VerticalFieldManager, it would simulate a bottom-up adding of Fields to the Manager.
Some of the answers so far are to use Manager.insert(Field, int), and keep inserting at position 0. This will work, but the running time of the insert is linear in the number of elements already added to the manager. Meaning this solution will have an overall quadratic running time. Not a big deal if you're adding under 10 fields, but if you're planning on adding more than that, the insert overhead will be substantial.
If you can do the inserts top to bottom, by reordering the fields as Muger's solution suggests, the running time will be much improved.
Finally, you can write your own BottomUpVerticalFieldManager that does the layout the way you want. When you write your own manager, you can layout the fields in whatever way pleases you. In this case, it would be bottom to top. Writing your own manager may seem daunting, but it will give you considerable freedom in the future when trying to solve layout issues.