|
|
本帖最后由 迷你强 于 2015-11-18 22:32 编辑
我們遊戲是控制紅燈移動,然後可以放水球放完後,過一段時間後會在十字方像爆炸,如果周圍有水球會連環一起爆炸。
可是像影片一,玩到一半遊戲突然就會當掉,變成全黑,或是亮很奇怪的燈(像最後)。影片2我在loop裡面不斷serial.out.println(22),當遊戲當掉時卻就停掉了。想請教大家可能是什麼原因。
影片下載網址:https://drive.google.com/file/d/ ... nc/view?usp=sharing
原始碼下載網址:https://drive.google.com/file/d/ ... lU/view?usp=sharing
我後來發現可能跟我寫的ArrayList有關,原始碼很多地方我都用自己寫的ArrayList來放物件,不知道有沒有寫錯
想請大家幫忙看一下。謝謝大家
- #ifndef _ARRAYLIST_H
- #define _ARRAYLIST_H
- template <class MT>
- class ArrayList{
- private:
- int size;
- MT *array;
- public:
- ArrayList();
- void addItem(MT item);//加入物件
- void removeItem(int index);//移除物件
- MT getItem(int index);//取得arraylist中指定index的物件
- void reset();//將arraylist清空
- int getSize();//取得arraylist裡面的物件個數
- void modifyItem(int index, MT item);//將arraylist中指定index的物件用新的物件取代
- };
- template <class MT>
- ArrayList<MT>::ArrayList(){
- this->size = 0;
- this->array = new MT[10];
- }
- template <class MT>
- void ArrayList<MT>::addItem(MT item) {
- this->array[size] = item;
- size++;
- }
- template <class MT>
- void ArrayList<MT>::removeItem(int index) {
- MT *temporary = new MT[10];
- for (int i = 0; i < index; i++){
- temporary[i] = this->array[i];
- }
- for (int i = index; i < size - 1; i++){
- temporary[i] = this->array[i + 1];
- }
- this->array = temporary;
- size--;
- }
- template <class MT>
- MT ArrayList<MT>::getItem(int index){
-
- return this->array[index];
- }
- template <class MT>
- void ArrayList<MT>::reset(){
- this->array = new MT[10];
- }
- template <class MT>
- int ArrayList<MT>::getSize(){
- return this->size;
- }
- template <class MT>
- void ArrayList<MT>::modifyItem(int index, MT item){
- array[index] = item;
- }
- #endif
复制代码 |
|