加入列表并进行比较

时间:2014-12-09 22:27:55

标签: c# list join

我真的希望在这里得到帮助。我正在努力制作像Rummy这样的纸牌游戏并且已经走得很远但是......

当玩家无法在棋盘上放下一些牌时,玩家有机会通过或换掉一些牌。游戏持续存在2副牌(104张牌),每位玩家从一开始就获得12张牌。甲板上卡片的解剖结构如下:

颜色,号码,标识

所有牌都在一个长长的牌组中,如下所示:

r,1,1,r,1,2,r,2,3,r,2,4 .....等

玩家卡片位于库存中,展示位置如下:

放置,颜色,号码,标识

1,B,9,17,2,R,6,34 .....等

桌子/桌面上的卡片是这样的:

放置,颜色,号码,标识

a1,y,7,65,a2,y,8,67 ....等

所以每个库存,卡片组和桌卡都是用逗号分隔的字符串,并且必须保持这种状态(对不起)。

现在,我正在尝试确保在游戏中没有多种类型,但运气不佳。有时我会在游戏中获得许多牌,相同颜色的3#13。但这是我目前的脚本:

// PLAYERCARDS //
playercardsArray = playercards.Split (","[0]);

q = 0;
m = "";
foreach(string thisvalue in playercardsArray){
    m += (q%4 == 3)?thisvalue+';':thisvalue+','; 
    q++;
}

playercardsArray = m.Split (";"[0]);

foreach(string thisCard in playercardsArray){
    playercardsList.Add(thisCard);
}

playercardsList.RemoveAt(playercardsList.Count-1); 

foreach(string remcards in playercardsList){
    joinedList.Add(remcards.Substring(remcards.IndexOf(",") + 1));
}


// OPPCARDS //
oppcardsArray = oppcards.Split (","[0]);

q = 0;
m = "";
foreach(string thisvalue in oppcardsArray){
    m += (q%4 == 3)?thisvalue+';':thisvalue+','; 
    q++;
}

oppcardsArray = m.Split (";"[0]);

foreach(string thisCard in oppcardsArray){
    oppcardsList.Add(thisCard);
}

oppcardsList.RemoveAt(oppcardsList.Count-1); 

foreach(string remcards in oppcardsList){
    joinedList.Add(remcards.Substring(remcards.IndexOf(",") + 1));
}

// BOARDCARDS //
boardcardsArray = tabletiles.Split (","[0]);

q = 0;
m = "";
foreach(string thisvalue in boardcardsArray){
    m += (q%4 == 3)?thisvalue+';':thisvalue+','; 
    q++;
}

boardcardsArray = m.Split (";"[0]);

foreach(string thisCard in boardcardsArray){
    boardcardsList.Add(thisCard);
}

boardcardsList.RemoveAt(boardcardsList.Count-1); 

foreach(string remcards in boardcardsList){
    joinedList.Add(remcards.Substring(remcards.IndexOf(",") + 1));
}

// NEWCARDS //
newcardsArray = newcards.Split (","[0]);

q = 0;
m = "";
foreach(string thisvalue in newcardsArray){
    m += (q%4 == 3)?thisvalue+';':thisvalue+','; 
    q++;
}

newcardsArray = m.Split (";"[0]);

foreach(string thisCard in newcardsArray){
    newcardsList.Add(thisCard);
}

newcardsList.RemoveAt(newcardsList.Count-1); 

foreach(string remcards in newcardsList){
    joinedList.Add(remcards.Substring(remcards.IndexOf(",") + 1));
}

// ALLCARDS //
cardsArray = new string[]{ "r,1,1","r,1,2","r,2,3","r,2,4","r,3,5","r,3,6","r,4,7","r,4,8","r,5,9","r,5,10","r,6,11","r,6,12","r,7,13","r,7,14","r,8,15","r,8,16","r,9,17","r,9,18","r,10,19","r,10,20","r,11,21","r,11,22","r,12,23","r,12,24","r,13,25","r,13,26","b,1,27","b,1,28","b,2,29","b,2,30","b,3,31","b,3,32","b,4,33","b,4,34","b,5,35","b,5,36","b,6,37","b,6,38","b,7,39","b,7,40","b,8,41","b,8,42","b,9,43","b,9,44","b,10,45","b,10,46","b,11,47","b,11,48","b,12,49","b,12,50","b,13,51","b,13,52","y,1,53","y,1,54","y,2,55","y,2,56","y,3,57","y,3,58","y,4,59","y,4,60","y,5,61","y,5,62","y,6,63","y,6,64","y,7,65","y,7,66","y,8,67","y,8,68","y,9,69","y,9,70","y,10,71","y,10,72","y,11,73","y,11,74","y,12,75","y,12,76","y,13,77","y,13,78","g,1,79","g,1,80","g,2,81","g,2,82","g,3,83","g,3,84","g,4,85","g,4,86","g,5,87","g,5,88","g,6,89","g,6,90","g,7,91","g,7,92","g,8,93","g,8,94","g,9,95","g,9,96","g,10,97","g,10,98","g,11,99","g,11,100","g,12,101","g,12,102","g,13,103","g,13,104"};
q = 0;

foreach(string thisCard in cardsArray){
    cardsList.Add(thisCard);
}

foreach (string s in joinedList){
    cardsList.Remove(s);
}

thedecks = "";
thedecks = string.Join(",", cardsList.ToArray());

我知道这是相当多的,而且它可以更聪明地完成,所以我希望在这件事上提供帮助。我现在已经尝试了很多次但没有运气

提前致谢: - )

0 个答案:

没有答案