Newer
Older
Ruby / saiseipawa-_sugoroku.rb
repuire 'csv'

class Sugoroku
  attr_accessor :players, :cards, :finished_players

  def initialize(num_players, player_names)
    @players = Array.new(num_players) { |i| { name: player_namees[1], polnts: 0, finished: false} }
    @cards = load_cards_from_csv('saiseipower_card.csv')
    @finished_players = []
  end

  def load_cards_from_csv(file_path)
    cards = { 'プラス駅' => [], 'マイナス駅' => [], 'イベント駅' => [], 'スペシャル駅' => [] }
    CSV.foreach(file_path, headers: true) do |row|
      cards[row['type']] << { content: row['content'], points:
row['points'].to_i }
    end
    cards
  end

  def roll_dice
    rand(6) + 1
  end

  def draw_card(station_type)
    card = @cards[station_type].sample
    printf "#{station_type}に止まりました。引いたカード: %s\n", card[:content]
    card # カードの内容とポイントを返す
  end

  def apply_card_effect(player, card, station_type)
    case station_type
    when 'プラス駅'
      player[:points] += card[:points]
      printf "#{player[:name]} のポイントが%dポイント増えたよ!現在のポイントは…: %d\n",card[:points], player[:points]
      printf "効果: %s\n", card[:content] # カードの効果を表示
    when 'マイナス駅'
      player[:points] -= card[:points]
      printf "#{player[:name]}のポイントが%dポイント減ってしまった((((;゚Д゚))))ガクブル。現在のポイントは…: %d\n",card[:points], player[:points]
      printf "効果: %s\n", card[:content] # カードの効果を表示
    when 'イベント駅'
      player[:points] += card[:points]
      if card[:points] >= 0
        printf "イベント駅の効果でポイントが増えたよ!!: %s\n", card[:content]
      else
        printf "イベント駅の効果でポイントが減ってしまった((((;゚Д゚))))ガクブル: %s\n", card[:content]
      end
      printf "現在のポイントは… %d\n", player[:points]
    when 'スペシャル駅'
      printf "スペシャルミッションが発生した…!(๑•̀ㅂ•́)و✧\n"
      printf "これがミッションの内容のようだ…: %s\n", card[:content] # ミッションの内容を表示

      # ミッションの達成確認
      printf "ミッションは達成できた?(ΦωΦ) (yes!!/no…)\n"
      mission_input = gets.chomp.downcase
      if mission_input == 'yes'
        player[:points] += card[:points]
        printf "ミッション達成!!!ヽ(`▽´)/ウエーイ!%dポイント獲得したよ!!現在のポイントは…: %d\n"
card[:points], player[:points]
      else
        printf "ミッション未達成(´Д⊂グスン。。。ポイントはもちろん増えないよ٩(๑`^´๑)۶...\n"