Desktop application written in php_PHP tutorial
复制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.'point');
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,"Congratulations, 5 cards are all small, the player wins! nDo you still want to continue playing?",'Victory',WBC_YESNO);
$sel==1?$this->start():$this->stop();
}elseif($user_total>21){
$this->total(20,'P');
$sel=wb_message_box($this->window,"Unfortunately, after 21 points, the dealer wins! nDo you still want to continue playing?",'Failed',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.'point');
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,"The dealer has all 5 cards, and the dealer wins! Do you still want to continue playing?",'Failed',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,"Congratulations, the dealer's points exceed 21, and the player wins! Do you still want to continue playing?",'Victory',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.'point');
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)?"Both sides have the same points, the banker wins!nDo you still want to continue playing?":"The banker's points are greater than yours, and the crop wins!nDo you still want to continue playing?";
$sel=wb_message_box($this->window,$msg,'failed',WBC_YESNO);
$sel==1?$this->start():$this->stop();
}else{
$this->total(20,'U');
$sel=wb_message_box($this->window,"Congratulations, the dealer's points are smaller than yours, the player wins! Do you still want to continue playing?",'Victory',WBC_YESNO);
$sel==1?$this->start():$this->stop();
}
}
}else{
usleep(800000);
$this->play();
}
}
unset($card_tem[$card_key]);
}
private function author(){
$inf="Hello everyone, this is machine_马, nnThis is the first desktop application in my life, nn is very bad, everyone laughs, hahaha ^_^. nnnntt Author: machine_马" ;
$author_window=wb_create_window($this->window,ModalDialog,'About the author',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);
}
}
?>

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools