Please help to solve a task on php - class

Got the following task:
create a prototype of the game - get the code below to work. Game is the class of the game, and Tile is a tile in the game (an individual area that has coordinates). Implement the missing classes and methods so that the result is a playing field as in the comments (there should be a house, trees, lawn and flowers).
class Game
{
}
class Tile
{
}
$game = new Game([
new House(0,0), //house
new Tree(1,0), //tree
new Tree(2,0), //tree
new Lawn(0,1), //lawn
new Lawn(0,2), //lawn
new Lawn(0,3), //lawn
new Lawn(0,3), //lawn
new Flower(3,0), //flower
new Flower(1,3), //flower
]);
/*
0 1 2 3
0 🏠 🌳 🌳 🌼
1 🌿
2 🌿
3 🌿 🌼
*/"
Could you please suggest what method can be used to display the specified playing field?
I suppose that this task can be solved by specific method but I have no clue.

Related

MapBox Symbol doesn't act like markers properly (clustering, click..)

I am trying to make moving cars on MapBox using new promising GL Symbol layer/source. It looks very nice both on android and ios, but I faced with two impossibilities.
Symbols are always clustering. setIconAllowOverlap() and setIconIgnorePlacement() don't help: on some zoom it WILL be clustered. On both platforms.
How can I disable symbols clustering completely?
UPDATE: the code and even fast solution! (possibly bug? see comment at withTextField)
in onStyleLoaded():
...
carManager = new SymbolManager(mapView, mapboxMap, style);
carManager.setIconAllowOverlap(true);//doesn't help
carManager.setIconIgnorePlacement(true);//doesn't help
...
in drawCarFunction():
...
SymbolOptions carOptions = new SymbolOptions()
.withLatLng(latLng)
.withIconImage(carPlate)
//.withTextField(carPlate) //!!!! here it will cluster if text exists, and will NOT - without any text
;
Symbol car= carManager.create(carOptions);
carSymbols.add(car);
...
Next question:
On Android we have symbolManager.addClickListener() , but how could I catch a click on iOS? I know I can catch the tap, calculate nearest marker etc but
How to get symbol click simpler in swift?
In Moving cars task I should enumerate existing cars, move running, add newest. Where should I store cars IDs to get it later on next move? Where are no even symbol.setTag() option... Storing IDs in snippet (as on GMaps) is not that choice I expected from MapBox. Sure, I can make an array of pairs "car ID = symbol ID", but
How to store my own UID in the symbol?
UPDATE: the code. Note the comment near getTag()
void moveExistingCarOrAddNew(int carId, LatLng newLocation){
for (int i = 0; i < carManager.getAnnotations().size(); i++) {
if (carManager.getAnnotations().get(i).getTag()==carId){ //but no getTag() here, I should fit data into text fields
car.setLatLng(newLocation); //move!
} else {
...//create new marker as shown above }
}
}
}

Adding a title in Custom Graph in Facebook

I using a custom graph api for publishing a story. While publishing the story the API always picks up the "One to One - Without Object Title" and not "One to One". I need to pick the "One to One" as it has an option to update the "level.title".
Question
How to make my code to pick "One to One"
How to correct my post to have "
James Jack cleared a level 1 in Puzzle Game - Ball Mania" Instead of "James Jack cleared a level in Puzzle Game - Ball Mania"
Code
// Create an object
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "puzzlegameballmania:level")
.putString("og:title", "Puzzle Game - Ball Mania")
.putString("og:image", "http://i67.tinypic.com/svl2qt.png")
.putString("og:url", "https://play.google.com/store/apps/details?id=memory.game.collection.free")
.putString("og:description", "Color of the balls matters more. Lets break the goal and go higher !")
.putString("puzzlegameballmania:level:title", "LEVEL 1")
.build();
// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("puzzlegameballmania:clear")
.putObject("puzzlegameballmania:level", object)
.build();
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("puzzlegameballmania:level")
.setAction(action)
.build();
ShareDialog.show(AndroidLauncher.this, content);

Drop detection in easeljs

I'm new to EaselJS. I wonder how I can detect a drop of one container on another container in EaselJS.
So I want to get the dropped container in an eventlistener of the drop target container.
Any examples on this?
I could not find this in the drag drop examples of EaselJS.
Thanks
You can also use getObjectsUnderPoint. Here is a quick sample I put together.
http://jsfiddle.net/lannymcnie/6rh7P/1/
var targets = stage.getObjectsUnderPoint(stage.mouseX, stage.mouseY);
This is from another post asking a similar question. I also posted more info about it.
EaselJS: connect 2 containers/shapes using a line
In the pressmove or stagemouseup event, you can verify if the mouse position (stage.mouseX and stage.mouseY) if over the parent container. To do the verification, you can use the hitTest.
Notice that, hitTest will only if your parent container has at least one mouse event listener, which I think is a bug on EaselJS 0.7.1
I made this class on coffeescript to solve that problem:
class DragContainer
DragContainer.prototype = new createjs.Container()
DragContainer::Container_initialize = DragContainer::initialize
constructor: (opts) ->
#initialize opts
DragContainer::initialize = (opts) ->
#Container_initialize()
#droptargets = new Array()
#on 'mousedown', #handleMouseDown
handleMouseDown: (e) =>
#on 'pressup', (ev)=>
#removeAllEventListeners 'pressup'
if #droptargets and #droptargets.length > 0
#evaluateDrop e
evaluateDrop: (e) =>
target = null
dropped = false
for drop in #droptargets
pt = drop.globalToLocal stage.mouseX, stage.mouseY
if drop.hitTest pt.x, pt.y
target = drop
dropped = true
if dropped
#dispatchEvent {type: 'dropped', currentTarget: target}
else
#dispatchEvent {type: 'dropped', currentTarget: null}
The droptargets property is an array that keeps the objects you want to associate with the drop of your container.

Event after DOM manipulation in Sencha Touch

Is their an event available after DOM manipulation in Sencha Touch has succeeded?
I want to measure the time it takes to render a list with 1000 elements.
Therefor, a timer is started when the list is initialized and stoppend when the list is painted like so:
listeners: {
initialize: function () {
start = new Date();
var store = Ext.getStore('Songs');
for (var i = 1; i <= 1000; i++) {
store.add({id: i});
}
},
painted: function () {
stop = new Date();
Ext.Msg("Timer", stop - start);
}
}
The painted event is triggerd before DOM manipulation so the 1000 listitems are not visible when the rentertime pops up.
Is there an other event that is triggerd after DOM has been manipulated and the list is updated?
Or is there an alternative method to measure the time it takes to do this?
Greets,
Sander Van Loock
Unfortunately you are not answering, therefore I can only guess:
You are adding each item seperately to the store. In Sencha Touch this will eat up time. Better to create an array of items and add them at once.
If you are adding items and the update of the store takes too long, stop sorting of the store.
If you are interested in the list you better work with before and after events. Something like before updatedata and after updatadata. Or you could add start to the first itemTpl.
But again. Painting of a list which is infinite will not take any real time. So the DOM part really is not what you are looking for.
If you are using the dataview, this might be different.

Can a dojo.dnd.Source object contains another dojo.dnd.Source object as one of the child nodes?

I have looked at the this link for a tutorial on dojo drag and drop feature. But one thing I have noticed is that in all cases of the examples, the items to be dragged around are always a simple item, just a string object...
I need to create something like an item group where you can drag an item into the item group to append into the group and to drag the item group around as a whole.
Hence my question, is it possible to drag and drop a dojo.dnd.Source item into another dojo.dnd.Source item?
Short answer: no. Many people tried to patch it, but found more and more non-working edge cases, so those patches never made the Dojo proper.
If you truly need to show and manipulate a hierarchical data, consider a Tree Dijit.
The problem is that when you start dragging and you drag over a Source of a child container, everything gets messed up. (Not exactly sure how). What you can do, is hide those child sources so that their overSource events never trigger:
1) Overrode the checkAcceptance function in Source.js. Just added the following for the if(!flag) return false;:
if(!flag){
/**
* Main Source
* - Group 1
* -- Child 1
* -- Child 2
* - Group 2
*/
var node = dojo.byId(this.node);
// If the node being moved is the source, skip, but don't hide from view.
if('#'+dojo.attr(source.node, 'id') != '#'+dojo.attr(node, 'id')){
// If the node being moved is an immediate child of the container, you can move it.
if(dojo.query('#'+dojo.attr(source.node, 'id') + '>#'+dojo.attr(node, 'id')).length) {
return true;
}
// If this source is not a parent of the element, hide it.
if(dojo.query('#'+dojo.attr(node, 'id') + ' #'+dojo.attr(source.node, 'id')).length == 0)
dojo.addClass(node, 'hiddenSource');
}
return false;
}
2) You need to also add the following as the first line under if(this.isDragging) in onMouseMove (important)
var node = dojo.byId(this.node);
// If this is immeditae child, drop it.
if(dojo.query('#'+dojo.attr(m.source.node, 'id') + '>#'+dojo.attr(node, 'id')).length){
m.canDrop(true);
return;
}
3) Extended onDndDrop to remove the added class to re display the hidden elements.
onDndDrop: function(source, nodes, copy, target)
{
this.inherited(arguments);
dojo.forEach(dojo.query('.hiddenSource'),
function(el){dojo.removeClass(el, 'hiddenSource');}
);
}
4) Extend onDndCancel to do the above
onDndCanel: function()
{
this.inherited(arguments);
dojo.forEach(dojo.query('.hiddenSource'),
function(el){dojo.removeClass(el, 'hiddenSource');}
);
}
This isn't the best solution since it hides the elements that can't be used with the current element that you are positioning, but it worked for me.