台灣最大程式設計社群網站
線上人數
1214
 
會員總數:243277
討論主題:188067
歡迎您免費加入會員
討論區列表 >> C# >> 請問為何有時候結果是兩個,有時是三個?要多嘗試幾次
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
請問為何有時候結果是兩個,有時是三個?要多嘗試幾次
價值 : 50 QP  點閱數:82 回應數:1

樓主

yellow
門外漢
0 1
12 1
發送站內信

//有一個轉盤圖形
//每個圓弧角度是45度
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Diagnostics;

namespace rotateCircle
{
public partial class Form1 : Form
{
int degree = 0;
Random rd = new Random();
int num = 0;
bool stop = true;


Pen MyPen_Frame = new Pen(Color.Black, 1);
int turn = 0;
int time = 0;
Pen pen = new Pen(Color.Red, 3);

Bitmap picture = new Bitmap(Properties.Resources.scoreBoard, 180, 180);

public Form1()
{
this.ClientSize = new Size(300, 300);
InitializeComponent();
}


private void Form1_Load_1(object sender, EventArgs e)
{

}

private void Form1_Paint_1(object sender, PaintEventArgs e)
{
e.Graphics.ResetTransform();

e.Graphics.TranslateTransform(this.ClientSize.Width / 2,
this.ClientSize.Height / 2);

e.Graphics.DrawEllipse(MyPen_Frame, -110, -110, 220, 220);

for (int i = 0; i < 360; i = i + 30)
{
e.Graphics.ResetTransform();
e.Graphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);
e.Graphics.RotateTransform(i);
e.Graphics.DrawLine(MyPen_Frame, 100, 0, 110, 0);
}

e.Graphics.ResetTransform();
e.Graphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);
e.Graphics.DrawLine(pen, 0, -110, 0, -95);

//DateTime t = DateTime.Now;

// 繪出 時針
//e.Graphics.ResetTransform();
//e.Graphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);
//// 旋轉表單畫布 1個小時為30度 要把分鐘轉為小時的小數部分
//e.Graphics.RotateTransform(((t.Hour % 12) + (t.Minute / 60.0f)) * 30.0f);
//e.Graphics.DrawLine(MyPen_H, 0, 0, 0, -60);

//// 繪出 分針
//e.Graphics.ResetTransform();
//e.Graphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);
//// 旋轉表單畫布 1分鐘為6度 要把秒數轉為分鐘的小數部分
//e.Graphics.RotateTransform((t.Minute + t.Second / 60.0f) * 6.0f);
//e.Graphics.DrawLine(MyPen_M, 0, 0, 0, -75);
e.Graphics.ResetTransform();
e.Graphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);

e.Graphics.RotateTransform(degree*45f);
e.Graphics.DrawImage(picture, -90, -90);
}

private void timer1_Tick(object sender, EventArgs e)
{
this.Invalidate();
}

private void timer2_Tick(object sender, EventArgs e)
{
degree++;
degree %= 8;

if (stop)
{
timer2.Enabled = false;

if (degree == 0)
{
scorelb.Text = "分數 : " + 75;
richTextBox1.Text += 75 + "\n";

timer4.Enabled = true;
time = 0;
}

else if (degree == 1 || degree == 3 || degree == 5)
{
scorelb.Text = "分數 : " + 30;
richTextBox1.Text += 30+"\n";

timer4.Enabled = true;
time = 0;
}

else if (degree == 2 || degree == 6)
{
scorelb.Text = "分數 : " + 40;
richTextBox1.Text += 40+"\n";

timer4.Enabled = true;
time = 0;
}

else if (degree == 4)
{
scorelb.Text = "分數 : " + 80;
richTextBox1.Text += 80+ "\n";

timer4.Enabled = true;
time = 0;
}

else if (degree == 7)
{
scorelb.Text = "分數 : " + 60;
richTextBox1.Text += 60 + "\n";

timer4.Enabled = true;
time = 0;

}
}
}

private void timer3_Tick(object sender, EventArgs e)
{
num--;

if (num == 0)
{
timer3.Enabled = false;
num = 0;
stop = true;

}
}

private void resetBtn_Click(object sender, EventArgs e)
{
num = rd.Next(33, 40);
stop = false;
timer2.Enabled = true;
timer3.Enabled = true;
scorelb.Text = "分數 : ";
timer1.Enabled = true;
richTextBox1.Text = null;
turn = 0;
}

private void Again()
{
num = rd.Next(33, 40);
stop = false;
timer2.Enabled = true;
timer3.Enabled = true;
}

private void timer4_Tick(object sender, EventArgs e)
{
time++;
if (time > 3)
{
time = 0;
++turn;
if (turn < 3)
{
timer4.Enabled = false;
Again();
}
timer4.Enabled = false;
}
}
}
}




搜尋相關Tags的文章: [ BUG ] ,
本篇文章發表於2018-10-10 13:45
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
1樓
作者回應

yellow
檢舉此回應


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Diagnostics;

namespace rotateCircle
{
public partial class Form1 : Form
{
int degree = 0;
Random rd = new Random();
int num = 0;
bool stop = true;


Pen MyPen_Frame = new Pen(Color.Black, 1);
int turn = 0;
int time = 0;
Pen pen = new Pen(Color.Red, 3);

Bitmap picture = new Bitmap(Properties.Resources.scoreBoard, 180, 180);

public Form1()
{
this.ClientSize = new Size(300, 300);
InitializeComponent();
}


private void Form1_Load_1(object sender, EventArgs e)
{

}

private void Form1_Paint_1(object sender, PaintEventArgs e)
{
e.Graphics.ResetTransform();

e.Graphics.TranslateTransform(this.ClientSize.Width / 2,
this.ClientSize.Height / 2);

e.Graphics.DrawEllipse(MyPen_Frame, -110, -110, 220, 220);

for (int i = 0; i < 360; i = i + 30)
{
e.Graphics.ResetTransform();
e.Graphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);
e.Graphics.RotateTransform(i);
e.Graphics.DrawLine(MyPen_Frame, 100, 0, 110, 0);
}

e.Graphics.ResetTransform();
e.Graphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);
e.Graphics.DrawLine(pen, 0, -110, 0, -95);


e.Graphics.ResetTransform();
e.Graphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);

e.Graphics.RotateTransform(degree*45f);
e.Graphics.DrawImage(picture, -90, -90);
}

private void timer1_Tick(object sender, EventArgs e)
{
this.Invalidate();
}

private void timer2_Tick(object sender, EventArgs e)
{
degree++;
degree %= 8;

if (stop)
{
timer2.Enabled = false;

if (degree == 0)
{
scorelb.Text = "分數 : " + 75;
richTextBox1.Text += 75 + "\n";

timer4.Enabled = true;
time = 0;
}

else if (degree == 1 || degree == 3 || degree == 5)
{
scorelb.Text = "分數 : " + 30;
richTextBox1.Text += 30+"\n";

timer4.Enabled = true;
time = 0;
}

else if (degree == 2 || degree == 6)
{
scorelb.Text = "分數 : " + 40;
richTextBox1.Text += 40+"\n";

timer4.Enabled = true;
time = 0;
}

else if (degree == 4)
{
scorelb.Text = "分數 : " + 80;
richTextBox1.Text += 80+ "\n";

timer4.Enabled = true;
time = 0;
}

else if (degree == 7)
{
scorelb.Text = "分數 : " + 60;
richTextBox1.Text += 60 + "\n";

timer4.Enabled = true;
time = 0;

}
}
}

private void timer3_Tick(object sender, EventArgs e)
{
num--;

if (num == 0)
{
timer3.Enabled = false;
num = 0;
stop = true;

}
}

private void resetBtn_Click(object sender, EventArgs e)
{
num = rd.Next(33, 40);
stop = false;
timer2.Enabled = true;
timer3.Enabled = true;
scorelb.Text = "分數 : ";
timer1.Enabled = true;
richTextBox1.Text = null;
turn = 0;
}

private void Again()
{
num = rd.Next(33, 40);
stop = false;
timer2.Enabled = true;
timer3.Enabled = true;
}

private void timer4_Tick(object sender, EventArgs e)
{
time++;
if (time > 3)
{
time = 0;
++turn;
if (turn < 3)
{
timer4.Enabled = false;
Again();
}
timer4.Enabled = false;
}
}
}
}
本篇文章回覆於2018-10-10 19:13
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.