Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.IO;
  10. using System.Windows.Forms;
  11.  
  12. namespace WindowsFormsApp1
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21.  
  22.  
  23.  
  24. int bodovi, pojam, ukupno;
  25. System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
  26.  
  27.  
  28. private void Button8_Click(object sender, EventArgs e)
  29. {
  30.  
  31. }
  32.  
  33. private void Label2_Click(object sender, EventArgs e)
  34. {
  35.  
  36. }
  37.  
  38. private void BtFormDat_Click(object sender, EventArgs e)
  39. {
  40. if (tbLevi1.Text == "" || tbDesni1.Text == "" ||
  41. tbLevi2.Text == "" || tbDesni2.Text == "" ||
  42. tbLevi3.Text == "" || tbDesni3.Text == "" ||
  43. tbLevi4.Text == "" || tbDesni4.Text == "" ||
  44. tbLevi5.Text == "" || tbDesni5.Text == "" ||
  45. tbLevi6.Text == "" || tbDesni6.Text == "" ||
  46. tbLevi7.Text == "" || tbDesni7.Text == "" ||
  47. tbImeDat.Text == "")
  48. MessageBox.Show("Morate popuniti sva polja!!!", "Greska!");
  49.  
  50.  
  51. else
  52. {
  53. string l1 = tbLevi1.Text, d1 = tbDesni1.Text,
  54. l2 = tbLevi2.Text, d2 = tbDesni2.Text,
  55. l3 = tbLevi3.Text, d3 = tbDesni3.Text,
  56. l4 = tbLevi4.Text, d4 = tbDesni4.Text,
  57. l5 = tbLevi5.Text, d5 = tbDesni5.Text,
  58. l6 = tbLevi6.Text, d6 = tbDesni6.Text,
  59. l7 = tbLevi7.Text, d7 = tbDesni7.Text;
  60.  
  61. string imefajla = tbImeDat.Text + " .txt ";
  62. StreamWriter sw = new StreamWriter(imefajla);
  63. sw.WriteLine(l1 + " / " + d1);
  64. sw.WriteLine(l2 + " / " + d2);
  65. sw.WriteLine(l3 + " / " + d3);
  66. sw.WriteLine(l4 + " / " + d4);
  67. sw.WriteLine(l5 + " / " + d5);
  68. sw.WriteLine(l6 + " / " + d6);
  69. sw.WriteLine(l7 + " / " + d7);
  70. sw.Close();
  71.  
  72.  
  73. cbIzbor.Items.Add(tbImeDat.Text);
  74. sw = new StreamWriter("Igre.txt", true);
  75. sw.WriteLine(tbImeDat.Text);
  76. sw.Close();
  77.  
  78. tbLevi1.Text = tbDesni1.Text = tbLevi2.Text = tbDesni2.Text =
  79. tbLevi3.Text = tbDesni3.Text = tbLevi4.Text = tbDesni4.Text =
  80. tbLevi5.Text = tbDesni5.Text = tbLevi6.Text = tbDesni6.Text =
  81. tbLevi7.Text = tbDesni7.Text=tbImeDat.Text;
  82.  
  83. }
  84.  
  85.  
  86.  
  87. }
  88.  
  89. private void Form1_Load(object sender, EventArgs e)
  90. {
  91. StreamWriter sw = new StreamWriter("Igre.txt", true);
  92. sw.Close();
  93. StreamReader sr = new StreamReader("Igre.txt");
  94. string s = sr.ReadLine();
  95. while (s!=null)
  96. {
  97. cbIzbor.Items.Add(s);
  98. s = sr.ReadLine();
  99.  
  100. }
  101. sr.Close();
  102. btPojam1.ForeColor =
  103. btPojam2.ForeColor =
  104. btPojam3.ForeColor =
  105. btPojam4.ForeColor =
  106. btPojam5.ForeColor =
  107. btPojam6.ForeColor =
  108. btPojam7.ForeColor = Color.DarkBlue;
  109.  
  110.  
  111. }
  112.  
  113. private void Timer1_Tick(object sender, EventArgs e)
  114. {
  115. bodovi -= 4;
  116. if (bodovi <= 0)
  117. KrajIgre();
  118. }
  119.  
  120. private void BtPojam1_Click(object sender, EventArgs e)
  121. {
  122. if(btPojam1.Text !="")
  123.  
  124. {
  125.  
  126. string s1 = lbSpisak.Text + "/" + btPojam1.Text;
  127. StreamReader sr = new StreamReader(cbIzbor.Text + ".txt");
  128. string s2 = sr.ReadLine();
  129. while (s2 != null && s2 != s1) s2 = sr.ReadLine();
  130. if (s2 == s1)
  131. {
  132.  
  133. ukupno += bodovi;
  134. btPojam1.BackColor = Color.Green;
  135.  
  136. }
  137. else btPojam1.BackColor = Color.Red;
  138. pojam++;
  139. if (pojam == 7)
  140. KrajIgre();
  141. else lbSpisak.SelectedIndex = pojam;
  142.  
  143. }
  144. }
  145.  
  146. private void BtPojam2_Click(object sender, EventArgs e)
  147. {
  148.  
  149. if (btPojam2.Text != "")
  150.  
  151. {
  152.  
  153. string s1 = lbSpisak.Text + "/" + btPojam2.Text;
  154. StreamReader sr = new StreamReader(cbIzbor.Text + ".txt");
  155. string s2 = sr.ReadLine();
  156. while (s2 != null && s2 != s1) s2 = sr.ReadLine();
  157. if (s2 == s1)
  158. {
  159.  
  160. ukupno += bodovi;
  161. btPojam2.BackColor = Color.Green;
  162.  
  163. }
  164. else btPojam2.BackColor = Color.Red;
  165. pojam++;
  166. if (pojam == 7)
  167. KrajIgre();
  168. else lbSpisak.SelectedIndex = pojam;
  169.  
  170. }
  171. }
  172.  
  173. private void BtPojam3_Click(object sender, EventArgs e)
  174. {
  175.  
  176. if (btPojam1.Text != "")
  177.  
  178. {
  179.  
  180. string s1 = lbSpisak.Text + "/" + btPojam3.Text;
  181. StreamReader sr = new StreamReader(cbIzbor.Text + ".txt");
  182. string s2 = sr.ReadLine();
  183. while (s2 != null && s2 != s1) s2 = sr.ReadLine();
  184. if (s2 == s1)
  185. {
  186.  
  187. ukupno += bodovi;
  188. btPojam3.BackColor = Color.Green;
  189.  
  190. }
  191. else btPojam3.BackColor = Color.Red;
  192. pojam++;
  193. if (pojam == 7)
  194. KrajIgre();
  195. else lbSpisak.SelectedIndex = pojam;
  196.  
  197. }
  198. }
  199.  
  200. private void BtPojam4_Click(object sender, EventArgs e)
  201. {
  202.  
  203. if (btPojam1.Text != "")
  204.  
  205. {
  206.  
  207. string s1 = lbSpisak.Text + "/" + btPojam4.Text;
  208. StreamReader sr = new StreamReader(cbIzbor.Text + ".txt");
  209. string s2 = sr.ReadLine();
  210. while (s2 != null && s2 != s1) s2 = sr.ReadLine();
  211. if (s2 == s1)
  212. {
  213.  
  214. ukupno += bodovi;
  215. btPojam4.BackColor = Color.Green;
  216.  
  217. }
  218. else btPojam4.BackColor = Color.Red;
  219. pojam++;
  220. if (pojam == 7)
  221. KrajIgre();
  222. else lbSpisak.SelectedIndex = pojam;
  223.  
  224. }
  225. }
  226.  
  227. private void BtPojam5_Click(object sender, EventArgs e)
  228. {
  229.  
  230. if (btPojam1.Text != "")
  231.  
  232. {
  233.  
  234. string s1 = lbSpisak.Text + "/" + btPojam5.Text;
  235. StreamReader sr = new StreamReader(cbIzbor.Text + ".txt");
  236. string s2 = sr.ReadLine();
  237. while (s2 != null && s2 != s1) s2 = sr.ReadLine();
  238. if (s2 == s1)
  239. {
  240.  
  241. ukupno += bodovi;
  242. btPojam5.BackColor = Color.Green;
  243.  
  244. }
  245. else btPojam5.BackColor = Color.Red;
  246. pojam++;
  247. if (pojam == 7)
  248. KrajIgre();
  249. else lbSpisak.SelectedIndex = pojam;
  250.  
  251. }
  252. }
  253.  
  254. private void BtPojam6_Click(object sender, EventArgs e)
  255. {
  256.  
  257. if (btPojam1.Text != "")
  258.  
  259. {
  260.  
  261. string s1 = lbSpisak.Text + "/" + btPojam6.Text;
  262. StreamReader sr = new StreamReader(cbIzbor.Text + ".txt");
  263. string s2 = sr.ReadLine();
  264. while (s2 != null && s2 != s1) s2 = sr.ReadLine();
  265. if (s2 == s1)
  266. {
  267.  
  268. ukupno += bodovi;
  269. btPojam6.BackColor = Color.Green;
  270.  
  271. }
  272. else btPojam6.BackColor = Color.Red;
  273. pojam++;
  274. if (pojam == 7)
  275. KrajIgre();
  276. else lbSpisak.SelectedIndex = pojam;
  277.  
  278. }
  279. }
  280.  
  281. private void TabPage1_Click(object sender, EventArgs e)
  282. {
  283.  
  284. }
  285.  
  286. private void BtPojam7_Click(object sender, EventArgs e)
  287. {
  288.  
  289. if (btPojam1.Text != "")
  290.  
  291. {
  292.  
  293. string s1 = lbSpisak.Text + "/" + btPojam7.Text;
  294. StreamReader sr = new StreamReader(cbIzbor.Text + ".txt");
  295. string s2 = sr.ReadLine();
  296. while (s2 != null && s2 != s1) s2 = sr.ReadLine();
  297. if (s2 == s1)
  298. {
  299.  
  300. ukupno += bodovi;
  301. btPojam7.BackColor = Color.Green;
  302.  
  303. }
  304. else btPojam7.BackColor = Color.Red;
  305. pojam++;
  306. if (pojam == 7)
  307. KrajIgre();
  308. else lbSpisak.SelectedIndex = pojam;
  309.  
  310. }
  311. }
  312.  
  313. private void CbIzbor_SelectedIndexChanged(object sender, EventArgs e)
  314. {
  315. Random r = new Random();
  316. int indeks;
  317. if (cbIzbor.Text != "IZABERITE IGRU!")
  318. {
  319. StreamReader sr = new StreamReader(cbIzbor.Text + ".txt");
  320. string s = sr.ReadLine();
  321. while (s!= null)
  322.  
  323. {
  324. lbSpisak.Items.Add(s.Substring(0, s.IndexOf('/')));
  325. bool ind = true;
  326. while(ind)
  327.  
  328. {
  329. indeks = r.Next(7);
  330. ind = false;
  331. switch(indeks)
  332.  
  333. {
  334.  
  335.  
  336. case 0:if (btPojam1.Text != "")
  337. ind = true;
  338.  
  339. else btPojam1.Text = s.Substring(s.IndexOf('/') + 1,
  340. s.Length-s.IndexOf('/')-1);
  341.  
  342. break;
  343.  
  344.  
  345.  
  346. case 1:
  347. if (btPojam2.Text != "")
  348. ind = true;
  349.  
  350. else btPojam2.Text = s.Substring(s.IndexOf('/') + 1,
  351. s.Length - s.IndexOf('/') - 1);
  352.  
  353. break;
  354.  
  355.  
  356. case 2:
  357. if (btPojam3.Text != "")
  358. ind = true;
  359.  
  360. else btPojam3.Text = s.Substring(s.IndexOf('/') + 1,
  361. s.Length - s.IndexOf('/') - 1);
  362.  
  363. break;
  364.  
  365.  
  366. case 3:
  367. if (btPojam4.Text != "")
  368. ind = true;
  369.  
  370. else btPojam4.Text = s.Substring(s.IndexOf('/') + 1,
  371. s.Length - s.IndexOf('/') - 1);
  372.  
  373. break;
  374.  
  375.  
  376. case 4:
  377. if (btPojam5.Text != "")
  378. ind = true;
  379.  
  380. else btPojam5.Text = s.Substring(s.IndexOf('/') + 1,
  381. s.Length - s.IndexOf('/') - 1);
  382.  
  383. break;
  384.  
  385.  
  386.  
  387. case 5:
  388. if (btPojam6.Text != "")
  389. ind = true;
  390.  
  391. else btPojam6.Text = s.Substring(s.IndexOf('/') + 1,
  392. s.Length - s.IndexOf('/') - 1);
  393.  
  394. break;
  395.  
  396.  
  397.  
  398. case 6:
  399. if (btPojam7.Text != "")
  400. ind = true;
  401.  
  402. else btPojam7.Text = s.Substring(s.IndexOf('/') + 1,
  403. s.Length - s.IndexOf('/') - 1);
  404.  
  405. break;
  406.  
  407.  
  408. }
  409.  
  410. }
  411. s = sr.ReadLine();
  412. }
  413.  
  414. lbSpisak.SelectedIndex = 0;
  415. sr.Close();
  416. cbIzbor.Enabled = false;
  417. timer1.Enabled = true;
  418. bodovi = 20;
  419. pojam = 0;
  420. ukupno = 0;
  421.  
  422. }
  423. }
  424.  
  425.  
  426. private void KrajIgre()
  427. {
  428.  
  429. timer1.Enabled = false;
  430. MessageBox.Show("Osvojili ste " + ukupno + "bodova !!!", "Kraj Igre");
  431. cbIzbor.Enabled = true;
  432. cbIzbor.Text = "IZABERITE IGRU";
  433. lbSpisak.Items.Clear();
  434. btPojam1.Text = btPojam2.Text =
  435. btPojam3.Text = btPojam4.Text =
  436. btPojam5.Text = btPojam6.Text =
  437. btPojam7.Text = "";
  438.  
  439. btPojam1.ForeColor =
  440. btPojam2.ForeColor =
  441. btPojam3.ForeColor =
  442. btPojam4.ForeColor =
  443. btPojam5.ForeColor =
  444. btPojam6.ForeColor =
  445. btPojam7.ForeColor = Color.DarkBlue;
  446.  
  447. cbIzbor.Focus();
  448.  
  449. }
  450.  
  451.  
  452.  
  453. }
  454. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement