Share code làm game cờ caro bằng lua script
Cờ caro là một trò chơi rất phổ biến với tất cả mọi lứa tuổi, Đây là một trò chơi đối kháng giữa hai người, thường được dùng nó để giải trí sau những giờ làm việc căng thẳng. Việc code game trên một nền tảng nào đó sẽ giúp các bạn thực hành kỹ năng lập trình của mình rất tốt.
Trò chơi này được chơi trên bàn cờ gồm các ô vuông nằm trên cách hàng và các cột. Hai bên sẽ thay phiên nhau tích vào những ô vuông chưa được đánh ở trên bàn cờ. Ký hiệu mỗi nước đi của từng người là X hoặc O.
Người chơi sẽ phải dùng chiến thuật và kinh nghiệm để tạo thành một hàng ngang, hàng dọc, hoặc đường chéo có đủ 5 quân cờ của mình, (có thể áp dụng luật chặn hai đầu hoặc không), người chiến thắng là người tạo được hàng, cột hoặc đường chéo đủ 5 nước đi của mình trước.
Để chiến thắng, bạn cần tạo ra những nước cờ hiểm và độc, điểm đặc biệt của Caro, là bạn rất dễ bị thua nếu không để ý từng nước đi của đối phương mặc dù bạn có chiến thuật tốt hơn.
Đây là một trò chơi giúp bạn giải trí sau những giờ làm việc và học tập căng thẳng hay những thời gian rảnh cùng với bạn bè.
Bên dưới đây là toàn bộ code về cờ caro bằng lua script bởi Nguyễn Xuân Dũng☭ Lập trình
-------------------------------------- code đặt giá trị cho biến----------------------ModMobile
--------- Phần có thể chỉnh sửa----------- ModMobile
win="you win"
lose="you lose"
draw="Bạn đã hòa😅"
thongbao="Vui lòng chọn cái khác, Đã có người chọn "
banner="👩💻Game cờ caro được lập trình bởi ModMobile🇻🇳"
p="Máy sẽ đánh trước"
c="Bạn sẽ đánh trước"
-------------------------------------------
gioithieu="0"
so1="1"
so2="2"
so3="3"
so4="4"
so5="5"
so6="6"
so7="7"
so8="8"
so9="9"
check1="❤ 1️⃣ ❤"
check2="❤ 2️⃣ ❤"
check3="❤ 3️⃣ ❤"
check4="❤ 4️⃣ ❤"
check5="❤ 5️⃣ ❤"
check6="❤ 6️⃣ ❤"
check7="❤ 7️⃣ ❤"
check8="❤ 8️⃣ ❤"
check9="❤ 9️⃣ ❤"
-----------------------------------------------------------------------------------------------ModMobile
-------------code giới thiệu người đã lập trình ra game ModMobile-----------ModMobile
if gioithieu=="0" then
gg.alert([[
||======]]..banner..[[======||
👩💻Luật chơi: -Bạn sẽ đấu với bot AI 😁
👩💻Luật chơi: -Do AI không thể smart bằng people lên AI sẽ đánh trước🥰
👨🦳Developer: -By ModMobile🇻🇳
👩Designer : -By ModMobile🇻🇳
]])
gioithieu="1"
end
--------------------------------------------------------------------------------------
function Main()
aurell= gg.choice({check1.."",check2.."",check3.."",check4.."",check5.."",check6.."",check7.."",check8.."",check9..""},nil,([[
||======]]..banner..[[======||
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
║ㅤ]]..so1..[[ㅤ║ㅤ]]..so2..[[ㅤ║ㅤ]]..so3..[[ㅤ║
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
║ㅤ]]..so4..[[ㅤ║ㅤ]]..so5..[[ㅤ║ㅤ]]..so6..[[ㅤ║
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
║ㅤ]]..so7..[[ㅤ║ㅤ]]..so8..[[ㅤ║ㅤ]]..so9..[[ㅤ║
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
]]))
if aurell == nil then else
if aurell == 1 and check1=="" then gg.alert(thongbao) Main() end if aurell == 1 and check1=="❤ 1️⃣ ❤"then so1="❌" check1="" trongtai() end
if aurell == 2 and check2=="" then gg.alert(thongbao) Main() end if aurell == 2 and check2=="❤ 2️⃣ ❤"then so2="❌" check2="" trongtai() end
if aurell == 3 and check3=="" then gg.alert(thongbao) Main() end if aurell == 3 and check3=="❤ 3️⃣ ❤"then so3="❌" check3="" trongtai() end
if aurell == 4 and check4=="" then gg.alert(thongbao) Main() end if aurell == 4 and check4=="❤ 4️⃣ ❤"then so4="❌" check4="" trongtai() end
if aurell == 5 and check5=="" then gg.alert(thongbao) Main() end if aurell == 5 and check5=="❤ 5️⃣ ❤"then so5="❌" check5="" trongtai() end
if aurell == 6 and check6=="" then gg.alert(thongbao) Main() end if aurell == 6 and check6=="❤ 6️⃣ ❤"then so6="❌" check6="" trongtai() end
if aurell == 7 and check7=="" then gg.alert(thongbao) Main() end if aurell == 7 and check7=="❤ 7️⃣ ❤"then so7="❌" check7="" trongtai() end
if aurell == 8 and check8=="" then gg.alert(thongbao) Main() end if aurell == 8 and check8=="❤ 8️⃣ ❤"then so8="❌" check8="" trongtai() end
if aurell == 9 and check9=="" then gg.alert(thongbao) Main() end if aurell == 9 and check9=="❤ 9️⃣ ❤"then so9="❌" check9="" trongtai() end
end
XGCK = -1
end
function trongtai()
-------------------------------------- code check xem ai thắng-1 -------------------ModMobile
if so1==so4 and so4==so7 and so4=="❌" then ketqua=win thangthuahoa()
elseif so2==so5 and so5==so8 and so5=="❌" then ketqua=win thangthuahoa()
elseif so3==so6 and so6==so9 and so6=="❌" then ketqua=win thangthuahoa()
elseif so1==so2 and so2==so3 and so2=="❌" then ketqua=win thangthuahoa()
elseif so4==so5 and so5==so6 and so5=="❌" then ketqua=win thangthuahoa()
elseif so7==so8 and so8==so9 and so8=="❌" then ketqua=win thangthuahoa()
elseif so1==so5 and so5==so9 and so5=="❌" then ketqua=win thangthuahoa()
elseif so3==so5 and so5==so7 and so5=="❌" then ketqua=win thangthuahoa()
elseif so1==so4 and so4==so7 and so4=="⭕" then ketqua=lose thangthuahoa()
elseif so2==so5 and so5==so8 and so5=="⭕" then ketqua=lose thangthuahoa()
elseif so3==so6 and so6==so9 and so6=="⭕" then ketqua=lose thangthuahoa()
elseif so1==so2 and so2==so3 and so2=="⭕" then ketqua=lose thangthuahoa()
elseif so4==so5 and so5==so6 and so5=="⭕" then ketqua=lose thangthuahoa()
elseif so7==so8 and so8==so9 and so8=="⭕" then ketqua=lose thangthuahoa()
elseif so1==so5 and so5==so9 and so5=="⭕" then ketqua=lose thangthuahoa()
elseif so3==so5 and so5==so7 and so5=="⭕" then ketqua=lose thangthuahoa()
elseif check1=="" and check2=="" and check3=="" and check4=="" and check5=="" and check6=="" and check7=="" and check8=="" and check9=="" then ketqua=draw thangthuahoa()
-----------------------------------------------------------------------------------------------ModMobile
-------------------------------------- code chặn thắng cho bot và tăng IQ cho Bot AI -------------------ModMobile
elseif check3=="❤ 3️⃣ ❤" and so1==so2 and so2=="❌" then so3="⭕" check3="" Main()
elseif check6=="❤ 6️⃣ ❤" and so4==so5 and so5=="❌" then so6="⭕" check6="" Main()
elseif check9=="❤ 9️⃣ ❤" and so7==so8 and so8=="❌" then so9="⭕" check9="" Main()
elseif check1=="❤ 1️⃣ ❤" and so3==so2 and so2=="❌" then so1="⭕" check1="" Main()
elseif check4=="❤ 4️⃣ ❤" and so6==so5 and so5=="❌" then so4="⭕" check4="" Main()
elseif check7=="❤ 7️⃣ ❤" and so9==so8 and so8=="❌" then so7="⭕" check7="" Main()
elseif check7=="❤ 7️⃣ ❤" and so1==so4 and so4=="❌" then so7="⭕" check7="" Main()
elseif check8=="❤ 8️⃣ ❤" and so2==so5 and so5=="❌" then so8="⭕" check8="" Main()
elseif check9=="❤ 9️⃣ ❤" and so3==so6 and so6=="❌" then so9="⭕" check9="" Main()
elseif check1=="❤ 1️⃣ ❤" and so7==so4 and so4=="❌" then so1="⭕" check1="" Main()
elseif check2=="❤ 2️⃣ ❤" and so8==so5 and so5=="❌" then so2="⭕" check2="" Main()
elseif check3=="❤ 3️⃣ ❤" and so9==so6 and so6=="❌" then so3="⭕" check3="" Main()
elseif check3=="❤ 3️⃣ ❤" and so7==so5 and so5=="❌" then so3="⭕" check3="" Main()
elseif check1=="❤ 1️⃣ ❤" and so9==so5 and so5=="❌" then so1="⭕" check1="" Main()
elseif check9=="❤ 9️⃣ ❤" and so1==so5 and so5=="❌" then so9="⭕" check9="" Main()
elseif check7=="❤ 7️⃣ ❤" and so3==so5 and so5=="❌" then so7="⭕" check7="" Main()
elseif check2=="❤ 2️⃣ ❤" and so1==so3 and so3=="❌" then so2="⭕" check2="" Main()
elseif check5=="❤ 5️⃣ ❤" and so4==so6 and so6=="❌" then so5="⭕" check5="" Main()
elseif check8=="❤ 8️⃣ ❤" and so7==so9 and so9=="❌" then so8="⭕" check8="" Main()
elseif check4=="❤ 4️⃣ ❤" and so1==so7 and so7=="❌" then so4="⭕" check4="" Main()
elseif check5=="❤ 5️⃣ ❤" and so2==so8 and so8=="❌" then so5="⭕" check5="" Main()
elseif check6=="❤ 6️⃣ ❤" and so3==so9 and so9=="❌" then so6="⭕" check6="" Main()
elseif check5=="❤ 5️⃣ ❤" and so1==so9 and so9=="❌" then so5="⭕" check5="" Main()
elseif check5=="❤ 5️⃣ ❤" and so3==so7 and so7=="❌" then so5="⭕" check5="" Main()
elseif check3=="❤ 3️⃣ ❤" and so1==so2 and so2=="⭕" then so3="⭕" check3="" Main()
elseif check6=="❤ 6️⃣ ❤" and so4==so5 and so5=="⭕" then so6="⭕" check6="" Main()
elseif check9=="❤ 9️⃣ ❤" and so7==so8 and so8=="⭕" then so9="⭕" check9="" Main()
elseif check1=="❤ 1️⃣ ❤" and so3==so2 and so2=="⭕" then so1="⭕" check1="" Main()
elseif check4=="❤ 4️⃣ ❤" and so6==so5 and so5=="⭕" then so4="⭕" check4="" Main()
elseif check7=="❤ 7️⃣ ❤" and so9==so8 and so8=="⭕" then so7="⭕" check7="" Main()
elseif check7=="❤ 7️⃣ ❤" and so1==so4 and so4=="⭕" then so7="⭕" check7="" Main()
elseif check8=="❤ 8️⃣ ❤" and so2==so5 and so5=="⭕" then so8="⭕" check8="" Main()
elseif check9=="❤ 9️⃣ ❤" and so3==so6 and so6=="⭕" then so9="⭕" check9="" Main()
elseif check1=="❤ 1️⃣ ❤" and so7==so4 and so4=="⭕" then so1="⭕" check1="" Main()
elseif check2=="❤ 2️⃣ ❤" and so8==so5 and so5=="⭕" then so2="⭕" check2="" Main()
elseif check3=="❤ 3️⃣ ❤" and so9==so6 and so6=="⭕" then so3="⭕" check3="" Main()
elseif check3=="❤ 3️⃣ ❤" and so7==so5 and so5=="⭕" then so3="⭕" check3="" Main()
elseif check1=="❤ 1️⃣ ❤" and so9==so5 and so5=="⭕" then so1="⭕" check1="" Main()
elseif check9=="❤ 9️⃣ ❤" and so1==so5 and so5=="⭕" then so9="⭕" check9="" Main()
elseif check7=="❤ 7️⃣ ❤" and so3==so5 and so5=="⭕" then so7="⭕" check7="" Main()
elseif check2=="❤ 2️⃣ ❤" and so1==so3 and so3=="⭕" then so2="⭕" check2="" Main()
elseif check5=="❤ 5️⃣ ❤" and so4==so6 and so6=="⭕" then so5="⭕" check5="" Main()
elseif check8=="❤ 8️⃣ ❤" and so7==so9 and so9=="⭕" then so8="⭕" check8="" Main()
elseif check4=="❤ 4️⃣ ❤" and so1==so7 and so7=="⭕" then so4="⭕" check4="" Main()
elseif check5=="❤ 5️⃣ ❤" and so2==so8 and so8=="⭕" then so5="⭕" check5="" Main()
elseif check6=="❤ 6️⃣ ❤" and so3==so9 and so9=="⭕" then so6="⭕" check6="" Main()
elseif check5=="❤ 5️⃣ ❤" and so1==so9 and so9=="⭕" then so5="⭕" check5="" Main()
elseif check5=="❤ 5️⃣ ❤" and so3==so7 and so7=="⭕" then so5="⭕" check5="" Main()
else
-----------------------------------------------------------------------------------------------ModMobile
-------------------------------------- code bot đánh random-------------------ModMobile
computer = math.random(1,9)
if computer==1 and check1=="❤ 1️⃣ ❤"then
so1="⭕" check1="" Main()
elseif computer==1 and check=="" then computer = math.random(1,9) end
if computer==2 and check2=="❤ 2️⃣ ❤" then
so2="⭕" check2="" Main()
elseif computer==2 and check=="" then computer = math.random(1,9) end
if computer==3 and check3=="❤ 3️⃣ ❤" then
so3="⭕" check3="" Main()
elseif computer==3 and check=="" then computer = math.random(1,9) end
if computer==4 and check4=="❤ 4️⃣ ❤" then
so4="⭕" check4="" Main()
elseif computer==4 and check=="" then computer = math.random(1,9) end
if computer==5 and check5=="❤ 5️⃣ ❤" then
so5="⭕" check5="" Main()
elseif computer==5 and check=="" then computer = math.random(1,9) end
if computer==6 and check6=="❤ 6️⃣ ❤" then
so6="⭕" check6="" Main()
elseif computer==6 and check=="" then computer = math.random(1,9) end
if computer==7 and check7=="❤ 7️⃣ ❤" then
so7="⭕" check7="" Main()
elseif computer==7 and check=="" then computer = math.random(1,9) end
if computer==8 and check8=="❤ 8️⃣ ❤" then
so8="⭕" check8="" Main()
elseif computer==8 and check=="" then computer = math.random(1,9) end
if computer==9 and check9=="❤ 9️⃣ ❤" then
so9="⭕" check9="" Main()
elseif computer==9 and check=="" then computer = math.random(1,9) end
end
-----------------------------------------------------------------------------------------------ModMobile
-------------------------------------- code check xem ai thắng-2 -------------------ModMobile
if so1==so4 and so4==so7 and so4=="❌" then ketqua=win thangthuahoa()
elseif so2==so5 and so5==so8 and so5=="❌" then ketqua=win thangthuahoa()
elseif so3==so6 and so6==so9 and so6=="❌" then ketqua=win thangthuahoa()
elseif so1==so2 and so2==so3 and so2=="❌" then ketqua=win thangthuahoa()
elseif so4==so5 and so5==so6 and so5=="❌" then ketqua=win thangthuahoa()
elseif so7==so8 and so8==so9 and so8=="❌" then ketqua=win thangthuahoa()
elseif so1==so5 and so5==so9 and so5=="❌" then ketqua=win thangthuahoa()
elseif so3==so5 and so5==so7 and so5=="❌" then ketqua=win thangthuahoa()
elseif so1==so4 and so4==so7 and so4=="⭕" then ketqua=lose thangthuahoa()
elseif so2==so5 and so5==so8 and so5=="⭕" then ketqua=lose thangthuahoa()
elseif so3==so6 and so6==so9 and so6=="⭕" then ketqua=lose thangthuahoa()
elseif so1==so2 and so2==so3 and so2=="⭕" then ketqua=lose thangthuahoa()
elseif so4==so5 and so5==so6 and so5=="⭕" then ketqua=lose thangthuahoa()
elseif so7==so8 and so8==so9 and so8=="⭕" then ketqua=lose thangthuahoa()
elseif so1==so5 and so5==so9 and so5=="⭕" then ketqua=lose thangthuahoa()
elseif so3==so5 and so5==so7 and so5=="⭕" then ketqua=lose thangthuahoa()
elseif check1=="" and check2=="" and check3=="" and check4=="" and check5=="" and check6=="" and check7=="" and check8=="" and check9=="" then ketqua=draw thangthuahoa()
end
-----------------------------------------------------------------------------------------------ModMobile
end
function thangthuahoa()
aurell= gg.choice({"thoát","chơi tiếp😏"},nil,([[
||====================]]..ketqua..[[======================||
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
║ㅤ]]..so1..[[ㅤ║ㅤ]]..so2..[[ㅤ║ㅤ]]..so3..[[ㅤ║
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
║ㅤ]]..so4..[[ㅤ║ㅤ]]..so5..[[ㅤ║ㅤ]]..so6..[[ㅤ║
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
║ㅤ]]..so7..[[ㅤ║ㅤ]]..so8..[[ㅤ║ㅤ]]..so9..[[ㅤ║
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
]]))
if aurell == nil then
gioithieu="0"
so1="1"
so2="2"
so3="3"
so4="4"
so5="5"
so6="6"
so7="7"
so8="8"
so9="9"
check1="❤ 1️⃣ ❤"
check2="❤ 2️⃣ ❤"
check3="❤ 3️⃣ ❤"
check4="❤ 4️⃣ ❤"
check5="❤ 5️⃣ ❤"
check6="❤ 6️⃣ ❤"
check7="❤ 7️⃣ ❤"
check8="❤ 8️⃣ ❤"
check9="❤ 9️⃣ ❤"
Main() else
if aurell == 1 then print(ketqua) os.exit() end
if aurell == 2 then
gioithieu="0"
so1="1"
so2="2"
so3="3"
so4="4"
so5="5"
so6="6"
so7="7"
so8="8"
so9="9"
check1="❤ 1️⃣ ❤"
check2="❤ 2️⃣ ❤"
check3="❤ 3️⃣ ❤"
check4="❤ 4️⃣ ❤"
check5="❤ 5️⃣ ❤"
check6="❤ 6️⃣ ❤"
check7="❤ 7️⃣ ❤"
check8="❤ 8️⃣ ❤"
check9="❤ 9️⃣ ❤" Main() end
end
XGCK = -1
end
while true do
if gg.isVisible(true) then
XGCK = 1
gg.setVisible(false)
end
gg.clearResults()
if XGCK == 1 then Main() end
end
Đăng nhận xét