一次寫通的代碼

ある日、boss給了一個很獨特的想法拂共,讓我實現(xiàn)牺弄,我知道要做什么東西出來,卻很沒底宜狐,因為感覺很容易寫錯势告,然后,我還在緊張的條件說想一下就能寫出來抚恒,然后咱台,寫完之后直接跑出正確的結(jié)果了,很開心俭驮,很開心

usingSystem;

usingUnityEngine;

usingSystem.IO;

usingSystem.Text;

usingSystem.Collections.Generic;

usingSystem.Text.RegularExpressions;

usingSystem.Collections;

usingSystem.Linq;

usingSystem.Reflection;

publicclassword_Map{

publicstringword;

publicList?wh;//坐標

//public?int?jianglicichangdu;//獎勵詞長度

}

publicclassMapee{

publicList?WMList;

publicintjianglicichangdu;//獎勵詞長度

publicintjiaochadiangeshu;//交叉點個數(shù)

publicintw;

publicinth;

publicintallwordlength;

}

publicclassmap{

privatestaticmap_instance;

publicstaticmapInstance

{

get

{

if(_instance?==null)

{

_instance?=newmap();

}

return_instance;

}

}

publicmap()

{

}

stringanswerPath?="Json/answer/";

publicList?getJsonArray(stringjson)

{

stringnewJson?="{\"array\":"+?json?+"}";

Wrapper?wrapper?=JsonUtility.FromJson>(newJson);

returnwrapper.array;

}

[Serializable]

privateclassWrapper

{

publicList?array?=null;

}

stringJsonPath?="Json/";

//統(tǒng)計交叉點和地圖

publicvoidsss()?{

File.Delete(Application.dataPath?+"http://"+"FileNamesss"+".txt");

StreamWritersw;

FileInfofi?=newFileInfo(Application.dataPath?+"http://"+"FileNamesss"+".txt");

if(!fi.Exists)

{

sw?=?fi.CreateText();

}

else{

sw?=?fi.AppendText();

}

stringdata?=?(Resources.Load(JsonPath?+"UpToServer")asTextAsset).text;

List?er?=?getJsonArray(data);

for(inti?=0;?i?<?er.Count;?i++)?{

GameLevelgl?=DictionaryManager.Instance.DealDictionaryString(er[i],false);

Mapeemp?=newMapee();

mp.w?=?gl.w;

mp.h?=?gl.h;

mp.allwordlength?=0;

List?WMLists=newList();

mp.jianglicichangdu?=0;

for(intj?=0;?j?<?gl.wordsList.Count;?j++)?{

mp.allwordlength?+=?gl.wordsList[j].word.Length;

word_MapWM?=newword_Map();

WM.word?=?gl.wordsList[j].word;

List?rto0?=newList();

intwordlength?=?gl.wordsList[j].word.Length;

if(gl.wordsList[j].d?==0)?{

for(intm?=0;?m?<?wordlength;?m++)?{

Vector2temp?=newVector2();

temp.x?=?gl.wordsList[j].x?+?m;

temp.y?=?gl.wordsList[j].y;

rto0.Add(temp);

}

}elseif(gl.wordsList[j].d?==1){

for(intm?=0;?m?<?wordlength;?m++)

{

Vector2temp?=newVector2();

temp.x?=?gl.wordsList[j].x?;

temp.y?=?gl.wordsList[j].y+m;

rto0.Add(temp);

}

}elseif(gl.wordsList[j].d?==2||gl.wordsList[j].d?==3)?{

//Debug.Log(i+"???"+er[i]);

mp.jianglicichangdu?+=?wordlength;

}

WM.wh?=?rto0;

WMLists.Add(WM);

}

mp.WMList?=?WMLists;

Dictionary?dic?=newDictionary();

for(intm?=0;?m?<?mp.WMList.Count;?m++){

List?removelist?=newList();

for(intn?=0;?n?<?mp.WMList[m].wh.Count;?n++)

{

if(dic.ContainsKey(mp.WMList[m].wh[n])?==false)?{

dic.Add(mp.WMList[m].wh[n],m);

}else{

removelist.Add(mp.WMList[m].wh[n]);

mp.WMList[dic[mp.WMList[m].wh[n]]].wh.Remove(mp.WMList[m].wh[n]);

}

}

mp.jiaochadiangeshu?+=?removelist.Count;

for(intn?=0;?n?<?removelist.Count;?n++)?{

mp.WMList[m].wh.Remove(removelist[n]);

}

}

//int?w_1?=?0;

//int?w_2?=?0;

//int?w_3?=?0;

//int?w_4?=?0;

//int?w_5?=?0;

//int?w_6?=?0;

//for?(int?m?=?0;?m?<?mp.WMList.Count;?m++)?{

//if?(mp.WMList[m].wh.Count?==?0)

//{

////獎勵詞

//}

//else?if?(mp.WMList[m].wh.Count?==?1)?{?w_1++;?}

//else?if?(mp.WMList[m].wh.Count?==?2)?{?w_2++;?}

//else?if?(mp.WMList[m].wh.Count?==?3)?{?w_3++;?}

//else?if?(mp.WMList[m].wh.Count?==?4)?{?w_4++;?}

//else?if?(mp.WMList[m].wh.Count?==?5)?{?w_5++;?}

//else?if?(mp.WMList[m].wh.Count?==?6)?{?w_6++;?}

//else?if?(mp.WMList[m].wh.Count?==?7)?{?w_7++;?}

//else?{

//Debug.Log("不可能"?+?mp.WMList[m].wh.Count?+?"_"?+?er[i]);

//}

//sw.WriteLine(w_6?+?"\t"?+?w_5?+?"\t"?+?w_4?+?"\t"?+?w_3?+?"\t"+?w_2?+?"\t"?+?w_1?+?"\t"?+?mp.jianglicichangdu);

sw.WriteLine(mp.w?+"\t"+?mp.h?+"\t"+?mp.WMList.Count?+"\t"+?mp.allwordlength?+"\t"+?mp.jiaochadiangeshu);

}

sw.Flush();

sw.Close();

}

//除去交叉點

publicvoidsss2()

{

File.Delete(Application.dataPath?+"http://"+"FileNamesss"+".txt");

StreamWritersw;

FileInfofi?=newFileInfo(Application.dataPath?+"http://"+"FileNamesss"+".txt");

if(!fi.Exists)

{

sw?=?fi.CreateText();

}

else{

sw?=?fi.AppendText();

}

stringdata?=?(Resources.Load(JsonPath?+"UpToServer")asTextAsset).text;

List?er?=?getJsonArray(data);

for(inti?=0;?i?<?er.Count;?i++)

{

GameLevelgl?=DictionaryManager.Instance.DealDictionaryString(er[i],false);

Mapeemp?=newMapee();

List?WMLists?=newList();

mp.jianglicichangdu?=0;

for(intj?=0;?j?<?gl.wordsList.Count;?j++)

{

word_MapWM?=newword_Map();

WM.word?=?gl.wordsList[j].word;

List?rto0?=newList();

intwordlength?=?gl.wordsList[j].word.Length;

if(gl.wordsList[j].d?==0)

{

for(intm?=0;?m?<?wordlength;?m++)

{

Vector2temp?=newVector2();

temp.x?=?gl.wordsList[j].x?+?m;

temp.y?=?gl.wordsList[j].y;

rto0.Add(temp);

}

}

elseif(gl.wordsList[j].d?==1)

{

for(intm?=0;?m?<?wordlength;?m++)

{

Vector2temp?=newVector2();

temp.x?=?gl.wordsList[j].x;

temp.y?=?gl.wordsList[j].y?+?m;

rto0.Add(temp);

}

}

elseif(gl.wordsList[j].d?==2||?gl.wordsList[j].d?==3)

{

mp.jianglicichangdu?+=?wordlength;

}

WM.wh?=?rto0;

WMLists.Add(WM);

}

mp.WMList?=?WMLists;

//Debug.Log(WMLists.Count);

//int?jiaochadian?=?0;

Dictionary?dic?=newDictionary();

dic.Clear();

for(intm?=0;?m?<?mp.WMList.Count;?m++)

{

List?removelist?=newList();

removelist.Clear();

for(intn?=0;?n?<?mp.WMList[m].wh.Count;?n++)

{

if(dic.ContainsKey(mp.WMList[m].wh[n])?==false)

{

dic.Add(mp.WMList[m].wh[n],?m);

}

else{

removelist.Add(mp.WMList[m].wh[n]);

mp.WMList[dic[mp.WMList[m].wh[n]]].wh.Remove(mp.WMList[m].wh[n]);

}

}

for(intn?=0;?n?<?removelist.Count;?n++)

{

mp.WMList[m].wh.Remove(removelist[n]);

}

}

intw_1?=0;

intw_2?=0;

intw_3?=0;

intw_4?=0;

intw_5?=0;

intw_6?=0;

intw_7?=0;

for(intm?=0;?m?<?mp.WMList.Count;?m++)

{

if(mp.WMList[m].wh.Count?==0)?{

//獎勵詞

}

elseif(mp.WMList[m].wh.Count?==1){w_1++;}

elseif(mp.WMList[m].wh.Count?==2){w_2++;}

elseif(mp.WMList[m].wh.Count?==3){w_3++;}

elseif(mp.WMList[m].wh.Count?==4)?{?w_4++;?}

elseif(mp.WMList[m].wh.Count?==5)?{?w_5++;?}

elseif(mp.WMList[m].wh.Count?==6)?{?w_6++;?}

elseif(mp.WMList[m].wh.Count?==7)?{?w_7++;?}

else{

Debug.Log("不可能"+mp.WMList[m].wh.Count+"_"+er[i]);

}

}

sw.WriteLine(w_7?+"\t"+w_6?+"\t"+?w_5?+"\t"+?w_4?+"\t"+?w_3?+"\t"+?w_2?+"\t"+?w_1?+"\t"+?mp.jianglicichangdu);

}

sw.Flush();

sw.Close();

}

//地圖

stringProblemPath?="Json/problems/";

publicvoidsss3(stringcountry,stringfileName)

{

stringdata?=?(Resources.Load(answerPath?+?country?+"/"+?fileName)asTextAsset).text;

List?er?=?getJsonArray(data);

for(inti?=0;?i?<?er.Count;?i++)

{

//int?x_Start?=?10,x_end=0,int?y_start=10,y_end=0;

Dictionary?dicry?=newDictionary();

dicry.Clear();

GameLevelgl?=DictionaryManager.Instance.DealDictionaryString(er[i],false);

for(intj?=0;?j?<?gl.wordsList.Count;?j++)

{

intwordlength?=?gl.wordsList[j].word.Length;

for(intm?=0;?m?<?wordlength;?m++)

{

Vector2temp?=newVector2();

if(gl.wordsList[j].d?==0||?gl.wordsList[j].d?==2)

{

temp.x?=?gl.wordsList[j].x?+?m;

temp.y?=?gl.wordsList[j].y;

}else{

temp.x?=?gl.wordsList[j].x?;

temp.y?=?gl.wordsList[j].y+m;

}

if(dicry.ContainsKey(temp)?==false)

{

dicry.Add(temp,0);

}

}

}

dealVec2dic(dicry,er[i],gl);

}

Debug.Log("over");

}

publicvoiddealVec2dic(Dictionary?dicry,stringtimu,GameLevelgls){

GameLevelgl?=?gls;

//File.Delete(Application.dataPath?+?"http://"?+?"FileNamesss"?+?".txt");

StreamWritersw;

FileInfofi?=newFileInfo(Application.dataPath?+"http://"+"FileNamesss"+".txt");

if(!fi.Exists)

{

sw?=?fi.CreateText();

}

else

{

sw?=?fi.AppendText();

}

//邊界

intx_Start?=20,?x_end?=0;

inty_start?=20,?y_end?=0;

foreach(KeyValuePair?kvindicry){

if(kv.Key.x>x_end){

x_end?=(int)(kv.Key.x);

}

if(kv.Key.x?<?x_Start)

{

x_Start?=?(int)(kv.Key.x);

}

if(kv.Key.y?>?y_end)

{

y_end?=?(int)(kv.Key.y);

}

if(kv.Key.y?<?y_start)

{

y_start?=?(int)(kv.Key.y);

}

}

if(x_Start!=0||x_end+1!=gl.w||y_start!=0||y_end+1!=gl.h){

Debug.Log(timu+"_"+x_Start+"_"+x_end+"_"+y_start?+"_"+y_end);

gl.w?=?x_end?+1-x_Start;

gl.h?=?y_end?+1-y_start;

if(x_Start?!=0||?y_start?!=0)

{

for(intre?=0;?re?<?gl.wordsList.Count;?re++)

{

WordStructws?=newWordStruct();

ws.word?=?gl.wordsList[re].word;

ws.x=gl.wordsList[re].x-x_Start;

ws.y?=?gl.wordsList[re].y?-?y_start;

ws.d?=?gl.wordsList[re].d;

gl.wordsList[re]?=?ws;

}

}

//Debug.Log(timu);

sw.WriteLine("\""+DictionaryManager.Instance.GameLeveLToString(gl)+"\",");

}

//Debug.Log(timu);

List?w_list?=newList();

w_list.Clear();

for(inti?=1;?i?<?gl.w-1;?i++)

{

boolma?=false;

for(intj?=0;?j?<?gl.h;?j++)

{

Vector2v2?=newVector2();

v2.x?=?i;

v2.y?=?j;

if(dicry.ContainsKey(v2)?==true){

ma?=true;

break;

}

}

if(ma?==false&&?w_list.Count?>0&&?w_list[w_list.Count?-1]?==false){

Debug.Log(timu?+"_"+"w:"+?i);

}

w_list.Add(ma);

}

w_list.Clear();

for(inti?=1;?i?<?gl.h-1;?i++)

{

boolma?=false;

for(intj?=0;?j?<?gl.w;?j++)

{

Vector2v2?=newVector2();

v2.x?=?j;

v2.y?=?i;

if(dicry.ContainsKey(v2)?==true)

{

ma?=true;

break;

}

}

if(ma?==false&&?w_list.Count?>0&&?w_list[w_list.Count?-1]?==false)

{

Debug.Log(timu?+"_"+"w:"+?i);

}

w_list.Add(ma);

}

sw.Flush();

sw.Close();

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末回溺,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子混萝,更是在濱河造成了極大的恐慌遗遵,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,858評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件逸嘀,死亡現(xiàn)場離奇詭異车要,居然都是意外死亡,警方通過查閱死者的電腦和手機崭倘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評論 3 395
  • 文/潘曉璐 我一進店門翼岁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來维哈,“玉大人,你說我怎么就攤上這事登澜。” “怎么了飘庄?”我有些...
    開封第一講書人閱讀 165,282評論 0 356
  • 文/不壞的土叔 我叫張陵脑蠕,是天一觀的道長。 經(jīng)常有香客問我跪削,道長谴仙,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,842評論 1 295
  • 正文 為了忘掉前任碾盐,我火速辦了婚禮晃跺,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘毫玖。我一直安慰自己掀虎,他們只是感情好,可當我...
    茶點故事閱讀 67,857評論 6 392
  • 文/花漫 我一把揭開白布付枫。 她就那樣靜靜地躺著烹玉,像睡著了一般。 火紅的嫁衣襯著肌膚如雪阐滩。 梳的紋絲不亂的頭發(fā)上二打,一...
    開封第一講書人閱讀 51,679評論 1 305
  • 那天,我揣著相機與錄音掂榔,去河邊找鬼继效。 笑死,一個胖子當著我的面吹牛装获,可吹牛的內(nèi)容都是我干的瑞信。 我是一名探鬼主播,決...
    沈念sama閱讀 40,406評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼饱溢,長吁一口氣:“原來是場噩夢啊……” “哼喧伞!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起绩郎,我...
    開封第一講書人閱讀 39,311評論 0 276
  • 序言:老撾萬榮一對情侶失蹤潘鲫,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后肋杖,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體溉仑,經(jīng)...
    沈念sama閱讀 45,767評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,945評論 3 336
  • 正文 我和宋清朗相戀三年状植,在試婚紗的時候發(fā)現(xiàn)自己被綠了浊竟。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片怨喘。...
    茶點故事閱讀 40,090評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖振定,靈堂內(nèi)的尸體忽然破棺而出必怜,到底是詐尸還是另有隱情,我是刑警寧澤后频,帶...
    沈念sama閱讀 35,785評論 5 346
  • 正文 年R本政府宣布梳庆,位于F島的核電站,受9級特大地震影響卑惜,放射性物質(zhì)發(fā)生泄漏膏执。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,420評論 3 331
  • 文/蒙蒙 一露久、第九天 我趴在偏房一處隱蔽的房頂上張望更米。 院中可真熱鬧,春花似錦毫痕、人聲如沸征峦。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,988評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽眶痰。三九已至,卻和暖如春梯啤,著一層夾襖步出監(jiān)牢的瞬間竖伯,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,101評論 1 271
  • 我被黑心中介騙來泰國打工因宇, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留七婴,地道東北人。 一個月前我還...
    沈念sama閱讀 48,298評論 3 372
  • 正文 我出身青樓察滑,卻偏偏與公主長得像打厘,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子贺辰,可洞房花燭夜當晚...
    茶點故事閱讀 45,033評論 2 355

推薦閱讀更多精彩內(nèi)容

  • thiele插值算法 1點插值算法 function [C,c]=thiele(X,Y,Z)%X為插值點橫坐標户盯,Y...
    00crazy00閱讀 1,990評論 0 4
  • 星期天,老楊一個人背著手在小區(qū)里溜達饲化,現(xiàn)在正是一年中最好的時光莽鸭,春光爛漫。 小區(qū)花壇里吃靠,各種花正在次第開放硫眨。老楊用...
    阿爾他霞閱讀 1,267評論 17 18
  • 1.對我們來說,投資等于出去賭馬巢块。我們要尋找一匹獲勝幾率是兩分之一礁阁、賠率是一賠三的馬巧号。你要尋找的是標錯賠率的賭局。...
    別樣的人生閱讀 278評論 0 1
  • 文/馭風者 天上十個太陽噴涌而出的巖漿 融化不了厚厚的城墻 地下十個太陽發(fā)出來的光 照不進月亮的邊疆 十個太陽在天...
    馭風者hou閱讀 2,199評論 11 14