Form1.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Net;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace SheepSheep
  14. {
  15. public partial class Form1 : Form
  16. {
  17. private int passWay = 0;
  18. private int state = 0;
  19. private string costTime = "10";
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. init();
  24. }
  25. private void init() {
  26. this.comboBox1.SelectedIndex = 0;
  27. }
  28. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  29. {
  30. this.passWay = this.comboBox1.SelectedIndex;
  31. if (this.passWay == 1) {
  32. string ret = string.Empty;
  33. InputDialog.Show(out ret, "请输入过关耗时: ");
  34. this.costTime = ret;
  35. Console.WriteLine(ret);
  36. }
  37. }
  38. private void passTheGame(int passTimes) {
  39. string apiUrl = string.Format("https://cat-match.easygame2021.com/sheep/v1/game/game_over?rank_score=1&rank_state=1&rank_time={0}&rank_role=1&skin=1", costTime);
  40. string json = "";
  41. for (int i = 0; i < passTimes; i++)
  42. {
  43. if (state == 0) {
  44. this.Invoke(new Action(() =>
  45. {
  46. MessageBox.Show(this, "已停止羊!", "Tips:", MessageBoxButtons.OK, MessageBoxIcon.Information);
  47. }));
  48. return;
  49. }
  50. if (passWay == 0)
  51. {
  52. try
  53. {
  54. Random r = new Random();
  55. costTime = r.Next(0, 3000).ToString();
  56. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiUrl);
  57. request.Method = "GET";
  58. request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.33";
  59. request.Host = "cat-match.easygame2021.com";
  60. request.Headers.Add("t", this.textBox1.Text);
  61. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  62. Stream myResponseStream = response.GetResponseStream();
  63. StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
  64. string retString = myStreamReader.ReadToEnd();
  65. myStreamReader.Close();
  66. myResponseStream.Close();
  67. if (retString.Contains("\"err_code\":0"))
  68. {
  69. this.Invoke(new Action(() =>
  70. {
  71. toolStripStatusLabel1.Text = "通关次数: " + i.ToString();
  72. }));
  73. Console.WriteLine(retString);
  74. }
  75. }
  76. catch { }
  77. }
  78. if (i == passTimes - 1) {
  79. this.Invoke(new Action(() =>
  80. {
  81. state = 0;
  82. this.button1.Text = "羊它!";
  83. }));
  84. }
  85. }
  86. }
  87. private void button1_Click(object sender, EventArgs e)
  88. {
  89. if (state == 0)
  90. {
  91. state = 1;
  92. Thread t = new Thread(() => passTheGame(int.Parse(this.textBox2.Text)));
  93. t.Start();
  94. this.button1.Text = "停止羊!";
  95. MessageBox.Show(this, "开始羊咯!", "Tips:", MessageBoxButtons.OK, MessageBoxIcon.Information);
  96. }
  97. else {
  98. state = 0;
  99. this.button1.Text = "羊它!";
  100. }
  101. }
  102. private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
  103. {
  104. if (e.KeyChar != '\b')
  105. {
  106. if ((e.KeyChar < '0') || (e.KeyChar > '9'))
  107. {
  108. e.Handled = true;
  109. }
  110. }
  111. }
  112. }
  113. }