void CreateLabel(string label, int numLine) { CryptoGrapher.ReadFile(ref buffer, fileName); int i, j; string[] newBuffer = new string[buffer.Length + numLine + 1]; for (i = 0; i < edLine; ++i) { newBuffer[i] = buffer[i]; } newBuffer[i++] = "//" + label; for (; i <= edLine + numLine; ++i) { newBuffer[i] = "Empty"; } newBuffer[i++] = "//End"; j = edLine + 1; for (; i < newBuffer.Length; ++i) { newBuffer[i] = buffer[j++]; } edLine += numLine + 1; CryptoGrapher.WriteFile(newBuffer, fileName); }
void ReadGame() // stLine, edLine 알아내기 { CryptoGrapher.ReadFile(ref buffer, fileName); stLine = -1; for (int i = 0; i < buffer.Length; ++i) { if (buffer[i] == "■" + game) { stLine = i; break; } } if (stLine == -1) // 해당 게임이 존재하지 않음 { stLine = buffer.Length; edLine = buffer.Length + 1; CreateGame(); } else { for (int i = stLine; i < buffer.Length; ++i) { if (buffer[i] == "//End") { edLine = i; break; } } } }
public string SelectMap(string digitMean) { quit = false; int numLabel = (edLine - stLine - 1) / (1 + l); if (numLabel == 0) { quit = true; return(""); } // 모든 label 알아내기 CryptoGrapher.ReadFile(ref buffer, FILENAME); string[] labels = new string[numLabel]; for (int i = 0; i < numLabel; ++i) { int labelLine = stLine + 1 + i * (1 + l); labels[i] = buffer[labelLine].Substring(2); } while (Console.KeyAvailable) { Console.ReadKey(true); } while (true) { ShowMap(labels[cur], 0, 0); ConsoleKeyInfo cki = Console.ReadKey(true); string s = cki.Key.ToString(); if (s == "Enter" || s == "Spacebar") { return(labels[cur]); } else if (s == "R") { RecordManager r = new RecordManager(game); r.ShowRecord(labels[cur], digitMean); MyFunction.WaitForExit(); } else if (s == "LeftArrow") { cur = (cur - 1 + numLabel) % numLabel; } else if (s == "RightArrow") { cur = (cur + 1) % numLabel; } else if (s == "Q") { quit = true; return(""); } } }
void CreateGame() { CryptoGrapher.ReadFile(ref buffer, fileName); string[] tmp = new string[buffer.Length + 2]; int i = 0; for (i = 0; i < buffer.Length; ++i) { tmp[i] = buffer[i]; } tmp[i++] = "■" + game; tmp[i] = "//End"; CryptoGrapher.WriteFile(tmp, fileName); }
public bool ReadLabel(string label, int numLine, ref string[] buffer) // labelLine 알아내기 { CryptoGrapher.ReadFile(ref buffer, fileName); int i; labelLine = -1; for (i = stLine; i <= edLine; ++i) { if (buffer[i] == "//" + label) { labelLine = i; break; } } if (labelLine == -1) // 해당 식별자가 존재하지 않음 { labelLine = edLine; CreateLabel(label, numLine); CryptoGrapher.ReadFile(ref buffer, fileName); return(false); } return(true); }
public static void OverWrite() { const string FILENAME1 = "Record1"; Console.ResetColor(); Console.Clear(); Console.SetCursorPosition(2, 1); Console.Write("※도움말※"); Console.SetCursorPosition(2, 3); Console.Write("1. 외부에서 {0}.dll 파일을 구해옵니다", FILENAME); Console.SetCursorPosition(2, 4); Console.Write("2. 파일 이름을 {0}.dll로 바꾸고 폴더 안에 넣어주세요", FILENAME1); Console.SetCursorPosition(2, 5); Console.Write("3. 덮어쓰기가 완료되면 Record1.dll을 폴더에서 빼내주세요"); Console.SetCursorPosition(2, 7); Console.Write("♠ W를 누르면 덮어쓰기를 시작합니다 ♠"); Console.SetCursorPosition(50, 10); Console.Write("뒤로가기(Spacebar/Enter)"); while (Console.KeyAvailable) { Console.ReadKey(true); } while (true) { ConsoleKeyInfo cki = Console.ReadKey(true); string s = cki.Key.ToString(); if (s == "W") { break; } else if (s == "Spacebar" || s == "Enter") { return; } } // 덮어쓰기 시작 Console.ForegroundColor = ConsoleColor.Yellow; Console.SetCursorPosition(2, 8); Console.Write("♠ 덮어쓰기중.. ♠"); Thread.Sleep(1000); // 덮어쓰기 실패 if (!File.Exists(FILENAME1 + ".dll")) { Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(2, 8); Console.Write("♠ 실패: Record1.dll을 찾을 수 없습니다 ♠"); MyFunction.WaitForExit(); return; } // 덮어쓰기 진행 string[] res = new string[1]; CryptoGrapher.ReadFile(ref res, FILENAME); string[] buffer = new string[1]; CryptoGrapher.ReadFile(ref buffer, FILENAME1); FileManager fm = new FileManager(); for (int i = 0; i < buffer.Length; ++i) { if (buffer[i][0] == '■') { string game = buffer[i].Substring(1); CryptoGrapher.WriteFile(res, FILENAME); fm = new FileManager(FILENAME, game); CryptoGrapher.ReadFile(ref res, FILENAME); } else if (buffer[i] == "Empty" || buffer[i] == "//End") { continue; } else if (buffer[i][0] == '/') { string label = buffer[i].Substring(2); CryptoGrapher.WriteFile(res, FILENAME); fm.ReadLabel(label, MAXRANK, ref res); } else // 현재 label의 점수에 대해 { string[] tmp = buffer[i].Split(' '); int newDigit = int.Parse(tmp[0]); string userName = tmp[1]; int curRank = -1; for (int j = fm.labelLine + 1; j <= fm.labelLine + MAXRANK; ++j) { int rank = j - fm.labelLine; int digit = 0; string name = "-"; if (res[j] != "Empty") { string[] tmp2 = res[j].Split(' '); digit = int.Parse(tmp2[0]); name = tmp2[1]; } if (digit <= newDigit) { if (digit != newDigit || userName != name) { curRank = rank; } break; } } if (curRank == -1) { continue; } for (int j = fm.labelLine + MAXRANK; j > fm.labelLine + curRank; --j) { res[j] = res[j - 1]; } res[fm.labelLine + curRank] = newDigit.ToString() + " " + userName; } } // 덮어쓰기 종료 CryptoGrapher.WriteFile(res, FILENAME); Console.ForegroundColor = ConsoleColor.Green; Console.SetCursorPosition(2, 8); Console.Write("♠ 덮어쓰기 성공 ♠"); MyFunction.WaitForExit(); }