目前分類:未分類文章 (15)

瀏覽方式: 標題列表 簡短摘要

import java.awt.*;
import java.awt.event.*;

D0037134 發表在 痞客邦 留言(0) 人氣()

class test
{

D0037134 發表在 痞客邦 留言(0) 人氣()

VB

Private Sub CommandButton1_Click()

D0037134 發表在 痞客邦 留言(0) 人氣()

<html>
<head>

D0037134 發表在 痞客邦 留言(0) 人氣()

電腦→內容→進階→PATH 貼入javac所在位置(要加分號;)

開一個Wordpad並寫入程式碼

D0037134 發表在 痞客邦 留言(0) 人氣()

目標』使被選定的方格內數字來源(位置i j)顯示清楚

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

D0037134 發表在 痞客邦 留言(0) 人氣()

使兩方格顯示之數字能夠互換

Private Sub CommandButton1_Click()
For i = 1 To 9
Cells(1, i) = i
Cells(1, i).Font.ColorIndex = 0

D0037134 發表在 痞客邦 留言(0) 人氣()

矩陣方式做出4*4方陣

namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
Button[,] buttons = new Button[4, 4];
public Form1()
{
InitializeComponent();
}

D0037134 發表在 痞客邦 留言(0) 人氣()

使用EXCEL內建VBA語言寫出陣列格式

 

D0037134 發表在 痞客邦 留言(0) 人氣()

判斷三格連線及勝利BOX跳出

int c=0, r;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button1.Text = "O";
}
else
{
button1.Text = "X";
}
button1.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button2.Text = "O";
}
else
{
button2.Text = "X";
}
button2.Enabled = false;
judge();
}
private void judge()
{
if( (button1.Text == "X" && button2.Text == "X" && button3.Text == "X")||
(button1.Text == "X" && button5.Text == "X" && button9.Text == "X") ||
(button1.Text == "X" && button4.Text == "X" && button7.Text == "X") ||
(button4.Text == "X" && button5.Text == "X" && button6.Text == "X") ||
(button7.Text == "X" && button8.Text == "X" && button9.Text == "X") ||
(button2.Text == "X" && button5.Text == "X" && button8.Text == "X") ||
(button3.Text == "X" && button6.Text == "X" && button9.Text == "X") ||
(button3.Text == "X" && button5.Text == "X" && button7.Text == "X"))

MessageBox.Show("X贏了");
}
private void button3_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button3.Text = "O";
}
else
{
button3.Text = "X";
}
button3.Enabled = false;
judge();
}
private void button4_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button4.Text = "O";
}
else
{
button4.Text = "X";
}
button4.Enabled = false;
judge();
}
private void button5_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button5.Text = "O";
}
else
{
button5.Text = "X";
}
button5.Enabled = false;
judge();
}
private void button6_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button6.Text = "O";
}
else
{
button6.Text = "X";
}
button6.Enabled = false;
judge();
}
private void button7_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button7.Text = "O";
}
else
{
button7.Text = "X";
}
button7.Enabled = false;
judge();
}
private void button8_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button8.Text = "O";
}
else
{
button8.Text = "X";
}
button8.Enabled = false;
judge();
}
private void button9_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button9.Text = "O";
}
else
{
button9.Text = "X";
}
button9.Enabled = false;
judge();
}
}
}

D0037134 發表在 痞客邦 留言(0) 人氣()

 

做出井字遊戲,判斷三連線及宣告勝利結果。

D0037134 發表在 痞客邦 留言(0) 人氣()

做出一個隨機骰子,其結果將決定Player1、Player2前進步數,順序輪流且至設定終點時跳出勝利宣告

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int ssum1 = 0;
int ssum2 = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int d1, d2,dsum;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
dsum = d1 + d2;
for (int i = 1; i <= d1 + d2; i++)
{
button2.Left = i+ssum1;
Thread.Sleep(100); //Delay 1秒
Application.DoEvents();
}
ssum1 = ssum1 + dsum;
textBox1.Text = Convert.ToString(ssum1);
if (button2.Left >= 30)
MessageBox.Show("甲贏");

}
private void button4_Click(object sender, EventArgs e)
{
int d1, d2, dsum;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
dsum = d1 + d2;
for (int i = 1; i <= d1 + d2; i++)
{
button3.Left = i + ssum2;
Thread.Sleep(100); //Delay 1秒
Application.DoEvents();
}
ssum2 = ssum2 + dsum;
textBox1.Text = Convert.ToString(ssum2);
if (button3.Left >= 30)
MessageBox.Show("乙贏");
}
}
}

D0037134 發表在 痞客邦 留言(0) 人氣()

做出一個隨機骰子,其結果將決定Player1、Player2前進步數,順序輪流且至設定終點時跳出勝利宣告

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
int d1, d2,r;
Random ran = new Random() ;
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);

label1.Text = Convert.ToString(d1);
textBox1.Text = Convert.ToString(d2);
for (int i = 1; i <= d1+d2; i++)
{

//Console.WriteLine(i);
Thread.Sleep(1000); //Delay 1秒
button1.Left = i;
Application.DoEvents();

}

if (button1.Left>=15)
MessageBox.Show("甲贏");
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
int d1, d2;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
textBox1.Text = Convert.ToString(d2);
for (int i = 1; i <= d1 + d2; i++)
{
//Console.WriteLine(i);
Thread.Sleep(1000); //Delay 1秒
button3.Left = i;
Application.DoEvents();
}
if (button3.Left >= 15)
MessageBox.Show("乙贏");
}
}
}

D0037134 發表在 痞客邦 留言(0) 人氣()

假設一button為車子,藉由按鍵觸發使其左右移動

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int c;
int d = 1;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
button1.Left = 100*c;
if(button1.Left>460)
{
d = -1;
}
if (button1.Left < 0)
{
d = 1;
}
c = c + d;
}
}
}

D0037134 發表在 痞客邦 留言(0) 人氣()

建立紅綠燈燈號轉換功能,藉由按鍵觸發開關

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int c, r;
public Form1()
{
InitializeComponent();
c = 0;
}
private void button2_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
label1.Text = "r=" + r;
if (r == 0)
{
button1.Location = new Point(0, 0);
button2.BackColor = Color.Black;
}
if (r == 1)
{
button1.Location = new Point(0, 0);
button2.BackColor = Color.Black;
}
else
{
button1.Location = new Point(100, 0);
button2.BackColor = Color.Yellow;
}
}
private void button3_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
label1.Text = "r=" + r;
if (r == 0)
{
button1.Location = new Point(0, 0);
button3.BackColor = Color.Black;
}
if (r == 1)
{
button1.Location = new Point(0, 0);
button3.BackColor = Color.Red;
}
else
{
button1.Location = new Point(100, 0);
button3.BackColor = Color.Black;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
label1.Text = "r=" + r;
if (r >= 1)
{
button3.BackColor = Color.Black;
button4.BackColor = Color.Yellow;
button5.BackColor = Color.Black;
if (r == 2)
{
button3.BackColor = Color.Red;
button4.BackColor = Color.Black;
button5.BackColor = Color.Black;
}
}
else
{
button3.BackColor = Color.Black;
button4.BackColor = Color.Black;
button5.BackColor = Color.Green;
}
}
}
}

D0037134 發表在 痞客邦 留言(0) 人氣()