js猜拳遊戲

2022-08-23 19:27:10 字數 2585 閱讀 1570

let readline = require("readline-sync")

let clear = () => process.stdout.write(process.platform === 'win32' ? '\x1bc' : '\x1b[2j\x1b[3j\x1b[h');

let takecard = function(player)`)

player.titlepoint += point

}let judge = function(player1,player2)else if(player1.titlepointreturn 2;

}else

}let main = function();

let computer =

let continueplay = true;

while(continueplay)`);

console.log("是否要抽取一張牌?(y/n)")

let istake = readline.question("");

switch(istake)

console.log("\n按回車繼續")

readline.question("")

break;

case "n":

case "n":

istakecard=false;

break;

default:

console.log("輸入有誤,請重新輸入");

readline.question("")}}

if(player.titlepoint>21)

else,電腦的總點數為$`);

let result = judge(player,computer);

switch(result)

}console.log("\n當前比分如下:");

console.log(`玩家:$ vs 電腦:$`);

readline.question("")

while(true)

else if(isagain ==="n" || isagain === `n`)

else}}

clear();

console.log("最終比分如下:")

console.log(`玩家:$ vs 電腦:$`);

console.log("\n按回車健返回");

readline.question("");

}break;

case 2:

;let player2 = ;

let continueplay = true;

while(continueplay)  vs  玩家b:$`);

console.log("玩家a是否抽牌?(y/n)");

let istake = readline.question("")

switch (istake)

break;

case  "n":

case "n":

inputvalidate = false;

player1.istakecard = false;

break;

default:

console.log("輸入有誤,請重新輸入");

readline.question("")}}

}if(player2.istakecard) vs 玩家b:$`)

console.log("玩家b 是否抽牌?(y/n)");

let istake = readline.question("")

switch(istake)

break;

case "n":

case "n":

inputvalidate = false;

player2.istakecard = false;

break;

default:

console.log("輸入有誤,請重新輸入");

readline.question("");}}

}}if(player1.titlepoint>21)

else if(player1.titlepoint>21)

else

}console.log("\n當前比分如下:");

console.log(`玩家a:$  vs  玩家b:$`);

readline.question("")

while(true)

else if(isagain === "n"  ||  isagain ==="n")

else}}

clear();

console.log("最終比分如下:");

console.log(`玩家a:$  vs 玩家b:$`);

console.log("\n按回車鍵返回");

readline.question("")

}break;

case 3:

break;

case 4:

break; }}

clear();

console.log("thank you for playing");

}main();

猜拳遊戲Java

拿到這道問題,大值瀏覽下需要的類,既然是遊戲,game類中包含了init 與begin 兩個方法,可以猜測,game類作為了乙個 控制器 的角色,在裡面進行操作,建立person與computer類的物件,並呼叫各showquan 方法,對結果進行比較,得出是否獲勝的結論。思路清晰後,開始編寫相關的...

python 猜拳遊戲

ubuntu下編寫的乙個小遊戲,強迫症患者表示玩了好久。the finger guessing game coding utf 8 匯入乙個包,可以理解為乙個工具箱 import random 等待玩家輸入 playerpls raw input 請輸入 剪刀 0 石頭 1 布 2 player i...

if應用 猜拳遊戲

猜拳遊戲的動作包括。玩家出拳,電腦出拳,判斷結果,反饋。玩家出拳 player int input 請出拳 剪刀 0 石頭 1 布 2 剪刀是0,石頭是1,布是2 print 玩家出拳 d player 通過簡單的數學來代替實際的出拳,從鍵盤中獲取玩家出拳資訊,並轉化為整數量。注釋掉的 是用來檢測這...