当前位置: 首页 > wzjs >正文

做中澳原产地证的网站长春网站优化团队

做中澳原产地证的网站,长春网站优化团队,青岛做网站费用,小奶猫w5c0com参考 基于 PHP Fiber(纤程)的游戏开发分析-腾讯云开发者社区-腾讯云PHP 8.1 引入的 Fibers 为游戏开发带来新机遇,能管理渲染、物理计算等任务且不阻塞主线程。它支持并发,提升效率,简单易用,但也有局限&a…

参考

基于 PHP Fiber(纤程)的游戏开发分析-腾讯云开发者社区-腾讯云PHP 8.1 引入的 Fibers 为游戏开发带来新机遇,能管理渲染、物理计算等任务且不阻塞主线程。它支持并发,提升效率,简单易用,但也有局限,如单线程本质、上下文切换开销、调试复杂及生态系统不成熟。https://cloud.tencent.com/developer/article/2509749说明

  • 多个用户参与游戏
  • 每个人猜各自的最终数字
  • 每人做多猜五次

代码:

function getroundnum() {$num = rand(0, 30);return $num;
}
class Persion {public function __construct(public string $name) {}
}
class GuessNum extends Persion {private int $resultnum;public bool $result;private int $num;private int $type;public function __construct(public string $name, public int $gap = 1) {$this->num = getroundnum();$this->resultnum = getroundnum();$this->result = false;}//type 1加数字 2减数字private function getnextnum() {if ($this->num === 0) {return $this->num;}$this->num = match ($this->type) {1 => $this->num + $this->gap,2 => $this->num - $this->gap,};}public function doguessonce() {var_dump("resultnum:" . $this->resultnum . " name:" . $this->name . " num:" . $this->num);$result = false;$this->type = 0;match (true) {$this->num == $this->resultnum => $result = true,$this->num > $this->resultnum => $this->type = 2, //减$this->num < $this->resultnum => $this->type = 1//加};$this->result = $result;if (!$result) {$this->getnextnum();}}
}
$persion_list = [new GuessNum("test1", 1),new GuessNum("npc", 2),
];$fibers = [];foreach ($persion_list as $entity) {$fibers[] = new Fiber(function () use ($entity) {while (true) {$entity->doguessonce($entity);Fiber::suspend($entity);}});
}// Start all fibers
$endresult = false;
foreach ($fibers as $fiber) {$value = $fiber->start();if ($value->result) {$endresult = true;var_dump("game end success name:" . $value->name);break;}
}
if (!$endresult) {for ($i = 0; $i < 5; $i++) {foreach ($fibers as $fiber) {$value = $fiber->resume();if ($value->result) {$endresult = true;var_dump("game end success name:" . $value->name);break;}}sleep(1);var_dump("once end");}
}
var_dump("game end ~");

输出

string(30) "resultnum:12 name:test1 num:22"
string(27) "resultnum:7 name:npc num:17"
string(30) "resultnum:12 name:test1 num:21"
string(27) "resultnum:7 name:npc num:15"
string(8) "once end"
string(30) "resultnum:12 name:test1 num:20"
string(27) "resultnum:7 name:npc num:13"
string(8) "once end"
string(30) "resultnum:12 name:test1 num:19"
string(27) "resultnum:7 name:npc num:11"
string(8) "once end"
string(30) "resultnum:12 name:test1 num:18"
string(26) "resultnum:7 name:npc num:9"
string(8) "once end"
string(30) "resultnum:12 name:test1 num:17"
string(26) "resultnum:7 name:npc num:7"
string(25) "game end success name:npc"
string(8) "once end"
string(10) "game end ~"

http://www.dtcms.com/wzjs/191196.html

相关文章:

  • 北京国税局网站做票种核定长沙关键词优化公司电话
  • 怎样在淘宝网做网站销售找客户的方法
  • 代理小企业网站建设淘宝数据查询
  • 小公司建网站 优帮云seo整站优化
  • .net网站开发岗位百度seo在线优化
  • ECS 安装wordpressseo优化一般包括哪些
  • 网站验证码是如何做的网站做seo教程
  • 海口网站建设fwlitapp推广引流
  • 保健品手机网站模板泉州关键词排名工具
  • 安仁网站制作镇江网站建设方案
  • 电子商务平台网站模板百度广告上的商家可靠吗
  • 有那些专门做财务分析的网站下载百度软件
  • 网站建设会使用的技术公众号推广方法
  • 科技公司网站源码如何做一个网站的seo
  • 成都网站制作工作室百度网讯科技客服人工电话
  • 网站开发商城app东莞seo外包公司
  • 网站搜索排名优化怎么做seo在线培训机构
  • 电商网站建设需要多少钱seo流量排名软件
  • 山东日照今天的疫情是啥情况无锡百度快照优化排名
  • 个性网站制作网店培训骗局
  • 网站开发的软件环境有哪些西安百度推广竞价托管
  • 网站设计服务流程论坛企业推广
  • php做网站用框架免费顶级域名注册网站
  • 疫情排行榜最新消息关键词优化排名软件哪家好
  • 常德网站建营销推广方案包括哪些内容
  • 做的网站如何放在电脑上百度公司名称
  • 网站的静态页面谁做百度合伙人答题兼职赚钱
  • 星辰wordpress太原seo全网营销
  • 网贷审核网站怎么做营销方式和渠道
  • 杰奇小说网站建设西安seo推广