/**
* NetScramble: unscramble a network and connect all the terminals.
*
* This is an Android implementation of the KDE game "knetwalk".
* The player is given a network diagram with the parts of the network
* randomly rotated; he/she must rotate them to connect all the terminals
* to the server.
*
* Original author:
* QNetwalk, Copyright (C) 2004, Andi Peredri <[email protected]>
*
* Ported to kde by:
* Thomas Nagy <tnagyemail-mail@yahoo@fr>
*
* Cell-locking implemented by:
* Reinhold Kainhofer <[email protected]>
*
* Ported to Android by:
* Ian Cameron Smith <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation (see COPYING).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package org.hermit.netscramble;
import java.util.EnumMap;
import java.util.Random;
import java.util.Vector;
import net.goui.util.MTRandom;
import org.hermit.netscramble.NetScramble.Sound;
import org.hermit.netscramble.NetScramble.State;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.RelativeLayout;
/**
* This implements the game board by laying out a grid of Cell objects.
*
* Unlike the original knetwalk, we have to deal with a physical display
* whose size can vary dramatically, but which we would like to fill;
* on the other hand, it may be too small for a "full-sized" game,
* particularly bearing in mind the minimum size a cell can be and still
* allow a finger to select it. We therefore put a lot of work into
* figuring out how big the board should be.
*/
public class BoardView
extends RelativeLayout
{
// ******************************************************************** //
// Configuration Constants.
// ******************************************************************** //
/**
* Maximum major dimension of the board. The "long" dimension of the
* board can't be more than this. This must match up with the dimensions
* given in enum Skill below.
*/
private static final int BOARD_MAJOR = 9;
/**
* Maximum minor dimension of the board. The "short" dimension of the
* board can't be more than this. This must match up with the dimensions
* given in enum Skill below.
*/
private static final int BOARD_MINOR = 6;
/**
* The minimum cell size in pixels.
*/
private static final int CELL_MIN = 28;
/**
* The maximum cell size in pixels.
*/
private static final int CELL_MAX = 64;
// ******************************************************************** //
// Public Types.
// ******************************************************************** //
/**
* Enumeration defining a game skill level. Each enum member also
* stores the configuration parameters for that skill level.
*
* Traditional knetwalk has these board sizes:
* Novice: 5x5 = 25 tiles = 31%
* Normal: 7x7 = 49 tiles = 60%
* Expert: 9x9 = 81 tiles = 100%
* Master: 9x9 = 81 tiles = 100% wrapped
*
* We have to deal with a small screen, and we want the cells to be big
* enough to touch. So, we set the board sizes as shown below. We also
* introduce the wrinkle of blind tiles, to make an insane level:
* Novice: 4x5
* Normal: 6x5
* Expert: 6x9
* Master: 6x9 wrapped
* Insane: 6x9 wrapped blind
*/
public enum Skill {
// Name id dims brch wrap blind
NOVICE(R.string.skill_novice, R.id.skill_novice, 4, 5, 2, false, 9),
NORMAL(R.string.skill_normal, R.id.skill_normal, 6, 5, 2, false, 9),
EXPERT(R.string.skill_expert, R.id.skill_expert, 6, 9, 2, false, 9),
MASTER(R.string.skill_master, R.id.skill_master, 6, 9, 3, true, 9),
INSANE(R.string.skill_insane, R.id.skill_insane, 6, 9, 3, true, 3);
private Skill(int lab, int i, int mn, int mj, int br, boolean w, int bd) {
label = lab;
id = i;
minDim = mn;
majDim = mj;
branches = br;
wrapped = w;
blind = bd;
}
public int label; // Res. ID of the label for this skill level.
public int id; // Numeric ID for this skill level.
public int minDim; // Shorter dimension of the playable board.
public int majDim; // Longer dimension of the playable board.
public int branches; // Max branches off each square; at least 2.
public boolean wrapped; // If true, network wraps around the edges.
public int blind; // Squares with this many or more connections
// are blind.
}
// ******************************************************************** //
// Constructor.
// ******************************************************************** //
/**
* Construct a board view.
*
* @param parent The application context we're running in.
*/
public BoardView(NetScramble parent) {
super(parent);
parentApp = parent;
// Find out the device's screen dimensions and calculate the
// size and shape of the cell matrix.
findMatrix(BOARD_MAJOR, BOARD_MINOR);
// Create all the cells in the calculated board. In onSizeChanged()
// we will take care of positioning them. Set the cell grid and root
// so we have a valid state to save.
Log.i(TAG, "Create board " + gridWidth + "x" + gridHeight);
cellMatrix = new Cell[gridWidth][gridHeight];
for (int y = 0; y < gridHeight; ++y) {
for (int x = 0; x < gridWidth; ++x) {
Cell cell = new Cell(parent, this, x, y);
cell.setId(y * gridWidth + x + 1);
cellMatrix[x][y] = cell;
addView(cell);
}
}
rootCell = cellMatrix[0][0];
// Create the animation objects used to animate moves.
cellRotator = new CellRotation();
cellBlinker = new CellBlink();
// Create the connected flags and connecting cell connectingCells
// (used in updateConnections()).
isConnected = new boolean[gridWidth][gridHeight];
connectingCells = new Vector<Cell>();
// Handle key events on the board.
setFocusable(true);
focusedCell = null;
setFocus(rootCell);
}
/**
* Find the size of board that can fit in the window.
*
* @param width Width of the window, in pixels.
* @param height Height of the window, in pixels.
* @param desiredCells Number of cells we'd like to have.
*/
private void findMatrix(int maj, int min) {
WindowManager wm =
(WindowManager) parentApp.getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();
int width = disp.getWidth();
int height = disp.getHeight();
Log.v(TAG, "findMatrix: screen=" + width + "x" + height);
if (width > height) {
gridWidth = maj;
gridHeight = min;
} else {
gridWidth = min;
gridHeight = maj;
}
}
// ******************************************************************** //
// Initialization.
// ******************************************************************** //
/**
* This is called during layout when the size of this view has
* changed. This is where we first discover our window size, so set
* our geometry to match.
*
* @param width Current width of this view.
* @param height Current height of this view.
* @param oldw Old width of this view. 0 if we were
没有合适的资源?快使用搜索试试~ 我知道了~
游戏源码 Scrambled Net(含截图).rar
共284个文件
svn-base:115个
class:33个
png:30个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 22 浏览量
2023-03-23
08:02:06
上传
评论
收藏 665KB RAR 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
收起资源包目录
游戏源码 Scrambled Net(含截图).rar (284个子文件)
all-wcprops 3KB
all-wcprops 3KB
all-wcprops 674B
all-wcprops 621B
all-wcprops 602B
all-wcprops 351B
all-wcprops 226B
all-wcprops 214B
all-wcprops 198B
all-wcprops 198B
all-wcprops 91B
all-wcprops 88B
all-wcprops 87B
all-wcprops 84B
all-wcprops 83B
all-wcprops 82B
all-wcprops 80B
all-wcprops 80B
all-wcprops 79B
resources.ap_ 66KB
Scrambled Net.apk 97KB
NetScramble.class 18KB
BoardView.class 17KB
Cell.class 11KB
InfoBox.class 4KB
Timer.class 3KB
MTRandom.class 3KB
BoardView$CellRotation.class 2KB
AppUtils.class 2KB
Cell$Dir.class 2KB
BoardView$Skill.class 2KB
R$string.class 2KB
Cell$Image.class 2KB
Timer$1.class 1KB
NetScramble$State.class 1KB
NetScramble$Sound.class 1KB
NetScramble$SoundMode.class 1KB
R$drawable.class 1KB
BoardView$CellBlink.class 1KB
AppUtils$Detail.class 1KB
InfoBox$Detail.class 1KB
NetScramble$3.class 1KB
NetScramble$1.class 1KB
NetScramble$2.class 1001B
NetScramble$5.class 941B
NetScramble$4.class 933B
R$id.class 917B
InfoBox$2.class 857B
InfoBox$1.class 753B
NetScramble$GameTimer.class 707B
R.class 603B
R$raw.class 513B
R$menu.class 405B
R$attr.class 352B
.classpath 280B
COPYING 18KB
COPYING-MTRandom 26KB
classes.dex 56KB
dir-prop-base 28B
entries 4KB
entries 3KB
entries 1KB
entries 910B
entries 801B
entries 526B
entries 392B
entries 388B
entries 385B
entries 378B
entries 309B
entries 290B
entries 267B
entries 266B
entries 264B
entries 261B
entries 254B
entries 249B
entries 246B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
BoardView.java 41KB
NetScramble.java 40KB
Cell.java 23KB
共 284 条
- 1
- 2
- 3
资源评论
荣华富贵8
- 粉丝: 150
- 资源: 7649
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 写入三菱plcD位寄存器的值
- 确保你的操作系统符合Docker的要求 Docker支持的操作系统包括Ubuntu、Debian、CentOS、Fedora和m
- 确保你的操作系统符合Docker的要求 Docker支持的操作系统包括Ubuntu、Debian、CentOS、Fedora和m
- HDMI 虚拟软件欺骗器
- 确保你的操作系统符合Docker的要求 Docker支持的操作系统包括Ubuntu、Debian、CentOS、Fedora和m
- 读取三菱PLC D位寄存器
- HDMI edid 编辑工具
- 要在你的计算机上安装Docker,你可以按照以下步骤进行:
- 要在你的计算机上安装Docker,你可以按照以下步骤进行:
- html加JavaScript进行表单验证
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功