Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
微笑面对bug
ddz
提交
5a32fcc4
ddz
项目概览
微笑面对bug
/
ddz
通知
5
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ddz
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5a32fcc4
编写于
10月 13, 2020
作者:
C
changjiuxiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增 金币系统
上级
1d2e18cf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
116 addition
and
22 deletion
+116
-22
src/components/Game.vue
src/components/Game.vue
+10
-1
src/doudizhu/Game.js
src/doudizhu/Game.js
+82
-8
src/doudizhu/Player.js
src/doudizhu/Player.js
+24
-13
未找到文件。
src/components/Game.vue
浏览文件 @
5a32fcc4
...
...
@@ -30,9 +30,12 @@
<button
v-show=
"true"
@
mousedown=
"game.playerList[0].setJiaoFen(3)"
style=
"font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;"
>
3分
</button>
</div>
<div
v-show=
"game.stage==='play'"
:style=
"
{ marginLeft: playerMarginLeft-150 + 'px' }" style="color:white;position: fixed;bottom:0;width: 100%;height: 200px;
line-height: 200px;
">
<div
v-show=
"game.stage==='play'"
:style=
"
{ marginLeft: playerMarginLeft-150 + 'px' }" style="color:white;position: fixed;bottom:0;width: 100%;height: 200px;">
你是
<span
style=
"color:red;font-size: 20px"
>
{{
game
.
playerList
[
0
].
type
===
'
nongmin
'
?
'
农民
'
:
'
地主
'
}}
</span>
</div>
<div
:style=
"
{ marginLeft: playerMarginLeft-150 + 'px' }" style="color:white;position: fixed;bottom:0;width: 100%;height: 100px;">
金币:
<span
style=
"color:greenyellow;font-size: 20px"
>
{{
game
.
playerList
[
0
].
money
}}
</span>
</div>
<div
:style=
"
{ marginLeft: playerMarginLeft + 'px' }" style="position: fixed;bottom:0;width: 100%;height: 200px;">
<div
@
mouseenter=
"enter($event,item)"
@
mousedown=
"pickPoker(item)"
v-for=
"item in game.playerList[0].pokerList"
:class=
"
{ selected: item.selected, s:item.number===16, x:item.number===17 }" class="poker pokerDesk" style="">
<span
v-show=
"item.number
<
16"
>
...
...
@@ -81,6 +84,9 @@
<p>
{{
game
.
playerList
[
2
].
name
}}
</p>
<p>
金币:
<span
style=
"color:green;"
>
{{
game
.
playerList
[
2
].
money
}}
</span>
</p>
<p>
剩余
{{
game
.
playerList
[
2
].
pokerList
.
length
}}
张
</p>
...
...
@@ -122,6 +128,9 @@
<p>
{{
game
.
playerList
[
1
].
name
}}
</p>
<p>
金币:
<span
style=
"color:green;"
>
{{
game
.
playerList
[
1
].
money
}}
</span>
</p>
<p>
剩余
{{
game
.
playerList
[
1
].
pokerList
.
length
}}
张
</p>
...
...
src/doudizhu/Game.js
浏览文件 @
5a32fcc4
...
...
@@ -3,6 +3,8 @@ import Poker from "./Poker";
class
Game
{
constructor
()
{
this
.
testModel
=
false
;
//测试模式 三个AI自动打牌
this
.
playerList
=
[];
this
.
pokerList
=
[];
this
.
dizhuPokerList
=
[];
...
...
@@ -12,8 +14,10 @@ class Game{
this
.
currentJiaoFenPlayer
=
null
;
this
.
jiaoFenCount
=
0
;
this
.
dizhu
=
null
;
this
.
MaxSecond
=
6
0
;
this
.
MaxSecond
=
2
0
;
this
.
second
=
this
.
MaxSecond
;
this
.
BaseScore
=
1
;
//每局底分
this
.
score
=
this
.
BaseScore
;
//当前局分
this
.
stage
=
'
ready
'
;
//阶段 ready\jiaoFen\play
this
.
init
();
...
...
@@ -40,12 +44,17 @@ class Game{
someOneJiaoFen
(){
let
that
=
this
;
this
.
jiaoFenCount
++
;
let
timeWait
=
1000
;
if
(
that
.
testModel
){
timeWait
=
0
;
}
if
(
this
.
jiaoFenCount
===
3
){
setTimeout
(
function
()
{
that
.
setDiZhu
();
},
1000
);
},
timeWait
);
return
;
}
else
{
this
.
currentJiaoFenPlayer
=
this
.
currentJiaoFenPlayer
.
next
;
...
...
@@ -53,8 +62,22 @@ class Game{
}
setDiZhu
(){
let
sortList
=
this
.
playerList
.
slice
(
0
).
sort
(
this
.
sortByJiaoFen
);
let
dizhu
=
sortList
[
0
];
let
dizhu
;
if
(
sortList
[
0
].
jiaoFen
===
sortList
[
1
].
jiaoFen
){
if
(
sortList
[
0
].
jiaoFen
===
sortList
[
2
].
jiaoFen
){
let
index
=
this
.
getRandomIntInclusive
(
0
,
2
);
dizhu
=
sortList
[
index
];
}
else
{
let
index
=
this
.
getRandomIntInclusive
(
0
,
1
);
dizhu
=
sortList
[
index
];
}
}
else
{
dizhu
=
sortList
[
0
];
}
dizhu
.
type
=
'
dizhu
'
;
this
.
dizhu
=
dizhu
;
...
...
@@ -115,17 +138,37 @@ class Game{
this
.
jiaoFenCount
=
0
;
this
.
dizhu
=
null
;
this
.
second
=
this
.
MaxSecond
;
this
.
score
=
this
.
BaseScore
;
this
.
stage
=
'
ready
'
;
this
.
initPokerList
();
}
next
(){
//有玩家出牌
someOneSendPoker
(
obj
){
this
.
clearDesk
();
this
.
deskPokerObj
=
obj
;
this
.
checkBoom
(
obj
);
let
over
=
this
.
checkGameOver
();
if
(
over
){
this
.
gameOver
();
return
;
}
this
.
next
();
}
//炸弹分数翻1番 火箭翻2番
checkBoom
(
obj
){
if
(
obj
.
type
===
'
four
'
){
this
.
score
*=
2
;
}
else
if
(
obj
.
type
===
'
four
'
){
this
.
score
*=
4
;
}
}
next
(){
this
.
resetTime
();
this
.
currentPlayer
=
this
.
currentPlayer
.
next
;
if
(
this
.
currentPlayer
.
isRobot
){
...
...
@@ -134,11 +177,41 @@ class Game{
}
gameOver
(){
alert
(
'
游戏结束!
'
+
this
.
currentPlayer
.
name
+
'
[
'
+
this
.
currentPlayer
.
type
+
'
] 胜!
'
);
if
(
!
this
.
testModel
){
alert
(
'
游戏结束!
'
+
this
.
currentPlayer
.
name
+
'
[
'
+
this
.
currentPlayer
.
type
+
'
] 胜!
'
);
}
else
{
console
.
log
(
this
.
playerList
[
0
].
money
+
'
'
+
this
.
playerList
[
1
].
money
+
'
'
+
this
.
playerList
[
2
].
money
+
'
'
);
}
this
.
settleMoney
();
this
.
reset
();
}
//结算金币得失
settleMoney
(){
if
(
this
.
currentPlayer
.
type
===
'
nongmin
'
){
this
.
currentPlayer
.
money
+=
this
.
score
;
if
(
this
.
currentPlayer
.
next
.
type
===
'
nongmin
'
){
this
.
currentPlayer
.
next
.
money
+=
this
.
score
;
}
else
{
this
.
currentPlayer
.
next
.
money
-=
this
.
score
*
2
;
}
if
(
this
.
currentPlayer
.
last
.
type
===
'
nongmin
'
){
this
.
currentPlayer
.
last
.
money
+=
this
.
score
;
}
else
{
this
.
currentPlayer
.
last
.
money
-=
this
.
score
*
2
;
}
}
else
{
this
.
currentPlayer
.
money
+=
this
.
score
*
2
;
this
.
currentPlayer
.
next
.
money
-=
this
.
score
;
this
.
currentPlayer
.
last
.
money
-=
this
.
score
;
}
}
checkGameOver
(){
if
(
this
.
currentPlayer
.
pokerList
.
length
===
0
)
{
return
true
;
...
...
@@ -178,10 +251,11 @@ class Game{
}
initPlayerList
(){
let
that
=
this
;
this
.
playerList
=
[];
let
player0
=
new
Player
({
name
:
'
player
'
,
isRobot
:
false
,
isRobot
:
that
.
testModel
,
game
:
this
,
});
let
player1
=
new
Player
({
...
...
src/doudizhu/Player.js
浏览文件 @
5a32fcc4
...
...
@@ -4,6 +4,7 @@ import AI from "./AI";
class
Player
{
constructor
(
param
)
{
param
=
param
||
{};
this
.
money
=
1000
;
//金币
this
.
ready
=
false
;
//已准备
this
.
jiaoFen
=
-
1
;
//叫分
this
.
pokerList
=
[];
...
...
@@ -32,19 +33,25 @@ class Player{
loopRobot
(){
let
that
=
this
;
if
(
that
.
isRobot
){
if
(
!
that
.
ready
){
that
.
setReady
();
}
}
if
(
that
.
game
.
stage
===
'
jiaoFen
'
&&
that
.
game
.
currentJiaoFenPlayer
===
that
){
let
fen
=
that
.
ai
.
getJiaoFen
();
that
.
setJiaoFen
(
fen
);
let
timeWait
=
1000
;
if
(
that
.
game
.
testModel
){
timeWait
=
0
;
}
setTimeout
(
function
(){
if
(
that
.
isRobot
){
if
(
!
that
.
ready
){
that
.
setReady
();
}
}
if
(
that
.
game
.
stage
===
'
jiaoFen
'
&&
that
.
game
.
currentJiaoFenPlayer
===
that
){
let
fen
=
that
.
ai
.
getJiaoFen
();
that
.
setJiaoFen
(
fen
);
}
that
.
loopRobot
();
},
2000
);
},
timeWait
);
}
setReady
(){
...
...
@@ -96,6 +103,11 @@ class Player{
that
.
getClassifyObj
();
let
timeWait
=
1000
;
if
(
that
.
game
.
testModel
){
timeWait
=
0
;
}
setTimeout
(
function
()
{
let
lastObj
=
that
.
getLastObj
();
if
(
lastObj
){
...
...
@@ -103,16 +115,15 @@ class Player{
}
else
{
that
.
ai
.
playByAllType
();
}
},
1000
);
},
timeWait
);
}
sendPoker
(
obj
){
obj
.
player
=
this
;
this
.
game
.
clearDesk
();
this
.
lastSendObj
=
obj
;
this
.
game
.
deskPokerObj
=
obj
;
this
.
game
.
next
(
);
this
.
game
.
someOneSendPoker
(
obj
);
}
deleteFromPokerListAndSendByObj
(
obj
){
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录