/*
* Copyright (c) 2021 Huawei Device Co., Ltd.All rights reserved.
* Licensed under the Apache License,Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ohos.samples.tictactoegame.slice;
import com.daimajia.ohosanimations.library.Techniques;
import com.daimajia.ohosanimations.library.YoYo;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.IAbilityConnection;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Image;
import ohos.agp.components.RoundProgressBar;
import ohos.app.dispatcher.TaskDispatcher;
import ohos.bundle.ElementName;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;
import ohos.eventhandler.InnerEvent;
import ohos.rpc.IRemoteObject;
import ohos.samples.tictactoegame.ResourceTable;
import ohos.samples.tictactoegame.connections.MyRemoteProxy;
import ohos.samples.tictactoegame.utils.DeviceUtils;
import ohos.samples.tictactoegame.utils.GameStatusUtils;
import ohos.samples.tictactoegame.utils.PkUtils;
import java.util.Timer;
import java.util.TimerTask;
/**
* StartAbilitySlice
*/
public class StartAbilitySlice extends AbilitySlice {
private static final int NOT_USE = 0;
private static final int USE = 1;
private static final int STATSUS_OFF = 0;
private static final int STATSUS_ON = 1;
private static final int IS_HOST = 1;
private static final int IS_ADV = 2;
private static final int IS_STOP = 3;
private static final int COL_NUM = 3;
private static final int ROW_NUM = 3;
private static final int GAME_LOSE = 0;
private static final int GAME_WIN = 1;
private static final int GAME_DOGFALL = 2;
private static final int GAME_COM_CLICK1 = 101;
private static final int GAME_COM_CLICK9 = 109;
private static final int GAME_COM_GAME_START = 110;
private static final int GAME_DEFAULT_VALUE = 0;
private static final int GAME_COM_IS_SLAVE = 301;
private static final int GAME_COM_LOST = 401;
private static final int GAME_COM_WIN = 402;
private static final int GAME_COM_DOGFALL = 403;
private static final int GAME_COM_EXIT = 404;
private static final int GAME_COM_RESTART = 501;
private static final int GAME_COUNT_TIME = 10;
private static final int GAME_DELAY_LONG = 1000;
private static final int GAME_DELAY_SHORT = 500;
private static final int HALF_GRID = 5;
private static final int BUTTON_IDX_0 = 0;
private static final int BUTTON_IDX_1 = BUTTON_IDX_0 + 1;
private static final int BUTTON_IDX_2 = BUTTON_IDX_1 + 1;
private static final int BUTTON_IDX_3 = BUTTON_IDX_2 + 1;
private static final int BUTTON_IDX_4 = BUTTON_IDX_3 + 1;
private static final int BUTTON_IDX_5 = BUTTON_IDX_4 + 1;
private static final int BUTTON_IDX_6 = BUTTON_IDX_5 + 1;
private static final int BUTTON_IDX_7 = BUTTON_IDX_6 + 1;
private static final int BUTTON_IDX_8 = BUTTON_IDX_7 + 1;
private final static int[][] HOST = {{NOT_USE, NOT_USE, NOT_USE},
{NOT_USE, NOT_USE, NOT_USE}, {NOT_USE, NOT_USE, NOT_USE}};
private final static int[][] ADVERSARY = {{NOT_USE, NOT_USE, NOT_USE},
{NOT_USE, NOT_USE, NOT_USE}, {NOT_USE, NOT_USE, NOT_USE}};
private static boolean isButtonRefresh;
private static boolean isButtonBack;
private int pageStatus = STATSUS_OFF;
private static int gameStatus = STATSUS_OFF;
private static int playGame;
private static Image image1;
private static Image image2;
private static Image image3;
private static Image image4;
private static Image image5;
private static Image image6;
private static Image image7;
private static Image image8;
private static Image image9;
private static Image imageBack;
private static Image imageRefresh;
private static Image imageMe;
private static int myImg;
private static int advImg;
private static int resetImg;
private static MyRemoteProxy myProxy = null;
private static boolean countDownSwitch;
private static Timer timer = null;
private static int midTime;
private static TaskDispatcher myTaskDis;
private static RoundProgressBar roPrbar;
private final IAbilityConnection conn = new IAbilityConnection() {
@Override
public void onAbilityConnectDone(ElementName elementName, IRemoteObject remoteObject, int i) {
myProxy = new MyRemoteProxy(remoteObject);
}
@Override
public void onAbilityDisconnectDone(ElementName elementName, int i) {
}
};
private void buttonClick(Image imageButton, int idx) {
int row = idx / ROW_NUM;
int column = idx % COL_NUM;
if (myProxy == null) {
return;
}
if ((HOST[row][column] != NOT_USE) || (ADVERSARY[row][column] != NOT_USE)) {
return;
}
if ((gameStatus == STATSUS_ON) && (playGame == IS_HOST)) {
HOST[row][column] = USE;
myProxy.sendCmd(GAME_COM_CLICK1 + idx);
imgUiGenOpe();
imageButton.setPixelMap(myImg);
}
}
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_start);
myTaskDis = getUITaskDispatcher();
resetImg = ResourceTable.Media_littleBK;
PkUtils.showTip(StartAbilitySlice.this);
preInit();
imageMe = (Image) findComponentById(ResourceTable.Id_img_me);
Image imageDv = (Image) findComponentById(ResourceTable.Id_img_dv);
int recParam = intent.getIntParam("data",GAME_DEFAULT_VALUE);
if (recParam == GAME_COM_IS_SLAVE) {
imageMe.setPixelMap(ResourceTable.Media_user_fork_me);
imageDv.setPixelMap(ResourceTable.Media_user_circled_huawei);
if (pageStatus == STATSUS_OFF) {
pageStatus = STATSUS_ON;
gameStatus = STATSUS_ON;
myImg = ResourceTable.Media_fork;
advImg = ResourceTable.Media_circled;
playGame = IS_ADV;
}
} else {
imageMe.setPixelMap(ResourceTable.Media_user_circled_me);
imageDv.setPixelMap(ResourceTable.Media_user_fork_huawei);
String recParamUser = intent.getStringParam("user");
if (recParamUser != null) {
pageStatus = STATSUS_ON;
gameStatus = STATSUS_ON;
myImg = ResourceTable.Media_circled;
advImg = ResourceTable.Media_fork;
playGame = IS_HOST;
countDownSwitch = true;
midTime = GAME_COUNT_TIME;
gameTimer();
}
}
initView();
initListener();
resetImg();
}
private void initView() {
String deviceId = DeviceUtils.getDeviceId();
if (deviceId != null) {
Intent connectPaIntent = new Intent();
Operation op1 = new Intent.OperationBuilder()
.withDeviceId(deviceId)
.withBundleName(getBundleName())
.withAbilityName("ohos.samples.tictactoegame.RemoteServiceAbility")
.withFlags(Intent.FLAG_ABILITYSLICE_MULTI_DEVICE)
.build();
connectPaIntent.setOperation(op1);
connectAbility(connectPaIntent, conn);
}
imageBack = (Image) findComponentById(ResourceTable.Id_img_back);
imageBack.setPixelMap
没有合适的资源?快使用搜索试试~ 我知道了~
Sample为帮助开发者快速熟悉HarmonyOS SDK所提供的API和应用开发流程,我们提供了一系列的应用示例
共3972个文件
png:1299个
json:554个
java:437个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 176 浏览量
2023-05-26
17:07:54
上传
评论
收藏 306.01MB ZIP 举报
温馨提示
为帮助开发者快速熟悉HarmonyOS SDK所提供的API和应用开发流程,我们提供了一系列的应用示例,即Sample。每一个应用示例都是一个独立的DevEco Studio工程项目,开发者可以将工程导入到DevEco Studio开发工具,通过浏览代码、编译工程、安装和运行应用示例来了解应用示例中涉及API的使用方法。
资源推荐
资源详情
资源评论
收起资源包目录
Sample为帮助开发者快速熟悉HarmonyOS SDK所提供的API和应用开发流程,我们提供了一系列的应用示例 (3972个子文件)
hvigorw.bat 1KB
hvigorw.bat 1KB
hvigorw.bat 1KB
hvigorw.bat 1KB
hvigorw.bat 1KB
hvigorw.bat 1KB
hvigorw.bat 1KB
hvigorw.bat 1KB
hvigorw.bat 1KB
hvigorw.bat 1KB
hvigorw.bat 1KB
hvigorw.bat 1KB
.clang-tidy 13B
.clang-tidy 13B
demo_javascript_class.cpp 3KB
nativeimage.cpp 2KB
hello.cpp 2KB
nativelayer.cpp 2KB
server.crt 769B
server.csr 603B
index.css 7KB
index.css 7KB
deliveryInfo.css 7KB
index.css 5KB
index.css 4KB
index.css 4KB
index.css 4KB
detail.css 3KB
performance.css 3KB
evaluation.css 3KB
microAmoy.css 3KB
index.css 2KB
index.css 2KB
index.css 2KB
template-group-header.css 2KB
index.css 2KB
template-card-item.css 2KB
index.css 2KB
bigimg.css 2KB
recommend.css 2KB
index.css 2KB
modalhalf.css 2KB
index.css 2KB
template-tabbar.css 2KB
setPage.css 2KB
index.css 2KB
setPage.css 2KB
index.css 1KB
index.css 1KB
index.css 1KB
index.css 1KB
modalpopup.css 1KB
productList.css 1KB
navbar.css 1KB
modalsemimode.css 1KB
searchbar.css 1KB
index.css 1KB
common.css 1KB
common.css 1KB
template-tabbar.css 1KB
index.css 1KB
index.css 1KB
index.css 1KB
success.css 1KB
recommended.css 1KB
coreModule.css 1KB
index.css 1KB
common.css 988B
comp.css 963B
index.css 951B
index.css 920B
banner.css 908B
commoditys.css 897B
common.css 890B
pageHome.css 828B
bannerSwiper.css 815B
mainContent.css 806B
index.css 776B
details.css 763B
FoodDetail.ets 13KB
EditPage.ets 13KB
DietRecord.ets 11KB
ChoicePhoto.ets 10KB
ChoicePhotos.ets 10KB
Home.ets 8KB
Index.ets 6KB
Index.ets 6KB
Index.ets 6KB
FoodCategoryList.ets 5KB
DataUtil.ets 5KB
FoodCategoryList.ets 5KB
CommonConstants.ets 5KB
ColorFilterPage.ets 5KB
Index.ets 5KB
MockData.ets 5KB
Index.ets 5KB
ListPage.ets 4KB
PlayListCover.ets 4KB
Chats.ets 4KB
CategoryPage.ets 4KB
共 3972 条
- 1
- 2
- 3
- 4
- 5
- 6
- 40
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6828
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功