본문으로 이동

사용자:Jinhoftyu/common.js: 두 판 사이의 차이

리버티게임, 모두가 만들어가는 자유로운 게임
Jinhoftyu (토론 | 기여)
편집 요약 없음
태그: 되돌려진 기여
Jinhoftyu (토론 | 기여)
플러그인 p21설치
(같은 사용자의 중간 판 21개는 보이지 않습니다)
1번째 줄: 1번째 줄:




/** 플러그인 uncydungeon***************************
/** 플러그인 p21***************************
* uncydungeon 실행
* 블랙잭
* 버전 => 0.1
* 버전 => 0.840a4
* 작성자 : [[사용자:Jinhoftyu|Jinhoftyu]]  
* 작성자 : [[사용자:Riemann|Riemann]]  
* JSON => uncydungeon = {"name":"uncydungeon","descript":"uncydungeon 실행","version":"0.1","local":true,"creat":"Jinhoftyu","state":"사용자:Jinhoftyu/Undungeon/플러그인","executable":true};  
* JSON => p21 = {"name":"p21","descript":"블랙잭","version":"0.840a4","local":true,"creat":"Riemann","state":"사용자:Riemann/p21","executable":true};  
*/  
*/  
function plugin_uncydungeon() {
function plugin_p21(){
   if($("[data-name='uncydungeon']").length >= 1){
   if($("[data-name='p21']").length >= 1){
// 이부분에 코드 입력 //
var title = mw.config.get('wgPageName');
class Random {
if (title.slice( 1, 2 ) == "라") {
  nextInt(max) {
    var blind = true;
    return Math.floor(Math.random() * max);
    var defa = 20;
  }
} else {
    var blind = false;
    var defa = 10;
}
}
var mult = defa;
$("#multiplier").text(mult);


class Item {
var coins = 100;
  constructor(type, name, value) {
var wincount = 0;
    this.type = type;
var losecount = 0;
    this.name = name;
//$("#console").text("스코어: " + coins + "점");
    this.value = value;
$("#console").text("스코어: " + wincount + "승 " + losecount + "패");
  }
$("#console").append("\n블랙잭에 오신 것을 환영합니다.");
 
  getType() {
    return this.type;
  }
 
  getName() {
    return this.name;
  }
 
  getValue() {
    return this.value;
  }
 
  setName(name) {
    this.name = name;
  }


  setValue(value) {
const pcLst = [
     this.value = value;
0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAD,0xAE,
  }
0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBD,0xBE,
0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCD,0xCE,
0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDD,0xDE];
const pointData = {a1:1,a2:2,a3:3,a4:4,a5:5,a6:6,a7:7,a8:8,a9:9,aa:10,ab:10,ad:10,ae:10,b1:1,b2:2,b3:3,b4:4,b5:5,b6:6,b7:7,b8:8,b9:9,ba:10,bb:10,bd:10,be:10,c1:1,c2:2,c3:3,c4:4,c5:5,c6:6,c7:7,c8:8,c9:9,ca:10,cb:10,cd:10,ce:10,d1:1,d2:2,d3:3,d4:4,d5:5,d6:6,d7:7,d8:8,d9:9,da:10,db:10,dd:10,de:10};
var pcSet = [];
function hexToChar(x) {
     return String.fromCharCode(0xD83C) +String.fromCharCode(x + 0xDC00);
}
}
 
function hexToStr(x) {
class Entity {
     return x.toString(16);
  constructor(type, name, x, y, health) {
    this.type = type;
    this.name = name;
    this.x = x;
    this.y = y;
    this.health = health;
  }
 
  getType() {
    return this.type;
  }
 
  getName() {
     return this.name;
  }
 
  getHealth() {
    return this.health;
  }
 
  getAttack() {
    return Main.getAttack(this.getName());
  }
 
  setHealth(health) {
    this.health = health;
  }
 
  getX() {
    return this.x;
  }
 
  setX(x) {
    this.x = x;
  }
 
  getY() {
    return this.y;
  }
 
  setY(y) {
    this.y = y;
  }
}
}
 
var dealerD, guestD;
class StringBuilder {
$("#deal").click(function(){
  constructor() {
    //$("#console").text("스코어: " + coins + "점");
     this.data = [];
     $("#console").text("스코어: " + wincount + "승 " + losecount + "패");
  }
    $("#console").append("\n새 판을 엽니다.");
 
    $("#deal").css("display", "none");
  append(text) {
    $("#dealerDeck").text("");
     this.data.push(text);
     $("#guestDeck").text("");
  }
    pcSet = Object.create(pcLst);
 
    deal();
  delete(start, end) {
    return 0;
     this.data.splice(start, end - start);
});
  }
$("#hit").click(function(){
 
    hit();
  length() {
    return 0;
     return this.data.length;
});
  }
$("#stand").click(function(){
 
     stand();
  charAt(index) {
    return 0;
     return this.data[index];
});
  }
$("#surrender").click(function(){
 
    surrender();
  toString() {
     return 0;
     return this.data.join('');
});
  }
$("#plus").click(function(){
    inc();
     return 0;
});
$("#minus").click(function(){
    dec();
     return 0;
});
$("#reset").click(function(){
    reset();
    return 0;
});
function reset() {
    mult = defa;
    $("#multiplier").text(mult);
}
}


const rand = new Random();
/*
let game = false;
function inc() {
const mapY = 20;
    if (mult < 100) {
const mapX = 80;
        mult += 2;
const base = new Array(mapY);
    } else {
const entity = new Array(mapY);
        alert("최대 100 코인까지만 걸 수 있습니다.");
const entities = [];
const item = [];
 
let dl;
let xl;
let hp;
let maxhp;
let pw;
let maxpw;
let time;
 
let role;
let name = null;
let pl;
const inv = [];
const log = new StringBuilder();
let showInv = false;
 
function refLog() {
  let size = 0;
  for (let i = 0; i < log.length(); i++) {
    if (log.charAt(i) === '\n') {
      size++;
     }
     }
  }
     $("#multiplier").text(mult);
 
  if (size > 3) {
     let index = log.toString().indexOf("\n") + 1;
    log.delete(0, index);
  }
}
}


function main() {
function dec() {
  for (let i = 0; i < mapY; i++) {
    if (mult > 2) {
    const row = new Array(mapX);
        mult -= 2;
    base[i] = row;
     } else {
 
        alert("설마 빚을 판돈으로 거시려고요?");
     const entityRow = new Array(mapX);
     }
    entity[i] = entityRow;
     $("#multiplier").text(mult);
  }
 
  const readline = require('readline');
  const rl = readline.createInterface({
    input: process.stdin,
     output: process.stdout
  });
 
  const askName = () => {
     rl.question("Your name? ", (answer) => {
      name = answer;
      while (!game) {
        console.log(`
        Your role?
        a) Monk
        b) Ranger
        c) Valkryie
        d) Wizard`);
        rl.question("Choose your role: ", (roleChoice) => {
          preset(roleChoice);
          mapGen();
          gameLoop();
        });
      }
    });
  };
 
  askName();
}
}
*/


function updateStack(x, y, items) {
function deal() {
  const row = item[y];
    dealerD = [];
  row[x] = items;
    guestD = [];
  item[y] = row;
    dealerD.push(cardPop());
    guestD.push(cardPop());
    dealerD.push(cardPop());
    guestD.push(cardPop());
    if (blind == true) {
        $("#dealerDeck").text("\u{1F0A0}\u{1F0A0}");
    } else {
        $("#dealerDeck").text(hexToChar(dealerD[0]) + "\u{1F0A0}");
    }
    $("#dealerS").text("?");
    if (blind == true) {
        $("#guestDeck").text("\u{1F0A0}\u{1F0A0}");
    } else {
        $("#guestDeck").text(hexToChar(guestD[0]) + hexToChar(guestD[1]));
    }
    var guestScore = [];
    var score = pointData[hexToStr(guestD[0])] + pointData[hexToStr(guestD[1])];
    $("#guestS").text(score);
    if ((pointData[hexToStr(guestD[0])] == 1 && pointData[hexToStr(guestD[1])] == 10) || (pointData[hexToStr(guestD[0])] == 10 && pointData[hexToStr(guestD[1])] == 1)) {
        $("#guestS").text(21);
        jack();
    } else {
        $("#hit").css("display", "inline-flex");
        $("#stand").css("display", "inline-flex");
        $("#surrender").css("display", "inline-flex");
    }
};
function hit() {
    $("#hit").css("display", "none");
    $("#stand").css("display", "none");
    $("#surrender").css("display", "none");
    guestD.push(cardPop());
    var guestDeq = "";
    for (i = 0; i < guestD.length; i++) {
        guestDeq += hexToChar(guestD[i]);
    }
    if (blind == true) {
        $("#guestDeck").text("\u{1F0A0}".repeat(guestDeq.length / 2));
    } else {
        $("#guestDeck").text(guestDeq);
    }
    var guestScore = [];
    var score = 0;
    for (i = 0; i < guestD.length; i++) {
        guestScore.push(pointData[hexToStr(guestD[i])]);
        score += guestScore[i];
    }
    $("#guestS").text(score);
    if (score == 21 || (score == 11 && guestScore.includes(1))) {
        $("#console").append("\n21점이므로 자동으로 스탠드를 외쳤습니다.")
        stand(dealerD,guestD);
    } else if (score > 21) {
        bust();
    } else  {
        $("#hit").css("display", "inline-flex");
        $("#stand").css("display", "inline-flex");
    }
    return 0;
}
}
 
function stand() {
function pickup() {
     $("#hit").css("display", "none");
  const plx = pl.getX();
     $("#stand").css("display", "none");
  const ply = pl.getY();
    $("#surrender").css("display", "none");
  const items = item[ply][plx];
    var dScore = 0;
  if (items.length > 0) {
    var dealerScore = []
     const item = items[0];
     for (i = 0; i < dealerD.length; i++) {
    inv.push(item);
        dealerScore.push(pointData[hexToStr(dealerD[i])]);
    items.shift();
        dScore += dealerScore[i];
    updateStack(plx, ply, items);
     }
    log.append("You picked up " + itemName(item) + ".\n");
     while (dScore < 17) {
     turn();
        dealerD.push(cardPop());
  } else {
        $("#console").append("\n딜러가 카드를 뽑았습니다.")
    log.append("There is nothing here.\n");
        dealerScore = [];
  }
        dScore = 0;
}
        for (i = 0; i < dealerD.length; i++) {
 
            dealerScore.push(pointData[hexToStr(dealerD[i])]);
function ascend() {
            dScore += dealerScore[i];
  const plx = pl.getX();
            dealerDeq += hexToChar(dealerD[i]);
  const ply = pl.getY();
        }
  if (base[ply][plx] === '<') {
    console.log("You escaped from the dungeon.");
    process.exit(0);
  } else {
    log.append("You can't go up here.\n");
  }
}
 
function itemName(item) {
  return item.getValue() + " " + item.getName() + (item.getValue() > 1 ? "s" : "");
}
 
function move(en, dx, dy) {
  const x = en.getX();
  const y = en.getY();
  if (base[y + dy][x + dx] !== '#' && entity[y + dy][x + dx] === null) {
     entity[y][x] = null;
    x += dx;
    y += dy;
    en.setX(x);
    en.setY(y);
    const floor = base[y][x];
    entity[y][x] = en;
    const items = item[y][x];
 
     // log output
     if (en === pl) {
      turn();
      if (floor !== '.' && floor !== '\0') {
        log.append("You are standing in " + floorDes(floor) + ".\n");
      }
      if (items.length > 1) {
        log.append("You see here several items.\n");
      } else if (items.length > 0) {
        const item = items[0];
        log.append("You see here " + itemName(item) + ".\n");
      }
     }
     }
  }
    var dealerDeq = "";
}
    for (i = 0; i < dealerD.length; i++) {
 
            dealerDeq += hexToChar(dealerD[i]);
function turn() {
  for (let i = 0; i < entities.length; i++) {
    const e = entities[i];
    if (e !== pl) {
      if (adjacent(e, pl)) {
        attack(e, pl);
      } else {
        const randChoice = rand.nextInt(8);
        switch (randChoice) {
          case 0:
            move(e, -1, 0);
            break;
          case 1:
            move(e, 1, 0);
            break;
          case 2:
            move(e, 0, -1);
            break;
          case 3:
            move(e, 0, 1);
            break;
          case 4:
            move(e, -1, -1);
            break;
          case 5:
            move(e, 1, -1);
            break;
          case 6:
            move(e, -1, 1);
            break;
          case 7:
            move(e, 1, 1);
            break;
         }
         }
      }
    $("#dealerS").text(dScore);
    $("#dealerDeck").text(dealerDeq);
    guestScore = [];
    score = 0;
    for (i = 0; i < guestD.length; i++) {
        guestScore.push(pointData[hexToStr(guestD[i])]);
        score += guestScore[i];
    }
    $("#guestS").text(score);
    if (score > 21) {
        bust()
    } else if (dScore > 21) {
        $("#console").append("\n딜러의 버스트.")
        win()
    } else {
        $("#console").append("\n딜러의 스탠드.")
        compare(dealerD,guestD);
     }
     }
  }
    return 0;
  time++;
}
}
 
function compare() {
function mapGen() {
    var dealerScore = [];
  for (let y = 0; y < mapY; y++) {
    var dScore = 0;
     for (let x = 0; x < mapX; x++) {
     for (i = 0; i < dealerD.length; i++) {
 
        dealerScore.push(pointData[hexToStr(dealerD[i])]);
      // old mapgen
        dScore += dealerScore[i];
      const xborder = (y === 1 || y === mapY - 2) && (x !== 0 && x !== mapX - 1);
    }
      const yborder = (x === 1 || x === mapX - 2) && (y !== 0 && y !== mapY - 1);
    var guestScore = [];
      const floor = y > 1 && y < mapY - 2 && x > 1 && x < mapX - 2;
    var score = 0;
      const up = x === 2 && y === 2;
    for (i = 0; i < guestD.length; i++) {
      const down = x === mapX - 3 && y === mapY - 3;
         guestScore.push(pointData[hexToStr(guestD[i])]);
      if (xborder || yborder) {
         score += guestScore[i];
        base[y][x] = '#';
    }
      } else if (up) {
    if (dScore < 12 && dealerScore.includes(1)) {
         base[y][x] = '<';
         dScore += 10
      } else if (down) {
    }
        base[y][x] = '>';
    if (score < 12 && guestScore.includes(1)) {
      } else if (floor) {
        score += 10
         base[y][x] = '.';
    }
      }
    $("#dealerS").text(dScore);
 
    $("#guestS").text(score);
      // item
    if (dScore > score) {
      if (base[y][x] === '.' && rand.nextInt(80) === 0) {
         lose()
         const items = [];
    } else if (dScore == score) {
        items.push((() => {
         push()
          switch (rand.nextInt(6)) {
    } else {
            case 0:
         win()
              return new Item('%', "food ration", 1);
            case 1:
              return new Item('$', "gold piece", 25);
            case 2:
              return new Item(')', "dagger", 1);
            case 3:
              return new Item('[', "leather armor", 1);
            case 4:
              return new Item('?', "scroll of upgrade", 1);
            case 5:
              return new Item('!', "potion of healing", 1);
          }
         })());
        item[y][x] = items;
      }
 
      // entity
      if (base[y][x] === '.' && rand.nextInt(100) === 0) {
         const e = (() => {
          switch (rand.nextInt(5)) {
            case 0:
              return new Entity('B', "bat", x, y, getHP("bat"));
            case 1:
              return new Entity('r', "sewer rat", x, y, getHP("sewer rat"));
            case 2:
              return new Entity('k', "kobold", x, y, getHP("kobold"));
            case 3:
              return new Entity('o', "goblin", x, y, getHP("goblin"));
            case 4:
              return new Entity('&', "Demogorgon", x, y, getHP("Demogorgon"));
          }
        })();
         entities.push(e);
        entity[y][x] = e;
      }
     }
     }
  }
    return 0;
  pl = new Entity('@', name, 2, 2, hp);
  entity[2][2] = pl;
}
}
 
function win() {
function getHP(name) {
    $("#console").append("\n축하합니다! 이겼습니다.")
  switch (name) {
     //$("#console").append("\n" + mult + "점을 얻었습니다.")
     case "bat":
    //coins += mult;
      return 2;
     wincount += 1;
     case "sewer rat":
     $("#deal").css("display", "inline-flex");
      return 4;
     return 0;
     case "kobold":
      return 5;
    case "goblin":
      return 8;
    case "Demogorgon":
      return 456;
     default:
      return 1;
  }
}
}
 
function lose() {
function getAttack(s) {
    $("#console").append("\n졌습니다...")
  switch (s) {
     //$("#console").append("\n" + mult + "점을 잃었습니다.")
     case "bat":
    //coins -= mult;
    case "goblin":
     losecount += 1;
    case "kobold":
     $("#deal").css("display", "inline-flex");
      return 4;
    publicAd();
     case "sewer rat":
     return 0;
      return 3;
     case "Demogorgon":
      return 48;
     default:
      return 1;
  }
}
}
 
function push() {
function adjacent(a, b) {
    $("#console").append("\n비겼습니다.")
  return Math.abs(a.getX() - b.getX()) <= 1 && Math.abs(a.getY() - b.getY()) <= 1;
    $("#deal").css("display", "inline-flex");
    return 0;
}
}
 
function surrender() {
function attack(damager, damagee) {
    $("#hit").css("display", "none");
  const dam = damager.getAttack();
    $("#stand").css("display", "none");
  const health = damagee.getHealth();
    $("#surrender").css("display", "none");
  if (damagee === pl) {
     $("#console").append("\n이번 판을 포기하셨습니다 (패배로 처리됩니다).")
     log.append("The " + damager.getName() + " hits!\n");
     //$("#console").append("\n" + (0.5 * mult) + "점을 잃었습니다.")
     hp -= dam;
    //coins -= 0.5 * mult;
  } else if (damager === pl) {
    losecount += 1;
    log.append("You hit the " + damagee.getName() + "\n");
    $("#deal").css("display", "inline-flex");
  }
     publicAd();
  if (dam >= health) {
    return 0;
    death(damagee);
  } else {
     damagee.setHealth(damagee.getHealth() - dam);
  }
}
}
 
function bust() {
function death(e) {
    $("#console").append("\n버스트! 유감입니다. 졌습니다...")
  if (e === pl) {
     //$("#console").append("\n" + mult + "점을 잃었습니다.")
    log.append("You were slain...");
    //coins -= mult;
     refLog();
     losecount += 1;
     display();
     $("#hit").css("display", "none");
     process.exit(0);
     $("#stand").css("display", "none");
  } else {
     $("#deal").css("display", "inline-flex");
     entities.splice(entities.indexOf(e), 1);
     publicAd();
     entity[e.getY()][e.getX()] = null;
    return 0;
     log.append(e.getName() + " died!\n");
  }
}
}
 
function jack() {
function display() {
     $("#console").append("\n블랙잭 달성! 축하합니다. 이겼습니다!")
  const display = new StringBuilder();
    //$("#console").append("\n" + (1.5 * mult) + "점을 획득했습니다.")
  for (let y = 0; y < mapY; y++) {
    //coins += 1.5 * mult;
     for (let x = 0; x < mapX; x++) {
    wincount += 1;
      const floor = base[y][x];
    $("#deal").css("display", "inline-flex");
      const it = item[y][x];
    return 0;
      const en = entity[y][x];
      let s = " ";
      if (floor !== '\0') {
        s = floor;
      }
      if (it.length > 0) {
        s = it[0].getType();
      }
      if (en !== null) {
        s = en.getType();
      }
      display.append(s);
    }
    display.append("\n");
  }
  refLog();
  console.log(log.toString());
  display.append(name + " the " + role + " t:" + time + "\nDlvl:" + dl + " Lv:" + xl + " HP:" + hp + "/" + maxhp + " Pw:" + pw + "/" + maxpw + "\n\n");
  console.log(display.toString());
}
}
 
function publicAd() {
function inventory() {
    if (coins < 0) {
  const display = new StringBuilder();
        $("#notice").text("땀 흘려 번 돈이 아름답습니다.");
  let c = 97;
  display.append("Your inventory:\n");
  if (inv.length === 0) {
    display.append("It's empty.\n");
  } else {
    for (let i = 0; i < inv.length; i++) {
      display.append(String.fromCharCode(c) + ") " + itemName(inv[i]) + "\n");
      c++;
     }
     }
  }
    return 0;
  display.append("\nType any command...\n");
  console.log(display.toString());
  showInv = false;
}
}
 
function cardPop() {
function preset(s) {
     var j, ret;
  switch (s) {
     j = Math.floor(Math.random() * pcSet.length);
     case "a":
     ret = pcSet[j];
      role = "Monk";
     pcSet.splice(j,1);
      maxhp = 20;
     return ret;
      maxpw = 10;
      break;
     case "b":
      role = "Ranger";
      maxhp = 15;
      maxpw = 5;
      break;
     case "c":
      role = "Valkriye";
      maxhp = 20;
      maxpw = 5;
      break;
     case "d":
      role = "Wizard";
      maxhp = 15;
      maxpw = 15;
      break;
     default:
      return;
  }
  xl = 1;
  hp = maxhp;
  pw = maxpw;
  game = true;
}
}


function floorDes(c) {
  switch (c) {
    case '<':
      return "staircase leading upward";
    case '>':
      return "staircase leading downward";
    default:
      return "nothing";
   }
   }
}


main();
}
}
}
$( plugin_uncydungeon );
$( plugin_p21 );
/* uncydungeon 끝 */
/* p21 끝 */

2023년 10월 21일 (토) 21:01 판

/** 플러그인 p21***************************
* 블랙잭
* 버전 => 0.840a4
* 작성자 : [[사용자:Riemann|Riemann]] 
* JSON => p21 = {"name":"p21","descript":"블랙잭","version":"0.840a4","local":true,"creat":"Riemann","state":"사용자:Riemann/p21","executable":true}; 
*/ 
function plugin_p21(){
  if($("[data-name='p21']").length >= 1){
		 var title = mw.config.get('wgPageName');
if (title.slice( 1, 2 ) == "라") {
    var blind = true;
    var defa = 20;
} else {
    var blind = false;
    var defa = 10;
}
var mult = defa;
$("#multiplier").text(mult);

var coins = 100;
var wincount = 0;
var losecount = 0;
//$("#console").text("스코어: " + coins + "점");
$("#console").text("스코어: " + wincount + "승 " + losecount + "패");
$("#console").append("\n블랙잭에 오신 것을 환영합니다.");

const pcLst = [
0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAD,0xAE,
0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBD,0xBE,
0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCD,0xCE,
0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDD,0xDE];
const pointData = {a1:1,a2:2,a3:3,a4:4,a5:5,a6:6,a7:7,a8:8,a9:9,aa:10,ab:10,ad:10,ae:10,b1:1,b2:2,b3:3,b4:4,b5:5,b6:6,b7:7,b8:8,b9:9,ba:10,bb:10,bd:10,be:10,c1:1,c2:2,c3:3,c4:4,c5:5,c6:6,c7:7,c8:8,c9:9,ca:10,cb:10,cd:10,ce:10,d1:1,d2:2,d3:3,d4:4,d5:5,d6:6,d7:7,d8:8,d9:9,da:10,db:10,dd:10,de:10};
var pcSet = [];
function hexToChar(x) {
    return String.fromCharCode(0xD83C) +String.fromCharCode(x + 0xDC00);
}
function hexToStr(x) {
    return x.toString(16);
}
var dealerD, guestD;
$("#deal").click(function(){
    //$("#console").text("스코어: " + coins + "점");
    $("#console").text("스코어: " + wincount + "승 " + losecount + "패");
    $("#console").append("\n새 판을 엽니다.");
    $("#deal").css("display", "none");
    $("#dealerDeck").text("");
    $("#guestDeck").text("");
    pcSet = Object.create(pcLst);
    deal();
    return 0;
});
$("#hit").click(function(){
    hit();
    return 0;
});
$("#stand").click(function(){
    stand();
    return 0;
});
$("#surrender").click(function(){
    surrender();
    return 0;
});
$("#plus").click(function(){
    inc();
    return 0;
});
$("#minus").click(function(){
    dec();
    return 0;
});
$("#reset").click(function(){
    reset();
    return 0;
});
function reset() {
    mult = defa;
    $("#multiplier").text(mult);
}

/*
function inc() {
    if (mult < 100) {
        mult += 2;
    } else {
        alert("최대 100 코인까지만 걸 수 있습니다.");
    }
    $("#multiplier").text(mult);
}

function dec() {
    if (mult > 2) {
        mult -= 2;
    } else {
        alert("설마 빚을 판돈으로 거시려고요?");
    }
    $("#multiplier").text(mult);
}
*/

function deal() {
    dealerD = [];
    guestD = [];
    dealerD.push(cardPop());
    guestD.push(cardPop());
    dealerD.push(cardPop());
    guestD.push(cardPop());
    if (blind == true) {
        $("#dealerDeck").text("\u{1F0A0}\u{1F0A0}");
    } else {
        $("#dealerDeck").text(hexToChar(dealerD[0]) + "\u{1F0A0}");
    }
    $("#dealerS").text("?");
    if (blind == true) {
        $("#guestDeck").text("\u{1F0A0}\u{1F0A0}");
    } else {
        $("#guestDeck").text(hexToChar(guestD[0]) + hexToChar(guestD[1]));
    }
    var guestScore = [];
    var score = pointData[hexToStr(guestD[0])] + pointData[hexToStr(guestD[1])];
    $("#guestS").text(score);
    if ((pointData[hexToStr(guestD[0])] == 1 && pointData[hexToStr(guestD[1])] == 10) || (pointData[hexToStr(guestD[0])] == 10 && pointData[hexToStr(guestD[1])] == 1)) {
        $("#guestS").text(21);
        jack();
    } else {
        $("#hit").css("display", "inline-flex");
        $("#stand").css("display", "inline-flex");
        $("#surrender").css("display", "inline-flex");
    }
};
function hit() {
    $("#hit").css("display", "none");
    $("#stand").css("display", "none");
    $("#surrender").css("display", "none");
    guestD.push(cardPop());
    var guestDeq = "";
    for (i = 0; i < guestD.length; i++) {
        guestDeq += hexToChar(guestD[i]);
    }
    if (blind == true) {
        $("#guestDeck").text("\u{1F0A0}".repeat(guestDeq.length / 2));
    } else {
        $("#guestDeck").text(guestDeq);
    }
    var guestScore = [];
    var score = 0;
    for (i = 0; i < guestD.length; i++) {
        guestScore.push(pointData[hexToStr(guestD[i])]);
        score += guestScore[i];
    }
    $("#guestS").text(score);
    if (score == 21 || (score == 11 && guestScore.includes(1))) {
        $("#console").append("\n21점이므로 자동으로 스탠드를 외쳤습니다.")
        stand(dealerD,guestD);
    } else if (score > 21) {
        bust();
    } else  {
        $("#hit").css("display", "inline-flex");
        $("#stand").css("display", "inline-flex");
    }
    return 0;
}
function stand() {
    $("#hit").css("display", "none");
    $("#stand").css("display", "none");
    $("#surrender").css("display", "none");
    var dScore = 0;
    var dealerScore = []
    for (i = 0; i < dealerD.length; i++) {
        dealerScore.push(pointData[hexToStr(dealerD[i])]);
        dScore += dealerScore[i];
    }
    while (dScore < 17) {
        dealerD.push(cardPop());
        $("#console").append("\n딜러가 카드를 뽑았습니다.")
        dealerScore = [];
        dScore = 0;
        for (i = 0; i < dealerD.length; i++) {
            dealerScore.push(pointData[hexToStr(dealerD[i])]);
            dScore += dealerScore[i];
            dealerDeq += hexToChar(dealerD[i]);
        }
    }
    var dealerDeq = "";
    for (i = 0; i < dealerD.length; i++) {
            dealerDeq += hexToChar(dealerD[i]);
        }
    $("#dealerS").text(dScore);
    $("#dealerDeck").text(dealerDeq);
    guestScore = [];
    score = 0;
    for (i = 0; i < guestD.length; i++) {
        guestScore.push(pointData[hexToStr(guestD[i])]);
        score += guestScore[i];
    }
    $("#guestS").text(score);
    if (score > 21) {
        bust()
    } else if (dScore > 21) {
        $("#console").append("\n딜러의 버스트.")
        win()
    } else {
        $("#console").append("\n딜러의 스탠드.")
        compare(dealerD,guestD);
    }
    return 0;
}
function compare() {
    var dealerScore = [];
    var dScore = 0;
    for (i = 0; i < dealerD.length; i++) {
        dealerScore.push(pointData[hexToStr(dealerD[i])]);
        dScore += dealerScore[i];
    }
    var guestScore = [];
    var score = 0;
    for (i = 0; i < guestD.length; i++) {
        guestScore.push(pointData[hexToStr(guestD[i])]);
        score += guestScore[i];
    }
    if (dScore < 12 && dealerScore.includes(1)) {
        dScore += 10
    }
    if (score < 12 && guestScore.includes(1)) {
        score += 10
    }
    $("#dealerS").text(dScore);
    $("#guestS").text(score);
    if (dScore > score) {
        lose()
    } else if (dScore == score) {
        push()
    } else {
        win()
    }
    return 0;
}
function win() {
    $("#console").append("\n축하합니다! 이겼습니다.")
    //$("#console").append("\n" + mult + "점을 얻었습니다.")
    //coins += mult;
    wincount += 1;
    $("#deal").css("display", "inline-flex");
    return 0;
}
function lose() {
    $("#console").append("\n졌습니다...")
    //$("#console").append("\n" + mult + "점을 잃었습니다.")
    //coins -= mult;
    losecount += 1;
    $("#deal").css("display", "inline-flex");
    publicAd();
    return 0;
}
function push() {
    $("#console").append("\n비겼습니다.")
    $("#deal").css("display", "inline-flex");
    return 0;
}
function surrender() {
    $("#hit").css("display", "none");
    $("#stand").css("display", "none");
    $("#surrender").css("display", "none");
    $("#console").append("\n이번 판을 포기하셨습니다 (패배로 처리됩니다).")
    //$("#console").append("\n" + (0.5 * mult) + "점을 잃었습니다.")
    //coins -= 0.5 * mult;
    losecount += 1;
    $("#deal").css("display", "inline-flex");
    publicAd();
    return 0;
}
function bust() {
    $("#console").append("\n버스트! 유감입니다. 졌습니다...")
    //$("#console").append("\n" + mult + "점을 잃었습니다.")
    //coins -= mult;
    losecount += 1;
    $("#hit").css("display", "none");
    $("#stand").css("display", "none");
    $("#deal").css("display", "inline-flex");
    publicAd();
    return 0;
}
function jack() {
    $("#console").append("\n블랙잭 달성! 축하합니다. 이겼습니다!")
    //$("#console").append("\n" + (1.5 * mult) + "점을 획득했습니다.")
    //coins += 1.5 * mult;
    wincount += 1;
    $("#deal").css("display", "inline-flex");
    return 0;
}
function publicAd() {
    if (coins < 0) {
        $("#notice").text("땀 흘려 번 돈이 아름답습니다.");
    }
    return 0;
}
function cardPop() {
    var j, ret;
    j = Math.floor(Math.random() * pcSet.length);
    ret = pcSet[j];
    pcSet.splice(j,1);
    return ret;
}

		
  }

}
$( plugin_p21 );
/* p21 끝 */