Breaking News
Loading...
Wednesday, August 22, 2012

Ứng dụng lớp điểm ký tự xây dựng trò chơi bắn chữ

8/22/2012 08:52:00 PM

CDIEM.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace bt18
{
   class 
CDIEM
    
{
        private 
int x;
        private 
int y;
        public 
char c;

        public 
CDIEM()
        {
        }

        public 
CDIEM(int xxint yychar cc)
        {
            
xx;
            
yy;
            
cc;
        }

        public 
bool KiemTraX(int xx)
        {
            if (
xx <= || xx >= Console.WindowWidth)
            {
                return 
false;
            }
            return 
true;
        }
        public 
bool KiemTraY(int yy)
        {
            if (
yy <= || yy >= Console.WindowHeight)
            {
                return 
false;
            }
            return 
true;
        }

        public 
void DichPhai(int k)
        {
            
+= k;
        }
        public 
void DichTrai(int k)
        {
            
-= k;
        }
        public 
void DichLen(int k)
        {
            
-= k;
        }
        public 
void DichXuong(int k)
        {
            
+= k;
        }

        public 
void Xuat()
        {
            
Console.SetCursorPosition(xy);
            
Console.Write(c);
        }

        public 
void Xoa()
        {
            
Console.Clear();
        }

        public 
float KhoangCach(CDIEM M)
        {
            return 
0;
        }
        public 
int KhoangCachX()
        {
            return 
x;
        }
        public 
int KhoangCachY()
        {
            return 
y;
        }

    }
}  

Program.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Collections;
namespace bt18
{
    class 
Program
    
{
        static 
ArrayList list = new ArrayList();
        static 
Random rnd = new Random();
        static 
int TOCDO 700;

        static 
void Main(string[] args)
        {
            
Console.CursorVisible false;
            do
            {
                
NhanPhimBam();
                
TaoChu();
                
RoiChu();             
                
Thread.Sleep(TOCDO);
            } while (
KiemTraTiepTuc());         
        }

        static 
void RoiChu()
        {         
            
Console.Clear();
            for (
int i 0< list.Counti++)
            {
                ((
CDIEM)list[i]).DichXuong(1);
                ((
CDIEM)list[i]).Xuat();
            }
         
        }

        static 
void TaoChu()
        {
            
char c;
            
//do
            //{
            //    c = (char)(rnd.Next(65, 90));
            //} while(KiemTraChuTonTai(c));
            
= (char)(rnd.Next(6590));
            list.
Add(new CDIEM(rnd.Next(1Console.WindowWidth 1), 0c));
        }

        static 
bool KiemTraTiepTuc()
        {
            if (((
CDIEM)list[0]).KhoangCachY() > Console.WindowHeight)
                return 
false;
            return 
true;
        }

        static 
void NhanPhimBam()
        {         
            while (
Console.KeyAvailable)
            {
                
char cc Console.ReadKey(true).KeyChar;

                for (
int i 0< list.Counti++)
                {
                    if (((
CDIEM)list[i]).== cc)
                    {
                        list.
RemoveAt(i);
                    }
                }

            }            
        }
    }
}  

1 comments:

  1. Anh giai thích dùm em chỗ ((CDIEM)list[i]) là sao ?

    Code theo cách binh thuong thì như thế nào?

    ReplyDelete

 
Toggle Footer