js实现简单狼人杀游戏代码

代码语言:html

所属分类:游戏

代码描述:js实现简单狼人杀游戏代码,你可以模拟任意的角色,其他角色有ai机器来模拟。

代码标签: js 简单 狼人杀 游戏 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>狼人杀 - 单机模拟版</title>
<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/all.6.4.0.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap');

        :root {
            --bg-color: #1a1a2e;
            --surface-color: #16213e;
            --primary-color: #0f3460;
            --secondary-color: #e94560;
            --text-color: #e0e0e0;
            --text-muted: #a0a0a0;
            --accent-good: #2ecc71;
            --accent-evil: #e74c3c;
            --font-family: 'Noto Sans SC', sans-serif;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: var(--font-family);
            background-color: var(--bg-color);
            color: var(--text-color);
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            overflow: hidden;
        }

        #game-container {
            width: 100%;
            max-width: 900px;
            height: 95vh;
            max-height: 700px;
            background-color: var(--surface-color);
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        /* Setup Screen */
        #setup-screen {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            padding: 40px;
            text-align: center;
            height: 100%;
        }

        #setup-screen h1 {
            font-size: 3rem;
            color: white;
            margin-bottom: 20px;
            text-shadow: 0 0 15px var(--secondary-color);
        }
        
        #setup-screen p {
            font-size: 1.1rem;
            color: var(--text-muted);
            margin-bottom: 40px;
        }

        .setup-option {
            margin-bottom: 25px;
            width: 100%;
            max-width: 400px;
        }

        .setup-option label {
            display: block;
            margin-bottom: 10px;
            font-size: 1.2rem;
            font-weight: 500;
        }

        .role-selection {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
            gap: 15px;
        }

        .role-card {
            background: var(--primary-color);
            padding: 15px;
            border-radius: 10px;
            cursor: pointer;
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .role-card:hover {
            transform: translateY(-5px);
            background: #e94560;
        }

        .role-card.selected {
            border-color: var(--secondary-color);
            background: #e94560;
            box-shadow: 0 0 15px var(--secondary-color);
        }

        .role-card i {
            font-size: 2rem;
        }

        .role-card span {
            display: block;
            margin-top: 5px;
            font-weight: 500;
        }

        #start-game-btn {
            background-color: var(--secondary-color);
            color: white;
            border: none;
            padding: 15px 40px;
            font-size: 1.2rem;
            font-weight: 700;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 20px;
        }

        #start-game-btn:hover {
            background-color: #c73850;
            transform: scale(1.05);
        }
        
        #start-game-btn:disabled {
            background-color: #555;
            cursor: not-allowed;
            transform: none;
        }

        /* Main Game Screen */
        #main-screen {
            display: none;
            flex-direction: column;
            height: 100%;
        }

        header {
            padding: 15px 20px;
            background-color: var(--primary-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-shrink: 0;
        }

        #game-status {
            font-size: 1.5rem;
            font-weight: 700;
        }
        
        #game-info {
            font-size: 1rem;
            color: var(--text-muted);
        }

        .game-area {
            display: flex;
            flex-grow: 1;
            overflow: hidden;
        }

        #player-grid {
            flex-basis: 65%;
            padding: 20px;
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 15px;
            align-content: flex-start;
            overflow-y: auto;
        }

        .player-card {
            background-color: var(--primary-color);
            border-radius: 10px;
            padding: 10px;
            text-align: center;
            position: relative;
            transition: all 0.3s ease;
            border: 2px solid transparent;
            overflow: hidden;
        }

        .player-card.human {
            border-color: var(--accent-good);
            box-shadow: 0 0 10px var(--accent-good);
        }

        .player-card.dead {
            opacity: 0.5;
            background-color: #333;
            transform: scale(0.95);
        }
        
        .player-card.dead .player-role {
            opacity: 1;
        }

        .player-number {
            font-size: 1.5rem;
            font-weight: 700;
        }
        
        .player-role {
            font-size: 0.8rem;
            font-weight: 500;
            color: var(--text-muted);
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .player-card.human .player-role {
             opacity: 1;
        }

        .player-card.targetable {
            cursor: pointer;
            border-color: var(--secondary-color);
        }
        
        .player-card.targetable:hover {
            transform: scale(1.05);
            background-color: #e94560;
        }

        .vote-count {
            position: absolute;
            top: 5px;
            right: 5px;
            background-color: rgba(233, 69, 96, 0.8);
            border-radius: 50%;
            width: 25px;
            height: 25px;
            display: flex;
            justify-content: center;
            align-items: center;
  .........完整代码请登录后点击上方下载按钮下载查看

网友评论0