This sample code has been developed by Streamezzo.
It is a memory game (cards match).

- This code does not need the server to run
- It also takes advantage of the dynamic layout generation by using the Adaptation framework API in order to create Containers in the RSP code
- While this code is prepared to accept any size of grid, some parts of the code will only work for a 4 x 3 grid.
<%@page import="com.streamezzo.odp.utils.ShapeUtils" %>
<%@page import="com.streamezzo.odp.adaptation.layout.box.BoxLayout" %>
<%@page import="com.streamezzo.odp.adaptation.layout.box.BoxLayoutDataFactory" %>
<%@page import="com.streamezzo.odp.adaptation.layout.LayoutFactory" %>
<%@page import="com.streamezzo.odp.adaptation.skin.Skin" %>
<%@page import="com.streamezzo.odp.adaptation.layout.Container" %>
<%@page import="com.streamezzo.odp.connector.AdaptationTransaction" %>
<%@page import="com.streamezzo.odp.connector.StzConnectorsManager" %>
<%@page import="com.streamezzo.odp.connector.AdaptationConnector" %>
" colorBits="8" lengthBits="16" resolution="2" idBits="16" scaleBits="15" encodingType="0"/>
![cdata[>
<%
// Get the connector using the ConnectorManager
AdaptationConnector adaptationConnector = StzConnectorsManager.getAdaptationConnector(stzRequest.getService(), 0);
// Begin a transaction for the current request.
String theme = "memorygame";
String layoutset = "memorygame";
AdaptationTransaction tx = null;
try {
tx = (AdaptationTransaction) adaptationConnector.beginTransaction(stzRequest, theme, layoutset);
// Main containers
Container root = tx.getRootContainer("main");
Container header = root.getChildByIdRecurs("header");
Container content = root.getChildByIdRecurs("content");
Container footer = root.getChildByIdRecurs("footer");
// Skin
Skin skin = tx.getSkin();
final int COLUMNS = Integer.valueOf(skin.getProperty("columns"));
final int LINES = Integer.valueOf(skin.getProperty("lines"));
// Layout the content
// This piece of code exists in order to present how to generate a layout inside the RSP code
content.setLayout(new BoxLayout(BoxLayout.VERTICAL));
final BoxLayoutDataFactory factory = new BoxLayoutDataFactory().create().hint("FILL", "FILL");
final BoxLayout lineLayout = new BoxLayout(BoxLayout.HORIZONTAL);
for (int l = 0; l < LINES; l++) {
Container lineContainer = LayoutFactory.createContainer("line" + l);
lineContainer.setLayout(lineLayout);
factory.applyTo(lineContainer);
for (int c = 0; c < COLUMNS; c++) {
Container square = LayoutFactory.createContainer("square" + l + "_" + c);
factory.applyTo(square);
lineContainer.addContainer(square);
}
content.addContainer(lineContainer);
}
content.layout(content.getWidth(), content.getHeight(), -content.getWidth() / 2, content.getHeight() / 2);
%>
boolean isFirstChoice = true;
int pairsFound = 0;
int totalPairs = 0;
int totalTries = 0;
<%
for (int l = 0; l < LINES; l++) {
Container line = content.getChildById("line" + l);
for (int c = 0; c < COLUMNS; c++) {
Container square = line.getChildById("square" + l + "_" + c);
if (square != null) {
%>
" translation="<%= square.getTranslation() %>" choice="-2" delta="<%= square.getSize() %>">
">
" color="#FF5D39" linecolor="#000000" filled="true"
points="<%= ShapeUtils.generateRectanglePoints((int) (square.getWidth()/2.5), (int) (square.getHeight()/1.5)) %>"/>
" size="LARGE" vertAlign="MIDDLE" horizAlign="CENTERED" style="BOLD_ITALIC"/>
">
" color="#FF5D39" linecolor="#000000" filled="true"
points="<%= ShapeUtils.generateRectanglePoints((int) (square.getWidth()/2.5), (int) (square.getHeight()/1.5)) %>" active="false"/>
" target="<%= "Local:CardCacheTrsf" + l + "_" + c %>">
" target="<%= "Local:CardTrsf" + l + "_" + c %>">
">
" field="Shape.active" booleanvalue="true"/>
"/>
" field="Conditional.startTime" timevalue="NOW"/>
" field="Conditional.startTime" timevalue="NOW"/>
" keyCodes="<%= l<3?""+(c+1+l*3):c==0?"*":c==1?"0":"SHARP" %>">
"/>
<%
}
}
}
%>
<%
} finally {
if (tx != null) {
tx.endTransaction();
}
}
%>
| Attachment | Size |
|---|---|
| Memory_game.swz | 579.36 KB |