私はブラックジャック ゲームを作成しています。これまでにカード クラスとデッキ クラスを作成しました。デッキ クラスに Print 関数を与えて、カードが作成され、適切にシャッフルされたかどうかを確認します。しかし、プログラムを実行すると、Segmentation fault: 11 というエラーが表示されますが、ビルドは成功しました。
メインクラス
using System;
using System.Collections.Generic;
using System.Text;
namespace BlackJackGameX
{
public class MainClass
{
public static void Main (string[] args)
{
Deck CardDeck = new Deck();
CardDeck.Print ();
}
}
}
カードクラス
using System;
using System.Collections.Generic;
using System.Text;
namespace BlackJackGameX
{
public enum Suit {Spades, Hearts, Clubs, Diamonds}
public enum FaceValue {Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King}
public class Card
{
public Suit CardSuit;
public FaceValue CardValue;
public int iValue;
public Card (Suit cardSuit, FaceValue cardValue, int ivalue)
{
CardSuit = cardSuit;
CardValue = cardValue;
iValue =ivalue;
}
public Card ()
{
}
}
}
デッキクラス
using System;
using System.Collections.Generic;
using System.Text;
namespace BlackJackGameX
{
public class Deck
{
Random rNumber = new Random();
List<Card> Cards;
public int iValue1 = 11;
public int iValue2 = 2;
public int iValue3 = 3;
public int iValue4 = 4;
public int iValue5 = 5;
public int iValue6 = 6;
public int iValue7 = 7;
public int iValue8 = 8;
public int iValue9 = 9;
public int iValue10 = 10;
public int iValue11 = 10;
public int iValue12 = 10;
public int iValue13 = 10;
public Deck()
{
Cards = NewDeck();
Shuffle();
}
public void Shuffle()
{
for (int i = 0; i <= 51; ++i)
{
int c = rNumber.Next (1, 53);
Cards.Add(Cards[c]);
}
}
private List<Card> NewDeck()
{
var AllSuits = new Suit[]
{
Suit.Spades,
Suit.Hearts,
Suit.Clubs,
Suit.Diamonds
};
var AllFaces = new FaceValue[]
{
FaceValue.Ace,
FaceValue.Two,
FaceValue.Three,
FaceValue.Four,
FaceValue.Five,
FaceValue.Six,
FaceValue.Seven,
FaceValue.Eight,
FaceValue.Nine,
FaceValue.Ten,
FaceValue.Jack,
FaceValue.Queen,
FaceValue.King
};
var AllValues = new int[]
{
iValue1,
iValue2,
iValue3,
iValue4,
iValue5,
iValue6,
iValue7,
iValue8,
iValue9,
iValue10,
iValue11,
iValue12,
iValue13
};
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 12; j++)
{
Card newCard = new Card(AllSuits[i], AllFaces[j], AllValues[j]);
NewDeck().Add(newCard);
}
}
return NewDeck();
}
public void Print()
{
Console.WriteLine(Cards[1].CardSuit);
Console.WriteLine(Cards[1].CardValue);
Console.WriteLine(Cards[1].iValue);
Console.ReadLine();
}
}
}