package edu.hzuapps.androidlabs.soft1614080902127;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Random;
public class SecondActivity extends Activity
{
private TextView txtMineCount;
private TextView txtTimer;
private ImageButton btnSmile;
private TableLayout mineField;
private Block blocks[][];
private int blockDimension = 24;
private int blockPadding = 2;
private int numberOfRowsInMineField = 9;
private int numberOfColumnsInMineField = 9;
private int totalNumberOfMines = 10;
private Handler timer = new Handler();
private int secondsPassed = 0;
private boolean isTimerStarted;
private boolean areMinesSet;
private boolean isGameOver;
private int minesToFind;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
txtMineCount = (TextView) findViewById(R.id.MineCount);
txtTimer = (TextView) findViewById(R.id.Timer);
// set font style for timer and mine count to LCD style
Typeface lcdFont = Typeface.createFromAsset(getAssets(),
"fonts/lcd2mono.ttf");
txtMineCount.setTypeface(lcdFont);
txtTimer.setTypeface(lcdFont);
btnSmile = (ImageButton) findViewById(R.id.Smiley);
btnSmile.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
endExistingGame();
startNewGame();
}
});
mineField = (TableLayout)findViewById(R.id.MineField);
showDialog("Click smiley to start New Game", 2000, true, false);
}
private void startNewGame()
{
// plant mines and do rest of the calculations
createMineField();
// display all blocks in UI
showMineField();
minesToFind = totalNumberOfMines;
isGameOver = false;
secondsPassed = 0;
}
private void showMineField()
{
// remember we will not show 0th and last Row and Columns
// they are used for calculation purposes only
for (int row = 1; row < numberOfRowsInMineField + 1; row++)
{
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableRow.LayoutParams((blockDimension + 2 * blockPadding) * numberOfColumnsInMineField, blockDimension + 2 * blockPadding));
for (int column = 1; column < numberOfColumnsInMineField + 1; column++)
{
blocks[row][column].setLayoutParams(new TableRow.LayoutParams(
blockDimension + 2 * blockPadding,
blockDimension + 2 * blockPadding));
blocks[row][column].setPadding(blockPadding, blockPadding, blockPadding, blockPadding);
tableRow.addView(blocks[row][column]);
}
mineField.addView(tableRow,new TableLayout.LayoutParams(
(blockDimension + 2 * blockPadding) * numberOfColumnsInMineField, blockDimension + 2 * blockPadding));
}
}
private void endExistingGame()
{
stopTimer(); // stop if timer is running
txtTimer.setText("000"); // revert all text
txtMineCount.setText("000"); // revert mines count
btnSmile.setBackgroundResource(R.drawable.smile);
// remove all rows from mineField TableLayout
mineField.removeAllViews();
// set all variables to support end of game
isTimerStarted = false;
areMinesSet = false;
isGameOver = false;
minesToFind = 0;
}
private void createMineField()
{
// we take one row extra row for each side
// overall two extra rows and two extra columns
// first and last row/column are used for calculations purposes only
// x|xxxxxxxxxxxxxx|x
// ------------------
// x| |x
// x| |x
// ------------------
// x|xxxxxxxxxxxxxx|x
// the row and columns marked as x are just used to keep counts of near by mines
blocks = new Block[numberOfRowsInMineField + 2][numberOfColumnsInMineField + 2];
for (int row = 0; row < numberOfRowsInMineField + 2; row++)
{
for (int column = 0; column < numberOfColumnsInMineField + 2; column++)
{
blocks[row][column] = new Block(this);
blocks[row][column].setDefaults();
// pass current row and column number as final int's to event listeners
// this way we can ensure that each event listener is associated to
// particular instance of block only
final int currentRow = row;
final int currentColumn = column;
// add Click Listener
// this is treated as Left Mouse click
blocks[row][column].setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
// start timer on first click
if (!isTimerStarted)
{
startTimer();
isTimerStarted = true;
}
// set mines on first click
if (!areMinesSet)
{
areMinesSet = true;
setMines(currentRow, currentColumn);
}
// this is not first click
// check if current block is flagged
// if flagged the don't do anything
// as that operation is handled by LongClick
// if block is not flagged then uncover nearby blocks
// till we get numbered mines
if (!blocks[currentRow][currentColumn].isFlagged())
{
// open nearby blocks till we get numbered blocks
rippleUncover(currentRow, currentColumn);
// did we clicked a mine
if (blocks[currentRow][currentColumn].hasMine())
{
// Oops, game over
finishGame(currentRow,currentColumn);
}
// check if we win the game
if (checkGameWin())
{
// mark game as win
winGame();
}
}
}
});
// add Long Click listener
// this is treated as right mouse click listener
blocks[row][column].setOnLongClickListener(new View.OnLongClickListener()
{
public boolean onLongClick(View view)
{
// simulate a left-right (middle) click
// if it is a long click on an opened mine then
// open all surrounding blocks
if (!blocks[currentRow][currentColumn].isCovered() && (blocks[currentRow][currentColumn].getNumberOfMinesInSorrounding() > 0) && !isGameOver)
{
没有合适的资源?快使用搜索试试~ 我知道了~
HZU 移动应用开发实验 2018.zip
共2000个文件
xml:938个
java:560个
md:473个
需积分: 5 0 下载量 115 浏览量
2024-04-23
22:55:04
上传
评论
收藏 459.88MB ZIP 举报
温馨提示
HZU 移动应用开发实验 2018.zip
资源推荐
资源详情
资源评论
收起资源包目录
HZU 移动应用开发实验 2018.zip (2000个子文件)
SecondActivity.java 23KB
MainActivity.java 21KB
ContentGson.java 17KB
Player.java 16KB
ShowMealActivity.java 15KB
MainActivity.java 13KB
PersonalSpace.java 12KB
LostActivity.java 11KB
add_music.java 9KB
ThirdActivity.java 9KB
SecActivity.java 9KB
SecondActivity.java 8KB
SecondActivity.java 8KB
rednews.java 8KB
DownloadTask.java 7KB
Main2Activity.java 7KB
Page1Fragment.java 7KB
Block.java 7KB
RW_file_musiclist.java 7KB
MyDownloadService.java 6KB
Soft1614080902433shiyan4commit.java 6KB
AlarmView.java 6KB
soft1614080902329RecordActivity.java 6KB
MainActivity.java 6KB
Page2Fragment.java 6KB
MainActivity.java 6KB
updateActivity.java 6KB
ThirdActivity.java 6KB
Soft1609081602308Activity.java 6KB
ThirdActivity.java 6KB
RecordSearchActivity.java 6KB
Soft1614080902129MainActivity2.java 5KB
Soft1614080902104Activity6.java 5KB
MainActivity1.java 5KB
SecondActivity.java 5KB
Main4Activity.java 5KB
MainActivity4.java 5KB
Soft1606081301325MainActivity.java 5KB
Main8Activity.java 5KB
Soft1606081301325MainActivity.java 5KB
Com1614080901217.java 5KB
PersonDBProvider.java 5KB
LostFragment.java 5KB
Soft614080902433shiyan4.java 5KB
Main4Activity.java 5KB
Soft1614080902216Activity.java 4KB
Main3Activity.java 4KB
Soft1614080902104Activity5.java 4KB
Soft1614080902309Activity.java 4KB
Main2Activity.java 4KB
MainActivity.java 4KB
Soft1614080902414a.java 4KB
ThirdActivity.java 4KB
Soft1614080902401.java 4KB
Main3Activity.java 4KB
RegisterFragment.java 4KB
MainActivity.java 4KB
Soft1614080902309Activity3.java 4KB
Soft1614080902309Activity2.java 4KB
SecordActivity.java 4KB
Soft1614080902410_2.java 4KB
soft1606081301337Activity2.java 4KB
soft1614080902430Activity_1.java 4KB
Main2Activity.java 4KB
LoginActivity.java 4KB
SecondActivity.java 4KB
Soft161408090211603Activity.java 4KB
Soft161408090211603Activity.java 4KB
Second_Activity.java 4KB
Main3Activity.java 4KB
save.java 4KB
save.java 4KB
SecondActivity.java 4KB
Soft1614080902127Activity.java 4KB
MainFragment.java 4KB
com1614080901221Activity.java 4KB
SecondActivity.java 4KB
SecondActivity.java 4KB
Soft1614080902108Activity2.java 4KB
Soft1614080902328Activity1.java 4KB
Com1614080901231Activity.java 4KB
secondActivity.java 4KB
Soft1614080902125Activity.java 4KB
soft1614080902314Activity3.java 4KB
ConnectwebActivity.java 4KB
Soft1614080902108Activity11.java 3KB
Third_Activity.java 3KB
ThreeActivity.java 3KB
soft1606081301337Activity3.java 3KB
FifthActivity.java 3KB
ThirdActivity.java 3KB
SecondActivit.java 3KB
jsonActivity.java 3KB
MainActivity.java 3KB
MainActivity3.java 3KB
soft1614080902429.java 3KB
Soft1614080902305Activity3.java 3KB
secondActivity.java 3KB
com1614080901230Activity.java 3KB
Soft1614080902305Activity1.java 3KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
JJJ69
- 粉丝: 6235
- 资源: 5778
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C语言文件读写代码.docx
- python的概要介绍与分析
- module-0982.SyncTensorsGraph.9515.sm-8.0-gpu-after-optimizations
- ChromeSetup20220804.exe
- 讲解记录 基于Java的小区物业管理系统
- module-0004.SyncTensorsGraph.7578.sm-8.0-gpu-after-optimizations
- python39.dll
- 【Matlab 六自由度机器人】Fixed Angles(固定角度) 和 Euler Angles(欧拉角) 之间的区别
- STLINK下载器调试过程中常见问题排查
- BMSP430工程PPT说明书.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功