首先來一下遊戲介紹:
這是主畫面
可以選擇新遊戲、繼續遊戲、功能選項、離開
這是功能表
可以選擇背景音效跟刪除遊戲紀錄
(PS.千萬別帶耳機....)
當選擇新遊戲時
就會出現前置背景故事,好像每個遊戲都要這樣搞~
現在開始才真正進入遊戲
可以選擇改變夥伴、戰鬥有兩種:故事模式跟亂鬥模式、強化卡片、抽卡片
當然還有儲存跟返回主選單
這裡可以選擇你要的卡片夥伴
這是故事模式
有1~5關
只有在故事模式中進行挑戰,勝利後才會開放後續關卡
這是戰鬥的情況
規則是:先猜拳,勝利或平手情況下才可以攻擊
再依屬性剋性分別會有不同的加成效果
按下中間有攻擊方向的按鈕就可以進行攻擊
當然只要在戰鬥後獲勝都可以獲得1枚幻幣
待會抽卡包時會很好用~
這是抽卡包的情況
每抽一次要3幻幣,賭個運氣吧
這裡是強化卡片
你可以選擇你所需要的卡片進行強化~~
PS.這部分快搞死我了......
好了,遊戲介紹完畢
再來聊聊有關我最棘手的一個功能:強化
流程:選擇卡片>鎖定卡片>強化卡片>刪除卡片
當然還是有一些小細節要注意,不然程式會出現一堆莫名其妙的問題(雖然都自己搞得......)。
首先宣告
int[] arrayS = new int[6]; //陣列S 用來存放所有選擇的卡片
int[] arrayC = new int[5]; //陣列C 用來存放強化素材
int n, button_key; //n是選取值 , button_key是用來判斷第幾個按鈕的變數
初始化(將資料載入listbox)
listBox_selectcard.Items.Add("Null");
global.addlistbox(listBox_selectcard);
listBox_selectcard.Visible = false;
返回鈕的判別
if (button_return.Text == "返回")
{
listBox_selectcard.Items.Clear();
Form2 frm = new Form2();
frm.Show();
this.Hide();
}//返回遊戲功能表
else
{
if (arrayS[button_key] != 0)
listBox_selectcard.Items[arrayS[button_key]] = "-----此卡鎖定-----";
clslistbox();
}//返回強化選單
這是要選擇強化卡片的按鈕(其他按鈕都長差不多不贅述)
button_key = 0; //非常實用的東西,可以用將listbox中所選定的值帶入陣列中
oplistbox(button_key);
清除鈕,基本上就重設listbox
resetlistbox();
clearpic();
強化鈕(整個功能這裡關鍵之一)
if (button_mixture.Text == "強化")
{
int count = 0;
for (int i = 1; i < 6; i++)
if (arrayS[i] != 0)
count++;
if (arrayS[0] != 0 && count != 0)
{
mixture();
MessageBox.Show("強化成功 !");
clearpic();
checkpartner();
}
else if(arrayS[0]==0)
MessageBox.Show("請選擇要強化的卡片 !");
else
MessageBox.Show("請選擇強化素材 !");
}//判斷是否可以強化
else
{
selectreturn(button_key);
clslistbox();
switch (button_key)
{
case 0:
if (arrayS[button_key] != 0)
global.imageload(global.PC[arrayS[button_key] - 1].C_number, pictureBox, filename......); //用了10張圖,所以filename會有10個 case情況相似不贅述
else
pictureBox1.Image = null;
break;
case 1
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
}//顯示被選定的卡片圖案
}//確定選取的卡片資料
PS.載入圖片的函式還好縮減這樣,不然我眼睛一定會花掉
listBox 紀錄選取值
int count=0; //紀錄卡片是否重複
for (int i = 0; i < 6; i++)
if (arrayS[i] == listBox_selectcard.SelectedIndex)
{
if (arrayS[i] != 0)
{
if (i == button_key)
count++;
else
count += 2; //直接可以跟arrayS[0]==0 的條件避開,省下不少麻煩
}
}
if (count < 2)
n = listBox_selectcard.SelectedIndex;
else
{
MessageBox.Show("此卡已被鎖定 !");
listBox_selectcard.SelectedIndex = 0;
}
}//判斷卡片是否重複
打開listbox(這是按選擇鈕會會執行的)
listBox_selectcard.Visible = true;
button_clear.Visible = false;
listBox_selectcard.SelectedIndex = 0;
if(arrayS[a]!=0)
listBox_selectcard.Items[arrayS[a]] = "ID: " + global.PC[arrayS[a] - 1].C_id + " 卡片no: " + global.PC[arrayS[a] - 1].C_number + " " + global.PC[arrayS[a] - 1].C_name + " " + global.PC[arrayS[a] - 1].C_attr + " ATK: " + global.PC[arrayS[a] - 1].C_atk + " ATK_Max: " + global.PC[arrayS[a] - 1].C_atkMax;
button_mixture.Text = "確認";
button_return.Text = "回強化介面";
關閉listbox(跟上面剛好是相反概念)
listBox_selectcard.Visible = false;
button_clear.Visible = true;
button_mixture.Text = "強化";
button_return.Text = "返回";
選擇時鎖定卡片
private void selectreturn(int a)
{
arrayS[a] = n;
if (arrayS[a] != 0)
listBox_selectcard.Items[arrayS[a]] = "-----此卡鎖定-----";
}
強化卡片流程
private void mixture()
{
exchangesort();
addatk();
checkatk(arrayS[0]-1);
removecard();
resetlistbox();
}//強化所經過的步驟
交換排序(這是去年暑假時寫的東西,結果把程式逐步印出來我才知道在寫啥@@)
private void exchangesort()
{
int count = 0;
for (int i = 0; i < 5; i++)
arrayC[i] = arrayS[i + 1];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
if (arrayC[j] > arrayC[j+1])
count++;
if (count == 4)
break;
else
{
count = 0;
for (int j = 1; j < 5; j++)
{
for (int k = j - 1; k >= 0; k--)
{
if (arrayC[k] < arrayC[j])
{
int tmp;
tmp = arrayC[j];
arrayC[j] = arrayC[k];
arrayC[k] = tmp;
}
else
break;
}
}
}
}
}//交換排序 大->小 為了防止待會在刪除List<T>時會發生錯誤,所以採用從後往前刪除的概念
增加攻擊力(依卡片張數做攻擊增加的基本,當滿5張同屬性則另有加成)
private void addatk()
{
string attr = global.PC[arrayS[0]-1].C_attr;
int countofcard = 0,countofsameattr=0;
for (int i = 0; i < 5; i++)
{
if (arrayC[i] != 0)
{
countofcard++;
if (global.PC[arrayC[0] - 1].C_attr == global.PC[arrayC[i] - 1].C_attr)
countofsameattr++;
}
}
if (countofcard == 5)
{
if (countofsameattr == 5)
{
if (attr == global.PC[arrayC[0] - 1].C_attr)
global.PC[arrayS[0] - 1].C_atk += countofcard + 5;
else
global.PC[arrayS[0] - 1].C_atk += countofcard + 3;
}
else
global.PC[arrayS[0] - 1].C_atk += countofcard;
}
else
global.PC[arrayS[0]-1].C_atk += countofcard;
}
檢查攻擊力是否超過
private void checkatk(int a)
{
if (global.PC[a].C_atk > global.PC[a].C_atkMax)
global.PC[a].C_atk = global.PC[a].C_atkMax;
}
刪除卡片資料(將資料從List<T>中移除)
private void removecard()
{
for (int i = 0; i < 5;i++ )
{
if(arrayC[i]!=0)
global.PC.RemoveAt(arrayC[i]-1);
}
}
重置listbox
private void resetlistbox()
{
for (int i = 0; i < 6; i++)
arrayS[i] = 0;
for (int i = 0; i < 5; i++)
arrayC[i] = 0;
listBox_selectcard.Items.Clear();
listBox_selectcard.Items.Add("Null");
global.addlistbox(listBox_selectcard);
}
清除圖片
private void clearpic()
{
pictureBox1.Image = null;
pictureBox2.Image = null;
pictureBox3.Image = null;
pictureBox4.Image = null;
pictureBox5.Image = null;
pictureBox6.Image = null;
}
檢查夥伴卡片是否存在(很重要,因為夥伴卡片被強化掉了,BUG就來了....)
private void checkpartner()
{
int check=0;
for (int i = 0; i < global.PC.Count; i++)
if (global.PC[i].C_id == global.PS[0].partnerID)
check++;
if (check == 0)
{
global.PS[0].partnerID = global.PC[0].C_id;
global.checkpartner(0);
}
else
{
int Cid=0;
Cid=global.searchid(global.PS[0].partnerID,Cid);
global.checkpartner(Cid);
global.PS[0].partnerID = global.CP[0].C_id;
}
}
已經2點半了,我該睡了,明天做最後展示
附上專案檔,晚安~~
附上專案檔,晚安~~
C#專案下載處:Brave road









