İçeriğe geç
Tüm kodlar

İstanbul'un Fethi

Yorumla oynanan TikTok LIVE strateji oyunu

50 satır · 1,9 KBHamİndir
// Sahte izleyici üretici: canlı yayın açmadan oyunu test etmek için.
const NAMES = [
  'aysu', 'mert', 'zeynep', 'emre', 'elif', 'burak', 'selin', 'can', 'deniz', 'ece',
  'kaan', 'irem', 'onur', 'melis', 'baris', 'naz', 'umut', 'derya', 'tolga', 'gizem',
  'sinan', 'pelin', 'yigit', 'busra', 'efe', 'damla', 'arda', 'ceren', 'kerem', 'ipek',
];
const SUFFIX = ['', '_', '.', '34', '06', '35', 'x', '_tr', '53', '1453'];
const CHAT = ['selam', 'ordu hazır', 'ileri', 'yaşasın', 'haydi', 'kim burda', 'geldim', 'sur yıkılsın', 'aslanlar', 'mehter çalsın'];
const CMDS = ['top', 'top', 'hücum', 'ok', 'saldır', 'gemi', 'tekbir'];

const pick = (a) => a[Math.floor(Math.random() * a.length)];

export function randomUser() {
  const id = pick(NAMES) + pick(SUFFIX) + (Math.random() < 0.5 ? Math.floor(Math.random() * 100) : '');
  return { id, name: id };
}

export function createSimulator(onEvent) {
  let timer = null;
  let rate = 2;
  const pool = [];
  function poolUser() {
    if (pool.length < 80 && (pool.length < 5 || Math.random() < 0.25)) {
      const u = randomUser();
      pool.push(u);
      return u;
    }
    return pick(pool);
  }
  function tick() {
    const user = poolUser();
    const r = Math.random();
    if (r < 0.35) onEvent({ type: 'chat', user, text: pick(CHAT) });
    else if (r < 0.65) onEvent({ type: 'chat', user, text: pick(CMDS) });
    else if (r < 0.9) onEvent({ type: 'like', user, count: 1 + Math.floor(Math.random() * 15) });
    else if (r < 0.95) onEvent({ type: 'join', user });
    else if (r < 0.98) onEvent({ type: 'follow', user });
    else onEvent({ type: 'gift', user, coins: 1, giftName: 'Gül' });
  }
  function start(newRate) {
    if (newRate) rate = Math.max(0.2, Math.min(20, Number(newRate)));
    stop();
    timer = setInterval(tick, 1000 / rate);
  }
  function stop() {
    clearInterval(timer);
    timer = null;
  }
  return { start, stop, isRunning: () => !!timer, getRate: () => rate };
}

Lisans bilgisi projenin LICENSE dosyasında.