--随机开奖颜色 function gamelogic:OpenResult() --红白颜色的次数 local tRed = 0 local tWhite = 0 local Result = {} for i = 1, 4, 1 do --随机开1或2 1代表红 2代表白 local RandNum = math.random(1,2) table.insert(Result, RandNum) if RandNum %2 == 0 then tRed = tRed + 1 else tWhite = tWhite + 1 end end return tRed, tWhite end --开奖区域 function gamelogic:OpenCardArry(nRed, nWhite) local AreaWinLose = 0 local nMultiple = 0 if nRed %2 == 0 or nWhite %2 == 0 then AreaWinLose = 1 end if nRed %2 ~= 0 or nWhite %2 ~= 0 then AreaWinLose = 2 end if nRed == 4 then AreaWinLose = 3 end if nRed == 4 then AreaWinLose = 4 end if nRed == 1 and nWhite == 3 then AreaWinLose = 5 end if nRed == 3 and nWhite == 1 then AreaWinLose = 6 end if AreaWinLose == 1 or AreaWinLose == 3 or AreaWinLose == 4 then nMultiple = 15 else nMultiple = 3 end return AreaWinLose, nMultiple end 不用位运算有没有其他的方法实现
时间: 2023-11-16 17:04:45 浏览: 31
是的,可以使用取模运算 `%` 来代替位运算符 `&` 和 `|`。例如,将 `RandNum & 1` 替换为 `RandNum % 2`,将 `RandNum | 0` 替换为 `RandNum`。取模运算和位运算的结果在这种情况下是等价的。因此,可以将代码修改为以下内容:
```
function gamelogic:OpenResult()
--红白颜色的次数
local tRed = 0
local tWhite = 0
local Result = {}
for i = 1, 4, 1 do
--随机开1或2 1代表红 2代表白
local RandNum = math.random(1,2)
table.insert(Result, RandNum)
if RandNum % 2 == 0 then
tRed = tRed + 1
else
tWhite = tWhite + 1
end
end
return tRed, tWhite
end
--开奖区域
function gamelogic:OpenCardArry(nRed, nWhite)
local AreaWinLose = 0
local nMultiple = 0
if nRed % 2 == 0 or nWhite % 2 == 0 then
AreaWinLose = 1
end
if nRed % 2 ~= 0 or nWhite % 2 ~= 0 then
AreaWinLose = 2
end
if nRed == 4 then
AreaWinLose = 3
end
if nRed == 4 then
AreaWinLose = 4
end
if nRed == 1 and nWhite == 3 then
AreaWinLose = 5
end
if nRed == 3 and nWhite == 1 then
AreaWinLose = 6
end
if AreaWinLose == 1 or AreaWinLose == 3 or AreaWinLose == 4 then
nMultiple = 15
else
nMultiple = 3
end
return AreaWinLose, nMultiple
end
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![crx](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)