搜索
首页php教程php手册用php写的桌面应用程序
用php写的桌面应用程序Jun 13, 2016 am 09:58 AM
createphp代码内容剪贴板复制应用程序桌面


复制PHP内容到剪贴板PHP代码:

$winmain=wb_create_window(null,AppWindow,'21点游戏',WBC_CENTER,WBC_CENTER,800,495,0,0);
wb_create_control($winmain,Label,'庄家',20,15,40,30,LB_1,0,0,0);
wb_create_control($winmain,Label,'玩家',20,200,40,30,LB_2,00,0,0);
wb_create_control($winmain,Frame,'',80,40,120,150,FR_PC_1,0,0,0);
wb_create_control($winmain,Frame,'',220,40,120,150,FR_PC_2,0,0,0);
wb_create_control($winmain,Frame,'',360,40,120,150,FR_PC_3,0,0,0);
wb_create_control($winmain,Frame,'',500,40,120,150,FR_PC_4,0,0,0);
wb_create_control($winmain,Frame,'',640,40,120,150,FR_PC_5,0,0,0);
wb_create_control($winmain,Frame,'',645,230,120,150,FR_U_5,0,0,0);
wb_create_control($winmain,Frame,'',500,230,120,150,FR_U_4,0,0,0);
wb_create_control($winmain,Frame,'',360,230,120,150,FR_U_3,0,0,0);
wb_create_control($winmain,Frame,'',220,230,120,150,FR_U_2,0,0,0);
wb_create_control($winmain,Frame,'',80,230,120,150,FR_U_1,0,0,0);
wb_create_control($winmain,Label,'',35,305,25,20,LB_U_T,0,0,0);
wb_create_control($winmain,Label,'',35,110,25,20,LB_P_T,0,0,0);
wb_create_control($winmain,PushButton,'发牌',320,400,70,25,B_GO,0x00000002,0,0);
wb_create_control($winmain,PushButton,'停止',435,400,70,25,B_CHANGE,0x00000002,0,0);
wb_create_control($winmain,Label,'',110,95,60,60,LB_PC_1,0x00000800,0,0);
wb_create_control($winmain,Label,'',250,95,60,60,LB_PC_2,0x00000800,0,0);
wb_create_control($winmain,Label,'',390,95,60,60,LB_PC_3,0x00000800,0,0);
wb_create_control($winmain,Label,'',530,95,60,60,LB_PC_4,0x00000800,0,0);
wb_create_control($winmain,Label,'',670,95,60,60,LB_PC_5,0x00000800,0,0);
wb_create_control($winmain,Label,'',110,285,60,60,LB_U_1,0x00000800,0,0);
wb_create_control($winmain,Label,'',250,285,60,60,LB_U_2,0x00000800,0,0);
wb_create_control($winmain,Label,'',390,285,60,60,LB_U_3,0x00000800,0,0);
wb_create_control($winmain,Label,'',530,285,60,60,LB_U_4,0x00000800,0,0);
wb_create_control($winmain,Label,'',670,285,60,60,LB_U_5,0x00000800,0,0);
wb_create_control($winmain,Label,'',70,20,90,20,PC_MON,0,0,0);
wb_create_control($winmain,Label,'',70,205,90,20,U_MON,0,0,0);

point_include.php文件


for ($i=1;$i switch($i){
  case 1j=1;$key='A';break;
  case 11j=10;$key='J';break;
  case 12j=10;$key='Q';break;
  case 13j=10;$key='K';break;
  default:
   $key=$j=$i;
}
$card["黑\n桃\n$key"]=$j;
$card["红\n桃\n$key"]=$j;
$card["梅\n花\n$key"]=$j;
$card["方\n片\n$key"]=$j;
}
$contorl_id=array(
'B_GO'=>1001,'B_CHANGE'=>1002,
'ME_START'=>2001,'ME_REMON'=>2002,'ME_AUTHOR'=>2003,'ME_QUIT'=>IDCLOSE,
'LB_1'=>3001,'LB_2'=>3002,'LB_U_T'=>3003,'LB_P_T'=>3004,
'PC_MON'=>3005,'U_MON'=>3006,
'LB_PC_1'=>3101,'LB_PC_2'=>3102,'LB_PC_3'=>3103,'LB_PC_4'=>3104,'LB_PC_5'=>3105,
'LB_U_1'=>3201,'LB_U_2'=>3202,'LB_U_3'=>3203,'LB_U_4'=>3204,'LB_U_5'=>3205,
'FR_PC_1'=>4001,'FR_PC_2'=>4002,'FR_PC_3'=>4003,'FR_PC_4'=>4004,'FR_PC_5'=>4005,
'FR_U_1'=>5001,'FR_U_2'=>5002,'FR_U_3'=>5003,'FR_U_4'=>5004,'FR_U_5'=>5005,
);
foreach ($contorl_id as $key=>$value){
if(!defined(strtoupper($key)))define(strtoupper($key),$value);
}
?>


21point.phpw文件


set_time_limit(0);
include_once('include/winbinder.php');
include_once('form/point_include.php');
include_once('form/21point.form.php');

class Ponit {
public $key_id;
private $user_point=10000;
private $pc_point=10000;
private $card;
private $player='user';
private $new_term=false;
private $remon=false;
public function __construct($winmain,$card){
  $f=file_get_contents('form/db.db');
  list($this->user_point,$this->pc_point)=explode('|',$f);
  $this->window=$winmain;
  $this->card=$card;
  $this->prepare();
}
private function prepare(){
  wb_set_image($this->window,'form/hyper.ico'); 
  wb_create_control($this->window,Menu,array(
  '游戏(&G)'  , null,
  array(ME_START , "开局\tCrtl+N",'','','Ctrl+N'),
  array(ME_REMON , "重计分"),
  array(ME_AUTHOR , "作者"),
  null   ,
  array(ME_QUIT , "退出\tCrtl+Q",'','','Ctrl+Q'),
  null
  ));
  wb_set_text(wb_get_control($this->window,U_MON),$this->user_point.'分');
  wb_set_text(wb_get_control($this->window,PC_MON),$this->pc_point.'分');
  $font=wb_create_font("Arial", 13, null, FTA_BOLD);
  wb_set_font(wb_get_control($this->window,LB_1),$font);
  wb_set_font(wb_get_control($this->window,LB_2),$font);
  $font=wb_create_font("Arial", 34, null, FTA_BOLD);
  for($i=1;$i    wb_set_font(wb_get_control($this->window,(3100+$i)),$font);
   wb_set_font(wb_get_control($this->window,(3200+$i)),$font);
  }
}
private function start(){
  $this->player='user';
  $this->new_term=true;
  $this->clear();
  $this->play();
  wb_set_enabled(wb_get_control($this->window,B_GO),true);
  wb_set_enabled(wb_get_control($this->window,B_CHANGE),true);
}
private function stop(){
  wb_set_enabled(wb_get_control($this->window,B_GO),false);
  wb_set_enabled(wb_get_control($this->window,B_CHANGE),false);
}
private function change_player(){
  $this->stop();
  $this->player='pc';
  $this->play();
}
private function total($num=0,$win){
  static $u_tem,$p_tem;
  if(empty($u_tem)||empty($p_tem)||$this->remon==true){
   $u_tem=$this->user_point;
   $p_tem=$this->pc_point;
   $this->remon=false;
  }
  if(strtoupper($win)=='U'){
   $u_tem+=$num;
   $p_tem-=$num;
  }else{
   $u_tem-=$num;
   $p_tem+=$num;
  }
  $this->user_point=$u_tem;
  $this->pc_point=$p_tem;
  wb_set_text(wb_get_control($this->window,U_MON),$this->user_point.'分');
  wb_set_text(wb_get_control($this->window,PC_MON),$this->pc_point.'分');
  $f=fopen('form/db.db','wb');
  fwrite($f,$this->user_point."|".$this->pc_point);
  fclose($f);
}
private function remon(){
  $this->remon=true;
  $this->user_point=10000;
  $this->pc_point=10000;
  wb_set_text(wb_get_control($this->window,U_MON),$this->user_point.'分');
  wb_set_text(wb_get_control($this->window,PC_MON),$this->pc_point.'分');
  $f=fopen('form/db.db','wb');
  fwrite($f,$this->user_point."|".$this->pc_point);
  fclose($f);
}
private function clear(){
  wb_set_text(wb_get_control($this->window,LB_U_T),'');
  wb_set_text(wb_get_control($this->window,LB_P_T),'');
  for($i=1;$i    wb_set_text(wb_get_control($this->window,(4000+$i)),'');
   wb_set_text(wb_get_control($this->window,(5000+$i)),'');
   wb_set_text(wb_get_control($this->window,(3100+$i)),'');
   wb_set_text(wb_get_control($this->window,(3200+$i)),'');
  }
}
private function play(){
  static $card_tem=array(),$i=0,$j=0,$user_total=0,$pc_total=0;
  if($this->new_term==true){
   $card_tem=$this->card;
   $this->new_term=false;
   $user_total=0;
   $pc_total=0;
   $i=0;$j=0;
  }
  if($this->player=='user'){
   $i++;
   $card_key=array_rand($card_tem);
   $card_value=$card_tem[$card_key];
   $user_total+=$card_value;
   wb_set_text(wb_get_control($this->window,LB_U_T),$user_total.'点');
   wb_set_text(wb_get_control($this->window,(5000+$i)),$card_key);
   wb_set_text(wb_get_control($this->window,(3200+$i)),$card_value);
   if($i>=5 && $user_total     $this->total(20,'U');
    $sel=wb_message_box($this->window,"恭喜你,5张全小,玩家获胜!\n您还想继续玩吗?",'胜利',WBC_YESNO);
    $sel==1?$this->start():$this->stop();
   }elseif($user_total>21){
    $this->total(20,'P');
    $sel=wb_message_box($this->window,"真不幸,超过21点,庄家获胜!\n您还想继续玩吗?",'失败',WBC_YESNO);
    $sel==1?$this->start():$this->stop();
   }
  }else{
   $j++;
   $card_key=array_rand($card_tem);
   $card_value=$card_tem[$card_key];
   $pc_total+=$card_value;
   wb_set_text(wb_get_control($this->window,LB_P_T),$pc_total.'点');
   wb_set_text(wb_get_control($this->window,(4000+$j)),$card_key);
   wb_set_text(wb_get_control($this->window,(3100+$j)),$card_value);
   if($j>=5 && $pc_total     $this->total(20,'P');
    $sel=wb_message_box($this->window,"庄家5张全小,庄家获胜!\n您还想继续玩吗?",'失败',WBC_YESNO);
    $sel==1?$this->start():$this->stop();
   }elseif($pc_total>21){
    if( $pc_total-$card_value      $this->total(20,'U');
     $sel=wb_message_box($this->window,"恭喜你,庄家点数超过21点,玩家获胜!\n您还想继续玩吗?",'胜利',WBC_YESNO);
     $sel==1?$this->start():$this->stop();
    }else{
     $pc_total=$pc_total-$card_value;
     wb_set_text(wb_get_control($this->window,LB_P_T),$pc_total.'点');
     wb_set_text(wb_get_control($this->window,(4000+$j)),'');
     wb_set_text(wb_get_control($this->window,(3100+$j)),'');
     if($pc_total>=$user_total){
      $this->total(20,'P');
      $msg=($pc_total==$user_total)?"双方点数一样,庄家获胜!\n您还想继续玩吗?":"庄家点数比你大,庄稼获胜!\n您还想继续玩吗?";
      $sel=wb_message_box($this->window,$msg,'失败',WBC_YESNO);
      $sel==1?$this->start():$this->stop();
     }else{
      $this->total(20,'U');
      $sel=wb_message_box($this->window,"恭喜你,庄家点数比你小,玩家获胜!\n您还想继续玩吗?",'胜利',WBC_YESNO);
      $sel==1?$this->start():$this->stop();
     }
    }
   }else{
    usleep(800000);
    $this->play();
   }
  }
  unset($card_tem[$card_key]);
}

private function author(){
  $inf="大家好,偶是machine_马,\n\n这是我人生中的第一个桌面应用程序,\n\n做得很烂,大家见笑了,哈哈哈^_^。\n\n\n\n\t\t作者:machine_马";
  $author_window=wb_create_window($this->window,ModalDialog,'作者简介',WBC_CENTER, WBC_CENTER, 360, 180, 0x00000000, 0);
  wb_set_handler($author_window,'author_handler');
  $image=wb_create_control($author_window,Frame,'123',0,0,128,144,110,WBC_IMAGE);
  wb_create_control($author_window,Label,$inf,140,20,200,150,120,WBC_IMAGE);
  wb_set_image($image, 'form/author.bmp', NOCOLOR);
}
public function main(){
  switch ($this->key_id){
   case IDCLOSE:
    wb_destroy_window($this->window);    break;
   case ME_START:
    $this->start();         break;
   case ME_AUTHOR:
    $this->author();        break;
   case B_GO:
    $this->play();         break;
   case B_CHANGE:
    $this->change_player();       break;
   case ME_REMON:
    $this->remon();         break;
  }
}
}
$wbd=new Ponit($winmain,$card);
wb_set_handler($winmain,'go_to');
wb_main_loop();
function go_to($window,$id){
global $wbd;
$wbd->key_id=$id;
return $wbd->main();
}
function author_handler($this_window,$id){
switch($id){
  case IDCLOSE:
   wb_destroy_window($this_window);
}
}
?>

 

 

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热工具

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境